mm_types.h 19.6 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2
3
4
#ifndef _LINUX_MM_TYPES_H
#define _LINUX_MM_TYPES_H

5
6
#include <linux/mm_types_task.h>

7
#include <linux/auxvec.h>
8
9
#include <linux/list.h>
#include <linux/spinlock.h>
10
11
12
#include <linux/rbtree.h>
#include <linux/rwsem.h>
#include <linux/completion.h>
Andrea Arcangeli's avatar
Andrea Arcangeli committed
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
21
22
23
24
#ifndef AT_VECTOR_SIZE_ARCH
#define AT_VECTOR_SIZE_ARCH 0
#endif
#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))

25
26
typedef int vm_fault_t;

27
struct address_space;
28
struct mem_cgroup;
29
struct hmm;
30
31
32
33
34
35

/*
 * Each physical page in the system has a struct page associated with
 * it to keep track of whatever it is we are using the page for at the
 * moment. Note that we have no way to track which tasks are using
 * a page, though if it is a pagecache page, rmap structures can tell us
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 * who is mapping it. If you allocate the page using alloc_pages(), you
 * can use some of the space in struct page for your own purposes.
 *
 * Pages that were once in the page cache may be found under the RCU lock
 * even after they have been recycled to a different purpose.  The page
 * cache reads and writes some of the fields in struct page to pin the
 * page before checking that it's still in the page cache.  It is vital
 * that all users of struct page:
 * 1. Use the first word as PageFlags.
 * 2. Clear or preserve bit 0 of page->compound_head.  It is used as
 *    PageTail for compound pages, and the page cache must not see false
 *    positives.  Some users put a pointer here (guaranteed to be at least
 *    4-byte aligned), other users avoid using the field altogether.
 * 3. page->_refcount must either not be used, or must be used in such a
 *    way that other CPUs temporarily incrementing and then decrementing the
 *    refcount does not cause problems.  On receiving the page from
 *    alloc_pages(), the refcount will be positive.
 * 4. Either preserve page->_mapcount or restore it to -1 before freeing it.
 *
 * If you allocate pages of order > 0, you can use the fields in the struct
 * page associated with each page, but bear in mind that the pages may have
 * been inserted individually into the page cache, so you must use the above
 * four fields in a compatible way for each struct page.
Christoph Lameter's avatar
Christoph Lameter committed
59
 *
60
61
62
63
64
 * SLUB uses cmpxchg_double() to atomically update its freelist and
 * counters.  That requires that freelist & counters be adjacent and
 * double-word aligned.  We align all struct pages to double-word
 * boundaries, and ensure that 'freelist' is aligned within the
 * struct.
65
 */
66
67
#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
#define _struct_page_alignment	__aligned(2 * sizeof(unsigned long))
Matthew Wilcox's avatar
Matthew Wilcox committed
68
69
#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE)
#define _slub_counter_t		unsigned long
70
#else
Matthew Wilcox's avatar
Matthew Wilcox committed
71
#define _slub_counter_t		unsigned int
72
#endif
Matthew Wilcox's avatar
Matthew Wilcox committed
73
74
75
76
#else /* !CONFIG_HAVE_ALIGNED_STRUCT_PAGE */
#define _struct_page_alignment
#define _slub_counter_t		unsigned int
#endif /* !CONFIG_HAVE_ALIGNED_STRUCT_PAGE */
77

78
struct page {
Christoph Lameter's avatar
Christoph Lameter committed
79
	/* First double word block */
80
81
	unsigned long flags;		/* Atomic flags, some possibly
					 * updated asynchronously */
82
	union {
83
84
85
		/* See page-flags.h for the definition of PAGE_MAPPING_FLAGS */
		struct address_space *mapping;

86
		void *s_mem;			/* slab first object */
87
		atomic_t compound_mapcount;	/* first tail page */
88
		/* page_deferred_list().next	 -- second tail page */
89
90
	};

Christoph Lameter's avatar
Christoph Lameter committed
91
	/* Second double word */
92
93
94
95
96
	union {
		pgoff_t index;		/* Our offset within mapping. */
		void *freelist;		/* sl[aou]b first free object */
		/* page_deferred_list().prev	-- second tail page */
	};
97

98
	union {
Matthew Wilcox's avatar
Matthew Wilcox committed
99
		_slub_counter_t counters;
Matthew Wilcox's avatar
Matthew Wilcox committed
100
101
102
103
104
105
106
		unsigned int active;		/* SLAB */
		struct {			/* SLUB */
			unsigned inuse:16;
			unsigned objects:15;
			unsigned frozen:1;
		};
		int units;			/* SLOB */
107

Matthew Wilcox's avatar
Matthew Wilcox committed
108
109
110
111
112
113
114
115
116
117
118
		struct {			/* Page cache */
			/*
			 * Count of ptes mapped in mms, to show when
			 * page is mapped & limit reverse map searches.
			 *
			 * Extra information about page type may be
			 * stored here for pages that are never mapped,
			 * in which case the value MUST BE <= -2.
			 * See page-flags.h for more details.
			 */
			atomic_t _mapcount;
119
120
121
122
123
124

			/*
			 * Usage count, *USE WRAPPER FUNCTION* when manual
			 * accounting. See page_ref.h
			 */
			atomic_t _refcount;
125
		};
Christoph Lameter's avatar
Christoph Lameter committed
126
	};
Christoph Lameter's avatar
Christoph Lameter committed
127

128
129
130
131
132
	/*
	 * WARNING: bit 0 of the first word encode PageTail(). That means
	 * the rest users of the storage space MUST NOT use the bit to
	 * avoid collision and false-positive PageTail().
	 */
133
134
	union {
		struct list_head lru;	/* Pageout list, eg. active_list
135
					 * protected by zone_lru_lock !
136
137
					 * Can be used as a generic list
					 * by the page owner.
Christoph Lameter's avatar
Christoph Lameter committed
138
					 */
139
140
141
142
143
		struct dev_pagemap *pgmap; /* ZONE_DEVICE pages are never on an
					    * lru or handled by a slab
					    * allocator, this points to the
					    * hosting device page map.
					    */
144
145
146
147
148
149
150
151
152
153
		struct {		/* slub per cpu partial pages */
			struct page *next;	/* Next partial slab */
#ifdef CONFIG_64BIT
			int pages;	/* Nr of partial slabs left */
			int pobjects;	/* Approximate # of objects */
#else
			short int pages;
			short int pobjects;
#endif
		};
154

155
156
157
		struct rcu_head rcu_head;	/* Used by SLAB
						 * when destroying via RCU
						 */
158
		/* Tail pages of compound page */
159
		struct {
160
161
162
			unsigned long compound_head; /* If bit zero is set */

			/* First tail page only */
163
164
165
			unsigned char compound_dtor;
			unsigned char compound_order;
			/* two/six bytes available here */
166
167
		};

168
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
169
170
171
172
173
174
175
		struct {
			unsigned long __pad;	/* do not overlay pmd_huge_pte
						 * with compound_head to avoid
						 * possible bit 0 collision.
						 */
			pgtable_t pmd_huge_pte; /* protected by page->ptl */
		};
176
#endif
177
	};
Christoph Lameter's avatar
Christoph Lameter committed
178

179
	union {
180
181
182
183
184
185
186
		/*
		 * Mapping-private opaque data:
		 * Usually used for buffer_heads if PagePrivate
		 * Used for swp_entry_t if PageSwapCache
		 * Indicates order in the buddy system if PageBuddy
		 */
		unsigned long private;
187
#if USE_SPLIT_PTE_PTLOCKS
188
#if ALLOC_SPLIT_PTLOCKS
189
190
191
192
		spinlock_t *ptl;
#else
		spinlock_t ptl;
#endif
193
#endif
194
		struct kmem_cache *slab_cache;	/* SL[AU]B: Pointer to slab */
Christoph Lameter's avatar
Christoph Lameter committed
195
	};
Christoph Lameter's avatar
Christoph Lameter committed
196

197
198
199
200
#ifdef CONFIG_MEMCG
	struct mem_cgroup *mem_cgroup;
#endif

201
202
203
204
205
206
207
208
209
210
211
212
213
214
	/*
	 * On machines where all RAM is mapped into kernel address space,
	 * we can simply calculate the virtual address. On machines with
	 * highmem some memory is mapped into kernel virtual memory
	 * dynamically, so we need a place to store that address.
	 * Note that this field could be 16 bits on x86 ... ;)
	 *
	 * Architectures with slow multiplication can define
	 * WANT_PAGE_VIRTUAL in asm/page.h
	 */
#if defined(WANT_PAGE_VIRTUAL)
	void *virtual;			/* Kernel virtual address (NULL if
					   not kmapped, ie. highmem) */
#endif /* WANT_PAGE_VIRTUAL */
215

216
217
#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
	int _last_cpupid;
218
#endif
219
} _struct_page_alignment;
220

221
222
223
224
225
226
227
228
229
230
231
232
#define PAGE_FRAG_CACHE_MAX_SIZE	__ALIGN_MASK(32768, ~PAGE_MASK)
#define PAGE_FRAG_CACHE_MAX_ORDER	get_order(PAGE_FRAG_CACHE_MAX_SIZE)

struct page_frag_cache {
	void * va;
#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
	__u16 offset;
	__u16 size;
#else
	__u32 offset;
#endif
	/* we maintain a pagecount bias, so that we dont dirty cache line
233
	 * containing page->_refcount every time we allocate a fragment.
234
235
236
237
238
	 */
	unsigned int		pagecnt_bias;
	bool pfmemalloc;
};

239
typedef unsigned long vm_flags_t;
240

241
242
243
244
245
246
247
/*
 * A region containing a mapping of a non-memory backed file under NOMMU
 * conditions.  These are held in a global tree and are pinned by the VMAs that
 * map parts of them.
 */
struct vm_region {
	struct rb_node	vm_rb;		/* link in global region tree */
248
	vm_flags_t	vm_flags;	/* VMA vm_flags */
249
250
	unsigned long	vm_start;	/* start address of region */
	unsigned long	vm_end;		/* region initialised to here */
251
	unsigned long	vm_top;		/* region allocated to here */
252
253
254
	unsigned long	vm_pgoff;	/* the offset in vm_file corresponding to vm_start */
	struct file	*vm_file;	/* the backing file or NULL */

255
	int		vm_usage;	/* region usage count (access under nommu_region_sem) */
256
257
	bool		vm_icache_flushed : 1; /* true if the icache has been flushed for
						* this region */
258
259
};

260
261
262
263
264
265
266
267
268
269
#ifdef CONFIG_USERFAULTFD
#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
struct vm_userfaultfd_ctx {
	struct userfaultfd_ctx *ctx;
};
#else /* CONFIG_USERFAULTFD */
#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
struct vm_userfaultfd_ctx {};
#endif /* CONFIG_USERFAULTFD */

270
271
272
273
274
275
276
/*
 * This struct defines a memory VMM memory area. There is one of these
 * per VM-area/task.  A VM area is any part of the process virtual memory
 * space that has a special rule for the page-fault handlers (ie a shared
 * library, the executable area etc).
 */
struct vm_area_struct {
277
278
	/* The first cache line has the info for VMA tree walking. */

279
280
281
282
283
	unsigned long vm_start;		/* Our start address within vm_mm. */
	unsigned long vm_end;		/* The first byte after our end address
					   within vm_mm. */

	/* linked list of VM areas per task, sorted by address */
284
	struct vm_area_struct *vm_next, *vm_prev;
285
286
287

	struct rb_node vm_rb;

288
289
290
291
292
293
294
295
	/*
	 * Largest free memory gap in bytes to the left of this VMA.
	 * Either between this VMA and vma->vm_prev, or between one of the
	 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
	 * get_unmapped_area find a free area of the right size.
	 */
	unsigned long rb_subtree_gap;

296
297
298
299
300
301
	/* Second cache line starts here. */

	struct mm_struct *vm_mm;	/* The address space we belong to. */
	pgprot_t vm_page_prot;		/* Access permissions of this VMA. */
	unsigned long vm_flags;		/* Flags, see mm.h. */

302
303
	/*
	 * For areas with an address space and backing store,
304
	 * linkage into the address_space->i_mmap interval tree.
305
	 */
306
307
308
	struct {
		struct rb_node rb;
		unsigned long rb_subtree_last;
309
310
311
312
313
314
315
316
	} shared;

	/*
	 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
	 * list, after a COW of one of the file pages.	A MAP_SHARED vma
	 * can only be in the i_mmap tree.  An anonymous MAP_PRIVATE, stack
	 * or brk vma (with NULL file) can only be in an anon_vma list.
	 */
317
318
	struct list_head anon_vma_chain; /* Serialized by mmap_sem &
					  * page_table_lock */
319
320
321
	struct anon_vma *anon_vma;	/* Serialized by page_table_lock */

	/* Function pointers to deal with this struct. */
322
	const struct vm_operations_struct *vm_ops;
323
324
325

	/* Information about our backing store: */
	unsigned long vm_pgoff;		/* Offset (within vm_file) in PAGE_SIZE
326
					   units */
327
328
329
	struct file * vm_file;		/* File we map to (can be NULL). */
	void * vm_private_data;		/* was vm_pte (shared mem) */

330
	atomic_long_t swap_readahead_info;
331
#ifndef CONFIG_MMU
332
	struct vm_region *vm_region;	/* NOMMU mapping region */
333
334
335
336
#endif
#ifdef CONFIG_NUMA
	struct mempolicy *vm_policy;	/* NUMA policy for the VMA */
#endif
337
	struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
338
} __randomize_layout;
339

340
341
342
343
344
struct core_thread {
	struct task_struct *task;
	struct core_thread *next;
};

345
struct core_state {
346
	atomic_t nr_threads;
347
	struct core_thread dumper;
348
349
350
	struct completion startup;
};

351
struct kioctx_table;
352
struct mm_struct {
Davidlohr Bueso's avatar
Davidlohr Bueso committed
353
	struct vm_area_struct *mmap;		/* list of VMAs */
354
	struct rb_root mm_rb;
Davidlohr Bueso's avatar
Davidlohr Bueso committed
355
	u32 vmacache_seqnum;                   /* per-thread vmacache */
356
#ifdef CONFIG_MMU
357
358
359
	unsigned long (*get_unmapped_area) (struct file *filp,
				unsigned long addr, unsigned long len,
				unsigned long pgoff, unsigned long flags);
360
#endif
361
	unsigned long mmap_base;		/* base of mmap area */
362
	unsigned long mmap_legacy_base;         /* base of mmap area in bottom-up allocations */
363
364
365
366
367
#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
	/* Base adresses for compatible mmap() */
	unsigned long mmap_compat_base;
	unsigned long mmap_compat_legacy_base;
#endif
368
	unsigned long task_size;		/* size of task vm space */
369
	unsigned long highest_vm_end;		/* highest vma end address */
370
	pgd_t * pgd;
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391

	/**
	 * @mm_users: The number of users including userspace.
	 *
	 * Use mmget()/mmget_not_zero()/mmput() to modify. When this drops
	 * to 0 (i.e. when the task exits and there are no other temporary
	 * reference holders), we also release a reference on @mm_count
	 * (which may then free the &struct mm_struct if @mm_count also
	 * drops to 0).
	 */
	atomic_t mm_users;

	/**
	 * @mm_count: The number of references to &struct mm_struct
	 * (@mm_users count as 1).
	 *
	 * Use mmgrab()/mmdrop() to modify. When this drops to 0, the
	 * &struct mm_struct is freed.
	 */
	atomic_t mm_count;

392
#ifdef CONFIG_MMU
393
	atomic_long_t pgtables_bytes;		/* PTE page table pages */
394
#endif
395
	int map_count;				/* number of VMAs */
396

397
	spinlock_t page_table_lock;		/* Protects page tables and some counters */
398
	struct rw_semaphore mmap_sem;
399
400
401
402
403
404
405
406
407
408

	struct list_head mmlist;		/* List of maybe swapped mm's.	These are globally strung
						 * together off init_mm.mmlist, and are protected
						 * by mmlist_lock
						 */


	unsigned long hiwater_rss;	/* High-watermark of RSS usage */
	unsigned long hiwater_vm;	/* High-water virtual memory usage */

409
410
411
	unsigned long total_vm;		/* Total pages mapped */
	unsigned long locked_vm;	/* Pages that have PG_mlocked set */
	unsigned long pinned_vm;	/* Refcount permanently increased */
412
413
414
	unsigned long data_vm;		/* VM_WRITE & ~VM_SHARED & ~VM_STACK */
	unsigned long exec_vm;		/* VM_EXEC & ~VM_WRITE & ~VM_STACK */
	unsigned long stack_vm;		/* VM_STACK */
415
	unsigned long def_flags;
416
417
418
419
420
421
	unsigned long start_code, end_code, start_data, end_data;
	unsigned long start_brk, brk, start_stack;
	unsigned long arg_start, arg_end, env_start, env_end;

	unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */

KAMEZAWA Hiroyuki's avatar
KAMEZAWA Hiroyuki committed
422
423
424
425
426
427
	/*
	 * Special counters, in some configurations protected by the
	 * page_table_lock, in other configurations by being atomic.
	 */
	struct mm_rss_stat rss_stat;

428
429
	struct linux_binfmt *binfmt;

430
431
	cpumask_var_t cpu_vm_mask_var;

432
433
434
435
436
	/* Architecture-specific MM context */
	mm_context_t context;

	unsigned long flags; /* Must use atomic bitops to access the bits */

Oleg Nesterov's avatar
Oleg Nesterov committed
437
	struct core_state *core_state; /* coredumping support */
438
439
440
#ifdef CONFIG_MEMBARRIER
	atomic_t membarrier_state;
#endif
441
#ifdef CONFIG_AIO
442
443
	spinlock_t			ioctx_lock;
	struct kioctx_table __rcu	*ioctx_table;
444
#endif
Oleg Nesterov's avatar
Oleg Nesterov committed
445
#ifdef CONFIG_MEMCG
446
447
448
449
450
451
452
453
454
455
	/*
	 * "owner" points to a task that is regarded as the canonical
	 * user/owner of this mm. All of the following must be true in
	 * order for it to be changed:
	 *
	 * current == mm->owner
	 * current->mm != mm
	 * new_owner->mm == mm
	 * new_owner->alloc_lock is held
	 */
Arnd Bergmann's avatar
Arnd Bergmann committed
456
	struct task_struct __rcu *owner;
457
#endif
458
	struct user_namespace *user_ns;
Matt Helsley's avatar
Matt Helsley committed
459
460

	/* store ref to file /proc/<pid>/exe symlink points to */
461
	struct file __rcu *exe_file;
Andrea Arcangeli's avatar
Andrea Arcangeli committed
462
463
#ifdef CONFIG_MMU_NOTIFIER
	struct mmu_notifier_mm *mmu_notifier_mm;
464
#endif
465
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
466
	pgtable_t pmd_huge_pte; /* protected by page_table_lock */
Andrea Arcangeli's avatar
Andrea Arcangeli committed
467
#endif
468
469
#ifdef CONFIG_CPUMASK_OFFSTACK
	struct cpumask cpumask_allocation;
470
471
472
#endif
#ifdef CONFIG_NUMA_BALANCING
	/*
473
474
475
	 * numa_next_scan is the next time that the PTEs will be marked
	 * pte_numa. NUMA hinting faults will gather statistics and migrate
	 * pages to new nodes if necessary.
476
477
478
	 */
	unsigned long numa_next_scan;

479
480
481
	/* Restart point for scanning and setting pte_numa */
	unsigned long numa_scan_offset;

482
483
	/* numa_scan_seq prevents two threads setting pte_numa */
	int numa_scan_seq;
484
485
486
487
488
489
#endif
	/*
	 * An operation with batched TLB flushing is going on. Anything that
	 * can move process memory needs to flush the TLB when moving a
	 * PROT_NONE or PROT_NUMA mapped page.
	 */
490
	atomic_t tlb_flush_pending;
491
492
493
#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
	/* See flush_tlb_batched_pending() */
	bool tlb_flush_batched;
494
#endif
495
	struct uprobes_state uprobes_state;
496
497
498
#ifdef CONFIG_HUGETLB_PAGE
	atomic_long_t hugetlb_usage;
#endif
499
	struct work_struct async_put_work;
500
501
502
503
504

#if IS_ENABLED(CONFIG_HMM)
	/* HMM needs to track a few things per mm */
	struct hmm *hmm;
#endif
505
} __randomize_layout;
506

507
508
extern struct mm_struct init_mm;

509
510
511
512
513
static inline void mm_init_cpumask(struct mm_struct *mm)
{
#ifdef CONFIG_CPUMASK_OFFSTACK
	mm->cpu_vm_mask_var = &mm->cpumask_allocation;
#endif
514
	cpumask_clear(mm->cpu_vm_mask_var);
515
516
}

517
/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
518
519
520
521
static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
{
	return mm->cpu_vm_mask_var;
}
522

Minchan Kim's avatar
Minchan Kim committed
523
524
525
526
527
528
struct mmu_gather;
extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,
				unsigned long start, unsigned long end);
extern void tlb_finish_mmu(struct mmu_gather *tlb,
				unsigned long start, unsigned long end);

529
static inline void init_tlb_flush_pending(struct mm_struct *mm)
530
{
531
	atomic_set(&mm->tlb_flush_pending, 0);
532
}
533
534

static inline void inc_tlb_flush_pending(struct mm_struct *mm)
535
{
536
	atomic_inc(&mm->tlb_flush_pending);
537
	/*
538
539
540
541
542
543
	 * The only time this value is relevant is when there are indeed pages
	 * to flush. And we'll only flush pages after changing them, which
	 * requires the PTL.
	 *
	 * So the ordering here is:
	 *
544
	 *	atomic_inc(&mm->tlb_flush_pending);
545
546
547
548
549
550
551
552
553
554
555
	 *	spin_lock(&ptl);
	 *	...
	 *	set_pte_at();
	 *	spin_unlock(&ptl);
	 *
	 *				spin_lock(&ptl)
	 *				mm_tlb_flush_pending();
	 *				....
	 *				spin_unlock(&ptl);
	 *
	 *	flush_tlb_range();
556
	 *	atomic_dec(&mm->tlb_flush_pending);
557
	 *
558
559
560
561
562
563
564
565
566
567
568
569
570
571
	 * Where the increment if constrained by the PTL unlock, it thus
	 * ensures that the increment is visible if the PTE modification is
	 * visible. After all, if there is no PTE modification, nobody cares
	 * about TLB flushes either.
	 *
	 * This very much relies on users (mm_tlb_flush_pending() and
	 * mm_tlb_flush_nested()) only caring about _specific_ PTEs (and
	 * therefore specific PTLs), because with SPLIT_PTE_PTLOCKS and RCpc
	 * locks (PPC) the unlock of one doesn't order against the lock of
	 * another PTL.
	 *
	 * The decrement is ordered by the flush_tlb_range(), such that
	 * mm_tlb_flush_pending() will not return false unless all flushes have
	 * completed.
572
	 */
573
}
574
575

static inline void dec_tlb_flush_pending(struct mm_struct *mm)
576
{
577
	/*
578
579
580
581
582
583
	 * See inc_tlb_flush_pending().
	 *
	 * This cannot be smp_mb__before_atomic() because smp_mb() simply does
	 * not order against TLB invalidate completion, which is what we need.
	 *
	 * Therefore we must rely on tlb_flush_*() to guarantee order.
584
	 */
585
	atomic_dec(&mm->tlb_flush_pending);
586
587
}

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
{
	/*
	 * Must be called after having acquired the PTL; orders against that
	 * PTLs release and therefore ensures that if we observe the modified
	 * PTE we must also observe the increment from inc_tlb_flush_pending().
	 *
	 * That is, it only guarantees to return true if there is a flush
	 * pending for _this_ PTL.
	 */
	return atomic_read(&mm->tlb_flush_pending);
}

static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
{
	/*
	 * Similar to mm_tlb_flush_pending(), we must have acquired the PTL
	 * for which there is a TLB flush pending in order to guarantee
	 * we've seen both that PTE modification and the increment.
	 *
	 * (no requirement on actually still holding the PTL, that is irrelevant)
	 */
	return atomic_read(&mm->tlb_flush_pending) > 1;
}

613
614
615
616
617
618
619
620
621
622
623
struct vm_fault;

struct vm_special_mapping {
	const char *name;	/* The name, e.g. "[vdso]". */

	/*
	 * If .fault is not provided, this points to a
	 * NULL-terminated array of pages that back the special mapping.
	 *
	 * This must not be NULL unless .fault is provided.
	 */
624
	struct page **pages;
625
626
627
628
629
630
631
632

	/*
	 * If non-NULL, then this is called to resolve page faults
	 * on the special mapping.  If used, .pages is not checked.
	 */
	int (*fault)(const struct vm_special_mapping *sm,
		     struct vm_area_struct *vma,
		     struct vm_fault *vmf);
633
634
635

	int (*mremap)(const struct vm_special_mapping *sm,
		     struct vm_area_struct *new_vma);
636
637
};

638
639
640
641
642
enum tlb_flush_reason {
	TLB_FLUSH_ON_TASK_SWITCH,
	TLB_REMOTE_SHOOTDOWN,
	TLB_LOCAL_SHOOTDOWN,
	TLB_LOCAL_MM_SHOOTDOWN,
643
	TLB_REMOTE_SEND_IPI,
644
645
646
	NR_TLB_FLUSH_REASONS,
};

647
648
649
650
651
652
653
654
 /*
  * A swap entry has to fit into a "unsigned long", as the entry is hidden
  * in the "index" field of the swapper address space.
  */
typedef struct {
	unsigned long val;
} swp_entry_t;

655
#endif /* _LINUX_MM_TYPES_H */