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