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