s390: use _refcount for pgtables
[linux-block.git] / include / linux / mm_types.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
5b99cd0e
HC
2#ifndef _LINUX_MM_TYPES_H
3#define _LINUX_MM_TYPES_H
4
2e58f173
IM
5#include <linux/mm_types_task.h>
6
4f9a58d7 7#include <linux/auxvec.h>
5b99cd0e
HC
8#include <linux/list.h>
9#include <linux/spinlock.h>
c92ff1bd
MS
10#include <linux/rbtree.h>
11#include <linux/rwsem.h>
12#include <linux/completion.h>
cddb8a5c 13#include <linux/cpumask.h>
d4b3b638 14#include <linux/uprobes.h>
bbeae5b0 15#include <linux/page-flags-layout.h>
ec8d7c14 16#include <linux/workqueue.h>
2e58f173 17
c92ff1bd 18#include <asm/mmu.h>
5b99cd0e 19
4f9a58d7
OH
20#ifndef AT_VECTOR_SIZE_ARCH
21#define AT_VECTOR_SIZE_ARCH 0
22#endif
23#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
24
1c8f4220
SJ
25typedef int vm_fault_t;
26
5b99cd0e 27struct address_space;
1306a85a 28struct mem_cgroup;
133ff0ea 29struct hmm;
5b99cd0e
HC
30
31/*
32 * Each physical page in the system has a struct page associated with
33 * it to keep track of whatever it is we are using the page for at the
34 * moment. Note that we have no way to track which tasks are using
35 * a page, though if it is a pagecache page, rmap structures can tell us
be50015d
MW
36 * who is mapping it. If you allocate the page using alloc_pages(), you
37 * can use some of the space in struct page for your own purposes.
38 *
39 * Pages that were once in the page cache may be found under the RCU lock
40 * even after they have been recycled to a different purpose. The page
41 * cache reads and writes some of the fields in struct page to pin the
42 * page before checking that it's still in the page cache. It is vital
43 * that all users of struct page:
44 * 1. Use the first word as PageFlags.
45 * 2. Clear or preserve bit 0 of page->compound_head. It is used as
46 * PageTail for compound pages, and the page cache must not see false
47 * positives. Some users put a pointer here (guaranteed to be at least
48 * 4-byte aligned), other users avoid using the field altogether.
49 * 3. page->_refcount must either not be used, or must be used in such a
50 * way that other CPUs temporarily incrementing and then decrementing the
51 * refcount does not cause problems. On receiving the page from
52 * alloc_pages(), the refcount will be positive.
53 * 4. Either preserve page->_mapcount or restore it to -1 before freeing it.
54 *
55 * If you allocate pages of order > 0, you can use the fields in the struct
56 * page associated with each page, but bear in mind that the pages may have
57 * been inserted individually into the page cache, so you must use the above
58 * four fields in a compatible way for each struct page.
fc9bb8c7 59 *
4cf7c8bf
MW
60 * SLUB uses cmpxchg_double() to atomically update its freelist and
61 * counters. That requires that freelist & counters be adjacent and
62 * double-word aligned. We align all struct pages to double-word
63 * boundaries, and ensure that 'freelist' is aligned within the
64 * struct.
5b99cd0e 65 */
e20df2c6
MW
66#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
67#define _struct_page_alignment __aligned(2 * sizeof(unsigned long))
0dd4da5b
MW
68#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE)
69#define _slub_counter_t unsigned long
e20df2c6 70#else
0dd4da5b 71#define _slub_counter_t unsigned int
e20df2c6 72#endif
0dd4da5b
MW
73#else /* !CONFIG_HAVE_ALIGNED_STRUCT_PAGE */
74#define _struct_page_alignment
75#define _slub_counter_t unsigned int
76#endif /* !CONFIG_HAVE_ALIGNED_STRUCT_PAGE */
e20df2c6 77
5b99cd0e 78struct page {
fc9bb8c7 79 /* First double word block */
5b99cd0e
HC
80 unsigned long flags; /* Atomic flags, some possibly
81 * updated asynchronously */
8456a648 82 union {
b26435a0
MW
83 /* See page-flags.h for the definition of PAGE_MAPPING_FLAGS */
84 struct address_space *mapping;
85
8456a648 86 void *s_mem; /* slab first object */
53f9263b 87 atomic_t compound_mapcount; /* first tail page */
9a982250 88 /* page_deferred_list().next -- second tail page */
8456a648
JK
89 };
90
fc9bb8c7 91 /* Second double word */
99691add
VD
92 union {
93 pgoff_t index; /* Our offset within mapping. */
94 void *freelist; /* sl[aou]b first free object */
95 /* page_deferred_list().prev -- second tail page */
96 };
013e8963 97
99691add 98 union {
0dd4da5b 99 _slub_counter_t counters;
ca9c88c7
MW
100 unsigned int active; /* SLAB */
101 struct { /* SLUB */
102 unsigned inuse:16;
103 unsigned objects:15;
104 unsigned frozen:1;
105 };
106 int units; /* SLOB */
013e8963 107
ca9c88c7
MW
108 struct { /* Page cache */
109 /*
110 * Count of ptes mapped in mms, to show when
111 * page is mapped & limit reverse map searches.
112 *
113 * Extra information about page type may be
114 * stored here for pages that are never mapped,
115 * in which case the value MUST BE <= -2.
116 * See page-flags.h for more details.
117 */
118 atomic_t _mapcount;
99691add 119
99691add
VD
120 /*
121 * Usage count, *USE WRAPPER FUNCTION* when manual
122 * accounting. See page_ref.h
123 */
124 atomic_t _refcount;
39b26464 125 };
81819f0f 126 };
fc9bb8c7 127
1d798ca3 128 /*
1d798ca3
KS
129 * WARNING: bit 0 of the first word encode PageTail(). That means
130 * the rest users of the storage space MUST NOT use the bit to
131 * avoid collision and false-positive PageTail().
132 */
49e22585
CL
133 union {
134 struct list_head lru; /* Pageout list, eg. active_list
a52633d8 135 * protected by zone_lru_lock !
34bf6ef9
DH
136 * Can be used as a generic list
137 * by the page owner.
fc9bb8c7 138 */
5c2c2587
DW
139 struct dev_pagemap *pgmap; /* ZONE_DEVICE pages are never on an
140 * lru or handled by a slab
141 * allocator, this points to the
142 * hosting device page map.
143 */
49e22585
CL
144 struct { /* slub per cpu partial pages */
145 struct page *next; /* Next partial slab */
146#ifdef CONFIG_64BIT
147 int pages; /* Nr of partial slabs left */
148 int pobjects; /* Approximate # of objects */
149#else
150 short int pages;
151 short int pobjects;
152#endif
153 };
b8c24c4a 154
68126702
JK
155 struct rcu_head rcu_head; /* Used by SLAB
156 * when destroying via RCU
157 */
1d798ca3 158 /* Tail pages of compound page */
e4b294c2 159 struct {
1d798ca3
KS
160 unsigned long compound_head; /* If bit zero is set */
161
162 /* First tail page only */
036e7aa4
MW
163 unsigned char compound_dtor;
164 unsigned char compound_order;
165 /* two/six bytes available here */
e4b294c2
KS
166 };
167
7aa555bf 168#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
1d798ca3
KS
169 struct {
170 unsigned long __pad; /* do not overlay pmd_huge_pte
171 * with compound_head to avoid
172 * possible bit 0 collision.
173 */
174 pgtable_t pmd_huge_pte; /* protected by page->ptl */
175 };
7aa555bf 176#endif
49e22585 177 };
fc9bb8c7 178
5b99cd0e 179 union {
ab8928b7
MW
180 /*
181 * Mapping-private opaque data:
182 * Usually used for buffer_heads if PagePrivate
183 * Used for swp_entry_t if PageSwapCache
184 * Indicates order in the buddy system if PageBuddy
185 */
186 unsigned long private;
57c1ffce 187#if USE_SPLIT_PTE_PTLOCKS
597d795a 188#if ALLOC_SPLIT_PTLOCKS
539edb58
PZ
189 spinlock_t *ptl;
190#else
191 spinlock_t ptl;
192#endif
5b99cd0e 193#endif
1b4f59e3 194 struct kmem_cache *slab_cache; /* SL[AU]B: Pointer to slab */
81819f0f 195 };
fc9bb8c7 196
1306a85a
JW
197#ifdef CONFIG_MEMCG
198 struct mem_cgroup *mem_cgroup;
199#endif
200
5b99cd0e
HC
201 /*
202 * On machines where all RAM is mapped into kernel address space,
203 * we can simply calculate the virtual address. On machines with
204 * highmem some memory is mapped into kernel virtual memory
205 * dynamically, so we need a place to store that address.
206 * Note that this field could be 16 bits on x86 ... ;)
207 *
208 * Architectures with slow multiplication can define
209 * WANT_PAGE_VIRTUAL in asm/page.h
210 */
211#if defined(WANT_PAGE_VIRTUAL)
212 void *virtual; /* Kernel virtual address (NULL if
213 not kmapped, ie. highmem) */
214#endif /* WANT_PAGE_VIRTUAL */
dfec072e 215
90572890
PZ
216#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
217 int _last_cpupid;
57e0a030 218#endif
e20df2c6 219} _struct_page_alignment;
5b99cd0e 220
b63ae8ca
AD
221#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
222#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
223
224struct page_frag_cache {
225 void * va;
226#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
227 __u16 offset;
228 __u16 size;
229#else
230 __u32 offset;
231#endif
232 /* we maintain a pagecount bias, so that we dont dirty cache line
0139aa7b 233 * containing page->_refcount every time we allocate a fragment.
b63ae8ca
AD
234 */
235 unsigned int pagecnt_bias;
236 bool pfmemalloc;
237};
238
64b990d2 239typedef unsigned long vm_flags_t;
ca16d140 240
8feae131
DH
241/*
242 * A region containing a mapping of a non-memory backed file under NOMMU
243 * conditions. These are held in a global tree and are pinned by the VMAs that
244 * map parts of them.
245 */
246struct vm_region {
247 struct rb_node vm_rb; /* link in global region tree */
ca16d140 248 vm_flags_t vm_flags; /* VMA vm_flags */
8feae131
DH
249 unsigned long vm_start; /* start address of region */
250 unsigned long vm_end; /* region initialised to here */
dd8632a1 251 unsigned long vm_top; /* region allocated to here */
8feae131
DH
252 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
253 struct file *vm_file; /* the backing file or NULL */
254
1e2ae599 255 int vm_usage; /* region usage count (access under nommu_region_sem) */
cfe79c00
MF
256 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
257 * this region */
8feae131
DH
258};
259
745f234b
AA
260#ifdef CONFIG_USERFAULTFD
261#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
262struct vm_userfaultfd_ctx {
263 struct userfaultfd_ctx *ctx;
264};
265#else /* CONFIG_USERFAULTFD */
266#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
267struct vm_userfaultfd_ctx {};
268#endif /* CONFIG_USERFAULTFD */
269
c92ff1bd
MS
270/*
271 * This struct defines a memory VMM memory area. There is one of these
272 * per VM-area/task. A VM area is any part of the process virtual memory
273 * space that has a special rule for the page-fault handlers (ie a shared
274 * library, the executable area etc).
275 */
276struct vm_area_struct {
e4c6bfd2
RR
277 /* The first cache line has the info for VMA tree walking. */
278
c92ff1bd
MS
279 unsigned long vm_start; /* Our start address within vm_mm. */
280 unsigned long vm_end; /* The first byte after our end address
281 within vm_mm. */
282
283 /* linked list of VM areas per task, sorted by address */
297c5eee 284 struct vm_area_struct *vm_next, *vm_prev;
c92ff1bd 285
c92ff1bd
MS
286 struct rb_node vm_rb;
287
d3737187
ML
288 /*
289 * Largest free memory gap in bytes to the left of this VMA.
290 * Either between this VMA and vma->vm_prev, or between one of the
291 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
292 * get_unmapped_area find a free area of the right size.
293 */
294 unsigned long rb_subtree_gap;
295
e4c6bfd2
RR
296 /* Second cache line starts here. */
297
298 struct mm_struct *vm_mm; /* The address space we belong to. */
299 pgprot_t vm_page_prot; /* Access permissions of this VMA. */
300 unsigned long vm_flags; /* Flags, see mm.h. */
301
c92ff1bd
MS
302 /*
303 * For areas with an address space and backing store,
27ba0644 304 * linkage into the address_space->i_mmap interval tree.
c92ff1bd 305 */
ac51b934
KS
306 struct {
307 struct rb_node rb;
308 unsigned long rb_subtree_last;
c92ff1bd
MS
309 } shared;
310
311 /*
312 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
313 * list, after a COW of one of the file pages. A MAP_SHARED vma
314 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
315 * or brk vma (with NULL file) can only be in an anon_vma list.
316 */
5beb4930
RR
317 struct list_head anon_vma_chain; /* Serialized by mmap_sem &
318 * page_table_lock */
c92ff1bd
MS
319 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
320
321 /* Function pointers to deal with this struct. */
f0f37e2f 322 const struct vm_operations_struct *vm_ops;
c92ff1bd
MS
323
324 /* Information about our backing store: */
325 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
ea1754a0 326 units */
c92ff1bd
MS
327 struct file * vm_file; /* File we map to (can be NULL). */
328 void * vm_private_data; /* was vm_pte (shared mem) */
c92ff1bd 329
ec560175 330 atomic_long_t swap_readahead_info;
c92ff1bd 331#ifndef CONFIG_MMU
8feae131 332 struct vm_region *vm_region; /* NOMMU mapping region */
c92ff1bd
MS
333#endif
334#ifdef CONFIG_NUMA
335 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
336#endif
745f234b 337 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
3859a271 338} __randomize_layout;
c92ff1bd 339
b564daf8
ON
340struct core_thread {
341 struct task_struct *task;
342 struct core_thread *next;
343};
344
32ecb1f2 345struct core_state {
c5f1cc8c 346 atomic_t nr_threads;
b564daf8 347 struct core_thread dumper;
32ecb1f2
ON
348 struct completion startup;
349};
350
db446a08 351struct kioctx_table;
c92ff1bd 352struct mm_struct {
615d6e87 353 struct vm_area_struct *mmap; /* list of VMAs */
c92ff1bd 354 struct rb_root mm_rb;
615d6e87 355 u32 vmacache_seqnum; /* per-thread vmacache */
efc1a3b1 356#ifdef CONFIG_MMU
c92ff1bd
MS
357 unsigned long (*get_unmapped_area) (struct file *filp,
358 unsigned long addr, unsigned long len,
359 unsigned long pgoff, unsigned long flags);
efc1a3b1 360#endif
c92ff1bd 361 unsigned long mmap_base; /* base of mmap area */
41aacc1e 362 unsigned long mmap_legacy_base; /* base of mmap area in bottom-up allocations */
1b028f78
DS
363#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
364 /* Base adresses for compatible mmap() */
365 unsigned long mmap_compat_base;
366 unsigned long mmap_compat_legacy_base;
367#endif
c92ff1bd 368 unsigned long task_size; /* size of task vm space */
d3737187 369 unsigned long highest_vm_end; /* highest vma end address */
c92ff1bd 370 pgd_t * pgd;
b279ddc3
VN
371
372 /**
373 * @mm_users: The number of users including userspace.
374 *
375 * Use mmget()/mmget_not_zero()/mmput() to modify. When this drops
376 * to 0 (i.e. when the task exits and there are no other temporary
377 * reference holders), we also release a reference on @mm_count
378 * (which may then free the &struct mm_struct if @mm_count also
379 * drops to 0).
380 */
381 atomic_t mm_users;
382
383 /**
384 * @mm_count: The number of references to &struct mm_struct
385 * (@mm_users count as 1).
386 *
387 * Use mmgrab()/mmdrop() to modify. When this drops to 0, the
388 * &struct mm_struct is freed.
389 */
390 atomic_t mm_count;
391
c4812909 392#ifdef CONFIG_MMU
af5b0f6a 393 atomic_long_t pgtables_bytes; /* PTE page table pages */
5a3fbef3 394#endif
c92ff1bd 395 int map_count; /* number of VMAs */
481b4bb5 396
c92ff1bd 397 spinlock_t page_table_lock; /* Protects page tables and some counters */
481b4bb5 398 struct rw_semaphore mmap_sem;
c92ff1bd
MS
399
400 struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
401 * together off init_mm.mmlist, and are protected
402 * by mmlist_lock
403 */
404
c92ff1bd
MS
405
406 unsigned long hiwater_rss; /* High-watermark of RSS usage */
407 unsigned long hiwater_vm; /* High-water virtual memory usage */
408
e10d59f2
CL
409 unsigned long total_vm; /* Total pages mapped */
410 unsigned long locked_vm; /* Pages that have PG_mlocked set */
411 unsigned long pinned_vm; /* Refcount permanently increased */
30bdbb78
KK
412 unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
413 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
414 unsigned long stack_vm; /* VM_STACK */
e10d59f2 415 unsigned long def_flags;
88aa7cc6
YS
416
417 spinlock_t arg_lock; /* protect the below fields */
c92ff1bd
MS
418 unsigned long start_code, end_code, start_data, end_data;
419 unsigned long start_brk, brk, start_stack;
420 unsigned long arg_start, arg_end, env_start, env_end;
421
422 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
423
d559db08
KH
424 /*
425 * Special counters, in some configurations protected by the
426 * page_table_lock, in other configurations by being atomic.
427 */
428 struct mm_rss_stat rss_stat;
429
801460d0
HS
430 struct linux_binfmt *binfmt;
431
6345d24d
LT
432 cpumask_var_t cpu_vm_mask_var;
433
c92ff1bd
MS
434 /* Architecture-specific MM context */
435 mm_context_t context;
436
c92ff1bd
MS
437 unsigned long flags; /* Must use atomic bitops to access the bits */
438
a94e2d40 439 struct core_state *core_state; /* coredumping support */
a961e409
MD
440#ifdef CONFIG_MEMBARRIER
441 atomic_t membarrier_state;
442#endif
858f0993 443#ifdef CONFIG_AIO
db446a08
BL
444 spinlock_t ioctx_lock;
445 struct kioctx_table __rcu *ioctx_table;
858f0993 446#endif
f98bafa0 447#ifdef CONFIG_MEMCG
4cd1a8fc
KM
448 /*
449 * "owner" points to a task that is regarded as the canonical
450 * user/owner of this mm. All of the following must be true in
451 * order for it to be changed:
452 *
453 * current == mm->owner
454 * current->mm != mm
455 * new_owner->mm == mm
456 * new_owner->alloc_lock is held
457 */
4d2deb40 458 struct task_struct __rcu *owner;
78fb7466 459#endif
bfedb589 460 struct user_namespace *user_ns;
925d1c40 461
925d1c40 462 /* store ref to file /proc/<pid>/exe symlink points to */
90f31d0e 463 struct file __rcu *exe_file;
cddb8a5c
AA
464#ifdef CONFIG_MMU_NOTIFIER
465 struct mmu_notifier_mm *mmu_notifier_mm;
e7a00c45 466#endif
e009bb30 467#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
e7a00c45 468 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
cddb8a5c 469#endif
6345d24d
LT
470#ifdef CONFIG_CPUMASK_OFFSTACK
471 struct cpumask cpumask_allocation;
cbee9f88
PZ
472#endif
473#ifdef CONFIG_NUMA_BALANCING
474 /*
34f0315a
MG
475 * numa_next_scan is the next time that the PTEs will be marked
476 * pte_numa. NUMA hinting faults will gather statistics and migrate
477 * pages to new nodes if necessary.
cbee9f88
PZ
478 */
479 unsigned long numa_next_scan;
480
6e5fb223
PZ
481 /* Restart point for scanning and setting pte_numa */
482 unsigned long numa_scan_offset;
483
cbee9f88
PZ
484 /* numa_scan_seq prevents two threads setting pte_numa */
485 int numa_scan_seq;
20841405 486#endif
20841405
RR
487 /*
488 * An operation with batched TLB flushing is going on. Anything that
489 * can move process memory needs to flush the TLB when moving a
490 * PROT_NONE or PROT_NUMA mapped page.
491 */
16af97dc 492 atomic_t tlb_flush_pending;
3ea27719
MG
493#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
494 /* See flush_tlb_batched_pending() */
495 bool tlb_flush_batched;
6345d24d 496#endif
d4b3b638 497 struct uprobes_state uprobes_state;
5d317b2b
NH
498#ifdef CONFIG_HUGETLB_PAGE
499 atomic_long_t hugetlb_usage;
500#endif
ec8d7c14 501 struct work_struct async_put_work;
133ff0ea
JG
502
503#if IS_ENABLED(CONFIG_HMM)
504 /* HMM needs to track a few things per mm */
505 struct hmm *hmm;
506#endif
3859a271 507} __randomize_layout;
c92ff1bd 508
abe722a1
IM
509extern struct mm_struct init_mm;
510
6345d24d
LT
511static inline void mm_init_cpumask(struct mm_struct *mm)
512{
513#ifdef CONFIG_CPUMASK_OFFSTACK
514 mm->cpu_vm_mask_var = &mm->cpumask_allocation;
515#endif
41f727fd 516 cpumask_clear(mm->cpu_vm_mask_var);
6345d24d
LT
517}
518
45e575ab 519/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
de03c72c
KM
520static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
521{
522 return mm->cpu_vm_mask_var;
523}
45e575ab 524
56236a59
MK
525struct mmu_gather;
526extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,
527 unsigned long start, unsigned long end);
528extern void tlb_finish_mmu(struct mmu_gather *tlb,
529 unsigned long start, unsigned long end);
530
16af97dc 531static inline void init_tlb_flush_pending(struct mm_struct *mm)
20841405 532{
16af97dc 533 atomic_set(&mm->tlb_flush_pending, 0);
20841405 534}
16af97dc
NA
535
536static inline void inc_tlb_flush_pending(struct mm_struct *mm)
20841405 537{
16af97dc 538 atomic_inc(&mm->tlb_flush_pending);
af2c1401 539 /*
8b1b436d
PZ
540 * The only time this value is relevant is when there are indeed pages
541 * to flush. And we'll only flush pages after changing them, which
542 * requires the PTL.
543 *
544 * So the ordering here is:
545 *
040cca3a 546 * atomic_inc(&mm->tlb_flush_pending);
8b1b436d
PZ
547 * spin_lock(&ptl);
548 * ...
549 * set_pte_at();
550 * spin_unlock(&ptl);
551 *
552 * spin_lock(&ptl)
553 * mm_tlb_flush_pending();
554 * ....
555 * spin_unlock(&ptl);
556 *
557 * flush_tlb_range();
040cca3a 558 * atomic_dec(&mm->tlb_flush_pending);
8b1b436d 559 *
0e709703
PZ
560 * Where the increment if constrained by the PTL unlock, it thus
561 * ensures that the increment is visible if the PTE modification is
562 * visible. After all, if there is no PTE modification, nobody cares
563 * about TLB flushes either.
564 *
565 * This very much relies on users (mm_tlb_flush_pending() and
566 * mm_tlb_flush_nested()) only caring about _specific_ PTEs (and
567 * therefore specific PTLs), because with SPLIT_PTE_PTLOCKS and RCpc
568 * locks (PPC) the unlock of one doesn't order against the lock of
569 * another PTL.
570 *
571 * The decrement is ordered by the flush_tlb_range(), such that
572 * mm_tlb_flush_pending() will not return false unless all flushes have
573 * completed.
af2c1401 574 */
20841405 575}
16af97dc 576
16af97dc 577static inline void dec_tlb_flush_pending(struct mm_struct *mm)
20841405 578{
0a2c4048 579 /*
0e709703
PZ
580 * See inc_tlb_flush_pending().
581 *
582 * This cannot be smp_mb__before_atomic() because smp_mb() simply does
583 * not order against TLB invalidate completion, which is what we need.
584 *
585 * Therefore we must rely on tlb_flush_*() to guarantee order.
0a2c4048 586 */
16af97dc 587 atomic_dec(&mm->tlb_flush_pending);
20841405 588}
20841405 589
0e709703
PZ
590static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
591{
592 /*
593 * Must be called after having acquired the PTL; orders against that
594 * PTLs release and therefore ensures that if we observe the modified
595 * PTE we must also observe the increment from inc_tlb_flush_pending().
596 *
597 * That is, it only guarantees to return true if there is a flush
598 * pending for _this_ PTL.
599 */
600 return atomic_read(&mm->tlb_flush_pending);
601}
602
603static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
604{
605 /*
606 * Similar to mm_tlb_flush_pending(), we must have acquired the PTL
607 * for which there is a TLB flush pending in order to guarantee
608 * we've seen both that PTE modification and the increment.
609 *
610 * (no requirement on actually still holding the PTL, that is irrelevant)
611 */
612 return atomic_read(&mm->tlb_flush_pending) > 1;
613}
614
f872f540
AL
615struct vm_fault;
616
617struct vm_special_mapping {
618 const char *name; /* The name, e.g. "[vdso]". */
619
620 /*
621 * If .fault is not provided, this points to a
622 * NULL-terminated array of pages that back the special mapping.
623 *
624 * This must not be NULL unless .fault is provided.
625 */
a62c34bd 626 struct page **pages;
f872f540
AL
627
628 /*
629 * If non-NULL, then this is called to resolve page faults
630 * on the special mapping. If used, .pages is not checked.
631 */
b3ec9f33
SJ
632 vm_fault_t (*fault)(const struct vm_special_mapping *sm,
633 struct vm_area_struct *vma,
634 struct vm_fault *vmf);
b059a453
DS
635
636 int (*mremap)(const struct vm_special_mapping *sm,
637 struct vm_area_struct *new_vma);
a62c34bd
AL
638};
639
d17d8f9d
DH
640enum tlb_flush_reason {
641 TLB_FLUSH_ON_TASK_SWITCH,
642 TLB_REMOTE_SHOOTDOWN,
643 TLB_LOCAL_SHOOTDOWN,
644 TLB_LOCAL_MM_SHOOTDOWN,
5b74283a 645 TLB_REMOTE_SEND_IPI,
d17d8f9d
DH
646 NR_TLB_FLUSH_REASONS,
647};
648
bd6dace7
TH
649 /*
650 * A swap entry has to fit into a "unsigned long", as the entry is hidden
651 * in the "index" field of the swapper address space.
652 */
653typedef struct {
654 unsigned long val;
655} swp_entry_t;
656
5b99cd0e 657#endif /* _LINUX_MM_TYPES_H */