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