mm_types.h 19 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
struct address_space;
26
struct mem_cgroup;
27
struct hmm;
28 29 30 31 32 33 34

/*
 * 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
 * who is mapping it.
Christoph Lameter's avatar
Christoph Lameter committed
35 36 37 38 39 40
 *
 * The objects in struct page are organized in double word blocks in
 * order to allows us to use atomic double word operations on portions
 * of struct page. That is currently only used by slub but the arrangement
 * allows the use of atomic double word operations on the flags/mapping
 * and lru list pointers also.
41 42
 */
struct page {
Christoph Lameter's avatar
Christoph Lameter committed
43
	/* First double word block */
44 45
	unsigned long flags;		/* Atomic flags, some possibly
					 * updated asynchronously */
46 47 48 49 50 51 52 53 54
	union {
		struct address_space *mapping;	/* If low bit clear, points to
						 * inode address_space, or NULL.
						 * If page mapped as anonymous
						 * memory, low bit is set, and
						 * it points to anon_vma object:
						 * see PAGE_MAPPING_ANON below.
						 */
		void *s_mem;			/* slab first object */
55
		atomic_t compound_mapcount;	/* first tail page */
56
		/* page_deferred_list().next	 -- second tail page */
57 58
	};

Christoph Lameter's avatar
Christoph Lameter committed
59
	/* Second double word */
60 61 62 63 64
	union {
		pgoff_t index;		/* Our offset within mapping. */
		void *freelist;		/* sl[aou]b first free object */
		/* page_deferred_list().prev	-- second tail page */
	};
65

66
	union {
67 68
#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
	defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
69 70
		/* Used for cmpxchg_double in slub */
		unsigned long counters;
71
#else
72 73 74 75 76 77
		/*
		 * Keep _refcount separate from slub cmpxchg_double data.
		 * As the rest of the double word is protected by slab_lock
		 * but _refcount is not.
		 */
		unsigned counters;
78
#endif
79
		struct {
80

81
			union {
82
				/*
83 84
				 * Count of ptes mapped in mms, to show when
				 * page is mapped & limit reverse map searches.
85 86 87 88 89
				 *
				 * 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.
90
				 */
91 92 93 94 95 96 97 98 99
				atomic_t _mapcount;

				unsigned int active;		/* SLAB */
				struct {			/* SLUB */
					unsigned inuse:16;
					unsigned objects:15;
					unsigned frozen:1;
				};
				int units;			/* SLOB */
Christoph Lameter's avatar
Christoph Lameter committed
100
			};
101 102 103 104 105
			/*
			 * Usage count, *USE WRAPPER FUNCTION* when manual
			 * accounting. See page_ref.h
			 */
			atomic_t _refcount;
106
		};
Christoph Lameter's avatar
Christoph Lameter committed
107
	};
Christoph Lameter's avatar
Christoph Lameter committed
108

109 110 111 112 113 114 115
	/*
	 * Third double word block
	 *
	 * 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().
	 */
116 117
	union {
		struct list_head lru;	/* Pageout list, eg. active_list
118
					 * protected by zone_lru_lock !
119 120
					 * Can be used as a generic list
					 * by the page owner.
Christoph Lameter's avatar
Christoph Lameter committed
121
					 */
122 123 124 125 126
		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.
					    */
127 128 129 130 131 132 133 134 135 136
		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
		};
137

138 139 140
		struct rcu_head rcu_head;	/* Used by SLAB
						 * when destroying via RCU
						 */
141
		/* Tail pages of compound page */
142
		struct {
143 144 145
			unsigned long compound_head; /* If bit zero is set */

			/* First tail page only */
146 147 148 149 150 151 152 153 154 155
#ifdef CONFIG_64BIT
			/*
			 * On 64 bit system we have enough space in struct page
			 * to encode compound_dtor and compound_order with
			 * unsigned int. It can help compiler generate better or
			 * smaller code on some archtectures.
			 */
			unsigned int compound_dtor;
			unsigned int compound_order;
#else
156 157
			unsigned short int compound_dtor;
			unsigned short int compound_order;
158
#endif
159 160
		};

161
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
162 163 164 165 166 167 168
		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 */
		};
169
#endif
170
	};
Christoph Lameter's avatar
Christoph Lameter committed
171 172

	/* Remainder is not double word aligned */
173 174 175 176 177 178 179 180
	union {
		unsigned long private;		/* Mapping-private opaque data:
					 	 * usually used for buffer_heads
						 * if PagePrivate set; used for
						 * swp_entry_t if PageSwapCache;
						 * indicates order in the buddy
						 * system if PG_buddy is set.
						 */
181
#if USE_SPLIT_PTE_PTLOCKS
182
#if ALLOC_SPLIT_PTLOCKS
183 184 185 186
		spinlock_t *ptl;
#else
		spinlock_t ptl;
#endif
187
#endif
188
		struct kmem_cache *slab_cache;	/* SL[AU]B: Pointer to slab */
Christoph Lameter's avatar
Christoph Lameter committed
189
	};
Christoph Lameter's avatar
Christoph Lameter committed
190

191 192 193 194
#ifdef CONFIG_MEMCG
	struct mem_cgroup *mem_cgroup;
#endif

195 196 197 198 199 200 201 202 203 204 205 206 207 208
	/*
	 * 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 */
209

210 211
#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
	int _last_cpupid;
212
#endif
Christoph Lameter's avatar
Christoph Lameter committed
213 214
}
/*
215 216
 * The struct page can be forced to be double word aligned so that atomic ops
 * on double words work. The SLUB allocator can make use of such a feature.
Christoph Lameter's avatar
Christoph Lameter committed
217
 */
218 219
#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
	__aligned(2 * sizeof(unsigned long))
Christoph Lameter's avatar
Christoph Lameter committed
220 221
#endif
;
222

223 224 225 226 227 228 229 230 231 232 233 234
#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
235
	 * containing page->_refcount every time we allocate a fragment.
236 237 238 239 240
	 */
	unsigned int		pagecnt_bias;
	bool pfmemalloc;
};

241
typedef unsigned long vm_flags_t;
242

243 244 245 246 247 248 249
/*
 * 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 */
250
	vm_flags_t	vm_flags;	/* VMA vm_flags */
251 252
	unsigned long	vm_start;	/* start address of region */
	unsigned long	vm_end;		/* region initialised to here */
253
	unsigned long	vm_top;		/* region allocated to here */
254 255 256
	unsigned long	vm_pgoff;	/* the offset in vm_file corresponding to vm_start */
	struct file	*vm_file;	/* the backing file or NULL */

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

262 263 264 265 266 267 268 269 270 271
#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 */

272 273 274 275 276 277 278
/*
 * 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 {
279 280
	/* The first cache line has the info for VMA tree walking. */

281 282 283 284 285
	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 */
286
	struct vm_area_struct *vm_next, *vm_prev;
287 288 289

	struct rb_node vm_rb;

290 291 292 293 294 295 296 297
	/*
	 * 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;

298 299 300 301 302 303
	/* 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. */

304 305
	/*
	 * For areas with an address space and backing store,
306
	 * linkage into the address_space->i_mmap interval tree.
307
	 */
308 309 310
	struct {
		struct rb_node rb;
		unsigned long rb_subtree_last;
311 312 313 314 315 316 317 318
	} 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.
	 */
319 320
	struct list_head anon_vma_chain; /* Serialized by mmap_sem &
					  * page_table_lock */
321 322 323
	struct anon_vma *anon_vma;	/* Serialized by page_table_lock */

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

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

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

342 343 344 345 346
struct core_thread {
	struct task_struct *task;
	struct core_thread *next;
};

347
struct core_state {
348
	atomic_t nr_threads;
349
	struct core_thread dumper;
350 351 352
	struct completion startup;
};

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

	/**
	 * @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;

394
	atomic_long_t nr_ptes;			/* PTE page table pages */
395
#if CONFIG_PGTABLE_LEVELS > 2
396
	atomic_long_t nr_pmds;			/* PMD page table pages */
397
#endif
398
	int map_count;				/* number of VMAs */
399

400
	spinlock_t page_table_lock;		/* Protects page tables and some counters */
401
	struct rw_semaphore mmap_sem;
402 403 404 405 406 407 408 409 410 411

	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 */

412 413 414
	unsigned long total_vm;		/* Total pages mapped */
	unsigned long locked_vm;	/* Pages that have PG_mlocked set */
	unsigned long pinned_vm;	/* Refcount permanently increased */
415 416 417
	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 */
418
	unsigned long def_flags;
419 420 421 422 423 424
	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
425 426 427 428 429 430
	/*
	 * Special counters, in some configurations protected by the
	 * page_table_lock, in other configurations by being atomic.
	 */
	struct mm_rss_stat rss_stat;

431 432
	struct linux_binfmt *binfmt;

433 434
	cpumask_var_t cpu_vm_mask_var;

435 436 437 438 439
	/* 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
440
	struct core_state *core_state; /* coredumping support */
441 442 443
#ifdef CONFIG_MEMBARRIER
	atomic_t membarrier_state;
#endif
444
#ifdef CONFIG_AIO
445 446
	spinlock_t			ioctx_lock;
	struct kioctx_table __rcu	*ioctx_table;
447
#endif
Oleg Nesterov's avatar
Oleg Nesterov committed
448
#ifdef CONFIG_MEMCG
449 450 451 452 453 454 455 456 457 458
	/*
	 * "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
459
	struct task_struct __rcu *owner;
460
#endif
461
	struct user_namespace *user_ns;
Matt Helsley's avatar
Matt Helsley committed
462 463

	/* store ref to file /proc/<pid>/exe symlink points to */
464
	struct file __rcu *exe_file;
Andrea Arcangeli's avatar
Andrea Arcangeli committed
465 466
#ifdef CONFIG_MMU_NOTIFIER
	struct mmu_notifier_mm *mmu_notifier_mm;
467
#endif
468
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
469
	pgtable_t pmd_huge_pte; /* protected by page_table_lock */
Andrea Arcangeli's avatar
Andrea Arcangeli committed
470
#endif
471 472
#ifdef CONFIG_CPUMASK_OFFSTACK
	struct cpumask cpumask_allocation;
473 474 475
#endif
#ifdef CONFIG_NUMA_BALANCING
	/*
476 477 478
	 * 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.
479 480 481
	 */
	unsigned long numa_next_scan;

482 483 484
	/* Restart point for scanning and setting pte_numa */
	unsigned long numa_scan_offset;

485 486
	/* numa_scan_seq prevents two threads setting pte_numa */
	int numa_scan_seq;
487 488 489 490 491 492
#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.
	 */
493
	atomic_t tlb_flush_pending;
494 495 496
#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
	/* See flush_tlb_batched_pending() */
	bool tlb_flush_batched;
497
#endif
498
	struct uprobes_state uprobes_state;
499 500 501
#ifdef CONFIG_HUGETLB_PAGE
	atomic_long_t hugetlb_usage;
#endif
502
	struct work_struct async_put_work;
503 504 505 506 507

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

510 511
extern struct mm_struct init_mm;

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

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

Minchan Kim's avatar
Minchan Kim committed
526 527 528 529 530 531
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);

532
static inline void init_tlb_flush_pending(struct mm_struct *mm)
533
{
534
	atomic_set(&mm->tlb_flush_pending, 0);
535
}
536 537

static inline void inc_tlb_flush_pending(struct mm_struct *mm)
538
{
539
	atomic_inc(&mm->tlb_flush_pending);
540
	/*
541 542 543 544 545 546
	 * 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:
	 *
547
	 *	atomic_inc(&mm->tlb_flush_pending);
548 549 550 551 552 553 554 555 556 557 558
	 *	spin_lock(&ptl);
	 *	...
	 *	set_pte_at();
	 *	spin_unlock(&ptl);
	 *
	 *				spin_lock(&ptl)
	 *				mm_tlb_flush_pending();
	 *				....
	 *				spin_unlock(&ptl);
	 *
	 *	flush_tlb_range();
559
	 *	atomic_dec(&mm->tlb_flush_pending);
560
	 *
561 562 563 564 565 566 567 568 569 570 571 572 573 574
	 * 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.
575
	 */
576
}
577 578

static inline void dec_tlb_flush_pending(struct mm_struct *mm)
579
{
580
	/*
581 582 583 584 585 586
	 * 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.
587
	 */
588
	atomic_dec(&mm->tlb_flush_pending);
589 590
}

591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
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;
}

616 617 618 619 620 621 622 623 624 625 626
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.
	 */
627
	struct page **pages;
628 629 630 631 632 633 634 635

	/*
	 * 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);
636 637 638

	int (*mremap)(const struct vm_special_mapping *sm,
		     struct vm_area_struct *new_vma);
639 640
};

641 642 643 644 645
enum tlb_flush_reason {
	TLB_FLUSH_ON_TASK_SWITCH,
	TLB_REMOTE_SHOOTDOWN,
	TLB_LOCAL_SHOOTDOWN,
	TLB_LOCAL_MM_SHOOTDOWN,
646
	TLB_REMOTE_SEND_IPI,
647 648 649
	NR_TLB_FLUSH_REASONS,
};

650 651 652 653 654 655 656 657
 /*
  * 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;

658
#endif /* _LINUX_MM_TYPES_H */