xref: /linux-6.15/include/linux/mm_types.h (revision 43b3dfdd)
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/kref.h>
9 #include <linux/list.h>
10 #include <linux/spinlock.h>
11 #include <linux/rbtree.h>
12 #include <linux/maple_tree.h>
13 #include <linux/rwsem.h>
14 #include <linux/completion.h>
15 #include <linux/cpumask.h>
16 #include <linux/uprobes.h>
17 #include <linux/rcupdate.h>
18 #include <linux/page-flags-layout.h>
19 #include <linux/workqueue.h>
20 #include <linux/seqlock.h>
21 #include <linux/percpu_counter.h>
22 
23 #include <asm/mmu.h>
24 
25 #ifndef AT_VECTOR_SIZE_ARCH
26 #define AT_VECTOR_SIZE_ARCH 0
27 #endif
28 #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
29 
30 #define INIT_PASID	0
31 
32 struct address_space;
33 struct mem_cgroup;
34 
35 /*
36  * Each physical page in the system has a struct page associated with
37  * it to keep track of whatever it is we are using the page for at the
38  * moment. Note that we have no way to track which tasks are using
39  * a page, though if it is a pagecache page, rmap structures can tell us
40  * who is mapping it.
41  *
42  * If you allocate the page using alloc_pages(), you can use some of the
43  * space in struct page for your own purposes.  The five words in the main
44  * union are available, except for bit 0 of the first word which must be
45  * kept clear.  Many users use this word to store a pointer to an object
46  * which is guaranteed to be aligned.  If you use the same storage as
47  * page->mapping, you must restore it to NULL before freeing the page.
48  *
49  * If your page will not be mapped to userspace, you can also use the four
50  * bytes in the mapcount union, but you must call page_mapcount_reset()
51  * before freeing it.
52  *
53  * If you want to use the refcount field, it must be used in such a way
54  * that other CPUs temporarily incrementing and then decrementing the
55  * refcount does not cause problems.  On receiving the page from
56  * alloc_pages(), the refcount will be positive.
57  *
58  * If you allocate pages of order > 0, you can use some of the fields
59  * in each subpage, but you may need to restore some of their values
60  * afterwards.
61  *
62  * SLUB uses cmpxchg_double() to atomically update its freelist and counters.
63  * That requires that freelist & counters in struct slab be adjacent and
64  * double-word aligned. Because struct slab currently just reinterprets the
65  * bits of struct page, we align all struct pages to double-word boundaries,
66  * and ensure that 'freelist' is aligned within struct slab.
67  */
68 #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
69 #define _struct_page_alignment	__aligned(2 * sizeof(unsigned long))
70 #else
71 #define _struct_page_alignment	__aligned(sizeof(unsigned long))
72 #endif
73 
74 struct page {
75 	unsigned long flags;		/* Atomic flags, some possibly
76 					 * updated asynchronously */
77 	/*
78 	 * Five words (20/40 bytes) are available in this union.
79 	 * WARNING: bit 0 of the first word is used for PageTail(). That
80 	 * means the other users of this union MUST NOT use the bit to
81 	 * avoid collision and false-positive PageTail().
82 	 */
83 	union {
84 		struct {	/* Page cache and anonymous pages */
85 			/**
86 			 * @lru: Pageout list, eg. active_list protected by
87 			 * lruvec->lru_lock.  Sometimes used as a generic list
88 			 * by the page owner.
89 			 */
90 			union {
91 				struct list_head lru;
92 
93 				/* Or, for the Unevictable "LRU list" slot */
94 				struct {
95 					/* Always even, to negate PageTail */
96 					void *__filler;
97 					/* Count page's or folio's mlocks */
98 					unsigned int mlock_count;
99 				};
100 
101 				/* Or, free page */
102 				struct list_head buddy_list;
103 				struct list_head pcp_list;
104 			};
105 			/* See page-flags.h for PAGE_MAPPING_FLAGS */
106 			struct address_space *mapping;
107 			union {
108 				pgoff_t index;		/* Our offset within mapping. */
109 				unsigned long share;	/* share count for fsdax */
110 			};
111 			/**
112 			 * @private: Mapping-private opaque data.
113 			 * Usually used for buffer_heads if PagePrivate.
114 			 * Used for swp_entry_t if PageSwapCache.
115 			 * Indicates order in the buddy system if PageBuddy.
116 			 */
117 			unsigned long private;
118 		};
119 		struct {	/* page_pool used by netstack */
120 			/**
121 			 * @pp_magic: magic value to avoid recycling non
122 			 * page_pool allocated pages.
123 			 */
124 			unsigned long pp_magic;
125 			struct page_pool *pp;
126 			unsigned long _pp_mapping_pad;
127 			unsigned long dma_addr;
128 			union {
129 				/**
130 				 * dma_addr_upper: might require a 64-bit
131 				 * value on 32-bit architectures.
132 				 */
133 				unsigned long dma_addr_upper;
134 				/**
135 				 * For frag page support, not supported in
136 				 * 32-bit architectures with 64-bit DMA.
137 				 */
138 				atomic_long_t pp_frag_count;
139 			};
140 		};
141 		struct {	/* Tail pages of compound page */
142 			unsigned long compound_head;	/* Bit zero is set */
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 			/*
148 			 * A PTE page table page might be freed by use of
149 			 * rcu_head: which overlays those two fields above.
150 			 */
151 			unsigned long _pt_pad_2;	/* mapping */
152 			union {
153 				struct mm_struct *pt_mm; /* x86 pgds only */
154 				atomic_t pt_frag_refcount; /* powerpc */
155 			};
156 #if ALLOC_SPLIT_PTLOCKS
157 			spinlock_t *ptl;
158 #else
159 			spinlock_t ptl;
160 #endif
161 		};
162 		struct {	/* ZONE_DEVICE pages */
163 			/** @pgmap: Points to the hosting device page map. */
164 			struct dev_pagemap *pgmap;
165 			void *zone_device_data;
166 			/*
167 			 * ZONE_DEVICE private pages are counted as being
168 			 * mapped so the next 3 words hold the mapping, index,
169 			 * and private fields from the source anonymous or
170 			 * page cache page while the page is migrated to device
171 			 * private memory.
172 			 * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also
173 			 * use the mapping, index, and private fields when
174 			 * pmem backed DAX files are mapped.
175 			 */
176 		};
177 
178 		/** @rcu_head: You can use this to free a page by RCU. */
179 		struct rcu_head rcu_head;
180 	};
181 
182 	union {		/* This union is 4 bytes in size. */
183 		/*
184 		 * If the page can be mapped to userspace, encodes the number
185 		 * of times this page is referenced by a page table.
186 		 */
187 		atomic_t _mapcount;
188 
189 		/*
190 		 * If the page is neither PageSlab nor mappable to userspace,
191 		 * the value stored here may help determine what this page
192 		 * is used for.  See page-flags.h for a list of page types
193 		 * which are currently stored here.
194 		 */
195 		unsigned int page_type;
196 	};
197 
198 	/* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */
199 	atomic_t _refcount;
200 
201 #ifdef CONFIG_MEMCG
202 	unsigned long memcg_data;
203 #endif
204 
205 	/*
206 	 * On machines where all RAM is mapped into kernel address space,
207 	 * we can simply calculate the virtual address. On machines with
208 	 * highmem some memory is mapped into kernel virtual memory
209 	 * dynamically, so we need a place to store that address.
210 	 * Note that this field could be 16 bits on x86 ... ;)
211 	 *
212 	 * Architectures with slow multiplication can define
213 	 * WANT_PAGE_VIRTUAL in asm/page.h
214 	 */
215 #if defined(WANT_PAGE_VIRTUAL)
216 	void *virtual;			/* Kernel virtual address (NULL if
217 					   not kmapped, ie. highmem) */
218 #endif /* WANT_PAGE_VIRTUAL */
219 
220 #ifdef CONFIG_KMSAN
221 	/*
222 	 * KMSAN metadata for this page:
223 	 *  - shadow page: every bit indicates whether the corresponding
224 	 *    bit of the original page is initialized (0) or not (1);
225 	 *  - origin page: every 4 bytes contain an id of the stack trace
226 	 *    where the uninitialized value was created.
227 	 */
228 	struct page *kmsan_shadow;
229 	struct page *kmsan_origin;
230 #endif
231 
232 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
233 	int _last_cpupid;
234 #endif
235 } _struct_page_alignment;
236 
237 /*
238  * struct encoded_page - a nonexistent type marking this pointer
239  *
240  * An 'encoded_page' pointer is a pointer to a regular 'struct page', but
241  * with the low bits of the pointer indicating extra context-dependent
242  * information. Not super-common, but happens in mmu_gather and mlock
243  * handling, and this acts as a type system check on that use.
244  *
245  * We only really have two guaranteed bits in general, although you could
246  * play with 'struct page' alignment (see CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
247  * for more.
248  *
249  * Use the supplied helper functions to endcode/decode the pointer and bits.
250  */
251 struct encoded_page;
252 #define ENCODE_PAGE_BITS 3ul
253 static __always_inline struct encoded_page *encode_page(struct page *page, unsigned long flags)
254 {
255 	BUILD_BUG_ON(flags > ENCODE_PAGE_BITS);
256 	return (struct encoded_page *)(flags | (unsigned long)page);
257 }
258 
259 static inline unsigned long encoded_page_flags(struct encoded_page *page)
260 {
261 	return ENCODE_PAGE_BITS & (unsigned long)page;
262 }
263 
264 static inline struct page *encoded_page_ptr(struct encoded_page *page)
265 {
266 	return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page);
267 }
268 
269 /**
270  * struct folio - Represents a contiguous set of bytes.
271  * @flags: Identical to the page flags.
272  * @lru: Least Recently Used list; tracks how recently this folio was used.
273  * @mlock_count: Number of times this folio has been pinned by mlock().
274  * @mapping: The file this page belongs to, or refers to the anon_vma for
275  *    anonymous memory.
276  * @index: Offset within the file, in units of pages.  For anonymous memory,
277  *    this is the index from the beginning of the mmap.
278  * @private: Filesystem per-folio data (see folio_attach_private()).
279  *    Used for swp_entry_t if folio_test_swapcache().
280  * @_mapcount: Do not access this member directly.  Use folio_mapcount() to
281  *    find out how many times this folio is mapped by userspace.
282  * @_refcount: Do not access this member directly.  Use folio_ref_count()
283  *    to find how many references there are to this folio.
284  * @memcg_data: Memory Control Group data.
285  * @_folio_dtor: Which destructor to use for this folio.
286  * @_folio_order: Do not use directly, call folio_order().
287  * @_entire_mapcount: Do not use directly, call folio_entire_mapcount().
288  * @_nr_pages_mapped: Do not use directly, call folio_mapcount().
289  * @_pincount: Do not use directly, call folio_maybe_dma_pinned().
290  * @_folio_nr_pages: Do not use directly, call folio_nr_pages().
291  * @_hugetlb_subpool: Do not use directly, use accessor in hugetlb.h.
292  * @_hugetlb_cgroup: Do not use directly, use accessor in hugetlb_cgroup.h.
293  * @_hugetlb_cgroup_rsvd: Do not use directly, use accessor in hugetlb_cgroup.h.
294  * @_hugetlb_hwpoison: Do not use directly, call raw_hwp_list_head().
295  * @_deferred_list: Folios to be split under memory pressure.
296  *
297  * A folio is a physically, virtually and logically contiguous set
298  * of bytes.  It is a power-of-two in size, and it is aligned to that
299  * same power-of-two.  It is at least as large as %PAGE_SIZE.  If it is
300  * in the page cache, it is at a file offset which is a multiple of that
301  * power-of-two.  It may be mapped into userspace at an address which is
302  * at an arbitrary page offset, but its kernel virtual address is aligned
303  * to its size.
304  */
305 struct folio {
306 	/* private: don't document the anon union */
307 	union {
308 		struct {
309 	/* public: */
310 			unsigned long flags;
311 			union {
312 				struct list_head lru;
313 	/* private: avoid cluttering the output */
314 				struct {
315 					void *__filler;
316 	/* public: */
317 					unsigned int mlock_count;
318 	/* private: */
319 				};
320 	/* public: */
321 			};
322 			struct address_space *mapping;
323 			pgoff_t index;
324 			void *private;
325 			atomic_t _mapcount;
326 			atomic_t _refcount;
327 #ifdef CONFIG_MEMCG
328 			unsigned long memcg_data;
329 #endif
330 	/* private: the union with struct page is transitional */
331 		};
332 		struct page page;
333 	};
334 	union {
335 		struct {
336 			unsigned long _flags_1;
337 			unsigned long _head_1;
338 	/* public: */
339 			unsigned char _folio_dtor;
340 			unsigned char _folio_order;
341 			atomic_t _entire_mapcount;
342 			atomic_t _nr_pages_mapped;
343 			atomic_t _pincount;
344 #ifdef CONFIG_64BIT
345 			unsigned int _folio_nr_pages;
346 #endif
347 	/* private: the union with struct page is transitional */
348 		};
349 		struct page __page_1;
350 	};
351 	union {
352 		struct {
353 			unsigned long _flags_2;
354 			unsigned long _head_2;
355 	/* public: */
356 			void *_hugetlb_subpool;
357 			void *_hugetlb_cgroup;
358 			void *_hugetlb_cgroup_rsvd;
359 			void *_hugetlb_hwpoison;
360 	/* private: the union with struct page is transitional */
361 		};
362 		struct {
363 			unsigned long _flags_2a;
364 			unsigned long _head_2a;
365 	/* public: */
366 			struct list_head _deferred_list;
367 	/* private: the union with struct page is transitional */
368 		};
369 		struct page __page_2;
370 	};
371 };
372 
373 #define FOLIO_MATCH(pg, fl)						\
374 	static_assert(offsetof(struct page, pg) == offsetof(struct folio, fl))
375 FOLIO_MATCH(flags, flags);
376 FOLIO_MATCH(lru, lru);
377 FOLIO_MATCH(mapping, mapping);
378 FOLIO_MATCH(compound_head, lru);
379 FOLIO_MATCH(index, index);
380 FOLIO_MATCH(private, private);
381 FOLIO_MATCH(_mapcount, _mapcount);
382 FOLIO_MATCH(_refcount, _refcount);
383 #ifdef CONFIG_MEMCG
384 FOLIO_MATCH(memcg_data, memcg_data);
385 #endif
386 #undef FOLIO_MATCH
387 #define FOLIO_MATCH(pg, fl)						\
388 	static_assert(offsetof(struct folio, fl) ==			\
389 			offsetof(struct page, pg) + sizeof(struct page))
390 FOLIO_MATCH(flags, _flags_1);
391 FOLIO_MATCH(compound_head, _head_1);
392 #undef FOLIO_MATCH
393 #define FOLIO_MATCH(pg, fl)						\
394 	static_assert(offsetof(struct folio, fl) ==			\
395 			offsetof(struct page, pg) + 2 * sizeof(struct page))
396 FOLIO_MATCH(flags, _flags_2);
397 FOLIO_MATCH(compound_head, _head_2);
398 #undef FOLIO_MATCH
399 
400 /*
401  * Used for sizing the vmemmap region on some architectures
402  */
403 #define STRUCT_PAGE_MAX_SHIFT	(order_base_2(sizeof(struct page)))
404 
405 #define PAGE_FRAG_CACHE_MAX_SIZE	__ALIGN_MASK(32768, ~PAGE_MASK)
406 #define PAGE_FRAG_CACHE_MAX_ORDER	get_order(PAGE_FRAG_CACHE_MAX_SIZE)
407 
408 /*
409  * page_private can be used on tail pages.  However, PagePrivate is only
410  * checked by the VM on the head page.  So page_private on the tail pages
411  * should be used for data that's ancillary to the head page (eg attaching
412  * buffer heads to tail pages after attaching buffer heads to the head page)
413  */
414 #define page_private(page)		((page)->private)
415 
416 static inline void set_page_private(struct page *page, unsigned long private)
417 {
418 	page->private = private;
419 }
420 
421 static inline void *folio_get_private(struct folio *folio)
422 {
423 	return folio->private;
424 }
425 
426 struct page_frag_cache {
427 	void * va;
428 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
429 	__u16 offset;
430 	__u16 size;
431 #else
432 	__u32 offset;
433 #endif
434 	/* we maintain a pagecount bias, so that we dont dirty cache line
435 	 * containing page->_refcount every time we allocate a fragment.
436 	 */
437 	unsigned int		pagecnt_bias;
438 	bool pfmemalloc;
439 };
440 
441 typedef unsigned long vm_flags_t;
442 
443 /*
444  * A region containing a mapping of a non-memory backed file under NOMMU
445  * conditions.  These are held in a global tree and are pinned by the VMAs that
446  * map parts of them.
447  */
448 struct vm_region {
449 	struct rb_node	vm_rb;		/* link in global region tree */
450 	vm_flags_t	vm_flags;	/* VMA vm_flags */
451 	unsigned long	vm_start;	/* start address of region */
452 	unsigned long	vm_end;		/* region initialised to here */
453 	unsigned long	vm_top;		/* region allocated to here */
454 	unsigned long	vm_pgoff;	/* the offset in vm_file corresponding to vm_start */
455 	struct file	*vm_file;	/* the backing file or NULL */
456 
457 	int		vm_usage;	/* region usage count (access under nommu_region_sem) */
458 	bool		vm_icache_flushed : 1; /* true if the icache has been flushed for
459 						* this region */
460 };
461 
462 #ifdef CONFIG_USERFAULTFD
463 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
464 struct vm_userfaultfd_ctx {
465 	struct userfaultfd_ctx *ctx;
466 };
467 #else /* CONFIG_USERFAULTFD */
468 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
469 struct vm_userfaultfd_ctx {};
470 #endif /* CONFIG_USERFAULTFD */
471 
472 struct anon_vma_name {
473 	struct kref kref;
474 	/* The name needs to be at the end because it is dynamically sized. */
475 	char name[];
476 };
477 
478 struct vma_lock {
479 	struct rw_semaphore lock;
480 };
481 
482 struct vma_numab_state {
483 	unsigned long next_scan;
484 	unsigned long next_pid_reset;
485 	unsigned long access_pids[2];
486 };
487 
488 /*
489  * This struct describes a virtual memory area. There is one of these
490  * per VM-area/task. A VM area is any part of the process virtual memory
491  * space that has a special rule for the page-fault handlers (ie a shared
492  * library, the executable area etc).
493  */
494 struct vm_area_struct {
495 	/* The first cache line has the info for VMA tree walking. */
496 
497 	union {
498 		struct {
499 			/* VMA covers [vm_start; vm_end) addresses within mm */
500 			unsigned long vm_start;
501 			unsigned long vm_end;
502 		};
503 #ifdef CONFIG_PER_VMA_LOCK
504 		struct rcu_head vm_rcu;	/* Used for deferred freeing. */
505 #endif
506 	};
507 
508 	struct mm_struct *vm_mm;	/* The address space we belong to. */
509 	pgprot_t vm_page_prot;          /* Access permissions of this VMA. */
510 
511 	/*
512 	 * Flags, see mm.h.
513 	 * To modify use vm_flags_{init|reset|set|clear|mod} functions.
514 	 */
515 	union {
516 		const vm_flags_t vm_flags;
517 		vm_flags_t __private __vm_flags;
518 	};
519 
520 #ifdef CONFIG_PER_VMA_LOCK
521 	/*
522 	 * Can only be written (using WRITE_ONCE()) while holding both:
523 	 *  - mmap_lock (in write mode)
524 	 *  - vm_lock->lock (in write mode)
525 	 * Can be read reliably while holding one of:
526 	 *  - mmap_lock (in read or write mode)
527 	 *  - vm_lock->lock (in read or write mode)
528 	 * Can be read unreliably (using READ_ONCE()) for pessimistic bailout
529 	 * while holding nothing (except RCU to keep the VMA struct allocated).
530 	 *
531 	 * This sequence counter is explicitly allowed to overflow; sequence
532 	 * counter reuse can only lead to occasional unnecessary use of the
533 	 * slowpath.
534 	 */
535 	int vm_lock_seq;
536 	struct vma_lock *vm_lock;
537 
538 	/* Flag to indicate areas detached from the mm->mm_mt tree */
539 	bool detached;
540 #endif
541 
542 	/*
543 	 * For areas with an address space and backing store,
544 	 * linkage into the address_space->i_mmap interval tree.
545 	 *
546 	 */
547 	struct {
548 		struct rb_node rb;
549 		unsigned long rb_subtree_last;
550 	} shared;
551 
552 	/*
553 	 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
554 	 * list, after a COW of one of the file pages.	A MAP_SHARED vma
555 	 * can only be in the i_mmap tree.  An anonymous MAP_PRIVATE, stack
556 	 * or brk vma (with NULL file) can only be in an anon_vma list.
557 	 */
558 	struct list_head anon_vma_chain; /* Serialized by mmap_lock &
559 					  * page_table_lock */
560 	struct anon_vma *anon_vma;	/* Serialized by page_table_lock */
561 
562 	/* Function pointers to deal with this struct. */
563 	const struct vm_operations_struct *vm_ops;
564 
565 	/* Information about our backing store: */
566 	unsigned long vm_pgoff;		/* Offset (within vm_file) in PAGE_SIZE
567 					   units */
568 	struct file * vm_file;		/* File we map to (can be NULL). */
569 	void * vm_private_data;		/* was vm_pte (shared mem) */
570 
571 #ifdef CONFIG_ANON_VMA_NAME
572 	/*
573 	 * For private and shared anonymous mappings, a pointer to a null
574 	 * terminated string containing the name given to the vma, or NULL if
575 	 * unnamed. Serialized by mmap_lock. Use anon_vma_name to access.
576 	 */
577 	struct anon_vma_name *anon_name;
578 #endif
579 #ifdef CONFIG_SWAP
580 	atomic_long_t swap_readahead_info;
581 #endif
582 #ifndef CONFIG_MMU
583 	struct vm_region *vm_region;	/* NOMMU mapping region */
584 #endif
585 #ifdef CONFIG_NUMA
586 	struct mempolicy *vm_policy;	/* NUMA policy for the VMA */
587 #endif
588 #ifdef CONFIG_NUMA_BALANCING
589 	struct vma_numab_state *numab_state;	/* NUMA Balancing state */
590 #endif
591 	struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
592 } __randomize_layout;
593 
594 #ifdef CONFIG_SCHED_MM_CID
595 struct mm_cid {
596 	u64 time;
597 	int cid;
598 };
599 #endif
600 
601 struct kioctx_table;
602 struct mm_struct {
603 	struct {
604 		/*
605 		 * Fields which are often written to are placed in a separate
606 		 * cache line.
607 		 */
608 		struct {
609 			/**
610 			 * @mm_count: The number of references to &struct
611 			 * mm_struct (@mm_users count as 1).
612 			 *
613 			 * Use mmgrab()/mmdrop() to modify. When this drops to
614 			 * 0, the &struct mm_struct is freed.
615 			 */
616 			atomic_t mm_count;
617 		} ____cacheline_aligned_in_smp;
618 
619 		struct maple_tree mm_mt;
620 #ifdef CONFIG_MMU
621 		unsigned long (*get_unmapped_area) (struct file *filp,
622 				unsigned long addr, unsigned long len,
623 				unsigned long pgoff, unsigned long flags);
624 #endif
625 		unsigned long mmap_base;	/* base of mmap area */
626 		unsigned long mmap_legacy_base;	/* base of mmap area in bottom-up allocations */
627 #ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
628 		/* Base addresses for compatible mmap() */
629 		unsigned long mmap_compat_base;
630 		unsigned long mmap_compat_legacy_base;
631 #endif
632 		unsigned long task_size;	/* size of task vm space */
633 		pgd_t * pgd;
634 
635 #ifdef CONFIG_MEMBARRIER
636 		/**
637 		 * @membarrier_state: Flags controlling membarrier behavior.
638 		 *
639 		 * This field is close to @pgd to hopefully fit in the same
640 		 * cache-line, which needs to be touched by switch_mm().
641 		 */
642 		atomic_t membarrier_state;
643 #endif
644 
645 		/**
646 		 * @mm_users: The number of users including userspace.
647 		 *
648 		 * Use mmget()/mmget_not_zero()/mmput() to modify. When this
649 		 * drops to 0 (i.e. when the task exits and there are no other
650 		 * temporary reference holders), we also release a reference on
651 		 * @mm_count (which may then free the &struct mm_struct if
652 		 * @mm_count also drops to 0).
653 		 */
654 		atomic_t mm_users;
655 
656 #ifdef CONFIG_SCHED_MM_CID
657 		/**
658 		 * @pcpu_cid: Per-cpu current cid.
659 		 *
660 		 * Keep track of the currently allocated mm_cid for each cpu.
661 		 * The per-cpu mm_cid values are serialized by their respective
662 		 * runqueue locks.
663 		 */
664 		struct mm_cid __percpu *pcpu_cid;
665 		/*
666 		 * @mm_cid_next_scan: Next mm_cid scan (in jiffies).
667 		 *
668 		 * When the next mm_cid scan is due (in jiffies).
669 		 */
670 		unsigned long mm_cid_next_scan;
671 #endif
672 #ifdef CONFIG_MMU
673 		atomic_long_t pgtables_bytes;	/* size of all page tables */
674 #endif
675 		int map_count;			/* number of VMAs */
676 
677 		spinlock_t page_table_lock; /* Protects page tables and some
678 					     * counters
679 					     */
680 		/*
681 		 * With some kernel config, the current mmap_lock's offset
682 		 * inside 'mm_struct' is at 0x120, which is very optimal, as
683 		 * its two hot fields 'count' and 'owner' sit in 2 different
684 		 * cachelines,  and when mmap_lock is highly contended, both
685 		 * of the 2 fields will be accessed frequently, current layout
686 		 * will help to reduce cache bouncing.
687 		 *
688 		 * So please be careful with adding new fields before
689 		 * mmap_lock, which can easily push the 2 fields into one
690 		 * cacheline.
691 		 */
692 		struct rw_semaphore mmap_lock;
693 
694 		struct list_head mmlist; /* List of maybe swapped mm's.	These
695 					  * are globally strung together off
696 					  * init_mm.mmlist, and are protected
697 					  * by mmlist_lock
698 					  */
699 #ifdef CONFIG_PER_VMA_LOCK
700 		/*
701 		 * This field has lock-like semantics, meaning it is sometimes
702 		 * accessed with ACQUIRE/RELEASE semantics.
703 		 * Roughly speaking, incrementing the sequence number is
704 		 * equivalent to releasing locks on VMAs; reading the sequence
705 		 * number can be part of taking a read lock on a VMA.
706 		 *
707 		 * Can be modified under write mmap_lock using RELEASE
708 		 * semantics.
709 		 * Can be read with no other protection when holding write
710 		 * mmap_lock.
711 		 * Can be read with ACQUIRE semantics if not holding write
712 		 * mmap_lock.
713 		 */
714 		int mm_lock_seq;
715 #endif
716 
717 
718 		unsigned long hiwater_rss; /* High-watermark of RSS usage */
719 		unsigned long hiwater_vm;  /* High-water virtual memory usage */
720 
721 		unsigned long total_vm;	   /* Total pages mapped */
722 		unsigned long locked_vm;   /* Pages that have PG_mlocked set */
723 		atomic64_t    pinned_vm;   /* Refcount permanently increased */
724 		unsigned long data_vm;	   /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
725 		unsigned long exec_vm;	   /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
726 		unsigned long stack_vm;	   /* VM_STACK */
727 		unsigned long def_flags;
728 
729 		/**
730 		 * @write_protect_seq: Locked when any thread is write
731 		 * protecting pages mapped by this mm to enforce a later COW,
732 		 * for instance during page table copying for fork().
733 		 */
734 		seqcount_t write_protect_seq;
735 
736 		spinlock_t arg_lock; /* protect the below fields */
737 
738 		unsigned long start_code, end_code, start_data, end_data;
739 		unsigned long start_brk, brk, start_stack;
740 		unsigned long arg_start, arg_end, env_start, env_end;
741 
742 		unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
743 
744 		struct percpu_counter rss_stat[NR_MM_COUNTERS];
745 
746 		struct linux_binfmt *binfmt;
747 
748 		/* Architecture-specific MM context */
749 		mm_context_t context;
750 
751 		unsigned long flags; /* Must use atomic bitops to access */
752 
753 #ifdef CONFIG_AIO
754 		spinlock_t			ioctx_lock;
755 		struct kioctx_table __rcu	*ioctx_table;
756 #endif
757 #ifdef CONFIG_MEMCG
758 		/*
759 		 * "owner" points to a task that is regarded as the canonical
760 		 * user/owner of this mm. All of the following must be true in
761 		 * order for it to be changed:
762 		 *
763 		 * current == mm->owner
764 		 * current->mm != mm
765 		 * new_owner->mm == mm
766 		 * new_owner->alloc_lock is held
767 		 */
768 		struct task_struct __rcu *owner;
769 #endif
770 		struct user_namespace *user_ns;
771 
772 		/* store ref to file /proc/<pid>/exe symlink points to */
773 		struct file __rcu *exe_file;
774 #ifdef CONFIG_MMU_NOTIFIER
775 		struct mmu_notifier_subscriptions *notifier_subscriptions;
776 #endif
777 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
778 		pgtable_t pmd_huge_pte; /* protected by page_table_lock */
779 #endif
780 #ifdef CONFIG_NUMA_BALANCING
781 		/*
782 		 * numa_next_scan is the next time that PTEs will be remapped
783 		 * PROT_NONE to trigger NUMA hinting faults; such faults gather
784 		 * statistics and migrate pages to new nodes if necessary.
785 		 */
786 		unsigned long numa_next_scan;
787 
788 		/* Restart point for scanning and remapping PTEs. */
789 		unsigned long numa_scan_offset;
790 
791 		/* numa_scan_seq prevents two threads remapping PTEs. */
792 		int numa_scan_seq;
793 #endif
794 		/*
795 		 * An operation with batched TLB flushing is going on. Anything
796 		 * that can move process memory needs to flush the TLB when
797 		 * moving a PROT_NONE mapped page.
798 		 */
799 		atomic_t tlb_flush_pending;
800 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
801 		/* See flush_tlb_batched_pending() */
802 		atomic_t tlb_flush_batched;
803 #endif
804 		struct uprobes_state uprobes_state;
805 #ifdef CONFIG_PREEMPT_RT
806 		struct rcu_head delayed_drop;
807 #endif
808 #ifdef CONFIG_HUGETLB_PAGE
809 		atomic_long_t hugetlb_usage;
810 #endif
811 		struct work_struct async_put_work;
812 
813 #ifdef CONFIG_IOMMU_SVA
814 		u32 pasid;
815 #endif
816 #ifdef CONFIG_KSM
817 		/*
818 		 * Represent how many pages of this process are involved in KSM
819 		 * merging (not including ksm_zero_pages).
820 		 */
821 		unsigned long ksm_merging_pages;
822 		/*
823 		 * Represent how many pages are checked for ksm merging
824 		 * including merged and not merged.
825 		 */
826 		unsigned long ksm_rmap_items;
827 		/*
828 		 * Represent how many empty pages are merged with kernel zero
829 		 * pages when enabling KSM use_zero_pages.
830 		 */
831 		unsigned long ksm_zero_pages;
832 #endif /* CONFIG_KSM */
833 #ifdef CONFIG_LRU_GEN
834 		struct {
835 			/* this mm_struct is on lru_gen_mm_list */
836 			struct list_head list;
837 			/*
838 			 * Set when switching to this mm_struct, as a hint of
839 			 * whether it has been used since the last time per-node
840 			 * page table walkers cleared the corresponding bits.
841 			 */
842 			unsigned long bitmap;
843 #ifdef CONFIG_MEMCG
844 			/* points to the memcg of "owner" above */
845 			struct mem_cgroup *memcg;
846 #endif
847 		} lru_gen;
848 #endif /* CONFIG_LRU_GEN */
849 	} __randomize_layout;
850 
851 	/*
852 	 * The mm_cpumask needs to be at the end of mm_struct, because it
853 	 * is dynamically sized based on nr_cpu_ids.
854 	 */
855 	unsigned long cpu_bitmap[];
856 };
857 
858 #define MM_MT_FLAGS	(MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \
859 			 MT_FLAGS_USE_RCU)
860 extern struct mm_struct init_mm;
861 
862 /* Pointer magic because the dynamic array size confuses some compilers. */
863 static inline void mm_init_cpumask(struct mm_struct *mm)
864 {
865 	unsigned long cpu_bitmap = (unsigned long)mm;
866 
867 	cpu_bitmap += offsetof(struct mm_struct, cpu_bitmap);
868 	cpumask_clear((struct cpumask *)cpu_bitmap);
869 }
870 
871 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
872 static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
873 {
874 	return (struct cpumask *)&mm->cpu_bitmap;
875 }
876 
877 #ifdef CONFIG_LRU_GEN
878 
879 struct lru_gen_mm_list {
880 	/* mm_struct list for page table walkers */
881 	struct list_head fifo;
882 	/* protects the list above */
883 	spinlock_t lock;
884 };
885 
886 void lru_gen_add_mm(struct mm_struct *mm);
887 void lru_gen_del_mm(struct mm_struct *mm);
888 #ifdef CONFIG_MEMCG
889 void lru_gen_migrate_mm(struct mm_struct *mm);
890 #endif
891 
892 static inline void lru_gen_init_mm(struct mm_struct *mm)
893 {
894 	INIT_LIST_HEAD(&mm->lru_gen.list);
895 	mm->lru_gen.bitmap = 0;
896 #ifdef CONFIG_MEMCG
897 	mm->lru_gen.memcg = NULL;
898 #endif
899 }
900 
901 static inline void lru_gen_use_mm(struct mm_struct *mm)
902 {
903 	/*
904 	 * When the bitmap is set, page reclaim knows this mm_struct has been
905 	 * used since the last time it cleared the bitmap. So it might be worth
906 	 * walking the page tables of this mm_struct to clear the accessed bit.
907 	 */
908 	WRITE_ONCE(mm->lru_gen.bitmap, -1);
909 }
910 
911 #else /* !CONFIG_LRU_GEN */
912 
913 static inline void lru_gen_add_mm(struct mm_struct *mm)
914 {
915 }
916 
917 static inline void lru_gen_del_mm(struct mm_struct *mm)
918 {
919 }
920 
921 #ifdef CONFIG_MEMCG
922 static inline void lru_gen_migrate_mm(struct mm_struct *mm)
923 {
924 }
925 #endif
926 
927 static inline void lru_gen_init_mm(struct mm_struct *mm)
928 {
929 }
930 
931 static inline void lru_gen_use_mm(struct mm_struct *mm)
932 {
933 }
934 
935 #endif /* CONFIG_LRU_GEN */
936 
937 struct vma_iterator {
938 	struct ma_state mas;
939 };
940 
941 #define VMA_ITERATOR(name, __mm, __addr)				\
942 	struct vma_iterator name = {					\
943 		.mas = {						\
944 			.tree = &(__mm)->mm_mt,				\
945 			.index = __addr,				\
946 			.node = MAS_START,				\
947 		},							\
948 	}
949 
950 static inline void vma_iter_init(struct vma_iterator *vmi,
951 		struct mm_struct *mm, unsigned long addr)
952 {
953 	mas_init(&vmi->mas, &mm->mm_mt, addr);
954 }
955 
956 #ifdef CONFIG_SCHED_MM_CID
957 
958 enum mm_cid_state {
959 	MM_CID_UNSET = -1U,		/* Unset state has lazy_put flag set. */
960 	MM_CID_LAZY_PUT = (1U << 31),
961 };
962 
963 static inline bool mm_cid_is_unset(int cid)
964 {
965 	return cid == MM_CID_UNSET;
966 }
967 
968 static inline bool mm_cid_is_lazy_put(int cid)
969 {
970 	return !mm_cid_is_unset(cid) && (cid & MM_CID_LAZY_PUT);
971 }
972 
973 static inline bool mm_cid_is_valid(int cid)
974 {
975 	return !(cid & MM_CID_LAZY_PUT);
976 }
977 
978 static inline int mm_cid_set_lazy_put(int cid)
979 {
980 	return cid | MM_CID_LAZY_PUT;
981 }
982 
983 static inline int mm_cid_clear_lazy_put(int cid)
984 {
985 	return cid & ~MM_CID_LAZY_PUT;
986 }
987 
988 /* Accessor for struct mm_struct's cidmask. */
989 static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
990 {
991 	unsigned long cid_bitmap = (unsigned long)mm;
992 
993 	cid_bitmap += offsetof(struct mm_struct, cpu_bitmap);
994 	/* Skip cpu_bitmap */
995 	cid_bitmap += cpumask_size();
996 	return (struct cpumask *)cid_bitmap;
997 }
998 
999 static inline void mm_init_cid(struct mm_struct *mm)
1000 {
1001 	int i;
1002 
1003 	for_each_possible_cpu(i) {
1004 		struct mm_cid *pcpu_cid = per_cpu_ptr(mm->pcpu_cid, i);
1005 
1006 		pcpu_cid->cid = MM_CID_UNSET;
1007 		pcpu_cid->time = 0;
1008 	}
1009 	cpumask_clear(mm_cidmask(mm));
1010 }
1011 
1012 static inline int mm_alloc_cid(struct mm_struct *mm)
1013 {
1014 	mm->pcpu_cid = alloc_percpu(struct mm_cid);
1015 	if (!mm->pcpu_cid)
1016 		return -ENOMEM;
1017 	mm_init_cid(mm);
1018 	return 0;
1019 }
1020 
1021 static inline void mm_destroy_cid(struct mm_struct *mm)
1022 {
1023 	free_percpu(mm->pcpu_cid);
1024 	mm->pcpu_cid = NULL;
1025 }
1026 
1027 static inline unsigned int mm_cid_size(void)
1028 {
1029 	return cpumask_size();
1030 }
1031 #else /* CONFIG_SCHED_MM_CID */
1032 static inline void mm_init_cid(struct mm_struct *mm) { }
1033 static inline int mm_alloc_cid(struct mm_struct *mm) { return 0; }
1034 static inline void mm_destroy_cid(struct mm_struct *mm) { }
1035 static inline unsigned int mm_cid_size(void)
1036 {
1037 	return 0;
1038 }
1039 #endif /* CONFIG_SCHED_MM_CID */
1040 
1041 struct mmu_gather;
1042 extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm);
1043 extern void tlb_gather_mmu_fullmm(struct mmu_gather *tlb, struct mm_struct *mm);
1044 extern void tlb_finish_mmu(struct mmu_gather *tlb);
1045 
1046 struct vm_fault;
1047 
1048 /**
1049  * typedef vm_fault_t - Return type for page fault handlers.
1050  *
1051  * Page fault handlers return a bitmask of %VM_FAULT values.
1052  */
1053 typedef __bitwise unsigned int vm_fault_t;
1054 
1055 /**
1056  * enum vm_fault_reason - Page fault handlers return a bitmask of
1057  * these values to tell the core VM what happened when handling the
1058  * fault. Used to decide whether a process gets delivered SIGBUS or
1059  * just gets major/minor fault counters bumped up.
1060  *
1061  * @VM_FAULT_OOM:		Out Of Memory
1062  * @VM_FAULT_SIGBUS:		Bad access
1063  * @VM_FAULT_MAJOR:		Page read from storage
1064  * @VM_FAULT_HWPOISON:		Hit poisoned small page
1065  * @VM_FAULT_HWPOISON_LARGE:	Hit poisoned large page. Index encoded
1066  *				in upper bits
1067  * @VM_FAULT_SIGSEGV:		segmentation fault
1068  * @VM_FAULT_NOPAGE:		->fault installed the pte, not return page
1069  * @VM_FAULT_LOCKED:		->fault locked the returned page
1070  * @VM_FAULT_RETRY:		->fault blocked, must retry
1071  * @VM_FAULT_FALLBACK:		huge page fault failed, fall back to small
1072  * @VM_FAULT_DONE_COW:		->fault has fully handled COW
1073  * @VM_FAULT_NEEDDSYNC:		->fault did not modify page tables and needs
1074  *				fsync() to complete (for synchronous page faults
1075  *				in DAX)
1076  * @VM_FAULT_COMPLETED:		->fault completed, meanwhile mmap lock released
1077  * @VM_FAULT_HINDEX_MASK:	mask HINDEX value
1078  *
1079  */
1080 enum vm_fault_reason {
1081 	VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
1082 	VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
1083 	VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
1084 	VM_FAULT_HWPOISON       = (__force vm_fault_t)0x000010,
1085 	VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
1086 	VM_FAULT_SIGSEGV        = (__force vm_fault_t)0x000040,
1087 	VM_FAULT_NOPAGE         = (__force vm_fault_t)0x000100,
1088 	VM_FAULT_LOCKED         = (__force vm_fault_t)0x000200,
1089 	VM_FAULT_RETRY          = (__force vm_fault_t)0x000400,
1090 	VM_FAULT_FALLBACK       = (__force vm_fault_t)0x000800,
1091 	VM_FAULT_DONE_COW       = (__force vm_fault_t)0x001000,
1092 	VM_FAULT_NEEDDSYNC      = (__force vm_fault_t)0x002000,
1093 	VM_FAULT_COMPLETED      = (__force vm_fault_t)0x004000,
1094 	VM_FAULT_HINDEX_MASK    = (__force vm_fault_t)0x0f0000,
1095 };
1096 
1097 /* Encode hstate index for a hwpoisoned large page */
1098 #define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
1099 #define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
1100 
1101 #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS |	\
1102 			VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON |	\
1103 			VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
1104 
1105 #define VM_FAULT_RESULT_TRACE \
1106 	{ VM_FAULT_OOM,                 "OOM" },	\
1107 	{ VM_FAULT_SIGBUS,              "SIGBUS" },	\
1108 	{ VM_FAULT_MAJOR,               "MAJOR" },	\
1109 	{ VM_FAULT_HWPOISON,            "HWPOISON" },	\
1110 	{ VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" },	\
1111 	{ VM_FAULT_SIGSEGV,             "SIGSEGV" },	\
1112 	{ VM_FAULT_NOPAGE,              "NOPAGE" },	\
1113 	{ VM_FAULT_LOCKED,              "LOCKED" },	\
1114 	{ VM_FAULT_RETRY,               "RETRY" },	\
1115 	{ VM_FAULT_FALLBACK,            "FALLBACK" },	\
1116 	{ VM_FAULT_DONE_COW,            "DONE_COW" },	\
1117 	{ VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
1118 
1119 struct vm_special_mapping {
1120 	const char *name;	/* The name, e.g. "[vdso]". */
1121 
1122 	/*
1123 	 * If .fault is not provided, this points to a
1124 	 * NULL-terminated array of pages that back the special mapping.
1125 	 *
1126 	 * This must not be NULL unless .fault is provided.
1127 	 */
1128 	struct page **pages;
1129 
1130 	/*
1131 	 * If non-NULL, then this is called to resolve page faults
1132 	 * on the special mapping.  If used, .pages is not checked.
1133 	 */
1134 	vm_fault_t (*fault)(const struct vm_special_mapping *sm,
1135 				struct vm_area_struct *vma,
1136 				struct vm_fault *vmf);
1137 
1138 	int (*mremap)(const struct vm_special_mapping *sm,
1139 		     struct vm_area_struct *new_vma);
1140 };
1141 
1142 enum tlb_flush_reason {
1143 	TLB_FLUSH_ON_TASK_SWITCH,
1144 	TLB_REMOTE_SHOOTDOWN,
1145 	TLB_LOCAL_SHOOTDOWN,
1146 	TLB_LOCAL_MM_SHOOTDOWN,
1147 	TLB_REMOTE_SEND_IPI,
1148 	NR_TLB_FLUSH_REASONS,
1149 };
1150 
1151  /*
1152   * A swap entry has to fit into a "unsigned long", as the entry is hidden
1153   * in the "index" field of the swapper address space.
1154   */
1155 typedef struct {
1156 	unsigned long val;
1157 } swp_entry_t;
1158 
1159 /**
1160  * enum fault_flag - Fault flag definitions.
1161  * @FAULT_FLAG_WRITE: Fault was a write fault.
1162  * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE.
1163  * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked.
1164  * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_lock and wait when retrying.
1165  * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region.
1166  * @FAULT_FLAG_TRIED: The fault has been tried once.
1167  * @FAULT_FLAG_USER: The fault originated in userspace.
1168  * @FAULT_FLAG_REMOTE: The fault is not for current task/mm.
1169  * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch.
1170  * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals.
1171  * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to break COW in a
1172  *                      COW mapping, making sure that an exclusive anon page is
1173  *                      mapped after the fault.
1174  * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached.
1175  *                        We should only access orig_pte if this flag set.
1176  * @FAULT_FLAG_VMA_LOCK: The fault is handled under VMA lock.
1177  *
1178  * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify
1179  * whether we would allow page faults to retry by specifying these two
1180  * fault flags correctly.  Currently there can be three legal combinations:
1181  *
1182  * (a) ALLOW_RETRY and !TRIED:  this means the page fault allows retry, and
1183  *                              this is the first try
1184  *
1185  * (b) ALLOW_RETRY and TRIED:   this means the page fault allows retry, and
1186  *                              we've already tried at least once
1187  *
1188  * (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry
1189  *
1190  * The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never
1191  * be used.  Note that page faults can be allowed to retry for multiple times,
1192  * in which case we'll have an initial fault with flags (a) then later on
1193  * continuous faults with flags (b).  We should always try to detect pending
1194  * signals before a retry to make sure the continuous page faults can still be
1195  * interrupted if necessary.
1196  *
1197  * The combination FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE is illegal.
1198  * FAULT_FLAG_UNSHARE is ignored and treated like an ordinary read fault when
1199  * applied to mappings that are not COW mappings.
1200  */
1201 enum fault_flag {
1202 	FAULT_FLAG_WRITE =		1 << 0,
1203 	FAULT_FLAG_MKWRITE =		1 << 1,
1204 	FAULT_FLAG_ALLOW_RETRY =	1 << 2,
1205 	FAULT_FLAG_RETRY_NOWAIT = 	1 << 3,
1206 	FAULT_FLAG_KILLABLE =		1 << 4,
1207 	FAULT_FLAG_TRIED = 		1 << 5,
1208 	FAULT_FLAG_USER =		1 << 6,
1209 	FAULT_FLAG_REMOTE =		1 << 7,
1210 	FAULT_FLAG_INSTRUCTION =	1 << 8,
1211 	FAULT_FLAG_INTERRUPTIBLE =	1 << 9,
1212 	FAULT_FLAG_UNSHARE =		1 << 10,
1213 	FAULT_FLAG_ORIG_PTE_VALID =	1 << 11,
1214 	FAULT_FLAG_VMA_LOCK =		1 << 12,
1215 };
1216 
1217 typedef unsigned int __bitwise zap_flags_t;
1218 
1219 /*
1220  * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each
1221  * other. Here is what they mean, and how to use them:
1222  *
1223  *
1224  * FIXME: For pages which are part of a filesystem, mappings are subject to the
1225  * lifetime enforced by the filesystem and we need guarantees that longterm
1226  * users like RDMA and V4L2 only establish mappings which coordinate usage with
1227  * the filesystem.  Ideas for this coordination include revoking the longterm
1228  * pin, delaying writeback, bounce buffer page writeback, etc.  As FS DAX was
1229  * added after the problem with filesystems was found FS DAX VMAs are
1230  * specifically failed.  Filesystem pages are still subject to bugs and use of
1231  * FOLL_LONGTERM should be avoided on those pages.
1232  *
1233  * In the CMA case: long term pins in a CMA region would unnecessarily fragment
1234  * that region.  And so, CMA attempts to migrate the page before pinning, when
1235  * FOLL_LONGTERM is specified.
1236  *
1237  * FOLL_PIN indicates that a special kind of tracking (not just page->_refcount,
1238  * but an additional pin counting system) will be invoked. This is intended for
1239  * anything that gets a page reference and then touches page data (for example,
1240  * Direct IO). This lets the filesystem know that some non-file-system entity is
1241  * potentially changing the pages' data. In contrast to FOLL_GET (whose pages
1242  * are released via put_page()), FOLL_PIN pages must be released, ultimately, by
1243  * a call to unpin_user_page().
1244  *
1245  * FOLL_PIN is similar to FOLL_GET: both of these pin pages. They use different
1246  * and separate refcounting mechanisms, however, and that means that each has
1247  * its own acquire and release mechanisms:
1248  *
1249  *     FOLL_GET: get_user_pages*() to acquire, and put_page() to release.
1250  *
1251  *     FOLL_PIN: pin_user_pages*() to acquire, and unpin_user_pages to release.
1252  *
1253  * FOLL_PIN and FOLL_GET are mutually exclusive for a given function call.
1254  * (The underlying pages may experience both FOLL_GET-based and FOLL_PIN-based
1255  * calls applied to them, and that's perfectly OK. This is a constraint on the
1256  * callers, not on the pages.)
1257  *
1258  * FOLL_PIN should be set internally by the pin_user_pages*() APIs, never
1259  * directly by the caller. That's in order to help avoid mismatches when
1260  * releasing pages: get_user_pages*() pages must be released via put_page(),
1261  * while pin_user_pages*() pages must be released via unpin_user_page().
1262  *
1263  * Please see Documentation/core-api/pin_user_pages.rst for more information.
1264  */
1265 
1266 enum {
1267 	/* check pte is writable */
1268 	FOLL_WRITE = 1 << 0,
1269 	/* do get_page on page */
1270 	FOLL_GET = 1 << 1,
1271 	/* give error on hole if it would be zero */
1272 	FOLL_DUMP = 1 << 2,
1273 	/* get_user_pages read/write w/o permission */
1274 	FOLL_FORCE = 1 << 3,
1275 	/*
1276 	 * if a disk transfer is needed, start the IO and return without waiting
1277 	 * upon it
1278 	 */
1279 	FOLL_NOWAIT = 1 << 4,
1280 	/* do not fault in pages */
1281 	FOLL_NOFAULT = 1 << 5,
1282 	/* check page is hwpoisoned */
1283 	FOLL_HWPOISON = 1 << 6,
1284 	/* don't do file mappings */
1285 	FOLL_ANON = 1 << 7,
1286 	/*
1287 	 * FOLL_LONGTERM indicates that the page will be held for an indefinite
1288 	 * time period _often_ under userspace control.  This is in contrast to
1289 	 * iov_iter_get_pages(), whose usages are transient.
1290 	 */
1291 	FOLL_LONGTERM = 1 << 8,
1292 	/* split huge pmd before returning */
1293 	FOLL_SPLIT_PMD = 1 << 9,
1294 	/* allow returning PCI P2PDMA pages */
1295 	FOLL_PCI_P2PDMA = 1 << 10,
1296 	/* allow interrupts from generic signals */
1297 	FOLL_INTERRUPTIBLE = 1 << 11,
1298 
1299 	/* See also internal only FOLL flags in mm/internal.h */
1300 };
1301 
1302 #endif /* _LINUX_MM_TYPES_H */
1303