Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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#include <linux/types.h>
23
24#include <asm/mmu.h>
25
26#ifndef AT_VECTOR_SIZE_ARCH
27#define AT_VECTOR_SIZE_ARCH 0
28#endif
29#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
30
31
32struct address_space;
33struct futex_private_hash;
34struct mem_cgroup;
35
36/*
37 * Each physical page in the system has a struct page associated with
38 * it to keep track of whatever it is we are using the page for at the
39 * moment. Note that we have no way to track which tasks are using
40 * a page, though if it is a pagecache page, rmap structures can tell us
41 * who is mapping it.
42 *
43 * If you allocate the page using alloc_pages(), you can use some of the
44 * space in struct page for your own purposes. The five words in the main
45 * union are available, except for bit 0 of the first word which must be
46 * kept clear. Many users use this word to store a pointer to an object
47 * which is guaranteed to be aligned. If you use the same storage as
48 * page->mapping, you must restore it to NULL before freeing the page.
49 *
50 * The mapcount field must not be used for own purposes.
51 *
52 * If you want to use the refcount field, it must be used in such a way
53 * that other CPUs temporarily incrementing and then decrementing the
54 * refcount does not cause problems. On receiving the page from
55 * alloc_pages(), the refcount will be positive.
56 *
57 * If you allocate pages of order > 0, you can use some of the fields
58 * in each subpage, but you may need to restore some of their values
59 * afterwards.
60 *
61 * SLUB uses cmpxchg_double() to atomically update its freelist and counters.
62 * That requires that freelist & counters in struct slab be adjacent and
63 * double-word aligned. Because struct slab currently just reinterprets the
64 * bits of struct page, we align all struct pages to double-word boundaries,
65 * and ensure that 'freelist' is aligned within struct slab.
66 */
67#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
68#define _struct_page_alignment __aligned(2 * sizeof(unsigned long))
69#else
70#define _struct_page_alignment __aligned(sizeof(unsigned long))
71#endif
72
73struct page {
74 unsigned long flags; /* Atomic flags, some possibly
75 * updated asynchronously */
76 /*
77 * Five words (20/40 bytes) are available in this union.
78 * WARNING: bit 0 of the first word is used for PageTail(). That
79 * means the other users of this union MUST NOT use the bit to
80 * avoid collision and false-positive PageTail().
81 */
82 union {
83 struct { /* Page cache and anonymous pages */
84 /**
85 * @lru: Pageout list, eg. active_list protected by
86 * lruvec->lru_lock. Sometimes used as a generic list
87 * by the page owner.
88 */
89 union {
90 struct list_head lru;
91
92 /* Or, for the Unevictable "LRU list" slot */
93 struct {
94 /* Always even, to negate PageTail */
95 void *__filler;
96 /* Count page's or folio's mlocks */
97 unsigned int mlock_count;
98 };
99
100 /* Or, free page */
101 struct list_head buddy_list;
102 struct list_head pcp_list;
103 struct {
104 struct llist_node pcp_llist;
105 unsigned int order;
106 };
107 };
108 struct address_space *mapping;
109 union {
110 pgoff_t __folio_index; /* Our offset within mapping. */
111 unsigned long share; /* share count for fsdax */
112 };
113 /**
114 * @private: Mapping-private opaque data.
115 * Usually used for buffer_heads if PagePrivate.
116 * Used for swp_entry_t if swapcache flag set.
117 * Indicates order in the buddy system if PageBuddy.
118 */
119 unsigned long private;
120 };
121 struct { /* page_pool used by netstack */
122 /**
123 * @pp_magic: magic value to avoid recycling non
124 * page_pool allocated pages.
125 */
126 unsigned long pp_magic;
127 struct page_pool *pp;
128 unsigned long _pp_mapping_pad;
129 unsigned long dma_addr;
130 atomic_long_t pp_ref_count;
131 };
132 struct { /* Tail pages of compound page */
133 unsigned long compound_head; /* Bit zero is set */
134 };
135 struct { /* ZONE_DEVICE pages */
136 /*
137 * The first word is used for compound_head or folio
138 * pgmap
139 */
140 void *_unused_pgmap_compound_head;
141 void *zone_device_data;
142 /*
143 * ZONE_DEVICE private pages are counted as being
144 * mapped so the next 3 words hold the mapping, index,
145 * and private fields from the source anonymous or
146 * page cache page while the page is migrated to device
147 * private memory.
148 * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also
149 * use the mapping, index, and private fields when
150 * pmem backed DAX files are mapped.
151 */
152 };
153
154 /** @rcu_head: You can use this to free a page by RCU. */
155 struct rcu_head rcu_head;
156 };
157
158 union { /* This union is 4 bytes in size. */
159 /*
160 * For head pages of typed folios, the value stored here
161 * allows for determining what this page is used for. The
162 * tail pages of typed folios will not store a type
163 * (page_type == _mapcount == -1).
164 *
165 * See page-flags.h for a list of page types which are currently
166 * stored here.
167 *
168 * Owners of typed folios may reuse the lower 16 bit of the
169 * head page page_type field after setting the page type,
170 * but must reset these 16 bit to -1 before clearing the
171 * page type.
172 */
173 unsigned int page_type;
174
175 /*
176 * For pages that are part of non-typed folios for which mappings
177 * are tracked via the RMAP, encodes the number of times this page
178 * is directly referenced by a page table.
179 *
180 * Note that the mapcount is always initialized to -1, so that
181 * transitions both from it and to it can be tracked, using
182 * atomic_inc_and_test() and atomic_add_negative(-1).
183 */
184 atomic_t _mapcount;
185 };
186
187 /* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */
188 atomic_t _refcount;
189
190#ifdef CONFIG_MEMCG
191 unsigned long memcg_data;
192#elif defined(CONFIG_SLAB_OBJ_EXT)
193 unsigned long _unused_slab_obj_exts;
194#endif
195
196 /*
197 * On machines where all RAM is mapped into kernel address space,
198 * we can simply calculate the virtual address. On machines with
199 * highmem some memory is mapped into kernel virtual memory
200 * dynamically, so we need a place to store that address.
201 * Note that this field could be 16 bits on x86 ... ;)
202 *
203 * Architectures with slow multiplication can define
204 * WANT_PAGE_VIRTUAL in asm/page.h
205 */
206#if defined(WANT_PAGE_VIRTUAL)
207 void *virtual; /* Kernel virtual address (NULL if
208 not kmapped, ie. highmem) */
209#endif /* WANT_PAGE_VIRTUAL */
210
211#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
212 int _last_cpupid;
213#endif
214
215#ifdef CONFIG_KMSAN
216 /*
217 * KMSAN metadata for this page:
218 * - shadow page: every bit indicates whether the corresponding
219 * bit of the original page is initialized (0) or not (1);
220 * - origin page: every 4 bytes contain an id of the stack trace
221 * where the uninitialized value was created.
222 */
223 struct page *kmsan_shadow;
224 struct page *kmsan_origin;
225#endif
226} _struct_page_alignment;
227
228/*
229 * struct encoded_page - a nonexistent type marking this pointer
230 *
231 * An 'encoded_page' pointer is a pointer to a regular 'struct page', but
232 * with the low bits of the pointer indicating extra context-dependent
233 * information. Only used in mmu_gather handling, and this acts as a type
234 * system check on that use.
235 *
236 * We only really have two guaranteed bits in general, although you could
237 * play with 'struct page' alignment (see CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
238 * for more.
239 *
240 * Use the supplied helper functions to endcode/decode the pointer and bits.
241 */
242struct encoded_page;
243
244#define ENCODED_PAGE_BITS 3ul
245
246/* Perform rmap removal after we have flushed the TLB. */
247#define ENCODED_PAGE_BIT_DELAY_RMAP 1ul
248
249/*
250 * The next item in an encoded_page array is the "nr_pages" argument, specifying
251 * the number of consecutive pages starting from this page, that all belong to
252 * the same folio. For example, "nr_pages" corresponds to the number of folio
253 * references that must be dropped. If this bit is not set, "nr_pages" is
254 * implicitly 1.
255 */
256#define ENCODED_PAGE_BIT_NR_PAGES_NEXT 2ul
257
258static __always_inline struct encoded_page *encode_page(struct page *page, unsigned long flags)
259{
260 BUILD_BUG_ON(flags > ENCODED_PAGE_BITS);
261 return (struct encoded_page *)(flags | (unsigned long)page);
262}
263
264static inline unsigned long encoded_page_flags(struct encoded_page *page)
265{
266 return ENCODED_PAGE_BITS & (unsigned long)page;
267}
268
269static inline struct page *encoded_page_ptr(struct encoded_page *page)
270{
271 return (struct page *)(~ENCODED_PAGE_BITS & (unsigned long)page);
272}
273
274static __always_inline struct encoded_page *encode_nr_pages(unsigned long nr)
275{
276 VM_WARN_ON_ONCE((nr << 2) >> 2 != nr);
277 return (struct encoded_page *)(nr << 2);
278}
279
280static __always_inline unsigned long encoded_nr_pages(struct encoded_page *page)
281{
282 return ((unsigned long)page) >> 2;
283}
284
285/*
286 * A swap entry has to fit into a "unsigned long", as the entry is hidden
287 * in the "index" field of the swapper address space.
288 */
289typedef struct {
290 unsigned long val;
291} swp_entry_t;
292
293#if defined(CONFIG_MEMCG) || defined(CONFIG_SLAB_OBJ_EXT)
294/* We have some extra room after the refcount in tail pages. */
295#define NR_PAGES_IN_LARGE_FOLIO
296#endif
297
298/*
299 * On 32bit, we can cut the required metadata in half, because:
300 * (a) PID_MAX_LIMIT implicitly limits the number of MMs we could ever have,
301 * so we can limit MM IDs to 15 bit (32767).
302 * (b) We don't expect folios where even a single complete PTE mapping by
303 * one MM would exceed 15 bits (order-15).
304 */
305#ifdef CONFIG_64BIT
306typedef int mm_id_mapcount_t;
307#define MM_ID_MAPCOUNT_MAX INT_MAX
308typedef unsigned int mm_id_t;
309#else /* !CONFIG_64BIT */
310typedef short mm_id_mapcount_t;
311#define MM_ID_MAPCOUNT_MAX SHRT_MAX
312typedef unsigned short mm_id_t;
313#endif /* CONFIG_64BIT */
314
315/* We implicitly use the dummy ID for init-mm etc. where we never rmap pages. */
316#define MM_ID_DUMMY 0
317#define MM_ID_MIN (MM_ID_DUMMY + 1)
318
319/*
320 * We leave the highest bit of each MM id unused, so we can store a flag
321 * in the highest bit of each folio->_mm_id[].
322 */
323#define MM_ID_BITS ((sizeof(mm_id_t) * BITS_PER_BYTE) - 1)
324#define MM_ID_MASK ((1U << MM_ID_BITS) - 1)
325#define MM_ID_MAX MM_ID_MASK
326
327/*
328 * In order to use bit_spin_lock(), which requires an unsigned long, we
329 * operate on folio->_mm_ids when working on flags.
330 */
331#define FOLIO_MM_IDS_LOCK_BITNUM MM_ID_BITS
332#define FOLIO_MM_IDS_LOCK_BIT BIT(FOLIO_MM_IDS_LOCK_BITNUM)
333#define FOLIO_MM_IDS_SHARED_BITNUM (2 * MM_ID_BITS + 1)
334#define FOLIO_MM_IDS_SHARED_BIT BIT(FOLIO_MM_IDS_SHARED_BITNUM)
335
336/**
337 * struct folio - Represents a contiguous set of bytes.
338 * @flags: Identical to the page flags.
339 * @lru: Least Recently Used list; tracks how recently this folio was used.
340 * @mlock_count: Number of times this folio has been pinned by mlock().
341 * @mapping: The file this page belongs to, or refers to the anon_vma for
342 * anonymous memory.
343 * @index: Offset within the file, in units of pages. For anonymous memory,
344 * this is the index from the beginning of the mmap.
345 * @share: number of DAX mappings that reference this folio. See
346 * dax_associate_entry.
347 * @private: Filesystem per-folio data (see folio_attach_private()).
348 * @swap: Used for swp_entry_t if folio_test_swapcache().
349 * @_mapcount: Do not access this member directly. Use folio_mapcount() to
350 * find out how many times this folio is mapped by userspace.
351 * @_refcount: Do not access this member directly. Use folio_ref_count()
352 * to find how many references there are to this folio.
353 * @memcg_data: Memory Control Group data.
354 * @pgmap: Metadata for ZONE_DEVICE mappings
355 * @virtual: Virtual address in the kernel direct map.
356 * @_last_cpupid: IDs of last CPU and last process that accessed the folio.
357 * @_entire_mapcount: Do not use directly, call folio_entire_mapcount().
358 * @_large_mapcount: Do not use directly, call folio_mapcount().
359 * @_nr_pages_mapped: Do not use outside of rmap and debug code.
360 * @_pincount: Do not use directly, call folio_maybe_dma_pinned().
361 * @_nr_pages: Do not use directly, call folio_nr_pages().
362 * @_mm_id: Do not use outside of rmap code.
363 * @_mm_ids: Do not use outside of rmap code.
364 * @_mm_id_mapcount: Do not use outside of rmap code.
365 * @_hugetlb_subpool: Do not use directly, use accessor in hugetlb.h.
366 * @_hugetlb_cgroup: Do not use directly, use accessor in hugetlb_cgroup.h.
367 * @_hugetlb_cgroup_rsvd: Do not use directly, use accessor in hugetlb_cgroup.h.
368 * @_hugetlb_hwpoison: Do not use directly, call raw_hwp_list_head().
369 * @_deferred_list: Folios to be split under memory pressure.
370 * @_unused_slab_obj_exts: Placeholder to match obj_exts in struct slab.
371 *
372 * A folio is a physically, virtually and logically contiguous set
373 * of bytes. It is a power-of-two in size, and it is aligned to that
374 * same power-of-two. It is at least as large as %PAGE_SIZE. If it is
375 * in the page cache, it is at a file offset which is a multiple of that
376 * power-of-two. It may be mapped into userspace at an address which is
377 * at an arbitrary page offset, but its kernel virtual address is aligned
378 * to its size.
379 */
380struct folio {
381 /* private: don't document the anon union */
382 union {
383 struct {
384 /* public: */
385 unsigned long flags;
386 union {
387 struct list_head lru;
388 /* private: avoid cluttering the output */
389 struct {
390 void *__filler;
391 /* public: */
392 unsigned int mlock_count;
393 /* private: */
394 };
395 /* public: */
396 struct dev_pagemap *pgmap;
397 };
398 struct address_space *mapping;
399 union {
400 pgoff_t index;
401 unsigned long share;
402 };
403 union {
404 void *private;
405 swp_entry_t swap;
406 };
407 atomic_t _mapcount;
408 atomic_t _refcount;
409#ifdef CONFIG_MEMCG
410 unsigned long memcg_data;
411#elif defined(CONFIG_SLAB_OBJ_EXT)
412 unsigned long _unused_slab_obj_exts;
413#endif
414#if defined(WANT_PAGE_VIRTUAL)
415 void *virtual;
416#endif
417#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
418 int _last_cpupid;
419#endif
420 /* private: the union with struct page is transitional */
421 };
422 struct page page;
423 };
424 union {
425 struct {
426 unsigned long _flags_1;
427 unsigned long _head_1;
428 union {
429 struct {
430 /* public: */
431 atomic_t _large_mapcount;
432 atomic_t _nr_pages_mapped;
433#ifdef CONFIG_64BIT
434 atomic_t _entire_mapcount;
435 atomic_t _pincount;
436#endif /* CONFIG_64BIT */
437 mm_id_mapcount_t _mm_id_mapcount[2];
438 union {
439 mm_id_t _mm_id[2];
440 unsigned long _mm_ids;
441 };
442 /* private: the union with struct page is transitional */
443 };
444 unsigned long _usable_1[4];
445 };
446 atomic_t _mapcount_1;
447 atomic_t _refcount_1;
448 /* public: */
449#ifdef NR_PAGES_IN_LARGE_FOLIO
450 unsigned int _nr_pages;
451#endif /* NR_PAGES_IN_LARGE_FOLIO */
452 /* private: the union with struct page is transitional */
453 };
454 struct page __page_1;
455 };
456 union {
457 struct {
458 unsigned long _flags_2;
459 unsigned long _head_2;
460 /* public: */
461 struct list_head _deferred_list;
462#ifndef CONFIG_64BIT
463 atomic_t _entire_mapcount;
464 atomic_t _pincount;
465#endif /* !CONFIG_64BIT */
466 /* private: the union with struct page is transitional */
467 };
468 struct page __page_2;
469 };
470 union {
471 struct {
472 unsigned long _flags_3;
473 unsigned long _head_3;
474 /* public: */
475 void *_hugetlb_subpool;
476 void *_hugetlb_cgroup;
477 void *_hugetlb_cgroup_rsvd;
478 void *_hugetlb_hwpoison;
479 /* private: the union with struct page is transitional */
480 };
481 struct page __page_3;
482 };
483};
484
485#define FOLIO_MATCH(pg, fl) \
486 static_assert(offsetof(struct page, pg) == offsetof(struct folio, fl))
487FOLIO_MATCH(flags, flags);
488FOLIO_MATCH(lru, lru);
489FOLIO_MATCH(mapping, mapping);
490FOLIO_MATCH(compound_head, lru);
491FOLIO_MATCH(__folio_index, index);
492FOLIO_MATCH(private, private);
493FOLIO_MATCH(_mapcount, _mapcount);
494FOLIO_MATCH(_refcount, _refcount);
495#ifdef CONFIG_MEMCG
496FOLIO_MATCH(memcg_data, memcg_data);
497#endif
498#if defined(WANT_PAGE_VIRTUAL)
499FOLIO_MATCH(virtual, virtual);
500#endif
501#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
502FOLIO_MATCH(_last_cpupid, _last_cpupid);
503#endif
504#undef FOLIO_MATCH
505#define FOLIO_MATCH(pg, fl) \
506 static_assert(offsetof(struct folio, fl) == \
507 offsetof(struct page, pg) + sizeof(struct page))
508FOLIO_MATCH(flags, _flags_1);
509FOLIO_MATCH(compound_head, _head_1);
510FOLIO_MATCH(_mapcount, _mapcount_1);
511FOLIO_MATCH(_refcount, _refcount_1);
512#undef FOLIO_MATCH
513#define FOLIO_MATCH(pg, fl) \
514 static_assert(offsetof(struct folio, fl) == \
515 offsetof(struct page, pg) + 2 * sizeof(struct page))
516FOLIO_MATCH(flags, _flags_2);
517FOLIO_MATCH(compound_head, _head_2);
518#undef FOLIO_MATCH
519#define FOLIO_MATCH(pg, fl) \
520 static_assert(offsetof(struct folio, fl) == \
521 offsetof(struct page, pg) + 3 * sizeof(struct page))
522FOLIO_MATCH(flags, _flags_3);
523FOLIO_MATCH(compound_head, _head_3);
524#undef FOLIO_MATCH
525
526/**
527 * struct ptdesc - Memory descriptor for page tables.
528 * @__page_flags: Same as page flags. Powerpc only.
529 * @pt_rcu_head: For freeing page table pages.
530 * @pt_list: List of used page tables. Used for s390 gmap shadow pages
531 * (which are not linked into the user page tables) and x86
532 * pgds.
533 * @_pt_pad_1: Padding that aliases with page's compound head.
534 * @pmd_huge_pte: Protected by ptdesc->ptl, used for THPs.
535 * @__page_mapping: Aliases with page->mapping. Unused for page tables.
536 * @pt_index: Used for s390 gmap.
537 * @pt_mm: Used for x86 pgds.
538 * @pt_frag_refcount: For fragmented page table tracking. Powerpc only.
539 * @pt_share_count: Used for HugeTLB PMD page table share count.
540 * @_pt_pad_2: Padding to ensure proper alignment.
541 * @ptl: Lock for the page table.
542 * @__page_type: Same as page->page_type. Unused for page tables.
543 * @__page_refcount: Same as page refcount.
544 * @pt_memcg_data: Memcg data. Tracked for page tables here.
545 *
546 * This struct overlays struct page for now. Do not modify without a good
547 * understanding of the issues.
548 */
549struct ptdesc {
550 unsigned long __page_flags;
551
552 union {
553 struct rcu_head pt_rcu_head;
554 struct list_head pt_list;
555 struct {
556 unsigned long _pt_pad_1;
557 pgtable_t pmd_huge_pte;
558 };
559 };
560 unsigned long __page_mapping;
561
562 union {
563 pgoff_t pt_index;
564 struct mm_struct *pt_mm;
565 atomic_t pt_frag_refcount;
566#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
567 atomic_t pt_share_count;
568#endif
569 };
570
571 union {
572 unsigned long _pt_pad_2;
573#if ALLOC_SPLIT_PTLOCKS
574 spinlock_t *ptl;
575#else
576 spinlock_t ptl;
577#endif
578 };
579 unsigned int __page_type;
580 atomic_t __page_refcount;
581#ifdef CONFIG_MEMCG
582 unsigned long pt_memcg_data;
583#endif
584};
585
586#define TABLE_MATCH(pg, pt) \
587 static_assert(offsetof(struct page, pg) == offsetof(struct ptdesc, pt))
588TABLE_MATCH(flags, __page_flags);
589TABLE_MATCH(compound_head, pt_list);
590TABLE_MATCH(compound_head, _pt_pad_1);
591TABLE_MATCH(mapping, __page_mapping);
592TABLE_MATCH(__folio_index, pt_index);
593TABLE_MATCH(rcu_head, pt_rcu_head);
594TABLE_MATCH(page_type, __page_type);
595TABLE_MATCH(_refcount, __page_refcount);
596#ifdef CONFIG_MEMCG
597TABLE_MATCH(memcg_data, pt_memcg_data);
598#endif
599#undef TABLE_MATCH
600static_assert(sizeof(struct ptdesc) <= sizeof(struct page));
601
602#define ptdesc_page(pt) (_Generic((pt), \
603 const struct ptdesc *: (const struct page *)(pt), \
604 struct ptdesc *: (struct page *)(pt)))
605
606#define ptdesc_folio(pt) (_Generic((pt), \
607 const struct ptdesc *: (const struct folio *)(pt), \
608 struct ptdesc *: (struct folio *)(pt)))
609
610#define page_ptdesc(p) (_Generic((p), \
611 const struct page *: (const struct ptdesc *)(p), \
612 struct page *: (struct ptdesc *)(p)))
613
614#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
615static inline void ptdesc_pmd_pts_init(struct ptdesc *ptdesc)
616{
617 atomic_set(&ptdesc->pt_share_count, 0);
618}
619
620static inline void ptdesc_pmd_pts_inc(struct ptdesc *ptdesc)
621{
622 atomic_inc(&ptdesc->pt_share_count);
623}
624
625static inline void ptdesc_pmd_pts_dec(struct ptdesc *ptdesc)
626{
627 atomic_dec(&ptdesc->pt_share_count);
628}
629
630static inline int ptdesc_pmd_pts_count(struct ptdesc *ptdesc)
631{
632 return atomic_read(&ptdesc->pt_share_count);
633}
634
635static inline bool ptdesc_pmd_is_shared(struct ptdesc *ptdesc)
636{
637 return !!ptdesc_pmd_pts_count(ptdesc);
638}
639#else
640static inline void ptdesc_pmd_pts_init(struct ptdesc *ptdesc)
641{
642}
643#endif
644
645/*
646 * Used for sizing the vmemmap region on some architectures
647 */
648#define STRUCT_PAGE_MAX_SHIFT (order_base_2(sizeof(struct page)))
649
650/*
651 * page_private can be used on tail pages. However, PagePrivate is only
652 * checked by the VM on the head page. So page_private on the tail pages
653 * should be used for data that's ancillary to the head page (eg attaching
654 * buffer heads to tail pages after attaching buffer heads to the head page)
655 */
656#define page_private(page) ((page)->private)
657
658static inline void set_page_private(struct page *page, unsigned long private)
659{
660 page->private = private;
661}
662
663static inline void *folio_get_private(struct folio *folio)
664{
665 return folio->private;
666}
667
668typedef unsigned long vm_flags_t;
669
670/*
671 * freeptr_t represents a SLUB freelist pointer, which might be encoded
672 * and not dereferenceable if CONFIG_SLAB_FREELIST_HARDENED is enabled.
673 */
674typedef struct { unsigned long v; } freeptr_t;
675
676/*
677 * A region containing a mapping of a non-memory backed file under NOMMU
678 * conditions. These are held in a global tree and are pinned by the VMAs that
679 * map parts of them.
680 */
681struct vm_region {
682 struct rb_node vm_rb; /* link in global region tree */
683 vm_flags_t vm_flags; /* VMA vm_flags */
684 unsigned long vm_start; /* start address of region */
685 unsigned long vm_end; /* region initialised to here */
686 unsigned long vm_top; /* region allocated to here */
687 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
688 struct file *vm_file; /* the backing file or NULL */
689
690 int vm_usage; /* region usage count (access under nommu_region_sem) */
691 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
692 * this region */
693};
694
695#ifdef CONFIG_USERFAULTFD
696#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
697struct vm_userfaultfd_ctx {
698 struct userfaultfd_ctx *ctx;
699};
700#else /* CONFIG_USERFAULTFD */
701#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
702struct vm_userfaultfd_ctx {};
703#endif /* CONFIG_USERFAULTFD */
704
705struct anon_vma_name {
706 struct kref kref;
707 /* The name needs to be at the end because it is dynamically sized. */
708 char name[];
709};
710
711#ifdef CONFIG_ANON_VMA_NAME
712/*
713 * mmap_lock should be read-locked when calling anon_vma_name(). Caller should
714 * either keep holding the lock while using the returned pointer or it should
715 * raise anon_vma_name refcount before releasing the lock.
716 */
717struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma);
718struct anon_vma_name *anon_vma_name_alloc(const char *name);
719void anon_vma_name_free(struct kref *kref);
720#else /* CONFIG_ANON_VMA_NAME */
721static inline struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma)
722{
723 return NULL;
724}
725
726static inline struct anon_vma_name *anon_vma_name_alloc(const char *name)
727{
728 return NULL;
729}
730#endif
731
732#define VMA_LOCK_OFFSET 0x40000000
733#define VMA_REF_LIMIT (VMA_LOCK_OFFSET - 1)
734
735struct vma_numab_state {
736 /*
737 * Initialised as time in 'jiffies' after which VMA
738 * should be scanned. Delays first scan of new VMA by at
739 * least sysctl_numa_balancing_scan_delay:
740 */
741 unsigned long next_scan;
742
743 /*
744 * Time in jiffies when pids_active[] is reset to
745 * detect phase change behaviour:
746 */
747 unsigned long pids_active_reset;
748
749 /*
750 * Approximate tracking of PIDs that trapped a NUMA hinting
751 * fault. May produce false positives due to hash collisions.
752 *
753 * [0] Previous PID tracking
754 * [1] Current PID tracking
755 *
756 * Window moves after next_pid_reset has expired approximately
757 * every VMA_PID_RESET_PERIOD jiffies:
758 */
759 unsigned long pids_active[2];
760
761 /* MM scan sequence ID when scan first started after VMA creation */
762 int start_scan_seq;
763
764 /*
765 * MM scan sequence ID when the VMA was last completely scanned.
766 * A VMA is not eligible for scanning if prev_scan_seq == numa_scan_seq
767 */
768 int prev_scan_seq;
769};
770
771#ifdef __HAVE_PFNMAP_TRACKING
772struct pfnmap_track_ctx {
773 struct kref kref;
774 unsigned long pfn;
775 unsigned long size; /* in bytes */
776};
777#endif
778
779/*
780 * Describes a VMA that is about to be mmap()'ed. Drivers may choose to
781 * manipulate mutable fields which will cause those fields to be updated in the
782 * resultant VMA.
783 *
784 * Helper functions are not required for manipulating any field.
785 */
786struct vm_area_desc {
787 /* Immutable state. */
788 struct mm_struct *mm;
789 unsigned long start;
790 unsigned long end;
791
792 /* Mutable fields. Populated with initial state. */
793 pgoff_t pgoff;
794 struct file *file;
795 vm_flags_t vm_flags;
796 pgprot_t page_prot;
797
798 /* Write-only fields. */
799 const struct vm_operations_struct *vm_ops;
800 void *private_data;
801};
802
803/*
804 * This struct describes a virtual memory area. There is one of these
805 * per VM-area/task. A VM area is any part of the process virtual memory
806 * space that has a special rule for the page-fault handlers (ie a shared
807 * library, the executable area etc).
808 *
809 * Only explicitly marked struct members may be accessed by RCU readers before
810 * getting a stable reference.
811 *
812 * WARNING: when adding new members, please update vm_area_init_from() to copy
813 * them during vm_area_struct content duplication.
814 */
815struct vm_area_struct {
816 /* The first cache line has the info for VMA tree walking. */
817
818 union {
819 struct {
820 /* VMA covers [vm_start; vm_end) addresses within mm */
821 unsigned long vm_start;
822 unsigned long vm_end;
823 };
824 freeptr_t vm_freeptr; /* Pointer used by SLAB_TYPESAFE_BY_RCU */
825 };
826
827 /*
828 * The address space we belong to.
829 * Unstable RCU readers are allowed to read this.
830 */
831 struct mm_struct *vm_mm;
832 pgprot_t vm_page_prot; /* Access permissions of this VMA. */
833
834 /*
835 * Flags, see mm.h.
836 * To modify use vm_flags_{init|reset|set|clear|mod} functions.
837 */
838 union {
839 const vm_flags_t vm_flags;
840 vm_flags_t __private __vm_flags;
841 };
842
843#ifdef CONFIG_PER_VMA_LOCK
844 /*
845 * Can only be written (using WRITE_ONCE()) while holding both:
846 * - mmap_lock (in write mode)
847 * - vm_refcnt bit at VMA_LOCK_OFFSET is set
848 * Can be read reliably while holding one of:
849 * - mmap_lock (in read or write mode)
850 * - vm_refcnt bit at VMA_LOCK_OFFSET is set or vm_refcnt > 1
851 * Can be read unreliably (using READ_ONCE()) for pessimistic bailout
852 * while holding nothing (except RCU to keep the VMA struct allocated).
853 *
854 * This sequence counter is explicitly allowed to overflow; sequence
855 * counter reuse can only lead to occasional unnecessary use of the
856 * slowpath.
857 */
858 unsigned int vm_lock_seq;
859#endif
860 /*
861 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
862 * list, after a COW of one of the file pages. A MAP_SHARED vma
863 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
864 * or brk vma (with NULL file) can only be in an anon_vma list.
865 */
866 struct list_head anon_vma_chain; /* Serialized by mmap_lock &
867 * page_table_lock */
868 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
869
870 /* Function pointers to deal with this struct. */
871 const struct vm_operations_struct *vm_ops;
872
873 /* Information about our backing store: */
874 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
875 units */
876 struct file * vm_file; /* File we map to (can be NULL). */
877 void * vm_private_data; /* was vm_pte (shared mem) */
878
879#ifdef CONFIG_SWAP
880 atomic_long_t swap_readahead_info;
881#endif
882#ifndef CONFIG_MMU
883 struct vm_region *vm_region; /* NOMMU mapping region */
884#endif
885#ifdef CONFIG_NUMA
886 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
887#endif
888#ifdef CONFIG_NUMA_BALANCING
889 struct vma_numab_state *numab_state; /* NUMA Balancing state */
890#endif
891#ifdef CONFIG_PER_VMA_LOCK
892 /* Unstable RCU readers are allowed to read this. */
893 refcount_t vm_refcnt ____cacheline_aligned_in_smp;
894#ifdef CONFIG_DEBUG_LOCK_ALLOC
895 struct lockdep_map vmlock_dep_map;
896#endif
897#endif
898 /*
899 * For areas with an address space and backing store,
900 * linkage into the address_space->i_mmap interval tree.
901 *
902 */
903 struct {
904 struct rb_node rb;
905 unsigned long rb_subtree_last;
906 } shared;
907#ifdef CONFIG_ANON_VMA_NAME
908 /*
909 * For private and shared anonymous mappings, a pointer to a null
910 * terminated string containing the name given to the vma, or NULL if
911 * unnamed. Serialized by mmap_lock. Use anon_vma_name to access.
912 */
913 struct anon_vma_name *anon_name;
914#endif
915 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
916#ifdef __HAVE_PFNMAP_TRACKING
917 struct pfnmap_track_ctx *pfnmap_track_ctx;
918#endif
919} __randomize_layout;
920
921#ifdef CONFIG_NUMA
922#define vma_policy(vma) ((vma)->vm_policy)
923#else
924#define vma_policy(vma) NULL
925#endif
926
927#ifdef CONFIG_SCHED_MM_CID
928struct mm_cid {
929 u64 time;
930 int cid;
931 int recent_cid;
932};
933#endif
934
935struct kioctx_table;
936struct iommu_mm_data;
937struct mm_struct {
938 struct {
939 /*
940 * Fields which are often written to are placed in a separate
941 * cache line.
942 */
943 struct {
944 /**
945 * @mm_count: The number of references to &struct
946 * mm_struct (@mm_users count as 1).
947 *
948 * Use mmgrab()/mmdrop() to modify. When this drops to
949 * 0, the &struct mm_struct is freed.
950 */
951 atomic_t mm_count;
952 } ____cacheline_aligned_in_smp;
953
954 struct maple_tree mm_mt;
955
956 unsigned long mmap_base; /* base of mmap area */
957 unsigned long mmap_legacy_base; /* base of mmap area in bottom-up allocations */
958#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
959 /* Base addresses for compatible mmap() */
960 unsigned long mmap_compat_base;
961 unsigned long mmap_compat_legacy_base;
962#endif
963 unsigned long task_size; /* size of task vm space */
964 pgd_t * pgd;
965
966#ifdef CONFIG_MEMBARRIER
967 /**
968 * @membarrier_state: Flags controlling membarrier behavior.
969 *
970 * This field is close to @pgd to hopefully fit in the same
971 * cache-line, which needs to be touched by switch_mm().
972 */
973 atomic_t membarrier_state;
974#endif
975
976 /**
977 * @mm_users: The number of users including userspace.
978 *
979 * Use mmget()/mmget_not_zero()/mmput() to modify. When this
980 * drops to 0 (i.e. when the task exits and there are no other
981 * temporary reference holders), we also release a reference on
982 * @mm_count (which may then free the &struct mm_struct if
983 * @mm_count also drops to 0).
984 */
985 atomic_t mm_users;
986
987#ifdef CONFIG_SCHED_MM_CID
988 /**
989 * @pcpu_cid: Per-cpu current cid.
990 *
991 * Keep track of the currently allocated mm_cid for each cpu.
992 * The per-cpu mm_cid values are serialized by their respective
993 * runqueue locks.
994 */
995 struct mm_cid __percpu *pcpu_cid;
996 /*
997 * @mm_cid_next_scan: Next mm_cid scan (in jiffies).
998 *
999 * When the next mm_cid scan is due (in jiffies).
1000 */
1001 unsigned long mm_cid_next_scan;
1002 /**
1003 * @nr_cpus_allowed: Number of CPUs allowed for mm.
1004 *
1005 * Number of CPUs allowed in the union of all mm's
1006 * threads allowed CPUs.
1007 */
1008 unsigned int nr_cpus_allowed;
1009 /**
1010 * @max_nr_cid: Maximum number of allowed concurrency
1011 * IDs allocated.
1012 *
1013 * Track the highest number of allowed concurrency IDs
1014 * allocated for the mm.
1015 */
1016 atomic_t max_nr_cid;
1017 /**
1018 * @cpus_allowed_lock: Lock protecting mm cpus_allowed.
1019 *
1020 * Provide mutual exclusion for mm cpus_allowed and
1021 * mm nr_cpus_allowed updates.
1022 */
1023 raw_spinlock_t cpus_allowed_lock;
1024#endif
1025#ifdef CONFIG_MMU
1026 atomic_long_t pgtables_bytes; /* size of all page tables */
1027#endif
1028 int map_count; /* number of VMAs */
1029
1030 spinlock_t page_table_lock; /* Protects page tables and some
1031 * counters
1032 */
1033 /*
1034 * With some kernel config, the current mmap_lock's offset
1035 * inside 'mm_struct' is at 0x120, which is very optimal, as
1036 * its two hot fields 'count' and 'owner' sit in 2 different
1037 * cachelines, and when mmap_lock is highly contended, both
1038 * of the 2 fields will be accessed frequently, current layout
1039 * will help to reduce cache bouncing.
1040 *
1041 * So please be careful with adding new fields before
1042 * mmap_lock, which can easily push the 2 fields into one
1043 * cacheline.
1044 */
1045 struct rw_semaphore mmap_lock;
1046
1047 struct list_head mmlist; /* List of maybe swapped mm's. These
1048 * are globally strung together off
1049 * init_mm.mmlist, and are protected
1050 * by mmlist_lock
1051 */
1052#ifdef CONFIG_PER_VMA_LOCK
1053 struct rcuwait vma_writer_wait;
1054 /*
1055 * This field has lock-like semantics, meaning it is sometimes
1056 * accessed with ACQUIRE/RELEASE semantics.
1057 * Roughly speaking, incrementing the sequence number is
1058 * equivalent to releasing locks on VMAs; reading the sequence
1059 * number can be part of taking a read lock on a VMA.
1060 * Incremented every time mmap_lock is write-locked/unlocked.
1061 * Initialized to 0, therefore odd values indicate mmap_lock
1062 * is write-locked and even values that it's released.
1063 *
1064 * Can be modified under write mmap_lock using RELEASE
1065 * semantics.
1066 * Can be read with no other protection when holding write
1067 * mmap_lock.
1068 * Can be read with ACQUIRE semantics if not holding write
1069 * mmap_lock.
1070 */
1071 seqcount_t mm_lock_seq;
1072#endif
1073#ifdef CONFIG_FUTEX_PRIVATE_HASH
1074 struct mutex futex_hash_lock;
1075 struct futex_private_hash __rcu *futex_phash;
1076 struct futex_private_hash *futex_phash_new;
1077 /* futex-ref */
1078 unsigned long futex_batches;
1079 struct rcu_head futex_rcu;
1080 atomic_long_t futex_atomic;
1081 unsigned int __percpu *futex_ref;
1082#endif
1083
1084 unsigned long hiwater_rss; /* High-watermark of RSS usage */
1085 unsigned long hiwater_vm; /* High-water virtual memory usage */
1086
1087 unsigned long total_vm; /* Total pages mapped */
1088 unsigned long locked_vm; /* Pages that have PG_mlocked set */
1089 atomic64_t pinned_vm; /* Refcount permanently increased */
1090 unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
1091 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
1092 unsigned long stack_vm; /* VM_STACK */
1093 vm_flags_t def_flags;
1094
1095 /**
1096 * @write_protect_seq: Locked when any thread is write
1097 * protecting pages mapped by this mm to enforce a later COW,
1098 * for instance during page table copying for fork().
1099 */
1100 seqcount_t write_protect_seq;
1101
1102 spinlock_t arg_lock; /* protect the below fields */
1103
1104 unsigned long start_code, end_code, start_data, end_data;
1105 unsigned long start_brk, brk, start_stack;
1106 unsigned long arg_start, arg_end, env_start, env_end;
1107
1108 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
1109
1110 struct percpu_counter rss_stat[NR_MM_COUNTERS];
1111
1112 struct linux_binfmt *binfmt;
1113
1114 /* Architecture-specific MM context */
1115 mm_context_t context;
1116
1117 unsigned long flags; /* Must use atomic bitops to access */
1118
1119#ifdef CONFIG_AIO
1120 spinlock_t ioctx_lock;
1121 struct kioctx_table __rcu *ioctx_table;
1122#endif
1123#ifdef CONFIG_MEMCG
1124 /*
1125 * "owner" points to a task that is regarded as the canonical
1126 * user/owner of this mm. All of the following must be true in
1127 * order for it to be changed:
1128 *
1129 * current == mm->owner
1130 * current->mm != mm
1131 * new_owner->mm == mm
1132 * new_owner->alloc_lock is held
1133 */
1134 struct task_struct __rcu *owner;
1135#endif
1136 struct user_namespace *user_ns;
1137
1138 /* store ref to file /proc/<pid>/exe symlink points to */
1139 struct file __rcu *exe_file;
1140#ifdef CONFIG_MMU_NOTIFIER
1141 struct mmu_notifier_subscriptions *notifier_subscriptions;
1142#endif
1143#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !defined(CONFIG_SPLIT_PMD_PTLOCKS)
1144 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
1145#endif
1146#ifdef CONFIG_NUMA_BALANCING
1147 /*
1148 * numa_next_scan is the next time that PTEs will be remapped
1149 * PROT_NONE to trigger NUMA hinting faults; such faults gather
1150 * statistics and migrate pages to new nodes if necessary.
1151 */
1152 unsigned long numa_next_scan;
1153
1154 /* Restart point for scanning and remapping PTEs. */
1155 unsigned long numa_scan_offset;
1156
1157 /* numa_scan_seq prevents two threads remapping PTEs. */
1158 int numa_scan_seq;
1159#endif
1160 /*
1161 * An operation with batched TLB flushing is going on. Anything
1162 * that can move process memory needs to flush the TLB when
1163 * moving a PROT_NONE mapped page.
1164 */
1165 atomic_t tlb_flush_pending;
1166#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
1167 /* See flush_tlb_batched_pending() */
1168 atomic_t tlb_flush_batched;
1169#endif
1170 struct uprobes_state uprobes_state;
1171#ifdef CONFIG_PREEMPT_RT
1172 struct rcu_head delayed_drop;
1173#endif
1174#ifdef CONFIG_HUGETLB_PAGE
1175 atomic_long_t hugetlb_usage;
1176#endif
1177 struct work_struct async_put_work;
1178
1179#ifdef CONFIG_IOMMU_MM_DATA
1180 struct iommu_mm_data *iommu_mm;
1181#endif
1182#ifdef CONFIG_KSM
1183 /*
1184 * Represent how many pages of this process are involved in KSM
1185 * merging (not including ksm_zero_pages).
1186 */
1187 unsigned long ksm_merging_pages;
1188 /*
1189 * Represent how many pages are checked for ksm merging
1190 * including merged and not merged.
1191 */
1192 unsigned long ksm_rmap_items;
1193 /*
1194 * Represent how many empty pages are merged with kernel zero
1195 * pages when enabling KSM use_zero_pages.
1196 */
1197 atomic_long_t ksm_zero_pages;
1198#endif /* CONFIG_KSM */
1199#ifdef CONFIG_LRU_GEN_WALKS_MMU
1200 struct {
1201 /* this mm_struct is on lru_gen_mm_list */
1202 struct list_head list;
1203 /*
1204 * Set when switching to this mm_struct, as a hint of
1205 * whether it has been used since the last time per-node
1206 * page table walkers cleared the corresponding bits.
1207 */
1208 unsigned long bitmap;
1209#ifdef CONFIG_MEMCG
1210 /* points to the memcg of "owner" above */
1211 struct mem_cgroup *memcg;
1212#endif
1213 } lru_gen;
1214#endif /* CONFIG_LRU_GEN_WALKS_MMU */
1215#ifdef CONFIG_MM_ID
1216 mm_id_t mm_id;
1217#endif /* CONFIG_MM_ID */
1218 } __randomize_layout;
1219
1220 /*
1221 * The mm_cpumask needs to be at the end of mm_struct, because it
1222 * is dynamically sized based on nr_cpu_ids.
1223 */
1224 unsigned long cpu_bitmap[];
1225};
1226
1227#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \
1228 MT_FLAGS_USE_RCU)
1229extern struct mm_struct init_mm;
1230
1231/* Pointer magic because the dynamic array size confuses some compilers. */
1232static inline void mm_init_cpumask(struct mm_struct *mm)
1233{
1234 unsigned long cpu_bitmap = (unsigned long)mm;
1235
1236 cpu_bitmap += offsetof(struct mm_struct, cpu_bitmap);
1237 cpumask_clear((struct cpumask *)cpu_bitmap);
1238}
1239
1240/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
1241static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
1242{
1243 return (struct cpumask *)&mm->cpu_bitmap;
1244}
1245
1246#ifdef CONFIG_LRU_GEN
1247
1248struct lru_gen_mm_list {
1249 /* mm_struct list for page table walkers */
1250 struct list_head fifo;
1251 /* protects the list above */
1252 spinlock_t lock;
1253};
1254
1255#endif /* CONFIG_LRU_GEN */
1256
1257#ifdef CONFIG_LRU_GEN_WALKS_MMU
1258
1259void lru_gen_add_mm(struct mm_struct *mm);
1260void lru_gen_del_mm(struct mm_struct *mm);
1261void lru_gen_migrate_mm(struct mm_struct *mm);
1262
1263static inline void lru_gen_init_mm(struct mm_struct *mm)
1264{
1265 INIT_LIST_HEAD(&mm->lru_gen.list);
1266 mm->lru_gen.bitmap = 0;
1267#ifdef CONFIG_MEMCG
1268 mm->lru_gen.memcg = NULL;
1269#endif
1270}
1271
1272static inline void lru_gen_use_mm(struct mm_struct *mm)
1273{
1274 /*
1275 * When the bitmap is set, page reclaim knows this mm_struct has been
1276 * used since the last time it cleared the bitmap. So it might be worth
1277 * walking the page tables of this mm_struct to clear the accessed bit.
1278 */
1279 WRITE_ONCE(mm->lru_gen.bitmap, -1);
1280}
1281
1282#else /* !CONFIG_LRU_GEN_WALKS_MMU */
1283
1284static inline void lru_gen_add_mm(struct mm_struct *mm)
1285{
1286}
1287
1288static inline void lru_gen_del_mm(struct mm_struct *mm)
1289{
1290}
1291
1292static inline void lru_gen_migrate_mm(struct mm_struct *mm)
1293{
1294}
1295
1296static inline void lru_gen_init_mm(struct mm_struct *mm)
1297{
1298}
1299
1300static inline void lru_gen_use_mm(struct mm_struct *mm)
1301{
1302}
1303
1304#endif /* CONFIG_LRU_GEN_WALKS_MMU */
1305
1306struct vma_iterator {
1307 struct ma_state mas;
1308};
1309
1310#define VMA_ITERATOR(name, __mm, __addr) \
1311 struct vma_iterator name = { \
1312 .mas = { \
1313 .tree = &(__mm)->mm_mt, \
1314 .index = __addr, \
1315 .node = NULL, \
1316 .status = ma_start, \
1317 }, \
1318 }
1319
1320static inline void vma_iter_init(struct vma_iterator *vmi,
1321 struct mm_struct *mm, unsigned long addr)
1322{
1323 mas_init(&vmi->mas, &mm->mm_mt, addr);
1324}
1325
1326#ifdef CONFIG_SCHED_MM_CID
1327
1328enum mm_cid_state {
1329 MM_CID_UNSET = -1U, /* Unset state has lazy_put flag set. */
1330 MM_CID_LAZY_PUT = (1U << 31),
1331};
1332
1333static inline bool mm_cid_is_unset(int cid)
1334{
1335 return cid == MM_CID_UNSET;
1336}
1337
1338static inline bool mm_cid_is_lazy_put(int cid)
1339{
1340 return !mm_cid_is_unset(cid) && (cid & MM_CID_LAZY_PUT);
1341}
1342
1343static inline bool mm_cid_is_valid(int cid)
1344{
1345 return !(cid & MM_CID_LAZY_PUT);
1346}
1347
1348static inline int mm_cid_set_lazy_put(int cid)
1349{
1350 return cid | MM_CID_LAZY_PUT;
1351}
1352
1353static inline int mm_cid_clear_lazy_put(int cid)
1354{
1355 return cid & ~MM_CID_LAZY_PUT;
1356}
1357
1358/*
1359 * mm_cpus_allowed: Union of all mm's threads allowed CPUs.
1360 */
1361static inline cpumask_t *mm_cpus_allowed(struct mm_struct *mm)
1362{
1363 unsigned long bitmap = (unsigned long)mm;
1364
1365 bitmap += offsetof(struct mm_struct, cpu_bitmap);
1366 /* Skip cpu_bitmap */
1367 bitmap += cpumask_size();
1368 return (struct cpumask *)bitmap;
1369}
1370
1371/* Accessor for struct mm_struct's cidmask. */
1372static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
1373{
1374 unsigned long cid_bitmap = (unsigned long)mm_cpus_allowed(mm);
1375
1376 /* Skip mm_cpus_allowed */
1377 cid_bitmap += cpumask_size();
1378 return (struct cpumask *)cid_bitmap;
1379}
1380
1381static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p)
1382{
1383 int i;
1384
1385 for_each_possible_cpu(i) {
1386 struct mm_cid *pcpu_cid = per_cpu_ptr(mm->pcpu_cid, i);
1387
1388 pcpu_cid->cid = MM_CID_UNSET;
1389 pcpu_cid->recent_cid = MM_CID_UNSET;
1390 pcpu_cid->time = 0;
1391 }
1392 mm->nr_cpus_allowed = p->nr_cpus_allowed;
1393 atomic_set(&mm->max_nr_cid, 0);
1394 raw_spin_lock_init(&mm->cpus_allowed_lock);
1395 cpumask_copy(mm_cpus_allowed(mm), &p->cpus_mask);
1396 cpumask_clear(mm_cidmask(mm));
1397}
1398
1399static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct *p)
1400{
1401 mm->pcpu_cid = alloc_percpu_noprof(struct mm_cid);
1402 if (!mm->pcpu_cid)
1403 return -ENOMEM;
1404 mm_init_cid(mm, p);
1405 return 0;
1406}
1407#define mm_alloc_cid(...) alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__))
1408
1409static inline void mm_destroy_cid(struct mm_struct *mm)
1410{
1411 free_percpu(mm->pcpu_cid);
1412 mm->pcpu_cid = NULL;
1413}
1414
1415static inline unsigned int mm_cid_size(void)
1416{
1417 return 2 * cpumask_size(); /* mm_cpus_allowed(), mm_cidmask(). */
1418}
1419
1420static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumask *cpumask)
1421{
1422 struct cpumask *mm_allowed = mm_cpus_allowed(mm);
1423
1424 if (!mm)
1425 return;
1426 /* The mm_cpus_allowed is the union of each thread allowed CPUs masks. */
1427 raw_spin_lock(&mm->cpus_allowed_lock);
1428 cpumask_or(mm_allowed, mm_allowed, cpumask);
1429 WRITE_ONCE(mm->nr_cpus_allowed, cpumask_weight(mm_allowed));
1430 raw_spin_unlock(&mm->cpus_allowed_lock);
1431}
1432#else /* CONFIG_SCHED_MM_CID */
1433static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) { }
1434static inline int mm_alloc_cid(struct mm_struct *mm, struct task_struct *p) { return 0; }
1435static inline void mm_destroy_cid(struct mm_struct *mm) { }
1436
1437static inline unsigned int mm_cid_size(void)
1438{
1439 return 0;
1440}
1441static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumask *cpumask) { }
1442#endif /* CONFIG_SCHED_MM_CID */
1443
1444struct mmu_gather;
1445extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm);
1446extern void tlb_gather_mmu_fullmm(struct mmu_gather *tlb, struct mm_struct *mm);
1447extern void tlb_finish_mmu(struct mmu_gather *tlb);
1448
1449struct vm_fault;
1450
1451/**
1452 * typedef vm_fault_t - Return type for page fault handlers.
1453 *
1454 * Page fault handlers return a bitmask of %VM_FAULT values.
1455 */
1456typedef __bitwise unsigned int vm_fault_t;
1457
1458/**
1459 * enum vm_fault_reason - Page fault handlers return a bitmask of
1460 * these values to tell the core VM what happened when handling the
1461 * fault. Used to decide whether a process gets delivered SIGBUS or
1462 * just gets major/minor fault counters bumped up.
1463 *
1464 * @VM_FAULT_OOM: Out Of Memory
1465 * @VM_FAULT_SIGBUS: Bad access
1466 * @VM_FAULT_MAJOR: Page read from storage
1467 * @VM_FAULT_HWPOISON: Hit poisoned small page
1468 * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
1469 * in upper bits
1470 * @VM_FAULT_SIGSEGV: segmentation fault
1471 * @VM_FAULT_NOPAGE: ->fault installed the pte, not return page
1472 * @VM_FAULT_LOCKED: ->fault locked the returned page
1473 * @VM_FAULT_RETRY: ->fault blocked, must retry
1474 * @VM_FAULT_FALLBACK: huge page fault failed, fall back to small
1475 * @VM_FAULT_DONE_COW: ->fault has fully handled COW
1476 * @VM_FAULT_NEEDDSYNC: ->fault did not modify page tables and needs
1477 * fsync() to complete (for synchronous page faults
1478 * in DAX)
1479 * @VM_FAULT_COMPLETED: ->fault completed, meanwhile mmap lock released
1480 * @VM_FAULT_HINDEX_MASK: mask HINDEX value
1481 *
1482 */
1483enum vm_fault_reason {
1484 VM_FAULT_OOM = (__force vm_fault_t)0x000001,
1485 VM_FAULT_SIGBUS = (__force vm_fault_t)0x000002,
1486 VM_FAULT_MAJOR = (__force vm_fault_t)0x000004,
1487 VM_FAULT_HWPOISON = (__force vm_fault_t)0x000010,
1488 VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
1489 VM_FAULT_SIGSEGV = (__force vm_fault_t)0x000040,
1490 VM_FAULT_NOPAGE = (__force vm_fault_t)0x000100,
1491 VM_FAULT_LOCKED = (__force vm_fault_t)0x000200,
1492 VM_FAULT_RETRY = (__force vm_fault_t)0x000400,
1493 VM_FAULT_FALLBACK = (__force vm_fault_t)0x000800,
1494 VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000,
1495 VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000,
1496 VM_FAULT_COMPLETED = (__force vm_fault_t)0x004000,
1497 VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000,
1498};
1499
1500/* Encode hstate index for a hwpoisoned large page */
1501#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
1502#define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
1503
1504#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \
1505 VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \
1506 VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
1507
1508#define VM_FAULT_RESULT_TRACE \
1509 { VM_FAULT_OOM, "OOM" }, \
1510 { VM_FAULT_SIGBUS, "SIGBUS" }, \
1511 { VM_FAULT_MAJOR, "MAJOR" }, \
1512 { VM_FAULT_HWPOISON, "HWPOISON" }, \
1513 { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \
1514 { VM_FAULT_SIGSEGV, "SIGSEGV" }, \
1515 { VM_FAULT_NOPAGE, "NOPAGE" }, \
1516 { VM_FAULT_LOCKED, "LOCKED" }, \
1517 { VM_FAULT_RETRY, "RETRY" }, \
1518 { VM_FAULT_FALLBACK, "FALLBACK" }, \
1519 { VM_FAULT_DONE_COW, "DONE_COW" }, \
1520 { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }, \
1521 { VM_FAULT_COMPLETED, "COMPLETED" }
1522
1523struct vm_special_mapping {
1524 const char *name; /* The name, e.g. "[vdso]". */
1525
1526 /*
1527 * If .fault is not provided, this points to a
1528 * NULL-terminated array of pages that back the special mapping.
1529 *
1530 * This must not be NULL unless .fault is provided.
1531 */
1532 struct page **pages;
1533
1534 /*
1535 * If non-NULL, then this is called to resolve page faults
1536 * on the special mapping. If used, .pages is not checked.
1537 */
1538 vm_fault_t (*fault)(const struct vm_special_mapping *sm,
1539 struct vm_area_struct *vma,
1540 struct vm_fault *vmf);
1541
1542 int (*mremap)(const struct vm_special_mapping *sm,
1543 struct vm_area_struct *new_vma);
1544
1545 void (*close)(const struct vm_special_mapping *sm,
1546 struct vm_area_struct *vma);
1547};
1548
1549enum tlb_flush_reason {
1550 TLB_FLUSH_ON_TASK_SWITCH,
1551 TLB_REMOTE_SHOOTDOWN,
1552 TLB_LOCAL_SHOOTDOWN,
1553 TLB_LOCAL_MM_SHOOTDOWN,
1554 TLB_REMOTE_SEND_IPI,
1555 TLB_REMOTE_WRONG_CPU,
1556 NR_TLB_FLUSH_REASONS,
1557};
1558
1559/**
1560 * enum fault_flag - Fault flag definitions.
1561 * @FAULT_FLAG_WRITE: Fault was a write fault.
1562 * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE.
1563 * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked.
1564 * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_lock and wait when retrying.
1565 * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region.
1566 * @FAULT_FLAG_TRIED: The fault has been tried once.
1567 * @FAULT_FLAG_USER: The fault originated in userspace.
1568 * @FAULT_FLAG_REMOTE: The fault is not for current task/mm.
1569 * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch.
1570 * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals.
1571 * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to break COW in a
1572 * COW mapping, making sure that an exclusive anon page is
1573 * mapped after the fault.
1574 * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached.
1575 * We should only access orig_pte if this flag set.
1576 * @FAULT_FLAG_VMA_LOCK: The fault is handled under VMA lock.
1577 *
1578 * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify
1579 * whether we would allow page faults to retry by specifying these two
1580 * fault flags correctly. Currently there can be three legal combinations:
1581 *
1582 * (a) ALLOW_RETRY and !TRIED: this means the page fault allows retry, and
1583 * this is the first try
1584 *
1585 * (b) ALLOW_RETRY and TRIED: this means the page fault allows retry, and
1586 * we've already tried at least once
1587 *
1588 * (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry
1589 *
1590 * The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never
1591 * be used. Note that page faults can be allowed to retry for multiple times,
1592 * in which case we'll have an initial fault with flags (a) then later on
1593 * continuous faults with flags (b). We should always try to detect pending
1594 * signals before a retry to make sure the continuous page faults can still be
1595 * interrupted if necessary.
1596 *
1597 * The combination FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE is illegal.
1598 * FAULT_FLAG_UNSHARE is ignored and treated like an ordinary read fault when
1599 * applied to mappings that are not COW mappings.
1600 */
1601enum fault_flag {
1602 FAULT_FLAG_WRITE = 1 << 0,
1603 FAULT_FLAG_MKWRITE = 1 << 1,
1604 FAULT_FLAG_ALLOW_RETRY = 1 << 2,
1605 FAULT_FLAG_RETRY_NOWAIT = 1 << 3,
1606 FAULT_FLAG_KILLABLE = 1 << 4,
1607 FAULT_FLAG_TRIED = 1 << 5,
1608 FAULT_FLAG_USER = 1 << 6,
1609 FAULT_FLAG_REMOTE = 1 << 7,
1610 FAULT_FLAG_INSTRUCTION = 1 << 8,
1611 FAULT_FLAG_INTERRUPTIBLE = 1 << 9,
1612 FAULT_FLAG_UNSHARE = 1 << 10,
1613 FAULT_FLAG_ORIG_PTE_VALID = 1 << 11,
1614 FAULT_FLAG_VMA_LOCK = 1 << 12,
1615};
1616
1617typedef unsigned int __bitwise zap_flags_t;
1618
1619/* Flags for clear_young_dirty_ptes(). */
1620typedef int __bitwise cydp_t;
1621
1622/* Clear the access bit */
1623#define CYDP_CLEAR_YOUNG ((__force cydp_t)BIT(0))
1624
1625/* Clear the dirty bit */
1626#define CYDP_CLEAR_DIRTY ((__force cydp_t)BIT(1))
1627
1628/*
1629 * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each
1630 * other. Here is what they mean, and how to use them:
1631 *
1632 *
1633 * FIXME: For pages which are part of a filesystem, mappings are subject to the
1634 * lifetime enforced by the filesystem and we need guarantees that longterm
1635 * users like RDMA and V4L2 only establish mappings which coordinate usage with
1636 * the filesystem. Ideas for this coordination include revoking the longterm
1637 * pin, delaying writeback, bounce buffer page writeback, etc. As FS DAX was
1638 * added after the problem with filesystems was found FS DAX VMAs are
1639 * specifically failed. Filesystem pages are still subject to bugs and use of
1640 * FOLL_LONGTERM should be avoided on those pages.
1641 *
1642 * In the CMA case: long term pins in a CMA region would unnecessarily fragment
1643 * that region. And so, CMA attempts to migrate the page before pinning, when
1644 * FOLL_LONGTERM is specified.
1645 *
1646 * FOLL_PIN indicates that a special kind of tracking (not just page->_refcount,
1647 * but an additional pin counting system) will be invoked. This is intended for
1648 * anything that gets a page reference and then touches page data (for example,
1649 * Direct IO). This lets the filesystem know that some non-file-system entity is
1650 * potentially changing the pages' data. In contrast to FOLL_GET (whose pages
1651 * are released via put_page()), FOLL_PIN pages must be released, ultimately, by
1652 * a call to unpin_user_page().
1653 *
1654 * FOLL_PIN is similar to FOLL_GET: both of these pin pages. They use different
1655 * and separate refcounting mechanisms, however, and that means that each has
1656 * its own acquire and release mechanisms:
1657 *
1658 * FOLL_GET: get_user_pages*() to acquire, and put_page() to release.
1659 *
1660 * FOLL_PIN: pin_user_pages*() to acquire, and unpin_user_pages to release.
1661 *
1662 * FOLL_PIN and FOLL_GET are mutually exclusive for a given function call.
1663 * (The underlying pages may experience both FOLL_GET-based and FOLL_PIN-based
1664 * calls applied to them, and that's perfectly OK. This is a constraint on the
1665 * callers, not on the pages.)
1666 *
1667 * FOLL_PIN should be set internally by the pin_user_pages*() APIs, never
1668 * directly by the caller. That's in order to help avoid mismatches when
1669 * releasing pages: get_user_pages*() pages must be released via put_page(),
1670 * while pin_user_pages*() pages must be released via unpin_user_page().
1671 *
1672 * Please see Documentation/core-api/pin_user_pages.rst for more information.
1673 */
1674
1675enum {
1676 /* check pte is writable */
1677 FOLL_WRITE = 1 << 0,
1678 /* do get_page on page */
1679 FOLL_GET = 1 << 1,
1680 /* give error on hole if it would be zero */
1681 FOLL_DUMP = 1 << 2,
1682 /* get_user_pages read/write w/o permission */
1683 FOLL_FORCE = 1 << 3,
1684 /*
1685 * if a disk transfer is needed, start the IO and return without waiting
1686 * upon it
1687 */
1688 FOLL_NOWAIT = 1 << 4,
1689 /* do not fault in pages */
1690 FOLL_NOFAULT = 1 << 5,
1691 /* check page is hwpoisoned */
1692 FOLL_HWPOISON = 1 << 6,
1693 /* don't do file mappings */
1694 FOLL_ANON = 1 << 7,
1695 /*
1696 * FOLL_LONGTERM indicates that the page will be held for an indefinite
1697 * time period _often_ under userspace control. This is in contrast to
1698 * iov_iter_get_pages(), whose usages are transient.
1699 */
1700 FOLL_LONGTERM = 1 << 8,
1701 /* split huge pmd before returning */
1702 FOLL_SPLIT_PMD = 1 << 9,
1703 /* allow returning PCI P2PDMA pages */
1704 FOLL_PCI_P2PDMA = 1 << 10,
1705 /* allow interrupts from generic signals */
1706 FOLL_INTERRUPTIBLE = 1 << 11,
1707 /*
1708 * Always honor (trigger) NUMA hinting faults.
1709 *
1710 * FOLL_WRITE implicitly honors NUMA hinting faults because a
1711 * PROT_NONE-mapped page is not writable (exceptions with FOLL_FORCE
1712 * apply). get_user_pages_fast_only() always implicitly honors NUMA
1713 * hinting faults.
1714 */
1715 FOLL_HONOR_NUMA_FAULT = 1 << 12,
1716
1717 /* See also internal only FOLL flags in mm/internal.h */
1718};
1719
1720/* mm flags */
1721
1722/*
1723 * The first two bits represent core dump modes for set-user-ID,
1724 * the modes are SUID_DUMP_* defined in linux/sched/coredump.h
1725 */
1726#define MMF_DUMPABLE_BITS 2
1727#define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
1728/* coredump filter bits */
1729#define MMF_DUMP_ANON_PRIVATE 2
1730#define MMF_DUMP_ANON_SHARED 3
1731#define MMF_DUMP_MAPPED_PRIVATE 4
1732#define MMF_DUMP_MAPPED_SHARED 5
1733#define MMF_DUMP_ELF_HEADERS 6
1734#define MMF_DUMP_HUGETLB_PRIVATE 7
1735#define MMF_DUMP_HUGETLB_SHARED 8
1736#define MMF_DUMP_DAX_PRIVATE 9
1737#define MMF_DUMP_DAX_SHARED 10
1738
1739#define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS
1740#define MMF_DUMP_FILTER_BITS 9
1741#define MMF_DUMP_FILTER_MASK \
1742 (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
1743#define MMF_DUMP_FILTER_DEFAULT \
1744 ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\
1745 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
1746
1747#ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
1748# define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS)
1749#else
1750# define MMF_DUMP_MASK_DEFAULT_ELF 0
1751#endif
1752 /* leave room for more dump flags */
1753#define MMF_VM_MERGEABLE 16 /* KSM may merge identical pages */
1754#define MMF_VM_HUGEPAGE 17 /* set when mm is available for khugepaged */
1755
1756/*
1757 * This one-shot flag is dropped due to necessity of changing exe once again
1758 * on NFS restore
1759 */
1760//#define MMF_EXE_FILE_CHANGED 18 /* see prctl_set_mm_exe_file() */
1761
1762#define MMF_HAS_UPROBES 19 /* has uprobes */
1763#define MMF_RECALC_UPROBES 20 /* MMF_HAS_UPROBES can be wrong */
1764#define MMF_OOM_SKIP 21 /* mm is of no interest for the OOM killer */
1765#define MMF_UNSTABLE 22 /* mm is unstable for copy_from_user */
1766#define MMF_HUGE_ZERO_PAGE 23 /* mm has ever used the global huge zero page */
1767#define MMF_DISABLE_THP 24 /* disable THP for all VMAs */
1768#define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)
1769#define MMF_OOM_REAP_QUEUED 25 /* mm was queued for oom_reaper */
1770#define MMF_MULTIPROCESS 26 /* mm is shared between processes */
1771/*
1772 * MMF_HAS_PINNED: Whether this mm has pinned any pages. This can be either
1773 * replaced in the future by mm.pinned_vm when it becomes stable, or grow into
1774 * a counter on its own. We're aggresive on this bit for now: even if the
1775 * pinned pages were unpinned later on, we'll still keep this bit set for the
1776 * lifecycle of this mm, just for simplicity.
1777 */
1778#define MMF_HAS_PINNED 27 /* FOLL_PIN has run, never cleared */
1779
1780#define MMF_HAS_MDWE 28
1781#define MMF_HAS_MDWE_MASK (1 << MMF_HAS_MDWE)
1782
1783
1784#define MMF_HAS_MDWE_NO_INHERIT 29
1785
1786#define MMF_VM_MERGE_ANY 30
1787#define MMF_VM_MERGE_ANY_MASK (1 << MMF_VM_MERGE_ANY)
1788
1789#define MMF_TOPDOWN 31 /* mm searches top down by default */
1790#define MMF_TOPDOWN_MASK (1 << MMF_TOPDOWN)
1791
1792#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\
1793 MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\
1794 MMF_VM_MERGE_ANY_MASK | MMF_TOPDOWN_MASK)
1795
1796static inline unsigned long mmf_init_flags(unsigned long flags)
1797{
1798 if (flags & (1UL << MMF_HAS_MDWE_NO_INHERIT))
1799 flags &= ~((1UL << MMF_HAS_MDWE) |
1800 (1UL << MMF_HAS_MDWE_NO_INHERIT));
1801 return flags & MMF_INIT_MASK;
1802}
1803
1804#endif /* _LINUX_MM_TYPES_H */