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