18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_MMU_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_MMU_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
68c2ecf20Sopenharmony_ci#include <linux/rwsem.h>
78c2ecf20Sopenharmony_ci#include <linux/mutex.h>
88c2ecf20Sopenharmony_ci#include <linux/atomic.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * x86 has arch-specific MMU state beyond what lives in mm_struct.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_citypedef struct {
148c2ecf20Sopenharmony_ci	/*
158c2ecf20Sopenharmony_ci	 * ctx_id uniquely identifies this mm_struct.  A ctx_id will never
168c2ecf20Sopenharmony_ci	 * be reused, and zero is not a valid ctx_id.
178c2ecf20Sopenharmony_ci	 */
188c2ecf20Sopenharmony_ci	u64 ctx_id;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	/*
218c2ecf20Sopenharmony_ci	 * Any code that needs to do any sort of TLB flushing for this
228c2ecf20Sopenharmony_ci	 * mm will first make its changes to the page tables, then
238c2ecf20Sopenharmony_ci	 * increment tlb_gen, then flush.  This lets the low-level
248c2ecf20Sopenharmony_ci	 * flushing code keep track of what needs flushing.
258c2ecf20Sopenharmony_ci	 *
268c2ecf20Sopenharmony_ci	 * This is not used on Xen PV.
278c2ecf20Sopenharmony_ci	 */
288c2ecf20Sopenharmony_ci	atomic64_t tlb_gen;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#ifdef CONFIG_MODIFY_LDT_SYSCALL
318c2ecf20Sopenharmony_ci	struct rw_semaphore	ldt_usr_sem;
328c2ecf20Sopenharmony_ci	struct ldt_struct	*ldt;
338c2ecf20Sopenharmony_ci#endif
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64
368c2ecf20Sopenharmony_ci	/* True if mm supports a task running in 32 bit compatibility mode. */
378c2ecf20Sopenharmony_ci	unsigned short ia32_compat;
388c2ecf20Sopenharmony_ci#endif
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	struct mutex lock;
418c2ecf20Sopenharmony_ci	void __user *vdso;			/* vdso base address */
428c2ecf20Sopenharmony_ci	const struct vdso_image *vdso_image;	/* vdso image in use */
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	atomic_t perf_rdpmc_allowed;	/* nonzero if rdpmc is allowed */
458c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
468c2ecf20Sopenharmony_ci	/*
478c2ecf20Sopenharmony_ci	 * One bit per protection key says whether userspace can
488c2ecf20Sopenharmony_ci	 * use it or not.  protected by mmap_lock.
498c2ecf20Sopenharmony_ci	 */
508c2ecf20Sopenharmony_ci	u16 pkey_allocation_map;
518c2ecf20Sopenharmony_ci	s16 execute_only_pkey;
528c2ecf20Sopenharmony_ci#endif
538c2ecf20Sopenharmony_ci} mm_context_t;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define INIT_MM_CONTEXT(mm)						\
568c2ecf20Sopenharmony_ci	.context = {							\
578c2ecf20Sopenharmony_ci		.ctx_id = 1,						\
588c2ecf20Sopenharmony_ci		.lock = __MUTEX_INITIALIZER(mm.context.lock),		\
598c2ecf20Sopenharmony_ci	}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_civoid leave_mm(int cpu);
628c2ecf20Sopenharmony_ci#define leave_mm leave_mm
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#endif /* _ASM_X86_MMU_H */
65