Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_MM_TYPES_H
3#define _LINUX_MM_TYPES_H
4
5#include <linux/mm_types_task.h>
6
7#include <linux/auxvec.h>
8#include <linux/kref.h>
9#include <linux/list.h>
10#include <linux/spinlock.h>
11#include <linux/rbtree.h>
12#include <linux/rwsem.h>
13#include <linux/completion.h>
14#include <linux/cpumask.h>
15#include <linux/uprobes.h>
16#include <linux/rcupdate.h>
17#include <linux/page-flags-layout.h>
18#include <linux/workqueue.h>
19#include <linux/seqlock.h>
20
21#include <asm/mmu.h>
22
23#ifndef AT_VECTOR_SIZE_ARCH
24#define AT_VECTOR_SIZE_ARCH 0
25#endif
26#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
27
28#define INIT_PASID 0
29
30struct address_space;
31struct mem_cgroup;
32
33/*
34 * Each physical page in the system has a struct page associated with
35 * it to keep track of whatever it is we are using the page for at the
36 * moment. Note that we have no way to track which tasks are using
37 * a page, though if it is a pagecache page, rmap structures can tell us
38 * who is mapping it.
39 *
40 * If you allocate the page using alloc_pages(), you can use some of the
41 * space in struct page for your own purposes. The five words in the main
42 * union are available, except for bit 0 of the first word which must be
43 * kept clear. Many users use this word to store a pointer to an object
44 * which is guaranteed to be aligned. If you use the same storage as
45 * page->mapping, you must restore it to NULL before freeing the page.
46 *
47 * If your page will not be mapped to userspace, you can also use the four
48 * bytes in the mapcount union, but you must call page_mapcount_reset()
49 * before freeing it.
50 *
51 * If you want to use the refcount field, it must be used in such a way
52 * that other CPUs temporarily incrementing and then decrementing the
53 * refcount does not cause problems. On receiving the page from
54 * alloc_pages(), the refcount will be positive.
55 *
56 * If you allocate pages of order > 0, you can use some of the fields
57 * in each subpage, but you may need to restore some of their values
58 * afterwards.
59 *
60 * SLUB uses cmpxchg_double() to atomically update its freelist and counters.
61 * That requires that freelist & counters in struct slab be adjacent and
62 * double-word aligned. Because struct slab currently just reinterprets the
63 * bits of struct page, we align all struct pages to double-word boundaries,
64 * and ensure that 'freelist' is aligned within struct slab.
65 */
66#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
67#define _struct_page_alignment __aligned(2 * sizeof(unsigned long))
68#else
69#define _struct_page_alignment
70#endif
71
72struct page {
73 unsigned long flags; /* Atomic flags, some possibly
74 * updated asynchronously */
75 /*
76 * Five words (20/40 bytes) are available in this union.
77 * WARNING: bit 0 of the first word is used for PageTail(). That
78 * means the other users of this union MUST NOT use the bit to
79 * avoid collision and false-positive PageTail().
80 */
81 union {
82 struct { /* Page cache and anonymous pages */
83 /**
84 * @lru: Pageout list, eg. active_list protected by
85 * lruvec->lru_lock. Sometimes used as a generic list
86 * by the page owner.
87 */
88 union {
89 struct list_head lru;
90 /* Or, for the Unevictable "LRU list" slot */
91 struct {
92 /* Always even, to negate PageTail */
93 void *__filler;
94 /* Count page's or folio's mlocks */
95 unsigned int mlock_count;
96 };
97 };
98 /* See page-flags.h for PAGE_MAPPING_FLAGS */
99 struct address_space *mapping;
100 pgoff_t index; /* Our offset within mapping. */
101 /**
102 * @private: Mapping-private opaque data.
103 * Usually used for buffer_heads if PagePrivate.
104 * Used for swp_entry_t if PageSwapCache.
105 * Indicates order in the buddy system if PageBuddy.
106 */
107 unsigned long private;
108 };
109 struct { /* page_pool used by netstack */
110 /**
111 * @pp_magic: magic value to avoid recycling non
112 * page_pool allocated pages.
113 */
114 unsigned long pp_magic;
115 struct page_pool *pp;
116 unsigned long _pp_mapping_pad;
117 unsigned long dma_addr;
118 union {
119 /**
120 * dma_addr_upper: might require a 64-bit
121 * value on 32-bit architectures.
122 */
123 unsigned long dma_addr_upper;
124 /**
125 * For frag page support, not supported in
126 * 32-bit architectures with 64-bit DMA.
127 */
128 atomic_long_t pp_frag_count;
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 atomic_t compound_pincount;
139#ifdef CONFIG_64BIT
140 unsigned int compound_nr; /* 1 << compound_order */
141#endif
142 };
143 struct { /* Second tail page of compound page */
144 unsigned long _compound_pad_1; /* compound_head */
145 unsigned long _compound_pad_2;
146 /* For both global and memcg */
147 struct list_head deferred_list;
148 };
149 struct { /* Page table pages */
150 unsigned long _pt_pad_1; /* compound_head */
151 pgtable_t pmd_huge_pte; /* protected by page->ptl */
152 unsigned long _pt_pad_2; /* mapping */
153 union {
154 struct mm_struct *pt_mm; /* x86 pgds only */
155 atomic_t pt_frag_refcount; /* powerpc */
156 };
157#if ALLOC_SPLIT_PTLOCKS
158 spinlock_t *ptl;
159#else
160 spinlock_t ptl;
161#endif
162 };
163 struct { /* ZONE_DEVICE pages */
164 /** @pgmap: Points to the hosting device page map. */
165 struct dev_pagemap *pgmap;
166 void *zone_device_data;
167 /*
168 * ZONE_DEVICE private pages are counted as being
169 * mapped so the next 3 words hold the mapping, index,
170 * and private fields from the source anonymous or
171 * page cache page while the page is migrated to device
172 * private memory.
173 * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also
174 * use the mapping, index, and private fields when
175 * pmem backed DAX files are mapped.
176 */
177 };
178
179 /** @rcu_head: You can use this to free a page by RCU. */
180 struct rcu_head rcu_head;
181 };
182
183 union { /* This union is 4 bytes in size. */
184 /*
185 * If the page can be mapped to userspace, encodes the number
186 * of times this page is referenced by a page table.
187 */
188 atomic_t _mapcount;
189
190 /*
191 * If the page is neither PageSlab nor mappable to userspace,
192 * the value stored here may help determine what this page
193 * is used for. See page-flags.h for a list of page types
194 * which are currently stored here.
195 */
196 unsigned int page_type;
197 };
198
199 /* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */
200 atomic_t _refcount;
201
202#ifdef CONFIG_MEMCG
203 unsigned long memcg_data;
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
226/**
227 * struct folio - Represents a contiguous set of bytes.
228 * @flags: Identical to the page flags.
229 * @lru: Least Recently Used list; tracks how recently this folio was used.
230 * @mapping: The file this page belongs to, or refers to the anon_vma for
231 * anonymous memory.
232 * @index: Offset within the file, in units of pages. For anonymous memory,
233 * this is the index from the beginning of the mmap.
234 * @private: Filesystem per-folio data (see folio_attach_private()).
235 * Used for swp_entry_t if folio_test_swapcache().
236 * @_mapcount: Do not access this member directly. Use folio_mapcount() to
237 * find out how many times this folio is mapped by userspace.
238 * @_refcount: Do not access this member directly. Use folio_ref_count()
239 * to find how many references there are to this folio.
240 * @memcg_data: Memory Control Group data.
241 *
242 * A folio is a physically, virtually and logically contiguous set
243 * of bytes. It is a power-of-two in size, and it is aligned to that
244 * same power-of-two. It is at least as large as %PAGE_SIZE. If it is
245 * in the page cache, it is at a file offset which is a multiple of that
246 * power-of-two. It may be mapped into userspace at an address which is
247 * at an arbitrary page offset, but its kernel virtual address is aligned
248 * to its size.
249 */
250struct folio {
251 /* private: don't document the anon union */
252 union {
253 struct {
254 /* public: */
255 unsigned long flags;
256 union {
257 struct list_head lru;
258 struct {
259 void *__filler;
260 unsigned int mlock_count;
261 };
262 };
263 struct address_space *mapping;
264 pgoff_t index;
265 void *private;
266 atomic_t _mapcount;
267 atomic_t _refcount;
268#ifdef CONFIG_MEMCG
269 unsigned long memcg_data;
270#endif
271 /* private: the union with struct page is transitional */
272 };
273 struct page page;
274 };
275};
276
277static_assert(sizeof(struct page) == sizeof(struct folio));
278#define FOLIO_MATCH(pg, fl) \
279 static_assert(offsetof(struct page, pg) == offsetof(struct folio, fl))
280FOLIO_MATCH(flags, flags);
281FOLIO_MATCH(lru, lru);
282FOLIO_MATCH(mapping, mapping);
283FOLIO_MATCH(compound_head, lru);
284FOLIO_MATCH(index, index);
285FOLIO_MATCH(private, private);
286FOLIO_MATCH(_mapcount, _mapcount);
287FOLIO_MATCH(_refcount, _refcount);
288#ifdef CONFIG_MEMCG
289FOLIO_MATCH(memcg_data, memcg_data);
290#endif
291#undef FOLIO_MATCH
292
293static inline atomic_t *folio_mapcount_ptr(struct folio *folio)
294{
295 struct page *tail = &folio->page + 1;
296 return &tail->compound_mapcount;
297}
298
299static inline atomic_t *compound_mapcount_ptr(struct page *page)
300{
301 return &page[1].compound_mapcount;
302}
303
304static inline atomic_t *compound_pincount_ptr(struct page *page)
305{
306 return &page[1].compound_pincount;
307}
308
309/*
310 * Used for sizing the vmemmap region on some architectures
311 */
312#define STRUCT_PAGE_MAX_SHIFT (order_base_2(sizeof(struct page)))
313
314#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
315#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
316
317/*
318 * page_private can be used on tail pages. However, PagePrivate is only
319 * checked by the VM on the head page. So page_private on the tail pages
320 * should be used for data that's ancillary to the head page (eg attaching
321 * buffer heads to tail pages after attaching buffer heads to the head page)
322 */
323#define page_private(page) ((page)->private)
324
325static inline void set_page_private(struct page *page, unsigned long private)
326{
327 page->private = private;
328}
329
330static inline void *folio_get_private(struct folio *folio)
331{
332 return folio->private;
333}
334
335struct page_frag_cache {
336 void * va;
337#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
338 __u16 offset;
339 __u16 size;
340#else
341 __u32 offset;
342#endif
343 /* we maintain a pagecount bias, so that we dont dirty cache line
344 * containing page->_refcount every time we allocate a fragment.
345 */
346 unsigned int pagecnt_bias;
347 bool pfmemalloc;
348};
349
350typedef unsigned long vm_flags_t;
351
352/*
353 * A region containing a mapping of a non-memory backed file under NOMMU
354 * conditions. These are held in a global tree and are pinned by the VMAs that
355 * map parts of them.
356 */
357struct vm_region {
358 struct rb_node vm_rb; /* link in global region tree */
359 vm_flags_t vm_flags; /* VMA vm_flags */
360 unsigned long vm_start; /* start address of region */
361 unsigned long vm_end; /* region initialised to here */
362 unsigned long vm_top; /* region allocated to here */
363 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
364 struct file *vm_file; /* the backing file or NULL */
365
366 int vm_usage; /* region usage count (access under nommu_region_sem) */
367 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
368 * this region */
369};
370
371#ifdef CONFIG_USERFAULTFD
372#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
373struct vm_userfaultfd_ctx {
374 struct userfaultfd_ctx *ctx;
375};
376#else /* CONFIG_USERFAULTFD */
377#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
378struct vm_userfaultfd_ctx {};
379#endif /* CONFIG_USERFAULTFD */
380
381struct anon_vma_name {
382 struct kref kref;
383 /* The name needs to be at the end because it is dynamically sized. */
384 char name[];
385};
386
387/*
388 * This struct describes a virtual memory area. There is one of these
389 * per VM-area/task. A VM area is any part of the process virtual memory
390 * space that has a special rule for the page-fault handlers (ie a shared
391 * library, the executable area etc).
392 */
393struct vm_area_struct {
394 /* The first cache line has the info for VMA tree walking. */
395
396 unsigned long vm_start; /* Our start address within vm_mm. */
397 unsigned long vm_end; /* The first byte after our end address
398 within vm_mm. */
399
400 /* linked list of VM areas per task, sorted by address */
401 struct vm_area_struct *vm_next, *vm_prev;
402
403 struct rb_node vm_rb;
404
405 /*
406 * Largest free memory gap in bytes to the left of this VMA.
407 * Either between this VMA and vma->vm_prev, or between one of the
408 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
409 * get_unmapped_area find a free area of the right size.
410 */
411 unsigned long rb_subtree_gap;
412
413 /* Second cache line starts here. */
414
415 struct mm_struct *vm_mm; /* The address space we belong to. */
416
417 /*
418 * Access permissions of this VMA.
419 * See vmf_insert_mixed_prot() for discussion.
420 */
421 pgprot_t vm_page_prot;
422 unsigned long vm_flags; /* Flags, see mm.h. */
423
424 /*
425 * For areas with an address space and backing store,
426 * linkage into the address_space->i_mmap interval tree.
427 *
428 * For private anonymous mappings, a pointer to a null terminated string
429 * containing the name given to the vma, or NULL if unnamed.
430 */
431
432 union {
433 struct {
434 struct rb_node rb;
435 unsigned long rb_subtree_last;
436 } shared;
437 /*
438 * Serialized by mmap_sem. Never use directly because it is
439 * valid only when vm_file is NULL. Use anon_vma_name instead.
440 */
441 struct anon_vma_name *anon_name;
442 };
443
444 /*
445 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
446 * list, after a COW of one of the file pages. A MAP_SHARED vma
447 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
448 * or brk vma (with NULL file) can only be in an anon_vma list.
449 */
450 struct list_head anon_vma_chain; /* Serialized by mmap_lock &
451 * page_table_lock */
452 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
453
454 /* Function pointers to deal with this struct. */
455 const struct vm_operations_struct *vm_ops;
456
457 /* Information about our backing store: */
458 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
459 units */
460 struct file * vm_file; /* File we map to (can be NULL). */
461 void * vm_private_data; /* was vm_pte (shared mem) */
462
463#ifdef CONFIG_SWAP
464 atomic_long_t swap_readahead_info;
465#endif
466#ifndef CONFIG_MMU
467 struct vm_region *vm_region; /* NOMMU mapping region */
468#endif
469#ifdef CONFIG_NUMA
470 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
471#endif
472 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
473} __randomize_layout;
474
475struct kioctx_table;
476struct mm_struct {
477 struct {
478 struct vm_area_struct *mmap; /* list of VMAs */
479 struct rb_root mm_rb;
480 u64 vmacache_seqnum; /* per-thread vmacache */
481#ifdef CONFIG_MMU
482 unsigned long (*get_unmapped_area) (struct file *filp,
483 unsigned long addr, unsigned long len,
484 unsigned long pgoff, unsigned long flags);
485#endif
486 unsigned long mmap_base; /* base of mmap area */
487 unsigned long mmap_legacy_base; /* base of mmap area in bottom-up allocations */
488#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
489 /* Base addresses for compatible mmap() */
490 unsigned long mmap_compat_base;
491 unsigned long mmap_compat_legacy_base;
492#endif
493 unsigned long task_size; /* size of task vm space */
494 unsigned long highest_vm_end; /* highest vma end address */
495 pgd_t * pgd;
496
497#ifdef CONFIG_MEMBARRIER
498 /**
499 * @membarrier_state: Flags controlling membarrier behavior.
500 *
501 * This field is close to @pgd to hopefully fit in the same
502 * cache-line, which needs to be touched by switch_mm().
503 */
504 atomic_t membarrier_state;
505#endif
506
507 /**
508 * @mm_users: The number of users including userspace.
509 *
510 * Use mmget()/mmget_not_zero()/mmput() to modify. When this
511 * drops to 0 (i.e. when the task exits and there are no other
512 * temporary reference holders), we also release a reference on
513 * @mm_count (which may then free the &struct mm_struct if
514 * @mm_count also drops to 0).
515 */
516 atomic_t mm_users;
517
518 /**
519 * @mm_count: The number of references to &struct mm_struct
520 * (@mm_users count as 1).
521 *
522 * Use mmgrab()/mmdrop() to modify. When this drops to 0, the
523 * &struct mm_struct is freed.
524 */
525 atomic_t mm_count;
526
527#ifdef CONFIG_MMU
528 atomic_long_t pgtables_bytes; /* PTE page table pages */
529#endif
530 int map_count; /* number of VMAs */
531
532 spinlock_t page_table_lock; /* Protects page tables and some
533 * counters
534 */
535 /*
536 * With some kernel config, the current mmap_lock's offset
537 * inside 'mm_struct' is at 0x120, which is very optimal, as
538 * its two hot fields 'count' and 'owner' sit in 2 different
539 * cachelines, and when mmap_lock is highly contended, both
540 * of the 2 fields will be accessed frequently, current layout
541 * will help to reduce cache bouncing.
542 *
543 * So please be careful with adding new fields before
544 * mmap_lock, which can easily push the 2 fields into one
545 * cacheline.
546 */
547 struct rw_semaphore mmap_lock;
548
549 struct list_head mmlist; /* List of maybe swapped mm's. These
550 * are globally strung together off
551 * init_mm.mmlist, and are protected
552 * by mmlist_lock
553 */
554
555
556 unsigned long hiwater_rss; /* High-watermark of RSS usage */
557 unsigned long hiwater_vm; /* High-water virtual memory usage */
558
559 unsigned long total_vm; /* Total pages mapped */
560 unsigned long locked_vm; /* Pages that have PG_mlocked set */
561 atomic64_t pinned_vm; /* Refcount permanently increased */
562 unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
563 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
564 unsigned long stack_vm; /* VM_STACK */
565 unsigned long def_flags;
566
567 /**
568 * @write_protect_seq: Locked when any thread is write
569 * protecting pages mapped by this mm to enforce a later COW,
570 * for instance during page table copying for fork().
571 */
572 seqcount_t write_protect_seq;
573
574 spinlock_t arg_lock; /* protect the below fields */
575
576 unsigned long start_code, end_code, start_data, end_data;
577 unsigned long start_brk, brk, start_stack;
578 unsigned long arg_start, arg_end, env_start, env_end;
579
580 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
581
582 /*
583 * Special counters, in some configurations protected by the
584 * page_table_lock, in other configurations by being atomic.
585 */
586 struct mm_rss_stat rss_stat;
587
588 struct linux_binfmt *binfmt;
589
590 /* Architecture-specific MM context */
591 mm_context_t context;
592
593 unsigned long flags; /* Must use atomic bitops to access */
594
595#ifdef CONFIG_AIO
596 spinlock_t ioctx_lock;
597 struct kioctx_table __rcu *ioctx_table;
598#endif
599#ifdef CONFIG_MEMCG
600 /*
601 * "owner" points to a task that is regarded as the canonical
602 * user/owner of this mm. All of the following must be true in
603 * order for it to be changed:
604 *
605 * current == mm->owner
606 * current->mm != mm
607 * new_owner->mm == mm
608 * new_owner->alloc_lock is held
609 */
610 struct task_struct __rcu *owner;
611#endif
612 struct user_namespace *user_ns;
613
614 /* store ref to file /proc/<pid>/exe symlink points to */
615 struct file __rcu *exe_file;
616#ifdef CONFIG_MMU_NOTIFIER
617 struct mmu_notifier_subscriptions *notifier_subscriptions;
618#endif
619#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
620 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
621#endif
622#ifdef CONFIG_NUMA_BALANCING
623 /*
624 * numa_next_scan is the next time that the PTEs will be marked
625 * pte_numa. NUMA hinting faults will gather statistics and
626 * migrate pages to new nodes if necessary.
627 */
628 unsigned long numa_next_scan;
629
630 /* Restart point for scanning and setting pte_numa */
631 unsigned long numa_scan_offset;
632
633 /* numa_scan_seq prevents two threads setting pte_numa */
634 int numa_scan_seq;
635#endif
636 /*
637 * An operation with batched TLB flushing is going on. Anything
638 * that can move process memory needs to flush the TLB when
639 * moving a PROT_NONE or PROT_NUMA mapped page.
640 */
641 atomic_t tlb_flush_pending;
642#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
643 /* See flush_tlb_batched_pending() */
644 atomic_t tlb_flush_batched;
645#endif
646 struct uprobes_state uprobes_state;
647#ifdef CONFIG_PREEMPT_RT
648 struct rcu_head delayed_drop;
649#endif
650#ifdef CONFIG_HUGETLB_PAGE
651 atomic_long_t hugetlb_usage;
652#endif
653 struct work_struct async_put_work;
654
655#ifdef CONFIG_IOMMU_SVA
656 u32 pasid;
657#endif
658 } __randomize_layout;
659
660 /*
661 * The mm_cpumask needs to be at the end of mm_struct, because it
662 * is dynamically sized based on nr_cpu_ids.
663 */
664 unsigned long cpu_bitmap[];
665};
666
667extern struct mm_struct init_mm;
668
669/* Pointer magic because the dynamic array size confuses some compilers. */
670static inline void mm_init_cpumask(struct mm_struct *mm)
671{
672 unsigned long cpu_bitmap = (unsigned long)mm;
673
674 cpu_bitmap += offsetof(struct mm_struct, cpu_bitmap);
675 cpumask_clear((struct cpumask *)cpu_bitmap);
676}
677
678/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
679static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
680{
681 return (struct cpumask *)&mm->cpu_bitmap;
682}
683
684struct mmu_gather;
685extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm);
686extern void tlb_gather_mmu_fullmm(struct mmu_gather *tlb, struct mm_struct *mm);
687extern void tlb_finish_mmu(struct mmu_gather *tlb);
688
689struct vm_fault;
690
691/**
692 * typedef vm_fault_t - Return type for page fault handlers.
693 *
694 * Page fault handlers return a bitmask of %VM_FAULT values.
695 */
696typedef __bitwise unsigned int vm_fault_t;
697
698/**
699 * enum vm_fault_reason - Page fault handlers return a bitmask of
700 * these values to tell the core VM what happened when handling the
701 * fault. Used to decide whether a process gets delivered SIGBUS or
702 * just gets major/minor fault counters bumped up.
703 *
704 * @VM_FAULT_OOM: Out Of Memory
705 * @VM_FAULT_SIGBUS: Bad access
706 * @VM_FAULT_MAJOR: Page read from storage
707 * @VM_FAULT_WRITE: Special case for get_user_pages
708 * @VM_FAULT_HWPOISON: Hit poisoned small page
709 * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
710 * in upper bits
711 * @VM_FAULT_SIGSEGV: segmentation fault
712 * @VM_FAULT_NOPAGE: ->fault installed the pte, not return page
713 * @VM_FAULT_LOCKED: ->fault locked the returned page
714 * @VM_FAULT_RETRY: ->fault blocked, must retry
715 * @VM_FAULT_FALLBACK: huge page fault failed, fall back to small
716 * @VM_FAULT_DONE_COW: ->fault has fully handled COW
717 * @VM_FAULT_NEEDDSYNC: ->fault did not modify page tables and needs
718 * fsync() to complete (for synchronous page faults
719 * in DAX)
720 * @VM_FAULT_HINDEX_MASK: mask HINDEX value
721 *
722 */
723enum vm_fault_reason {
724 VM_FAULT_OOM = (__force vm_fault_t)0x000001,
725 VM_FAULT_SIGBUS = (__force vm_fault_t)0x000002,
726 VM_FAULT_MAJOR = (__force vm_fault_t)0x000004,
727 VM_FAULT_WRITE = (__force vm_fault_t)0x000008,
728 VM_FAULT_HWPOISON = (__force vm_fault_t)0x000010,
729 VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
730 VM_FAULT_SIGSEGV = (__force vm_fault_t)0x000040,
731 VM_FAULT_NOPAGE = (__force vm_fault_t)0x000100,
732 VM_FAULT_LOCKED = (__force vm_fault_t)0x000200,
733 VM_FAULT_RETRY = (__force vm_fault_t)0x000400,
734 VM_FAULT_FALLBACK = (__force vm_fault_t)0x000800,
735 VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000,
736 VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000,
737 VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000,
738};
739
740/* Encode hstate index for a hwpoisoned large page */
741#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
742#define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
743
744#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \
745 VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \
746 VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
747
748#define VM_FAULT_RESULT_TRACE \
749 { VM_FAULT_OOM, "OOM" }, \
750 { VM_FAULT_SIGBUS, "SIGBUS" }, \
751 { VM_FAULT_MAJOR, "MAJOR" }, \
752 { VM_FAULT_WRITE, "WRITE" }, \
753 { VM_FAULT_HWPOISON, "HWPOISON" }, \
754 { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \
755 { VM_FAULT_SIGSEGV, "SIGSEGV" }, \
756 { VM_FAULT_NOPAGE, "NOPAGE" }, \
757 { VM_FAULT_LOCKED, "LOCKED" }, \
758 { VM_FAULT_RETRY, "RETRY" }, \
759 { VM_FAULT_FALLBACK, "FALLBACK" }, \
760 { VM_FAULT_DONE_COW, "DONE_COW" }, \
761 { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }
762
763struct vm_special_mapping {
764 const char *name; /* The name, e.g. "[vdso]". */
765
766 /*
767 * If .fault is not provided, this points to a
768 * NULL-terminated array of pages that back the special mapping.
769 *
770 * This must not be NULL unless .fault is provided.
771 */
772 struct page **pages;
773
774 /*
775 * If non-NULL, then this is called to resolve page faults
776 * on the special mapping. If used, .pages is not checked.
777 */
778 vm_fault_t (*fault)(const struct vm_special_mapping *sm,
779 struct vm_area_struct *vma,
780 struct vm_fault *vmf);
781
782 int (*mremap)(const struct vm_special_mapping *sm,
783 struct vm_area_struct *new_vma);
784};
785
786enum tlb_flush_reason {
787 TLB_FLUSH_ON_TASK_SWITCH,
788 TLB_REMOTE_SHOOTDOWN,
789 TLB_LOCAL_SHOOTDOWN,
790 TLB_LOCAL_MM_SHOOTDOWN,
791 TLB_REMOTE_SEND_IPI,
792 NR_TLB_FLUSH_REASONS,
793};
794
795 /*
796 * A swap entry has to fit into a "unsigned long", as the entry is hidden
797 * in the "index" field of the swapper address space.
798 */
799typedef struct {
800 unsigned long val;
801} swp_entry_t;
802
803/**
804 * enum fault_flag - Fault flag definitions.
805 * @FAULT_FLAG_WRITE: Fault was a write fault.
806 * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE.
807 * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked.
808 * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_lock and wait when retrying.
809 * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region.
810 * @FAULT_FLAG_TRIED: The fault has been tried once.
811 * @FAULT_FLAG_USER: The fault originated in userspace.
812 * @FAULT_FLAG_REMOTE: The fault is not for current task/mm.
813 * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch.
814 * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals.
815 *
816 * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify
817 * whether we would allow page faults to retry by specifying these two
818 * fault flags correctly. Currently there can be three legal combinations:
819 *
820 * (a) ALLOW_RETRY and !TRIED: this means the page fault allows retry, and
821 * this is the first try
822 *
823 * (b) ALLOW_RETRY and TRIED: this means the page fault allows retry, and
824 * we've already tried at least once
825 *
826 * (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry
827 *
828 * The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never
829 * be used. Note that page faults can be allowed to retry for multiple times,
830 * in which case we'll have an initial fault with flags (a) then later on
831 * continuous faults with flags (b). We should always try to detect pending
832 * signals before a retry to make sure the continuous page faults can still be
833 * interrupted if necessary.
834 */
835enum fault_flag {
836 FAULT_FLAG_WRITE = 1 << 0,
837 FAULT_FLAG_MKWRITE = 1 << 1,
838 FAULT_FLAG_ALLOW_RETRY = 1 << 2,
839 FAULT_FLAG_RETRY_NOWAIT = 1 << 3,
840 FAULT_FLAG_KILLABLE = 1 << 4,
841 FAULT_FLAG_TRIED = 1 << 5,
842 FAULT_FLAG_USER = 1 << 6,
843 FAULT_FLAG_REMOTE = 1 << 7,
844 FAULT_FLAG_INSTRUCTION = 1 << 8,
845 FAULT_FLAG_INTERRUPTIBLE = 1 << 9,
846};
847
848#endif /* _LINUX_MM_TYPES_H */