]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/mm_types.h
Merge tag 'fs.move_mount.move_mount_set_group.v5.15' of git://git.kernel.org/pub...
[mirror_ubuntu-jammy-kernel.git] / include / linux / mm_types.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
5b99cd0e
HC
2#ifndef _LINUX_MM_TYPES_H
3#define _LINUX_MM_TYPES_H
4
2e58f173
IM
5#include <linux/mm_types_task.h>
6
4f9a58d7 7#include <linux/auxvec.h>
5b99cd0e
HC
8#include <linux/list.h>
9#include <linux/spinlock.h>
c92ff1bd
MS
10#include <linux/rbtree.h>
11#include <linux/rwsem.h>
12#include <linux/completion.h>
cddb8a5c 13#include <linux/cpumask.h>
d4b3b638 14#include <linux/uprobes.h>
bbeae5b0 15#include <linux/page-flags-layout.h>
ec8d7c14 16#include <linux/workqueue.h>
57efa1fe 17#include <linux/seqlock.h>
2e58f173 18
c92ff1bd 19#include <asm/mmu.h>
5b99cd0e 20
4f9a58d7
OH
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
82e69a12 26#define INIT_PASID 0
1c8f4220 27
5b99cd0e 28struct address_space;
1306a85a 29struct mem_cgroup;
5b99cd0e
HC
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
97b4a671 36 * who is mapping it.
be50015d 37 *
97b4a671
MW
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.
be50015d 44 *
97b4a671
MW
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.
fc9bb8c7 57 *
4cf7c8bf
MW
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.
5b99cd0e 63 */
e20df2c6
MW
64#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
65#define _struct_page_alignment __aligned(2 * sizeof(unsigned long))
66#else
0dd4da5b 67#define _struct_page_alignment
7d27a04b 68#endif
e20df2c6 69
5b99cd0e
HC
70struct page {
71 unsigned long flags; /* Atomic flags, some possibly
72 * updated asynchronously */
b7ccc7f8 73 /*
4da1984e
MW
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
b7ccc7f8
MW
77 * avoid collision and false-positive PageTail().
78 */
8456a648 79 union {
66a6ffd2 80 struct { /* Page cache and anonymous pages */
4da1984e
MW
81 /**
82 * @lru: Pageout list, eg. active_list protected by
15b44736 83 * lruvec->lru_lock. Sometimes used as a generic list
4da1984e
MW
84 * by the page owner.
85 */
86 struct list_head lru;
66a6ffd2
MW
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 };
c25fff71 98 struct { /* page_pool used by netstack */
c07aea3e
MC
99 /**
100 * @pp_magic: magic value to avoid recycling non
101 * page_pool allocated pages.
102 */
103 unsigned long pp_magic;
104 struct page_pool *pp;
105 unsigned long _pp_mapping_pad;
c25fff71 106 /**
9ddb3c14 107 * @dma_addr: might require a 64-bit value on
c25fff71
JDB
108 * 32-bit architectures.
109 */
9ddb3c14 110 unsigned long dma_addr[2];
c25fff71 111 };
66a6ffd2 112 struct { /* slab, slob and slub */
4da1984e 113 union {
3e05617c 114 struct list_head slab_list;
4da1984e
MW
115 struct { /* Partial pages */
116 struct page *next;
117#ifdef CONFIG_64BIT
118 int pages; /* Nr of pages left */
119 int pobjects; /* Approximate count */
120#else
121 short int pages;
122 short int pobjects;
123#endif
124 };
125 };
66a6ffd2
MW
126 struct kmem_cache *slab_cache; /* not slob */
127 /* Double-word boundary */
128 void *freelist; /* first free object */
129 union {
130 void *s_mem; /* slab: first object */
131 unsigned long counters; /* SLUB */
132 struct { /* SLUB */
133 unsigned inuse:16;
134 unsigned objects:15;
135 unsigned frozen:1;
136 };
137 };
138 };
4da1984e
MW
139 struct { /* Tail pages of compound page */
140 unsigned long compound_head; /* Bit zero is set */
141
142 /* First tail page only */
143 unsigned char compound_dtor;
144 unsigned char compound_order;
145 atomic_t compound_mapcount;
1378a5ee 146 unsigned int compound_nr; /* 1 << compound_order */
4da1984e
MW
147 };
148 struct { /* Second tail page of compound page */
149 unsigned long _compound_pad_1; /* compound_head */
47e29d32 150 atomic_t hpage_pinned_refcount;
87eaceb3 151 /* For both global and memcg */
4da1984e
MW
152 struct list_head deferred_list;
153 };
66a6ffd2 154 struct { /* Page table pages */
4da1984e
MW
155 unsigned long _pt_pad_1; /* compound_head */
156 pgtable_t pmd_huge_pte; /* protected by page->ptl */
66a6ffd2 157 unsigned long _pt_pad_2; /* mapping */
4231aba0
NP
158 union {
159 struct mm_struct *pt_mm; /* x86 pgds only */
160 atomic_t pt_frag_refcount; /* powerpc */
161 };
7d27a04b 162#if ALLOC_SPLIT_PTLOCKS
66a6ffd2 163 spinlock_t *ptl;
7d27a04b 164#else
66a6ffd2 165 spinlock_t ptl;
7d27a04b 166#endif
7d27a04b 167 };
50e7fbc3
MW
168 struct { /* ZONE_DEVICE pages */
169 /** @pgmap: Points to the hosting device page map. */
170 struct dev_pagemap *pgmap;
8a164fef 171 void *zone_device_data;
76470ccd
RC
172 /*
173 * ZONE_DEVICE private pages are counted as being
174 * mapped so the next 3 words hold the mapping, index,
175 * and private fields from the source anonymous or
176 * page cache page while the page is migrated to device
177 * private memory.
178 * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also
179 * use the mapping, index, and private fields when
180 * pmem backed DAX files are mapped.
181 */
50e7fbc3 182 };
4da1984e
MW
183
184 /** @rcu_head: You can use this to free a page by RCU. */
185 struct rcu_head rcu_head;
7d27a04b
MW
186 };
187
b21999da
MW
188 union { /* This union is 4 bytes in size. */
189 /*
190 * If the page can be mapped to userspace, encodes the number
191 * of times this page is referenced by a page table.
192 */
193 atomic_t _mapcount;
194
6e292b9b
MW
195 /*
196 * If the page is neither PageSlab nor mappable to userspace,
197 * the value stored here may help determine what this page
198 * is used for. See page-flags.h for a list of page types
199 * which are currently stored here.
200 */
201 unsigned int page_type;
202
ca9c88c7 203 unsigned int active; /* SLAB */
ca9c88c7 204 int units; /* SLOB */
81819f0f 205 };
fc9bb8c7 206
b21999da
MW
207 /* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */
208 atomic_t _refcount;
209
1306a85a 210#ifdef CONFIG_MEMCG
bcfe06bf 211 unsigned long memcg_data;
1306a85a
JW
212#endif
213
5b99cd0e
HC
214 /*
215 * On machines where all RAM is mapped into kernel address space,
216 * we can simply calculate the virtual address. On machines with
217 * highmem some memory is mapped into kernel virtual memory
218 * dynamically, so we need a place to store that address.
219 * Note that this field could be 16 bits on x86 ... ;)
220 *
221 * Architectures with slow multiplication can define
222 * WANT_PAGE_VIRTUAL in asm/page.h
223 */
224#if defined(WANT_PAGE_VIRTUAL)
225 void *virtual; /* Kernel virtual address (NULL if
226 not kmapped, ie. highmem) */
227#endif /* WANT_PAGE_VIRTUAL */
dfec072e 228
90572890
PZ
229#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
230 int _last_cpupid;
57e0a030 231#endif
e20df2c6 232} _struct_page_alignment;
5b99cd0e 233
169226f7
YS
234static inline atomic_t *compound_mapcount_ptr(struct page *page)
235{
236 return &page[1].compound_mapcount;
237}
238
47e29d32
JH
239static inline atomic_t *compound_pincount_ptr(struct page *page)
240{
241 return &page[2].hpage_pinned_refcount;
242}
243
d1402fc7
LG
244/*
245 * Used for sizing the vmemmap region on some architectures
246 */
247#define STRUCT_PAGE_MAX_SHIFT (order_base_2(sizeof(struct page)))
248
b63ae8ca
AD
249#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
250#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
251
b03641af 252#define page_private(page) ((page)->private)
60e65a6f
GJ
253
254static inline void set_page_private(struct page *page, unsigned long private)
255{
256 page->private = private;
257}
b03641af 258
b63ae8ca
AD
259struct page_frag_cache {
260 void * va;
261#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
262 __u16 offset;
263 __u16 size;
264#else
265 __u32 offset;
266#endif
267 /* we maintain a pagecount bias, so that we dont dirty cache line
0139aa7b 268 * containing page->_refcount every time we allocate a fragment.
b63ae8ca
AD
269 */
270 unsigned int pagecnt_bias;
271 bool pfmemalloc;
272};
273
64b990d2 274typedef unsigned long vm_flags_t;
ca16d140 275
8feae131
DH
276/*
277 * A region containing a mapping of a non-memory backed file under NOMMU
278 * conditions. These are held in a global tree and are pinned by the VMAs that
279 * map parts of them.
280 */
281struct vm_region {
282 struct rb_node vm_rb; /* link in global region tree */
ca16d140 283 vm_flags_t vm_flags; /* VMA vm_flags */
8feae131
DH
284 unsigned long vm_start; /* start address of region */
285 unsigned long vm_end; /* region initialised to here */
dd8632a1 286 unsigned long vm_top; /* region allocated to here */
8feae131
DH
287 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
288 struct file *vm_file; /* the backing file or NULL */
289
1e2ae599 290 int vm_usage; /* region usage count (access under nommu_region_sem) */
cfe79c00
MF
291 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
292 * this region */
8feae131
DH
293};
294
745f234b
AA
295#ifdef CONFIG_USERFAULTFD
296#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
297struct vm_userfaultfd_ctx {
298 struct userfaultfd_ctx *ctx;
299};
300#else /* CONFIG_USERFAULTFD */
301#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
302struct vm_userfaultfd_ctx {};
303#endif /* CONFIG_USERFAULTFD */
304
c92ff1bd 305/*
552657b7 306 * This struct describes a virtual memory area. There is one of these
307 * per VM-area/task. A VM area is any part of the process virtual memory
c92ff1bd
MS
308 * space that has a special rule for the page-fault handlers (ie a shared
309 * library, the executable area etc).
310 */
311struct vm_area_struct {
e4c6bfd2
RR
312 /* The first cache line has the info for VMA tree walking. */
313
c92ff1bd
MS
314 unsigned long vm_start; /* Our start address within vm_mm. */
315 unsigned long vm_end; /* The first byte after our end address
316 within vm_mm. */
317
318 /* linked list of VM areas per task, sorted by address */
297c5eee 319 struct vm_area_struct *vm_next, *vm_prev;
c92ff1bd 320
c92ff1bd
MS
321 struct rb_node vm_rb;
322
d3737187
ML
323 /*
324 * Largest free memory gap in bytes to the left of this VMA.
325 * Either between this VMA and vma->vm_prev, or between one of the
326 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
327 * get_unmapped_area find a free area of the right size.
328 */
329 unsigned long rb_subtree_gap;
330
e4c6bfd2
RR
331 /* Second cache line starts here. */
332
333 struct mm_struct *vm_mm; /* The address space we belong to. */
574c5b3d
TH
334
335 /*
336 * Access permissions of this VMA.
337 * See vmf_insert_mixed_prot() for discussion.
338 */
339 pgprot_t vm_page_prot;
e4c6bfd2
RR
340 unsigned long vm_flags; /* Flags, see mm.h. */
341
c92ff1bd
MS
342 /*
343 * For areas with an address space and backing store,
27ba0644 344 * linkage into the address_space->i_mmap interval tree.
c92ff1bd 345 */
ac51b934
KS
346 struct {
347 struct rb_node rb;
348 unsigned long rb_subtree_last;
c92ff1bd
MS
349 } shared;
350
351 /*
352 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
353 * list, after a COW of one of the file pages. A MAP_SHARED vma
354 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
355 * or brk vma (with NULL file) can only be in an anon_vma list.
356 */
c1e8d7c6 357 struct list_head anon_vma_chain; /* Serialized by mmap_lock &
5beb4930 358 * page_table_lock */
c92ff1bd
MS
359 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
360
361 /* Function pointers to deal with this struct. */
f0f37e2f 362 const struct vm_operations_struct *vm_ops;
c92ff1bd
MS
363
364 /* Information about our backing store: */
365 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
ea1754a0 366 units */
c92ff1bd
MS
367 struct file * vm_file; /* File we map to (can be NULL). */
368 void * vm_private_data; /* was vm_pte (shared mem) */
c92ff1bd 369
219f8a2e 370#ifdef CONFIG_SWAP
ec560175 371 atomic_long_t swap_readahead_info;
219f8a2e 372#endif
c92ff1bd 373#ifndef CONFIG_MMU
8feae131 374 struct vm_region *vm_region; /* NOMMU mapping region */
c92ff1bd
MS
375#endif
376#ifdef CONFIG_NUMA
377 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
378#endif
745f234b 379 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
3859a271 380} __randomize_layout;
c92ff1bd 381
b564daf8
ON
382struct core_thread {
383 struct task_struct *task;
384 struct core_thread *next;
385};
386
32ecb1f2 387struct core_state {
c5f1cc8c 388 atomic_t nr_threads;
b564daf8 389 struct core_thread dumper;
32ecb1f2
ON
390 struct completion startup;
391};
392
db446a08 393struct kioctx_table;
c92ff1bd 394struct mm_struct {
c1a2f7f0
RR
395 struct {
396 struct vm_area_struct *mmap; /* list of VMAs */
397 struct rb_root mm_rb;
7a9cdebd 398 u64 vmacache_seqnum; /* per-thread vmacache */
efc1a3b1 399#ifdef CONFIG_MMU
c1a2f7f0 400 unsigned long (*get_unmapped_area) (struct file *filp,
c92ff1bd
MS
401 unsigned long addr, unsigned long len,
402 unsigned long pgoff, unsigned long flags);
efc1a3b1 403#endif
c1a2f7f0
RR
404 unsigned long mmap_base; /* base of mmap area */
405 unsigned long mmap_legacy_base; /* base of mmap area in bottom-up allocations */
1b028f78 406#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
041711ce 407 /* Base addresses for compatible mmap() */
c1a2f7f0
RR
408 unsigned long mmap_compat_base;
409 unsigned long mmap_compat_legacy_base;
1b028f78 410#endif
c1a2f7f0
RR
411 unsigned long task_size; /* size of task vm space */
412 unsigned long highest_vm_end; /* highest vma end address */
413 pgd_t * pgd;
414
227a4aad
MD
415#ifdef CONFIG_MEMBARRIER
416 /**
417 * @membarrier_state: Flags controlling membarrier behavior.
418 *
419 * This field is close to @pgd to hopefully fit in the same
420 * cache-line, which needs to be touched by switch_mm().
421 */
422 atomic_t membarrier_state;
423#endif
424
c1a2f7f0
RR
425 /**
426 * @mm_users: The number of users including userspace.
427 *
428 * Use mmget()/mmget_not_zero()/mmput() to modify. When this
429 * drops to 0 (i.e. when the task exits and there are no other
430 * temporary reference holders), we also release a reference on
431 * @mm_count (which may then free the &struct mm_struct if
432 * @mm_count also drops to 0).
433 */
434 atomic_t mm_users;
435
436 /**
437 * @mm_count: The number of references to &struct mm_struct
438 * (@mm_users count as 1).
439 *
440 * Use mmgrab()/mmdrop() to modify. When this drops to 0, the
441 * &struct mm_struct is freed.
442 */
443 atomic_t mm_count;
b279ddc3 444
c4812909 445#ifdef CONFIG_MMU
c1a2f7f0 446 atomic_long_t pgtables_bytes; /* PTE page table pages */
5a3fbef3 447#endif
c1a2f7f0 448 int map_count; /* number of VMAs */
481b4bb5 449
c1a2f7f0
RR
450 spinlock_t page_table_lock; /* Protects page tables and some
451 * counters
452 */
2e302543
FT
453 /*
454 * With some kernel config, the current mmap_lock's offset
455 * inside 'mm_struct' is at 0x120, which is very optimal, as
456 * its two hot fields 'count' and 'owner' sit in 2 different
457 * cachelines, and when mmap_lock is highly contended, both
458 * of the 2 fields will be accessed frequently, current layout
459 * will help to reduce cache bouncing.
460 *
461 * So please be careful with adding new fields before
462 * mmap_lock, which can easily push the 2 fields into one
463 * cacheline.
464 */
da1c55f1 465 struct rw_semaphore mmap_lock;
c92ff1bd 466
c1a2f7f0
RR
467 struct list_head mmlist; /* List of maybe swapped mm's. These
468 * are globally strung together off
469 * init_mm.mmlist, and are protected
470 * by mmlist_lock
471 */
c92ff1bd 472
c92ff1bd 473
c1a2f7f0
RR
474 unsigned long hiwater_rss; /* High-watermark of RSS usage */
475 unsigned long hiwater_vm; /* High-water virtual memory usage */
c92ff1bd 476
c1a2f7f0
RR
477 unsigned long total_vm; /* Total pages mapped */
478 unsigned long locked_vm; /* Pages that have PG_mlocked set */
70f8a3ca 479 atomic64_t pinned_vm; /* Refcount permanently increased */
c1a2f7f0
RR
480 unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
481 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
482 unsigned long stack_vm; /* VM_STACK */
483 unsigned long def_flags;
88aa7cc6 484
2e302543
FT
485 /**
486 * @write_protect_seq: Locked when any thread is write
487 * protecting pages mapped by this mm to enforce a later COW,
488 * for instance during page table copying for fork().
489 */
490 seqcount_t write_protect_seq;
491
c1a2f7f0 492 spinlock_t arg_lock; /* protect the below fields */
2e302543 493
c1a2f7f0
RR
494 unsigned long start_code, end_code, start_data, end_data;
495 unsigned long start_brk, brk, start_stack;
496 unsigned long arg_start, arg_end, env_start, env_end;
c92ff1bd 497
c1a2f7f0 498 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
c92ff1bd 499
c1a2f7f0
RR
500 /*
501 * Special counters, in some configurations protected by the
502 * page_table_lock, in other configurations by being atomic.
503 */
504 struct mm_rss_stat rss_stat;
801460d0 505
c1a2f7f0 506 struct linux_binfmt *binfmt;
6345d24d 507
c1a2f7f0
RR
508 /* Architecture-specific MM context */
509 mm_context_t context;
c92ff1bd 510
c1a2f7f0 511 unsigned long flags; /* Must use atomic bitops to access */
c92ff1bd 512
c1a2f7f0 513 struct core_state *core_state; /* coredumping support */
227a4aad 514
858f0993 515#ifdef CONFIG_AIO
c1a2f7f0
RR
516 spinlock_t ioctx_lock;
517 struct kioctx_table __rcu *ioctx_table;
858f0993 518#endif
f98bafa0 519#ifdef CONFIG_MEMCG
c1a2f7f0
RR
520 /*
521 * "owner" points to a task that is regarded as the canonical
522 * user/owner of this mm. All of the following must be true in
523 * order for it to be changed:
524 *
525 * current == mm->owner
526 * current->mm != mm
527 * new_owner->mm == mm
528 * new_owner->alloc_lock is held
529 */
530 struct task_struct __rcu *owner;
78fb7466 531#endif
c1a2f7f0 532 struct user_namespace *user_ns;
925d1c40 533
c1a2f7f0
RR
534 /* store ref to file /proc/<pid>/exe symlink points to */
535 struct file __rcu *exe_file;
cddb8a5c 536#ifdef CONFIG_MMU_NOTIFIER
984cfe4e 537 struct mmu_notifier_subscriptions *notifier_subscriptions;
e7a00c45 538#endif
e009bb30 539#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
c1a2f7f0 540 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
cbee9f88
PZ
541#endif
542#ifdef CONFIG_NUMA_BALANCING
c1a2f7f0
RR
543 /*
544 * numa_next_scan is the next time that the PTEs will be marked
545 * pte_numa. NUMA hinting faults will gather statistics and
546 * migrate pages to new nodes if necessary.
547 */
548 unsigned long numa_next_scan;
cbee9f88 549
c1a2f7f0
RR
550 /* Restart point for scanning and setting pte_numa */
551 unsigned long numa_scan_offset;
6e5fb223 552
c1a2f7f0
RR
553 /* numa_scan_seq prevents two threads setting pte_numa */
554 int numa_scan_seq;
20841405 555#endif
c1a2f7f0
RR
556 /*
557 * An operation with batched TLB flushing is going on. Anything
558 * that can move process memory needs to flush the TLB when
559 * moving a PROT_NONE or PROT_NUMA mapped page.
560 */
561 atomic_t tlb_flush_pending;
3ea27719 562#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
c1a2f7f0
RR
563 /* See flush_tlb_batched_pending() */
564 bool tlb_flush_batched;
6345d24d 565#endif
c1a2f7f0 566 struct uprobes_state uprobes_state;
5d317b2b 567#ifdef CONFIG_HUGETLB_PAGE
c1a2f7f0 568 atomic_long_t hugetlb_usage;
5d317b2b 569#endif
c1a2f7f0 570 struct work_struct async_put_work;
52ad9bc6
FY
571
572#ifdef CONFIG_IOMMU_SUPPORT
573 u32 pasid;
574#endif
c1a2f7f0
RR
575 } __randomize_layout;
576
577 /*
578 * The mm_cpumask needs to be at the end of mm_struct, because it
579 * is dynamically sized based on nr_cpu_ids.
580 */
581 unsigned long cpu_bitmap[];
582};
c92ff1bd 583
abe722a1
IM
584extern struct mm_struct init_mm;
585
c1a2f7f0 586/* Pointer magic because the dynamic array size confuses some compilers. */
6345d24d
LT
587static inline void mm_init_cpumask(struct mm_struct *mm)
588{
c1a2f7f0
RR
589 unsigned long cpu_bitmap = (unsigned long)mm;
590
591 cpu_bitmap += offsetof(struct mm_struct, cpu_bitmap);
592 cpumask_clear((struct cpumask *)cpu_bitmap);
6345d24d
LT
593}
594
45e575ab 595/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
de03c72c
KM
596static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
597{
c1a2f7f0 598 return (struct cpumask *)&mm->cpu_bitmap;
de03c72c 599}
45e575ab 600
56236a59 601struct mmu_gather;
a72afd87 602extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm);
d8b45053 603extern void tlb_gather_mmu_fullmm(struct mmu_gather *tlb, struct mm_struct *mm);
ae8eba8b 604extern void tlb_finish_mmu(struct mmu_gather *tlb);
56236a59 605
16af97dc 606static inline void init_tlb_flush_pending(struct mm_struct *mm)
20841405 607{
16af97dc 608 atomic_set(&mm->tlb_flush_pending, 0);
20841405 609}
16af97dc
NA
610
611static inline void inc_tlb_flush_pending(struct mm_struct *mm)
20841405 612{
16af97dc 613 atomic_inc(&mm->tlb_flush_pending);
af2c1401 614 /*
8b1b436d
PZ
615 * The only time this value is relevant is when there are indeed pages
616 * to flush. And we'll only flush pages after changing them, which
617 * requires the PTL.
618 *
619 * So the ordering here is:
620 *
040cca3a 621 * atomic_inc(&mm->tlb_flush_pending);
8b1b436d
PZ
622 * spin_lock(&ptl);
623 * ...
624 * set_pte_at();
625 * spin_unlock(&ptl);
626 *
627 * spin_lock(&ptl)
628 * mm_tlb_flush_pending();
629 * ....
630 * spin_unlock(&ptl);
631 *
632 * flush_tlb_range();
040cca3a 633 * atomic_dec(&mm->tlb_flush_pending);
8b1b436d 634 *
0e709703
PZ
635 * Where the increment if constrained by the PTL unlock, it thus
636 * ensures that the increment is visible if the PTE modification is
637 * visible. After all, if there is no PTE modification, nobody cares
638 * about TLB flushes either.
639 *
640 * This very much relies on users (mm_tlb_flush_pending() and
641 * mm_tlb_flush_nested()) only caring about _specific_ PTEs (and
642 * therefore specific PTLs), because with SPLIT_PTE_PTLOCKS and RCpc
643 * locks (PPC) the unlock of one doesn't order against the lock of
644 * another PTL.
645 *
646 * The decrement is ordered by the flush_tlb_range(), such that
647 * mm_tlb_flush_pending() will not return false unless all flushes have
648 * completed.
af2c1401 649 */
20841405 650}
16af97dc 651
16af97dc 652static inline void dec_tlb_flush_pending(struct mm_struct *mm)
20841405 653{
0a2c4048 654 /*
0e709703
PZ
655 * See inc_tlb_flush_pending().
656 *
657 * This cannot be smp_mb__before_atomic() because smp_mb() simply does
658 * not order against TLB invalidate completion, which is what we need.
659 *
660 * Therefore we must rely on tlb_flush_*() to guarantee order.
0a2c4048 661 */
16af97dc 662 atomic_dec(&mm->tlb_flush_pending);
20841405 663}
20841405 664
0e709703
PZ
665static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
666{
667 /*
668 * Must be called after having acquired the PTL; orders against that
669 * PTLs release and therefore ensures that if we observe the modified
670 * PTE we must also observe the increment from inc_tlb_flush_pending().
671 *
672 * That is, it only guarantees to return true if there is a flush
673 * pending for _this_ PTL.
674 */
675 return atomic_read(&mm->tlb_flush_pending);
676}
677
678static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
679{
680 /*
681 * Similar to mm_tlb_flush_pending(), we must have acquired the PTL
682 * for which there is a TLB flush pending in order to guarantee
683 * we've seen both that PTE modification and the increment.
684 *
685 * (no requirement on actually still holding the PTL, that is irrelevant)
686 */
687 return atomic_read(&mm->tlb_flush_pending) > 1;
688}
689
f872f540
AL
690struct vm_fault;
691
3d353901
SJ
692/**
693 * typedef vm_fault_t - Return type for page fault handlers.
694 *
695 * Page fault handlers return a bitmask of %VM_FAULT values.
696 */
697typedef __bitwise unsigned int vm_fault_t;
698
699/**
700 * enum vm_fault_reason - Page fault handlers return a bitmask of
701 * these values to tell the core VM what happened when handling the
702 * fault. Used to decide whether a process gets delivered SIGBUS or
703 * just gets major/minor fault counters bumped up.
704 *
705 * @VM_FAULT_OOM: Out Of Memory
706 * @VM_FAULT_SIGBUS: Bad access
707 * @VM_FAULT_MAJOR: Page read from storage
708 * @VM_FAULT_WRITE: Special case for get_user_pages
709 * @VM_FAULT_HWPOISON: Hit poisoned small page
710 * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
711 * in upper bits
712 * @VM_FAULT_SIGSEGV: segmentation fault
713 * @VM_FAULT_NOPAGE: ->fault installed the pte, not return page
714 * @VM_FAULT_LOCKED: ->fault locked the returned page
715 * @VM_FAULT_RETRY: ->fault blocked, must retry
716 * @VM_FAULT_FALLBACK: huge page fault failed, fall back to small
717 * @VM_FAULT_DONE_COW: ->fault has fully handled COW
718 * @VM_FAULT_NEEDDSYNC: ->fault did not modify page tables and needs
719 * fsync() to complete (for synchronous page faults
720 * in DAX)
721 * @VM_FAULT_HINDEX_MASK: mask HINDEX value
722 *
723 */
724enum vm_fault_reason {
725 VM_FAULT_OOM = (__force vm_fault_t)0x000001,
726 VM_FAULT_SIGBUS = (__force vm_fault_t)0x000002,
727 VM_FAULT_MAJOR = (__force vm_fault_t)0x000004,
728 VM_FAULT_WRITE = (__force vm_fault_t)0x000008,
729 VM_FAULT_HWPOISON = (__force vm_fault_t)0x000010,
730 VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
731 VM_FAULT_SIGSEGV = (__force vm_fault_t)0x000040,
732 VM_FAULT_NOPAGE = (__force vm_fault_t)0x000100,
733 VM_FAULT_LOCKED = (__force vm_fault_t)0x000200,
734 VM_FAULT_RETRY = (__force vm_fault_t)0x000400,
735 VM_FAULT_FALLBACK = (__force vm_fault_t)0x000800,
736 VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000,
737 VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000,
738 VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000,
739};
740
741/* Encode hstate index for a hwpoisoned large page */
742#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
fcae96ff 743#define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
3d353901
SJ
744
745#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \
746 VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \
747 VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
748
749#define VM_FAULT_RESULT_TRACE \
750 { VM_FAULT_OOM, "OOM" }, \
751 { VM_FAULT_SIGBUS, "SIGBUS" }, \
752 { VM_FAULT_MAJOR, "MAJOR" }, \
753 { VM_FAULT_WRITE, "WRITE" }, \
754 { VM_FAULT_HWPOISON, "HWPOISON" }, \
755 { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \
756 { VM_FAULT_SIGSEGV, "SIGSEGV" }, \
757 { VM_FAULT_NOPAGE, "NOPAGE" }, \
758 { VM_FAULT_LOCKED, "LOCKED" }, \
759 { VM_FAULT_RETRY, "RETRY" }, \
760 { VM_FAULT_FALLBACK, "FALLBACK" }, \
761 { VM_FAULT_DONE_COW, "DONE_COW" }, \
762 { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }
763
f872f540
AL
764struct vm_special_mapping {
765 const char *name; /* The name, e.g. "[vdso]". */
766
767 /*
768 * If .fault is not provided, this points to a
769 * NULL-terminated array of pages that back the special mapping.
770 *
771 * This must not be NULL unless .fault is provided.
772 */
a62c34bd 773 struct page **pages;
f872f540
AL
774
775 /*
776 * If non-NULL, then this is called to resolve page faults
777 * on the special mapping. If used, .pages is not checked.
778 */
b3ec9f33
SJ
779 vm_fault_t (*fault)(const struct vm_special_mapping *sm,
780 struct vm_area_struct *vma,
781 struct vm_fault *vmf);
b059a453
DS
782
783 int (*mremap)(const struct vm_special_mapping *sm,
784 struct vm_area_struct *new_vma);
a62c34bd
AL
785};
786
d17d8f9d
DH
787enum tlb_flush_reason {
788 TLB_FLUSH_ON_TASK_SWITCH,
789 TLB_REMOTE_SHOOTDOWN,
790 TLB_LOCAL_SHOOTDOWN,
791 TLB_LOCAL_MM_SHOOTDOWN,
5b74283a 792 TLB_REMOTE_SEND_IPI,
d17d8f9d
DH
793 NR_TLB_FLUSH_REASONS,
794};
795
bd6dace7
TH
796 /*
797 * A swap entry has to fit into a "unsigned long", as the entry is hidden
798 * in the "index" field of the swapper address space.
799 */
800typedef struct {
801 unsigned long val;
802} swp_entry_t;
803
5b99cd0e 804#endif /* _LINUX_MM_TYPES_H */