xref: /linux-6.15/include/linux/mm_types.h (revision 4e108d4f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MM_TYPES_H
3 #define _LINUX_MM_TYPES_H
4 
5 #include <linux/mm_types_task.h>
6 
7 #include <linux/auxvec.h>
8 #include <linux/list.h>
9 #include <linux/spinlock.h>
10 #include <linux/rbtree.h>
11 #include <linux/rwsem.h>
12 #include <linux/completion.h>
13 #include <linux/cpumask.h>
14 #include <linux/uprobes.h>
15 #include <linux/page-flags-layout.h>
16 #include <linux/workqueue.h>
17 
18 #include <asm/mmu.h>
19 
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 
25 
26 struct address_space;
27 struct mem_cgroup;
28 
29 /*
30  * Each physical page in the system has a struct page associated with
31  * it to keep track of whatever it is we are using the page for at the
32  * moment. Note that we have no way to track which tasks are using
33  * a page, though if it is a pagecache page, rmap structures can tell us
34  * who is mapping it.
35  *
36  * If you allocate the page using alloc_pages(), you can use some of the
37  * space in struct page for your own purposes.  The five words in the main
38  * union are available, except for bit 0 of the first word which must be
39  * kept clear.  Many users use this word to store a pointer to an object
40  * which is guaranteed to be aligned.  If you use the same storage as
41  * page->mapping, you must restore it to NULL before freeing the page.
42  *
43  * If your page will not be mapped to userspace, you can also use the four
44  * bytes in the mapcount union, but you must call page_mapcount_reset()
45  * before freeing it.
46  *
47  * If you want to use the refcount field, it must be used in such a way
48  * that other CPUs temporarily incrementing and then decrementing the
49  * refcount does not cause problems.  On receiving the page from
50  * alloc_pages(), the refcount will be positive.
51  *
52  * If you allocate pages of order > 0, you can use some of the fields
53  * in each subpage, but you may need to restore some of their values
54  * afterwards.
55  *
56  * SLUB uses cmpxchg_double() to atomically update its freelist and
57  * counters.  That requires that freelist & counters be adjacent and
58  * double-word aligned.  We align all struct pages to double-word
59  * boundaries, and ensure that 'freelist' is aligned within the
60  * struct.
61  */
62 #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
63 #define _struct_page_alignment	__aligned(2 * sizeof(unsigned long))
64 #else
65 #define _struct_page_alignment
66 #endif
67 
68 struct page {
69 	unsigned long flags;		/* Atomic flags, some possibly
70 					 * updated asynchronously */
71 	/*
72 	 * Five words (20/40 bytes) are available in this union.
73 	 * WARNING: bit 0 of the first word is used for PageTail(). That
74 	 * means the other users of this union MUST NOT use the bit to
75 	 * avoid collision and false-positive PageTail().
76 	 */
77 	union {
78 		struct {	/* Page cache and anonymous pages */
79 			/**
80 			 * @lru: Pageout list, eg. active_list protected by
81 			 * pgdat->lru_lock.  Sometimes used as a generic list
82 			 * by the page owner.
83 			 */
84 			struct list_head lru;
85 			/* See page-flags.h for PAGE_MAPPING_FLAGS */
86 			struct address_space *mapping;
87 			pgoff_t index;		/* Our offset within mapping. */
88 			/**
89 			 * @private: Mapping-private opaque data.
90 			 * Usually used for buffer_heads if PagePrivate.
91 			 * Used for swp_entry_t if PageSwapCache.
92 			 * Indicates order in the buddy system if PageBuddy.
93 			 */
94 			unsigned long private;
95 		};
96 		struct {	/* page_pool used by netstack */
97 			/**
98 			 * @dma_addr: might require a 64-bit value even on
99 			 * 32-bit architectures.
100 			 */
101 			dma_addr_t dma_addr;
102 		};
103 		struct {	/* slab, slob and slub */
104 			union {
105 				struct list_head slab_list;
106 				struct {	/* Partial pages */
107 					struct page *next;
108 #ifdef CONFIG_64BIT
109 					int pages;	/* Nr of pages left */
110 					int pobjects;	/* Approximate count */
111 #else
112 					short int pages;
113 					short int pobjects;
114 #endif
115 				};
116 			};
117 			struct kmem_cache *slab_cache; /* not slob */
118 			/* Double-word boundary */
119 			void *freelist;		/* first free object */
120 			union {
121 				void *s_mem;	/* slab: first object */
122 				unsigned long counters;		/* SLUB */
123 				struct {			/* SLUB */
124 					unsigned inuse:16;
125 					unsigned objects:15;
126 					unsigned frozen:1;
127 				};
128 			};
129 		};
130 		struct {	/* Tail pages of compound page */
131 			unsigned long compound_head;	/* Bit zero is set */
132 
133 			/* First tail page only */
134 			unsigned char compound_dtor;
135 			unsigned char compound_order;
136 			atomic_t compound_mapcount;
137 		};
138 		struct {	/* Second tail page of compound page */
139 			unsigned long _compound_pad_1;	/* compound_head */
140 			atomic_t hpage_pinned_refcount;
141 			/* For both global and memcg */
142 			struct list_head deferred_list;
143 		};
144 		struct {	/* Page table pages */
145 			unsigned long _pt_pad_1;	/* compound_head */
146 			pgtable_t pmd_huge_pte; /* protected by page->ptl */
147 			unsigned long _pt_pad_2;	/* mapping */
148 			union {
149 				struct mm_struct *pt_mm; /* x86 pgds only */
150 				atomic_t pt_frag_refcount; /* powerpc */
151 			};
152 #if ALLOC_SPLIT_PTLOCKS
153 			spinlock_t *ptl;
154 #else
155 			spinlock_t ptl;
156 #endif
157 		};
158 		struct {	/* ZONE_DEVICE pages */
159 			/** @pgmap: Points to the hosting device page map. */
160 			struct dev_pagemap *pgmap;
161 			void *zone_device_data;
162 			/*
163 			 * ZONE_DEVICE private pages are counted as being
164 			 * mapped so the next 3 words hold the mapping, index,
165 			 * and private fields from the source anonymous or
166 			 * page cache page while the page is migrated to device
167 			 * private memory.
168 			 * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also
169 			 * use the mapping, index, and private fields when
170 			 * pmem backed DAX files are mapped.
171 			 */
172 		};
173 
174 		/** @rcu_head: You can use this to free a page by RCU. */
175 		struct rcu_head rcu_head;
176 	};
177 
178 	union {		/* This union is 4 bytes in size. */
179 		/*
180 		 * If the page can be mapped to userspace, encodes the number
181 		 * of times this page is referenced by a page table.
182 		 */
183 		atomic_t _mapcount;
184 
185 		/*
186 		 * If the page is neither PageSlab nor mappable to userspace,
187 		 * the value stored here may help determine what this page
188 		 * is used for.  See page-flags.h for a list of page types
189 		 * which are currently stored here.
190 		 */
191 		unsigned int page_type;
192 
193 		unsigned int active;		/* SLAB */
194 		int units;			/* SLOB */
195 	};
196 
197 	/* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */
198 	atomic_t _refcount;
199 
200 #ifdef CONFIG_MEMCG
201 	struct mem_cgroup *mem_cgroup;
202 #endif
203 
204 	/*
205 	 * On machines where all RAM is mapped into kernel address space,
206 	 * we can simply calculate the virtual address. On machines with
207 	 * highmem some memory is mapped into kernel virtual memory
208 	 * dynamically, so we need a place to store that address.
209 	 * Note that this field could be 16 bits on x86 ... ;)
210 	 *
211 	 * Architectures with slow multiplication can define
212 	 * WANT_PAGE_VIRTUAL in asm/page.h
213 	 */
214 #if defined(WANT_PAGE_VIRTUAL)
215 	void *virtual;			/* Kernel virtual address (NULL if
216 					   not kmapped, ie. highmem) */
217 #endif /* WANT_PAGE_VIRTUAL */
218 
219 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
220 	int _last_cpupid;
221 #endif
222 } _struct_page_alignment;
223 
224 static inline atomic_t *compound_mapcount_ptr(struct page *page)
225 {
226 	return &page[1].compound_mapcount;
227 }
228 
229 static inline atomic_t *compound_pincount_ptr(struct page *page)
230 {
231 	return &page[2].hpage_pinned_refcount;
232 }
233 
234 /*
235  * Used for sizing the vmemmap region on some architectures
236  */
237 #define STRUCT_PAGE_MAX_SHIFT	(order_base_2(sizeof(struct page)))
238 
239 #define PAGE_FRAG_CACHE_MAX_SIZE	__ALIGN_MASK(32768, ~PAGE_MASK)
240 #define PAGE_FRAG_CACHE_MAX_ORDER	get_order(PAGE_FRAG_CACHE_MAX_SIZE)
241 
242 #define page_private(page)		((page)->private)
243 
244 static inline void set_page_private(struct page *page, unsigned long private)
245 {
246 	page->private = private;
247 }
248 
249 struct page_frag_cache {
250 	void * va;
251 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
252 	__u16 offset;
253 	__u16 size;
254 #else
255 	__u32 offset;
256 #endif
257 	/* we maintain a pagecount bias, so that we dont dirty cache line
258 	 * containing page->_refcount every time we allocate a fragment.
259 	 */
260 	unsigned int		pagecnt_bias;
261 	bool pfmemalloc;
262 };
263 
264 typedef unsigned long vm_flags_t;
265 
266 /*
267  * A region containing a mapping of a non-memory backed file under NOMMU
268  * conditions.  These are held in a global tree and are pinned by the VMAs that
269  * map parts of them.
270  */
271 struct vm_region {
272 	struct rb_node	vm_rb;		/* link in global region tree */
273 	vm_flags_t	vm_flags;	/* VMA vm_flags */
274 	unsigned long	vm_start;	/* start address of region */
275 	unsigned long	vm_end;		/* region initialised to here */
276 	unsigned long	vm_top;		/* region allocated to here */
277 	unsigned long	vm_pgoff;	/* the offset in vm_file corresponding to vm_start */
278 	struct file	*vm_file;	/* the backing file or NULL */
279 
280 	int		vm_usage;	/* region usage count (access under nommu_region_sem) */
281 	bool		vm_icache_flushed : 1; /* true if the icache has been flushed for
282 						* this region */
283 };
284 
285 #ifdef CONFIG_USERFAULTFD
286 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
287 struct vm_userfaultfd_ctx {
288 	struct userfaultfd_ctx *ctx;
289 };
290 #else /* CONFIG_USERFAULTFD */
291 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
292 struct vm_userfaultfd_ctx {};
293 #endif /* CONFIG_USERFAULTFD */
294 
295 /*
296  * This struct describes a virtual memory area. There is one of these
297  * per VM-area/task. A VM area is any part of the process virtual memory
298  * space that has a special rule for the page-fault handlers (ie a shared
299  * library, the executable area etc).
300  */
301 struct vm_area_struct {
302 	/* The first cache line has the info for VMA tree walking. */
303 
304 	unsigned long vm_start;		/* Our start address within vm_mm. */
305 	unsigned long vm_end;		/* The first byte after our end address
306 					   within vm_mm. */
307 
308 	/* linked list of VM areas per task, sorted by address */
309 	struct vm_area_struct *vm_next, *vm_prev;
310 
311 	struct rb_node vm_rb;
312 
313 	/*
314 	 * Largest free memory gap in bytes to the left of this VMA.
315 	 * Either between this VMA and vma->vm_prev, or between one of the
316 	 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
317 	 * get_unmapped_area find a free area of the right size.
318 	 */
319 	unsigned long rb_subtree_gap;
320 
321 	/* Second cache line starts here. */
322 
323 	struct mm_struct *vm_mm;	/* The address space we belong to. */
324 
325 	/*
326 	 * Access permissions of this VMA.
327 	 * See vmf_insert_mixed_prot() for discussion.
328 	 */
329 	pgprot_t vm_page_prot;
330 	unsigned long vm_flags;		/* Flags, see mm.h. */
331 
332 	/*
333 	 * For areas with an address space and backing store,
334 	 * linkage into the address_space->i_mmap interval tree.
335 	 */
336 	struct {
337 		struct rb_node rb;
338 		unsigned long rb_subtree_last;
339 	} shared;
340 
341 	/*
342 	 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
343 	 * list, after a COW of one of the file pages.	A MAP_SHARED vma
344 	 * can only be in the i_mmap tree.  An anonymous MAP_PRIVATE, stack
345 	 * or brk vma (with NULL file) can only be in an anon_vma list.
346 	 */
347 	struct list_head anon_vma_chain; /* Serialized by mmap_lock &
348 					  * page_table_lock */
349 	struct anon_vma *anon_vma;	/* Serialized by page_table_lock */
350 
351 	/* Function pointers to deal with this struct. */
352 	const struct vm_operations_struct *vm_ops;
353 
354 	/* Information about our backing store: */
355 	unsigned long vm_pgoff;		/* Offset (within vm_file) in PAGE_SIZE
356 					   units */
357 	struct file * vm_file;		/* File we map to (can be NULL). */
358 	void * vm_private_data;		/* was vm_pte (shared mem) */
359 
360 #ifdef CONFIG_SWAP
361 	atomic_long_t swap_readahead_info;
362 #endif
363 #ifndef CONFIG_MMU
364 	struct vm_region *vm_region;	/* NOMMU mapping region */
365 #endif
366 #ifdef CONFIG_NUMA
367 	struct mempolicy *vm_policy;	/* NUMA policy for the VMA */
368 #endif
369 	struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
370 } __randomize_layout;
371 
372 struct core_thread {
373 	struct task_struct *task;
374 	struct core_thread *next;
375 };
376 
377 struct core_state {
378 	atomic_t nr_threads;
379 	struct core_thread dumper;
380 	struct completion startup;
381 };
382 
383 struct kioctx_table;
384 struct mm_struct {
385 	struct {
386 		struct vm_area_struct *mmap;		/* list of VMAs */
387 		struct rb_root mm_rb;
388 		u64 vmacache_seqnum;                   /* per-thread vmacache */
389 #ifdef CONFIG_MMU
390 		unsigned long (*get_unmapped_area) (struct file *filp,
391 				unsigned long addr, unsigned long len,
392 				unsigned long pgoff, unsigned long flags);
393 #endif
394 		unsigned long mmap_base;	/* base of mmap area */
395 		unsigned long mmap_legacy_base;	/* base of mmap area in bottom-up allocations */
396 #ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
397 		/* Base adresses for compatible mmap() */
398 		unsigned long mmap_compat_base;
399 		unsigned long mmap_compat_legacy_base;
400 #endif
401 		unsigned long task_size;	/* size of task vm space */
402 		unsigned long highest_vm_end;	/* highest vma end address */
403 		pgd_t * pgd;
404 
405 #ifdef CONFIG_MEMBARRIER
406 		/**
407 		 * @membarrier_state: Flags controlling membarrier behavior.
408 		 *
409 		 * This field is close to @pgd to hopefully fit in the same
410 		 * cache-line, which needs to be touched by switch_mm().
411 		 */
412 		atomic_t membarrier_state;
413 #endif
414 
415 		/**
416 		 * @mm_users: The number of users including userspace.
417 		 *
418 		 * Use mmget()/mmget_not_zero()/mmput() to modify. When this
419 		 * drops to 0 (i.e. when the task exits and there are no other
420 		 * temporary reference holders), we also release a reference on
421 		 * @mm_count (which may then free the &struct mm_struct if
422 		 * @mm_count also drops to 0).
423 		 */
424 		atomic_t mm_users;
425 
426 		/**
427 		 * @mm_count: The number of references to &struct mm_struct
428 		 * (@mm_users count as 1).
429 		 *
430 		 * Use mmgrab()/mmdrop() to modify. When this drops to 0, the
431 		 * &struct mm_struct is freed.
432 		 */
433 		atomic_t mm_count;
434 
435 #ifdef CONFIG_MMU
436 		atomic_long_t pgtables_bytes;	/* PTE page table pages */
437 #endif
438 		int map_count;			/* number of VMAs */
439 
440 		spinlock_t page_table_lock; /* Protects page tables and some
441 					     * counters
442 					     */
443 		struct rw_semaphore mmap_lock;
444 
445 		struct list_head mmlist; /* List of maybe swapped mm's.	These
446 					  * are globally strung together off
447 					  * init_mm.mmlist, and are protected
448 					  * by mmlist_lock
449 					  */
450 
451 
452 		unsigned long hiwater_rss; /* High-watermark of RSS usage */
453 		unsigned long hiwater_vm;  /* High-water virtual memory usage */
454 
455 		unsigned long total_vm;	   /* Total pages mapped */
456 		unsigned long locked_vm;   /* Pages that have PG_mlocked set */
457 		atomic64_t    pinned_vm;   /* Refcount permanently increased */
458 		unsigned long data_vm;	   /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
459 		unsigned long exec_vm;	   /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
460 		unsigned long stack_vm;	   /* VM_STACK */
461 		unsigned long def_flags;
462 
463 		spinlock_t arg_lock; /* protect the below fields */
464 		unsigned long start_code, end_code, start_data, end_data;
465 		unsigned long start_brk, brk, start_stack;
466 		unsigned long arg_start, arg_end, env_start, env_end;
467 
468 		unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
469 
470 		/*
471 		 * Special counters, in some configurations protected by the
472 		 * page_table_lock, in other configurations by being atomic.
473 		 */
474 		struct mm_rss_stat rss_stat;
475 
476 		struct linux_binfmt *binfmt;
477 
478 		/* Architecture-specific MM context */
479 		mm_context_t context;
480 
481 		unsigned long flags; /* Must use atomic bitops to access */
482 
483 		struct core_state *core_state; /* coredumping support */
484 
485 #ifdef CONFIG_AIO
486 		spinlock_t			ioctx_lock;
487 		struct kioctx_table __rcu	*ioctx_table;
488 #endif
489 #ifdef CONFIG_MEMCG
490 		/*
491 		 * "owner" points to a task that is regarded as the canonical
492 		 * user/owner of this mm. All of the following must be true in
493 		 * order for it to be changed:
494 		 *
495 		 * current == mm->owner
496 		 * current->mm != mm
497 		 * new_owner->mm == mm
498 		 * new_owner->alloc_lock is held
499 		 */
500 		struct task_struct __rcu *owner;
501 #endif
502 		struct user_namespace *user_ns;
503 
504 		/* store ref to file /proc/<pid>/exe symlink points to */
505 		struct file __rcu *exe_file;
506 #ifdef CONFIG_MMU_NOTIFIER
507 		struct mmu_notifier_subscriptions *notifier_subscriptions;
508 #endif
509 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
510 		pgtable_t pmd_huge_pte; /* protected by page_table_lock */
511 #endif
512 #ifdef CONFIG_NUMA_BALANCING
513 		/*
514 		 * numa_next_scan is the next time that the PTEs will be marked
515 		 * pte_numa. NUMA hinting faults will gather statistics and
516 		 * migrate pages to new nodes if necessary.
517 		 */
518 		unsigned long numa_next_scan;
519 
520 		/* Restart point for scanning and setting pte_numa */
521 		unsigned long numa_scan_offset;
522 
523 		/* numa_scan_seq prevents two threads setting pte_numa */
524 		int numa_scan_seq;
525 #endif
526 		/*
527 		 * An operation with batched TLB flushing is going on. Anything
528 		 * that can move process memory needs to flush the TLB when
529 		 * moving a PROT_NONE or PROT_NUMA mapped page.
530 		 */
531 		atomic_t tlb_flush_pending;
532 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
533 		/* See flush_tlb_batched_pending() */
534 		bool tlb_flush_batched;
535 #endif
536 		struct uprobes_state uprobes_state;
537 #ifdef CONFIG_HUGETLB_PAGE
538 		atomic_long_t hugetlb_usage;
539 #endif
540 		struct work_struct async_put_work;
541 	} __randomize_layout;
542 
543 	/*
544 	 * The mm_cpumask needs to be at the end of mm_struct, because it
545 	 * is dynamically sized based on nr_cpu_ids.
546 	 */
547 	unsigned long cpu_bitmap[];
548 };
549 
550 extern struct mm_struct init_mm;
551 
552 /* Pointer magic because the dynamic array size confuses some compilers. */
553 static inline void mm_init_cpumask(struct mm_struct *mm)
554 {
555 	unsigned long cpu_bitmap = (unsigned long)mm;
556 
557 	cpu_bitmap += offsetof(struct mm_struct, cpu_bitmap);
558 	cpumask_clear((struct cpumask *)cpu_bitmap);
559 }
560 
561 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
562 static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
563 {
564 	return (struct cpumask *)&mm->cpu_bitmap;
565 }
566 
567 struct mmu_gather;
568 extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,
569 				unsigned long start, unsigned long end);
570 extern void tlb_finish_mmu(struct mmu_gather *tlb,
571 				unsigned long start, unsigned long end);
572 
573 static inline void init_tlb_flush_pending(struct mm_struct *mm)
574 {
575 	atomic_set(&mm->tlb_flush_pending, 0);
576 }
577 
578 static inline void inc_tlb_flush_pending(struct mm_struct *mm)
579 {
580 	atomic_inc(&mm->tlb_flush_pending);
581 	/*
582 	 * The only time this value is relevant is when there are indeed pages
583 	 * to flush. And we'll only flush pages after changing them, which
584 	 * requires the PTL.
585 	 *
586 	 * So the ordering here is:
587 	 *
588 	 *	atomic_inc(&mm->tlb_flush_pending);
589 	 *	spin_lock(&ptl);
590 	 *	...
591 	 *	set_pte_at();
592 	 *	spin_unlock(&ptl);
593 	 *
594 	 *				spin_lock(&ptl)
595 	 *				mm_tlb_flush_pending();
596 	 *				....
597 	 *				spin_unlock(&ptl);
598 	 *
599 	 *	flush_tlb_range();
600 	 *	atomic_dec(&mm->tlb_flush_pending);
601 	 *
602 	 * Where the increment if constrained by the PTL unlock, it thus
603 	 * ensures that the increment is visible if the PTE modification is
604 	 * visible. After all, if there is no PTE modification, nobody cares
605 	 * about TLB flushes either.
606 	 *
607 	 * This very much relies on users (mm_tlb_flush_pending() and
608 	 * mm_tlb_flush_nested()) only caring about _specific_ PTEs (and
609 	 * therefore specific PTLs), because with SPLIT_PTE_PTLOCKS and RCpc
610 	 * locks (PPC) the unlock of one doesn't order against the lock of
611 	 * another PTL.
612 	 *
613 	 * The decrement is ordered by the flush_tlb_range(), such that
614 	 * mm_tlb_flush_pending() will not return false unless all flushes have
615 	 * completed.
616 	 */
617 }
618 
619 static inline void dec_tlb_flush_pending(struct mm_struct *mm)
620 {
621 	/*
622 	 * See inc_tlb_flush_pending().
623 	 *
624 	 * This cannot be smp_mb__before_atomic() because smp_mb() simply does
625 	 * not order against TLB invalidate completion, which is what we need.
626 	 *
627 	 * Therefore we must rely on tlb_flush_*() to guarantee order.
628 	 */
629 	atomic_dec(&mm->tlb_flush_pending);
630 }
631 
632 static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
633 {
634 	/*
635 	 * Must be called after having acquired the PTL; orders against that
636 	 * PTLs release and therefore ensures that if we observe the modified
637 	 * PTE we must also observe the increment from inc_tlb_flush_pending().
638 	 *
639 	 * That is, it only guarantees to return true if there is a flush
640 	 * pending for _this_ PTL.
641 	 */
642 	return atomic_read(&mm->tlb_flush_pending);
643 }
644 
645 static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
646 {
647 	/*
648 	 * Similar to mm_tlb_flush_pending(), we must have acquired the PTL
649 	 * for which there is a TLB flush pending in order to guarantee
650 	 * we've seen both that PTE modification and the increment.
651 	 *
652 	 * (no requirement on actually still holding the PTL, that is irrelevant)
653 	 */
654 	return atomic_read(&mm->tlb_flush_pending) > 1;
655 }
656 
657 struct vm_fault;
658 
659 /**
660  * typedef vm_fault_t - Return type for page fault handlers.
661  *
662  * Page fault handlers return a bitmask of %VM_FAULT values.
663  */
664 typedef __bitwise unsigned int vm_fault_t;
665 
666 /**
667  * enum vm_fault_reason - Page fault handlers return a bitmask of
668  * these values to tell the core VM what happened when handling the
669  * fault. Used to decide whether a process gets delivered SIGBUS or
670  * just gets major/minor fault counters bumped up.
671  *
672  * @VM_FAULT_OOM:		Out Of Memory
673  * @VM_FAULT_SIGBUS:		Bad access
674  * @VM_FAULT_MAJOR:		Page read from storage
675  * @VM_FAULT_WRITE:		Special case for get_user_pages
676  * @VM_FAULT_HWPOISON:		Hit poisoned small page
677  * @VM_FAULT_HWPOISON_LARGE:	Hit poisoned large page. Index encoded
678  *				in upper bits
679  * @VM_FAULT_SIGSEGV:		segmentation fault
680  * @VM_FAULT_NOPAGE:		->fault installed the pte, not return page
681  * @VM_FAULT_LOCKED:		->fault locked the returned page
682  * @VM_FAULT_RETRY:		->fault blocked, must retry
683  * @VM_FAULT_FALLBACK:		huge page fault failed, fall back to small
684  * @VM_FAULT_DONE_COW:		->fault has fully handled COW
685  * @VM_FAULT_NEEDDSYNC:		->fault did not modify page tables and needs
686  *				fsync() to complete (for synchronous page faults
687  *				in DAX)
688  * @VM_FAULT_HINDEX_MASK:	mask HINDEX value
689  *
690  */
691 enum vm_fault_reason {
692 	VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
693 	VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
694 	VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
695 	VM_FAULT_WRITE          = (__force vm_fault_t)0x000008,
696 	VM_FAULT_HWPOISON       = (__force vm_fault_t)0x000010,
697 	VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
698 	VM_FAULT_SIGSEGV        = (__force vm_fault_t)0x000040,
699 	VM_FAULT_NOPAGE         = (__force vm_fault_t)0x000100,
700 	VM_FAULT_LOCKED         = (__force vm_fault_t)0x000200,
701 	VM_FAULT_RETRY          = (__force vm_fault_t)0x000400,
702 	VM_FAULT_FALLBACK       = (__force vm_fault_t)0x000800,
703 	VM_FAULT_DONE_COW       = (__force vm_fault_t)0x001000,
704 	VM_FAULT_NEEDDSYNC      = (__force vm_fault_t)0x002000,
705 	VM_FAULT_HINDEX_MASK    = (__force vm_fault_t)0x0f0000,
706 };
707 
708 /* Encode hstate index for a hwpoisoned large page */
709 #define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
710 #define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
711 
712 #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS |	\
713 			VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON |	\
714 			VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
715 
716 #define VM_FAULT_RESULT_TRACE \
717 	{ VM_FAULT_OOM,                 "OOM" },	\
718 	{ VM_FAULT_SIGBUS,              "SIGBUS" },	\
719 	{ VM_FAULT_MAJOR,               "MAJOR" },	\
720 	{ VM_FAULT_WRITE,               "WRITE" },	\
721 	{ VM_FAULT_HWPOISON,            "HWPOISON" },	\
722 	{ VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" },	\
723 	{ VM_FAULT_SIGSEGV,             "SIGSEGV" },	\
724 	{ VM_FAULT_NOPAGE,              "NOPAGE" },	\
725 	{ VM_FAULT_LOCKED,              "LOCKED" },	\
726 	{ VM_FAULT_RETRY,               "RETRY" },	\
727 	{ VM_FAULT_FALLBACK,            "FALLBACK" },	\
728 	{ VM_FAULT_DONE_COW,            "DONE_COW" },	\
729 	{ VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
730 
731 struct vm_special_mapping {
732 	const char *name;	/* The name, e.g. "[vdso]". */
733 
734 	/*
735 	 * If .fault is not provided, this points to a
736 	 * NULL-terminated array of pages that back the special mapping.
737 	 *
738 	 * This must not be NULL unless .fault is provided.
739 	 */
740 	struct page **pages;
741 
742 	/*
743 	 * If non-NULL, then this is called to resolve page faults
744 	 * on the special mapping.  If used, .pages is not checked.
745 	 */
746 	vm_fault_t (*fault)(const struct vm_special_mapping *sm,
747 				struct vm_area_struct *vma,
748 				struct vm_fault *vmf);
749 
750 	int (*mremap)(const struct vm_special_mapping *sm,
751 		     struct vm_area_struct *new_vma);
752 };
753 
754 enum tlb_flush_reason {
755 	TLB_FLUSH_ON_TASK_SWITCH,
756 	TLB_REMOTE_SHOOTDOWN,
757 	TLB_LOCAL_SHOOTDOWN,
758 	TLB_LOCAL_MM_SHOOTDOWN,
759 	TLB_REMOTE_SEND_IPI,
760 	NR_TLB_FLUSH_REASONS,
761 };
762 
763  /*
764   * A swap entry has to fit into a "unsigned long", as the entry is hidden
765   * in the "index" field of the swapper address space.
766   */
767 typedef struct {
768 	unsigned long val;
769 } swp_entry_t;
770 
771 #endif /* _LINUX_MM_TYPES_H */
772