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