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