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