162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_X86_PROCESSOR_H
362306a36Sopenharmony_ci#define _ASM_X86_PROCESSOR_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <asm/processor-flags.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/* Forward declaration, a strange C thing */
862306a36Sopenharmony_cistruct task_struct;
962306a36Sopenharmony_cistruct mm_struct;
1062306a36Sopenharmony_cistruct io_bitmap;
1162306a36Sopenharmony_cistruct vm86;
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <asm/math_emu.h>
1462306a36Sopenharmony_ci#include <asm/segment.h>
1562306a36Sopenharmony_ci#include <asm/types.h>
1662306a36Sopenharmony_ci#include <uapi/asm/sigcontext.h>
1762306a36Sopenharmony_ci#include <asm/current.h>
1862306a36Sopenharmony_ci#include <asm/cpufeatures.h>
1962306a36Sopenharmony_ci#include <asm/cpuid.h>
2062306a36Sopenharmony_ci#include <asm/page.h>
2162306a36Sopenharmony_ci#include <asm/pgtable_types.h>
2262306a36Sopenharmony_ci#include <asm/percpu.h>
2362306a36Sopenharmony_ci#include <asm/msr.h>
2462306a36Sopenharmony_ci#include <asm/desc_defs.h>
2562306a36Sopenharmony_ci#include <asm/nops.h>
2662306a36Sopenharmony_ci#include <asm/special_insns.h>
2762306a36Sopenharmony_ci#include <asm/fpu/types.h>
2862306a36Sopenharmony_ci#include <asm/unwind_hints.h>
2962306a36Sopenharmony_ci#include <asm/vmxfeatures.h>
3062306a36Sopenharmony_ci#include <asm/vdso/processor.h>
3162306a36Sopenharmony_ci#include <asm/shstk.h>
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#include <linux/personality.h>
3462306a36Sopenharmony_ci#include <linux/cache.h>
3562306a36Sopenharmony_ci#include <linux/threads.h>
3662306a36Sopenharmony_ci#include <linux/math64.h>
3762306a36Sopenharmony_ci#include <linux/err.h>
3862306a36Sopenharmony_ci#include <linux/irqflags.h>
3962306a36Sopenharmony_ci#include <linux/mem_encrypt.h>
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*
4262306a36Sopenharmony_ci * We handle most unaligned accesses in hardware.  On the other hand
4362306a36Sopenharmony_ci * unaligned DMA can be quite expensive on some Nehalem processors.
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci * Based on this we disable the IP header alignment in network drivers.
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_ci#define NET_IP_ALIGN	0
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define HBP_NUM 4
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/*
5262306a36Sopenharmony_ci * These alignment constraints are for performance in the vSMP case,
5362306a36Sopenharmony_ci * but in the task_struct case we must also meet hardware imposed
5462306a36Sopenharmony_ci * alignment requirements of the FPU state:
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_ci#ifdef CONFIG_X86_VSMP
5762306a36Sopenharmony_ci# define ARCH_MIN_TASKALIGN		(1 << INTERNODE_CACHE_SHIFT)
5862306a36Sopenharmony_ci# define ARCH_MIN_MMSTRUCT_ALIGN	(1 << INTERNODE_CACHE_SHIFT)
5962306a36Sopenharmony_ci#else
6062306a36Sopenharmony_ci# define ARCH_MIN_TASKALIGN		__alignof__(union fpregs_state)
6162306a36Sopenharmony_ci# define ARCH_MIN_MMSTRUCT_ALIGN	0
6262306a36Sopenharmony_ci#endif
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_cienum tlb_infos {
6562306a36Sopenharmony_ci	ENTRIES,
6662306a36Sopenharmony_ci	NR_INFO
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciextern u16 __read_mostly tlb_lli_4k[NR_INFO];
7062306a36Sopenharmony_ciextern u16 __read_mostly tlb_lli_2m[NR_INFO];
7162306a36Sopenharmony_ciextern u16 __read_mostly tlb_lli_4m[NR_INFO];
7262306a36Sopenharmony_ciextern u16 __read_mostly tlb_lld_4k[NR_INFO];
7362306a36Sopenharmony_ciextern u16 __read_mostly tlb_lld_2m[NR_INFO];
7462306a36Sopenharmony_ciextern u16 __read_mostly tlb_lld_4m[NR_INFO];
7562306a36Sopenharmony_ciextern u16 __read_mostly tlb_lld_1g[NR_INFO];
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/*
7862306a36Sopenharmony_ci *  CPU type and hardware bug flags. Kept separately for each CPU.
7962306a36Sopenharmony_ci *  Members of this structure are referenced in head_32.S, so think twice
8062306a36Sopenharmony_ci *  before touching them. [mj]
8162306a36Sopenharmony_ci */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_cistruct cpuinfo_x86 {
8462306a36Sopenharmony_ci	__u8			x86;		/* CPU family */
8562306a36Sopenharmony_ci	__u8			x86_vendor;	/* CPU vendor */
8662306a36Sopenharmony_ci	__u8			x86_model;
8762306a36Sopenharmony_ci	__u8			x86_stepping;
8862306a36Sopenharmony_ci#ifdef CONFIG_X86_64
8962306a36Sopenharmony_ci	/* Number of 4K pages in DTLB/ITLB combined(in pages): */
9062306a36Sopenharmony_ci	int			x86_tlbsize;
9162306a36Sopenharmony_ci#endif
9262306a36Sopenharmony_ci#ifdef CONFIG_X86_VMX_FEATURE_NAMES
9362306a36Sopenharmony_ci	__u32			vmx_capability[NVMXINTS];
9462306a36Sopenharmony_ci#endif
9562306a36Sopenharmony_ci	__u8			x86_virt_bits;
9662306a36Sopenharmony_ci	__u8			x86_phys_bits;
9762306a36Sopenharmony_ci	/* CPUID returned core id bits: */
9862306a36Sopenharmony_ci	__u8			x86_coreid_bits;
9962306a36Sopenharmony_ci	__u8			cu_id;
10062306a36Sopenharmony_ci	/* Max extended CPUID function supported: */
10162306a36Sopenharmony_ci	__u32			extended_cpuid_level;
10262306a36Sopenharmony_ci	/* Maximum supported CPUID level, -1=no CPUID: */
10362306a36Sopenharmony_ci	int			cpuid_level;
10462306a36Sopenharmony_ci	/*
10562306a36Sopenharmony_ci	 * Align to size of unsigned long because the x86_capability array
10662306a36Sopenharmony_ci	 * is passed to bitops which require the alignment. Use unnamed
10762306a36Sopenharmony_ci	 * union to enforce the array is aligned to size of unsigned long.
10862306a36Sopenharmony_ci	 */
10962306a36Sopenharmony_ci	union {
11062306a36Sopenharmony_ci		__u32		x86_capability[NCAPINTS + NBUGINTS];
11162306a36Sopenharmony_ci		unsigned long	x86_capability_alignment;
11262306a36Sopenharmony_ci	};
11362306a36Sopenharmony_ci	char			x86_vendor_id[16];
11462306a36Sopenharmony_ci	char			x86_model_id[64];
11562306a36Sopenharmony_ci	/* in KB - valid for CPUS which support this call: */
11662306a36Sopenharmony_ci	unsigned int		x86_cache_size;
11762306a36Sopenharmony_ci	int			x86_cache_alignment;	/* In bytes */
11862306a36Sopenharmony_ci	/* Cache QoS architectural values, valid only on the BSP: */
11962306a36Sopenharmony_ci	int			x86_cache_max_rmid;	/* max index */
12062306a36Sopenharmony_ci	int			x86_cache_occ_scale;	/* scale to bytes */
12162306a36Sopenharmony_ci	int			x86_cache_mbm_width_offset;
12262306a36Sopenharmony_ci	int			x86_power;
12362306a36Sopenharmony_ci	unsigned long		loops_per_jiffy;
12462306a36Sopenharmony_ci	/* protected processor identification number */
12562306a36Sopenharmony_ci	u64			ppin;
12662306a36Sopenharmony_ci	/* cpuid returned max cores value: */
12762306a36Sopenharmony_ci	u16			x86_max_cores;
12862306a36Sopenharmony_ci	u16			apicid;
12962306a36Sopenharmony_ci	u16			initial_apicid;
13062306a36Sopenharmony_ci	u16			x86_clflush_size;
13162306a36Sopenharmony_ci	/* number of cores as seen by the OS: */
13262306a36Sopenharmony_ci	u16			booted_cores;
13362306a36Sopenharmony_ci	/* Physical processor id: */
13462306a36Sopenharmony_ci	u16			phys_proc_id;
13562306a36Sopenharmony_ci	/* Logical processor id: */
13662306a36Sopenharmony_ci	u16			logical_proc_id;
13762306a36Sopenharmony_ci	/* Core id: */
13862306a36Sopenharmony_ci	u16			cpu_core_id;
13962306a36Sopenharmony_ci	u16			cpu_die_id;
14062306a36Sopenharmony_ci	u16			logical_die_id;
14162306a36Sopenharmony_ci	/* Index into per_cpu list: */
14262306a36Sopenharmony_ci	u16			cpu_index;
14362306a36Sopenharmony_ci	/*  Is SMT active on this core? */
14462306a36Sopenharmony_ci	bool			smt_active;
14562306a36Sopenharmony_ci	u32			microcode;
14662306a36Sopenharmony_ci	/* Address space bits used by the cache internally */
14762306a36Sopenharmony_ci	u8			x86_cache_bits;
14862306a36Sopenharmony_ci	unsigned		initialized : 1;
14962306a36Sopenharmony_ci} __randomize_layout;
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define X86_VENDOR_INTEL	0
15262306a36Sopenharmony_ci#define X86_VENDOR_CYRIX	1
15362306a36Sopenharmony_ci#define X86_VENDOR_AMD		2
15462306a36Sopenharmony_ci#define X86_VENDOR_UMC		3
15562306a36Sopenharmony_ci#define X86_VENDOR_CENTAUR	5
15662306a36Sopenharmony_ci#define X86_VENDOR_TRANSMETA	7
15762306a36Sopenharmony_ci#define X86_VENDOR_NSC		8
15862306a36Sopenharmony_ci#define X86_VENDOR_HYGON	9
15962306a36Sopenharmony_ci#define X86_VENDOR_ZHAOXIN	10
16062306a36Sopenharmony_ci#define X86_VENDOR_VORTEX	11
16162306a36Sopenharmony_ci#define X86_VENDOR_NUM		12
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci#define X86_VENDOR_UNKNOWN	0xff
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/*
16662306a36Sopenharmony_ci * capabilities of CPUs
16762306a36Sopenharmony_ci */
16862306a36Sopenharmony_ciextern struct cpuinfo_x86	boot_cpu_data;
16962306a36Sopenharmony_ciextern struct cpuinfo_x86	new_cpu_data;
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ciextern __u32			cpu_caps_cleared[NCAPINTS + NBUGINTS];
17262306a36Sopenharmony_ciextern __u32			cpu_caps_set[NCAPINTS + NBUGINTS];
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci#ifdef CONFIG_SMP
17562306a36Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
17662306a36Sopenharmony_ci#define cpu_data(cpu)		per_cpu(cpu_info, cpu)
17762306a36Sopenharmony_ci#else
17862306a36Sopenharmony_ci#define cpu_info		boot_cpu_data
17962306a36Sopenharmony_ci#define cpu_data(cpu)		boot_cpu_data
18062306a36Sopenharmony_ci#endif
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ciextern const struct seq_operations cpuinfo_op;
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#define cache_line_size()	(boot_cpu_data.x86_cache_alignment)
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ciextern void cpu_detect(struct cpuinfo_x86 *c);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_cistatic inline unsigned long long l1tf_pfn_limit(void)
18962306a36Sopenharmony_ci{
19062306a36Sopenharmony_ci	return BIT_ULL(boot_cpu_data.x86_cache_bits - 1 - PAGE_SHIFT);
19162306a36Sopenharmony_ci}
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ciextern void early_cpu_init(void);
19462306a36Sopenharmony_ciextern void identify_secondary_cpu(struct cpuinfo_x86 *);
19562306a36Sopenharmony_ciextern void print_cpu_info(struct cpuinfo_x86 *);
19662306a36Sopenharmony_civoid print_cpu_msr(struct cpuinfo_x86 *);
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci/*
19962306a36Sopenharmony_ci * Friendlier CR3 helpers.
20062306a36Sopenharmony_ci */
20162306a36Sopenharmony_cistatic inline unsigned long read_cr3_pa(void)
20262306a36Sopenharmony_ci{
20362306a36Sopenharmony_ci	return __read_cr3() & CR3_ADDR_MASK;
20462306a36Sopenharmony_ci}
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_cistatic inline unsigned long native_read_cr3_pa(void)
20762306a36Sopenharmony_ci{
20862306a36Sopenharmony_ci	return __native_read_cr3() & CR3_ADDR_MASK;
20962306a36Sopenharmony_ci}
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_cistatic inline void load_cr3(pgd_t *pgdir)
21262306a36Sopenharmony_ci{
21362306a36Sopenharmony_ci	write_cr3(__sme_pa(pgdir));
21462306a36Sopenharmony_ci}
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci/*
21762306a36Sopenharmony_ci * Note that while the legacy 'TSS' name comes from 'Task State Segment',
21862306a36Sopenharmony_ci * on modern x86 CPUs the TSS also holds information important to 64-bit mode,
21962306a36Sopenharmony_ci * unrelated to the task-switch mechanism:
22062306a36Sopenharmony_ci */
22162306a36Sopenharmony_ci#ifdef CONFIG_X86_32
22262306a36Sopenharmony_ci/* This is the TSS defined by the hardware. */
22362306a36Sopenharmony_cistruct x86_hw_tss {
22462306a36Sopenharmony_ci	unsigned short		back_link, __blh;
22562306a36Sopenharmony_ci	unsigned long		sp0;
22662306a36Sopenharmony_ci	unsigned short		ss0, __ss0h;
22762306a36Sopenharmony_ci	unsigned long		sp1;
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	/*
23062306a36Sopenharmony_ci	 * We don't use ring 1, so ss1 is a convenient scratch space in
23162306a36Sopenharmony_ci	 * the same cacheline as sp0.  We use ss1 to cache the value in
23262306a36Sopenharmony_ci	 * MSR_IA32_SYSENTER_CS.  When we context switch
23362306a36Sopenharmony_ci	 * MSR_IA32_SYSENTER_CS, we first check if the new value being
23462306a36Sopenharmony_ci	 * written matches ss1, and, if it's not, then we wrmsr the new
23562306a36Sopenharmony_ci	 * value and update ss1.
23662306a36Sopenharmony_ci	 *
23762306a36Sopenharmony_ci	 * The only reason we context switch MSR_IA32_SYSENTER_CS is
23862306a36Sopenharmony_ci	 * that we set it to zero in vm86 tasks to avoid corrupting the
23962306a36Sopenharmony_ci	 * stack if we were to go through the sysenter path from vm86
24062306a36Sopenharmony_ci	 * mode.
24162306a36Sopenharmony_ci	 */
24262306a36Sopenharmony_ci	unsigned short		ss1;	/* MSR_IA32_SYSENTER_CS */
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	unsigned short		__ss1h;
24562306a36Sopenharmony_ci	unsigned long		sp2;
24662306a36Sopenharmony_ci	unsigned short		ss2, __ss2h;
24762306a36Sopenharmony_ci	unsigned long		__cr3;
24862306a36Sopenharmony_ci	unsigned long		ip;
24962306a36Sopenharmony_ci	unsigned long		flags;
25062306a36Sopenharmony_ci	unsigned long		ax;
25162306a36Sopenharmony_ci	unsigned long		cx;
25262306a36Sopenharmony_ci	unsigned long		dx;
25362306a36Sopenharmony_ci	unsigned long		bx;
25462306a36Sopenharmony_ci	unsigned long		sp;
25562306a36Sopenharmony_ci	unsigned long		bp;
25662306a36Sopenharmony_ci	unsigned long		si;
25762306a36Sopenharmony_ci	unsigned long		di;
25862306a36Sopenharmony_ci	unsigned short		es, __esh;
25962306a36Sopenharmony_ci	unsigned short		cs, __csh;
26062306a36Sopenharmony_ci	unsigned short		ss, __ssh;
26162306a36Sopenharmony_ci	unsigned short		ds, __dsh;
26262306a36Sopenharmony_ci	unsigned short		fs, __fsh;
26362306a36Sopenharmony_ci	unsigned short		gs, __gsh;
26462306a36Sopenharmony_ci	unsigned short		ldt, __ldth;
26562306a36Sopenharmony_ci	unsigned short		trace;
26662306a36Sopenharmony_ci	unsigned short		io_bitmap_base;
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci} __attribute__((packed));
26962306a36Sopenharmony_ci#else
27062306a36Sopenharmony_cistruct x86_hw_tss {
27162306a36Sopenharmony_ci	u32			reserved1;
27262306a36Sopenharmony_ci	u64			sp0;
27362306a36Sopenharmony_ci	u64			sp1;
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci	/*
27662306a36Sopenharmony_ci	 * Since Linux does not use ring 2, the 'sp2' slot is unused by
27762306a36Sopenharmony_ci	 * hardware.  entry_SYSCALL_64 uses it as scratch space to stash
27862306a36Sopenharmony_ci	 * the user RSP value.
27962306a36Sopenharmony_ci	 */
28062306a36Sopenharmony_ci	u64			sp2;
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci	u64			reserved2;
28362306a36Sopenharmony_ci	u64			ist[7];
28462306a36Sopenharmony_ci	u32			reserved3;
28562306a36Sopenharmony_ci	u32			reserved4;
28662306a36Sopenharmony_ci	u16			reserved5;
28762306a36Sopenharmony_ci	u16			io_bitmap_base;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci} __attribute__((packed));
29062306a36Sopenharmony_ci#endif
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci/*
29362306a36Sopenharmony_ci * IO-bitmap sizes:
29462306a36Sopenharmony_ci */
29562306a36Sopenharmony_ci#define IO_BITMAP_BITS			65536
29662306a36Sopenharmony_ci#define IO_BITMAP_BYTES			(IO_BITMAP_BITS / BITS_PER_BYTE)
29762306a36Sopenharmony_ci#define IO_BITMAP_LONGS			(IO_BITMAP_BYTES / sizeof(long))
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci#define IO_BITMAP_OFFSET_VALID_MAP				\
30062306a36Sopenharmony_ci	(offsetof(struct tss_struct, io_bitmap.bitmap) -	\
30162306a36Sopenharmony_ci	 offsetof(struct tss_struct, x86_tss))
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci#define IO_BITMAP_OFFSET_VALID_ALL				\
30462306a36Sopenharmony_ci	(offsetof(struct tss_struct, io_bitmap.mapall) -	\
30562306a36Sopenharmony_ci	 offsetof(struct tss_struct, x86_tss))
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci#ifdef CONFIG_X86_IOPL_IOPERM
30862306a36Sopenharmony_ci/*
30962306a36Sopenharmony_ci * sizeof(unsigned long) coming from an extra "long" at the end of the
31062306a36Sopenharmony_ci * iobitmap. The limit is inclusive, i.e. the last valid byte.
31162306a36Sopenharmony_ci */
31262306a36Sopenharmony_ci# define __KERNEL_TSS_LIMIT	\
31362306a36Sopenharmony_ci	(IO_BITMAP_OFFSET_VALID_ALL + IO_BITMAP_BYTES + \
31462306a36Sopenharmony_ci	 sizeof(unsigned long) - 1)
31562306a36Sopenharmony_ci#else
31662306a36Sopenharmony_ci# define __KERNEL_TSS_LIMIT	\
31762306a36Sopenharmony_ci	(offsetof(struct tss_struct, x86_tss) + sizeof(struct x86_hw_tss) - 1)
31862306a36Sopenharmony_ci#endif
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci/* Base offset outside of TSS_LIMIT so unpriviledged IO causes #GP */
32162306a36Sopenharmony_ci#define IO_BITMAP_OFFSET_INVALID	(__KERNEL_TSS_LIMIT + 1)
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_cistruct entry_stack {
32462306a36Sopenharmony_ci	char	stack[PAGE_SIZE];
32562306a36Sopenharmony_ci};
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_cistruct entry_stack_page {
32862306a36Sopenharmony_ci	struct entry_stack stack;
32962306a36Sopenharmony_ci} __aligned(PAGE_SIZE);
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ci/*
33262306a36Sopenharmony_ci * All IO bitmap related data stored in the TSS:
33362306a36Sopenharmony_ci */
33462306a36Sopenharmony_cistruct x86_io_bitmap {
33562306a36Sopenharmony_ci	/* The sequence number of the last active bitmap. */
33662306a36Sopenharmony_ci	u64			prev_sequence;
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci	/*
33962306a36Sopenharmony_ci	 * Store the dirty size of the last io bitmap offender. The next
34062306a36Sopenharmony_ci	 * one will have to do the cleanup as the switch out to a non io
34162306a36Sopenharmony_ci	 * bitmap user will just set x86_tss.io_bitmap_base to a value
34262306a36Sopenharmony_ci	 * outside of the TSS limit. So for sane tasks there is no need to
34362306a36Sopenharmony_ci	 * actually touch the io_bitmap at all.
34462306a36Sopenharmony_ci	 */
34562306a36Sopenharmony_ci	unsigned int		prev_max;
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci	/*
34862306a36Sopenharmony_ci	 * The extra 1 is there because the CPU will access an
34962306a36Sopenharmony_ci	 * additional byte beyond the end of the IO permission
35062306a36Sopenharmony_ci	 * bitmap. The extra byte must be all 1 bits, and must
35162306a36Sopenharmony_ci	 * be within the limit.
35262306a36Sopenharmony_ci	 */
35362306a36Sopenharmony_ci	unsigned long		bitmap[IO_BITMAP_LONGS + 1];
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci	/*
35662306a36Sopenharmony_ci	 * Special I/O bitmap to emulate IOPL(3). All bytes zero,
35762306a36Sopenharmony_ci	 * except the additional byte at the end.
35862306a36Sopenharmony_ci	 */
35962306a36Sopenharmony_ci	unsigned long		mapall[IO_BITMAP_LONGS + 1];
36062306a36Sopenharmony_ci};
36162306a36Sopenharmony_ci
36262306a36Sopenharmony_cistruct tss_struct {
36362306a36Sopenharmony_ci	/*
36462306a36Sopenharmony_ci	 * The fixed hardware portion.  This must not cross a page boundary
36562306a36Sopenharmony_ci	 * at risk of violating the SDM's advice and potentially triggering
36662306a36Sopenharmony_ci	 * errata.
36762306a36Sopenharmony_ci	 */
36862306a36Sopenharmony_ci	struct x86_hw_tss	x86_tss;
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci	struct x86_io_bitmap	io_bitmap;
37162306a36Sopenharmony_ci} __aligned(PAGE_SIZE);
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ciDECLARE_PER_CPU_PAGE_ALIGNED(struct tss_struct, cpu_tss_rw);
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci/* Per CPU interrupt stacks */
37662306a36Sopenharmony_cistruct irq_stack {
37762306a36Sopenharmony_ci	char		stack[IRQ_STACK_SIZE];
37862306a36Sopenharmony_ci} __aligned(IRQ_STACK_SIZE);
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci#ifdef CONFIG_X86_64
38162306a36Sopenharmony_cistruct fixed_percpu_data {
38262306a36Sopenharmony_ci	/*
38362306a36Sopenharmony_ci	 * GCC hardcodes the stack canary as %gs:40.  Since the
38462306a36Sopenharmony_ci	 * irq_stack is the object at %gs:0, we reserve the bottom
38562306a36Sopenharmony_ci	 * 48 bytes of the irq stack for the canary.
38662306a36Sopenharmony_ci	 *
38762306a36Sopenharmony_ci	 * Once we are willing to require -mstack-protector-guard-symbol=
38862306a36Sopenharmony_ci	 * support for x86_64 stackprotector, we can get rid of this.
38962306a36Sopenharmony_ci	 */
39062306a36Sopenharmony_ci	char		gs_base[40];
39162306a36Sopenharmony_ci	unsigned long	stack_canary;
39262306a36Sopenharmony_ci};
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ciDECLARE_PER_CPU_FIRST(struct fixed_percpu_data, fixed_percpu_data) __visible;
39562306a36Sopenharmony_ciDECLARE_INIT_PER_CPU(fixed_percpu_data);
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_cistatic inline unsigned long cpu_kernelmode_gs_base(int cpu)
39862306a36Sopenharmony_ci{
39962306a36Sopenharmony_ci	return (unsigned long)per_cpu(fixed_percpu_data.gs_base, cpu);
40062306a36Sopenharmony_ci}
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_ciextern asmlinkage void ignore_sysret(void);
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ci/* Save actual FS/GS selectors and bases to current->thread */
40562306a36Sopenharmony_civoid current_save_fsgs(void);
40662306a36Sopenharmony_ci#else	/* X86_64 */
40762306a36Sopenharmony_ci#ifdef CONFIG_STACKPROTECTOR
40862306a36Sopenharmony_ciDECLARE_PER_CPU(unsigned long, __stack_chk_guard);
40962306a36Sopenharmony_ci#endif
41062306a36Sopenharmony_ci#endif	/* !X86_64 */
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_cistruct perf_event;
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_cistruct thread_struct {
41562306a36Sopenharmony_ci	/* Cached TLS descriptors: */
41662306a36Sopenharmony_ci	struct desc_struct	tls_array[GDT_ENTRY_TLS_ENTRIES];
41762306a36Sopenharmony_ci#ifdef CONFIG_X86_32
41862306a36Sopenharmony_ci	unsigned long		sp0;
41962306a36Sopenharmony_ci#endif
42062306a36Sopenharmony_ci	unsigned long		sp;
42162306a36Sopenharmony_ci#ifdef CONFIG_X86_32
42262306a36Sopenharmony_ci	unsigned long		sysenter_cs;
42362306a36Sopenharmony_ci#else
42462306a36Sopenharmony_ci	unsigned short		es;
42562306a36Sopenharmony_ci	unsigned short		ds;
42662306a36Sopenharmony_ci	unsigned short		fsindex;
42762306a36Sopenharmony_ci	unsigned short		gsindex;
42862306a36Sopenharmony_ci#endif
42962306a36Sopenharmony_ci
43062306a36Sopenharmony_ci#ifdef CONFIG_X86_64
43162306a36Sopenharmony_ci	unsigned long		fsbase;
43262306a36Sopenharmony_ci	unsigned long		gsbase;
43362306a36Sopenharmony_ci#else
43462306a36Sopenharmony_ci	/*
43562306a36Sopenharmony_ci	 * XXX: this could presumably be unsigned short.  Alternatively,
43662306a36Sopenharmony_ci	 * 32-bit kernels could be taught to use fsindex instead.
43762306a36Sopenharmony_ci	 */
43862306a36Sopenharmony_ci	unsigned long fs;
43962306a36Sopenharmony_ci	unsigned long gs;
44062306a36Sopenharmony_ci#endif
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci	/* Save middle states of ptrace breakpoints */
44362306a36Sopenharmony_ci	struct perf_event	*ptrace_bps[HBP_NUM];
44462306a36Sopenharmony_ci	/* Debug status used for traps, single steps, etc... */
44562306a36Sopenharmony_ci	unsigned long           virtual_dr6;
44662306a36Sopenharmony_ci	/* Keep track of the exact dr7 value set by the user */
44762306a36Sopenharmony_ci	unsigned long           ptrace_dr7;
44862306a36Sopenharmony_ci	/* Fault info: */
44962306a36Sopenharmony_ci	unsigned long		cr2;
45062306a36Sopenharmony_ci	unsigned long		trap_nr;
45162306a36Sopenharmony_ci	unsigned long		error_code;
45262306a36Sopenharmony_ci#ifdef CONFIG_VM86
45362306a36Sopenharmony_ci	/* Virtual 86 mode info */
45462306a36Sopenharmony_ci	struct vm86		*vm86;
45562306a36Sopenharmony_ci#endif
45662306a36Sopenharmony_ci	/* IO permissions: */
45762306a36Sopenharmony_ci	struct io_bitmap	*io_bitmap;
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci	/*
46062306a36Sopenharmony_ci	 * IOPL. Privilege level dependent I/O permission which is
46162306a36Sopenharmony_ci	 * emulated via the I/O bitmap to prevent user space from disabling
46262306a36Sopenharmony_ci	 * interrupts.
46362306a36Sopenharmony_ci	 */
46462306a36Sopenharmony_ci	unsigned long		iopl_emul;
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci	unsigned int		iopl_warn:1;
46762306a36Sopenharmony_ci	unsigned int		sig_on_uaccess_err:1;
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci	/*
47062306a36Sopenharmony_ci	 * Protection Keys Register for Userspace.  Loaded immediately on
47162306a36Sopenharmony_ci	 * context switch. Store it in thread_struct to avoid a lookup in
47262306a36Sopenharmony_ci	 * the tasks's FPU xstate buffer. This value is only valid when a
47362306a36Sopenharmony_ci	 * task is scheduled out. For 'current' the authoritative source of
47462306a36Sopenharmony_ci	 * PKRU is the hardware itself.
47562306a36Sopenharmony_ci	 */
47662306a36Sopenharmony_ci	u32			pkru;
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci#ifdef CONFIG_X86_USER_SHADOW_STACK
47962306a36Sopenharmony_ci	unsigned long		features;
48062306a36Sopenharmony_ci	unsigned long		features_locked;
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci	struct thread_shstk	shstk;
48362306a36Sopenharmony_ci#endif
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ci	/* Floating point and extended processor state */
48662306a36Sopenharmony_ci	struct fpu		fpu;
48762306a36Sopenharmony_ci	/*
48862306a36Sopenharmony_ci	 * WARNING: 'fpu' is dynamically-sized.  It *MUST* be at
48962306a36Sopenharmony_ci	 * the end.
49062306a36Sopenharmony_ci	 */
49162306a36Sopenharmony_ci};
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ciextern void fpu_thread_struct_whitelist(unsigned long *offset, unsigned long *size);
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_cistatic inline void arch_thread_struct_whitelist(unsigned long *offset,
49662306a36Sopenharmony_ci						unsigned long *size)
49762306a36Sopenharmony_ci{
49862306a36Sopenharmony_ci	fpu_thread_struct_whitelist(offset, size);
49962306a36Sopenharmony_ci}
50062306a36Sopenharmony_ci
50162306a36Sopenharmony_cistatic inline void
50262306a36Sopenharmony_cinative_load_sp0(unsigned long sp0)
50362306a36Sopenharmony_ci{
50462306a36Sopenharmony_ci	this_cpu_write(cpu_tss_rw.x86_tss.sp0, sp0);
50562306a36Sopenharmony_ci}
50662306a36Sopenharmony_ci
50762306a36Sopenharmony_cistatic __always_inline void native_swapgs(void)
50862306a36Sopenharmony_ci{
50962306a36Sopenharmony_ci#ifdef CONFIG_X86_64
51062306a36Sopenharmony_ci	asm volatile("swapgs" ::: "memory");
51162306a36Sopenharmony_ci#endif
51262306a36Sopenharmony_ci}
51362306a36Sopenharmony_ci
51462306a36Sopenharmony_cistatic __always_inline unsigned long current_top_of_stack(void)
51562306a36Sopenharmony_ci{
51662306a36Sopenharmony_ci	/*
51762306a36Sopenharmony_ci	 *  We can't read directly from tss.sp0: sp0 on x86_32 is special in
51862306a36Sopenharmony_ci	 *  and around vm86 mode and sp0 on x86_64 is special because of the
51962306a36Sopenharmony_ci	 *  entry trampoline.
52062306a36Sopenharmony_ci	 */
52162306a36Sopenharmony_ci	return this_cpu_read_stable(pcpu_hot.top_of_stack);
52262306a36Sopenharmony_ci}
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_cistatic __always_inline bool on_thread_stack(void)
52562306a36Sopenharmony_ci{
52662306a36Sopenharmony_ci	return (unsigned long)(current_top_of_stack() -
52762306a36Sopenharmony_ci			       current_stack_pointer) < THREAD_SIZE;
52862306a36Sopenharmony_ci}
52962306a36Sopenharmony_ci
53062306a36Sopenharmony_ci#ifdef CONFIG_PARAVIRT_XXL
53162306a36Sopenharmony_ci#include <asm/paravirt.h>
53262306a36Sopenharmony_ci#else
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_cistatic inline void load_sp0(unsigned long sp0)
53562306a36Sopenharmony_ci{
53662306a36Sopenharmony_ci	native_load_sp0(sp0);
53762306a36Sopenharmony_ci}
53862306a36Sopenharmony_ci
53962306a36Sopenharmony_ci#endif /* CONFIG_PARAVIRT_XXL */
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ciunsigned long __get_wchan(struct task_struct *p);
54262306a36Sopenharmony_ci
54362306a36Sopenharmony_ciextern void select_idle_routine(const struct cpuinfo_x86 *c);
54462306a36Sopenharmony_ciextern void amd_e400_c1e_apic_setup(void);
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ciextern unsigned long		boot_option_idle_override;
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_cienum idle_boot_override {IDLE_NO_OVERRIDE=0, IDLE_HALT, IDLE_NOMWAIT,
54962306a36Sopenharmony_ci			 IDLE_POLL};
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ciextern void enable_sep_cpu(void);
55262306a36Sopenharmony_ci
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci/* Defined in head.S */
55562306a36Sopenharmony_ciextern struct desc_ptr		early_gdt_descr;
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ciextern void switch_gdt_and_percpu_base(int);
55862306a36Sopenharmony_ciextern void load_direct_gdt(int);
55962306a36Sopenharmony_ciextern void load_fixmap_gdt(int);
56062306a36Sopenharmony_ciextern void cpu_init(void);
56162306a36Sopenharmony_ciextern void cpu_init_exception_handling(void);
56262306a36Sopenharmony_ciextern void cr4_init(void);
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_cistatic inline unsigned long get_debugctlmsr(void)
56562306a36Sopenharmony_ci{
56662306a36Sopenharmony_ci	unsigned long debugctlmsr = 0;
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci#ifndef CONFIG_X86_DEBUGCTLMSR
56962306a36Sopenharmony_ci	if (boot_cpu_data.x86 < 6)
57062306a36Sopenharmony_ci		return 0;
57162306a36Sopenharmony_ci#endif
57262306a36Sopenharmony_ci	rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_ci	return debugctlmsr;
57562306a36Sopenharmony_ci}
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_cistatic inline void update_debugctlmsr(unsigned long debugctlmsr)
57862306a36Sopenharmony_ci{
57962306a36Sopenharmony_ci#ifndef CONFIG_X86_DEBUGCTLMSR
58062306a36Sopenharmony_ci	if (boot_cpu_data.x86 < 6)
58162306a36Sopenharmony_ci		return;
58262306a36Sopenharmony_ci#endif
58362306a36Sopenharmony_ci	wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
58462306a36Sopenharmony_ci}
58562306a36Sopenharmony_ci
58662306a36Sopenharmony_ciextern void set_task_blockstep(struct task_struct *task, bool on);
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ci/* Boot loader type from the setup header: */
58962306a36Sopenharmony_ciextern int			bootloader_type;
59062306a36Sopenharmony_ciextern int			bootloader_version;
59162306a36Sopenharmony_ci
59262306a36Sopenharmony_ciextern char			ignore_fpu_irq;
59362306a36Sopenharmony_ci
59462306a36Sopenharmony_ci#define HAVE_ARCH_PICK_MMAP_LAYOUT 1
59562306a36Sopenharmony_ci#define ARCH_HAS_PREFETCHW
59662306a36Sopenharmony_ci
59762306a36Sopenharmony_ci#ifdef CONFIG_X86_32
59862306a36Sopenharmony_ci# define BASE_PREFETCH		""
59962306a36Sopenharmony_ci# define ARCH_HAS_PREFETCH
60062306a36Sopenharmony_ci#else
60162306a36Sopenharmony_ci# define BASE_PREFETCH		"prefetcht0 %P1"
60262306a36Sopenharmony_ci#endif
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_ci/*
60562306a36Sopenharmony_ci * Prefetch instructions for Pentium III (+) and AMD Athlon (+)
60662306a36Sopenharmony_ci *
60762306a36Sopenharmony_ci * It's not worth to care about 3dnow prefetches for the K6
60862306a36Sopenharmony_ci * because they are microcoded there and very slow.
60962306a36Sopenharmony_ci */
61062306a36Sopenharmony_cistatic inline void prefetch(const void *x)
61162306a36Sopenharmony_ci{
61262306a36Sopenharmony_ci	alternative_input(BASE_PREFETCH, "prefetchnta %P1",
61362306a36Sopenharmony_ci			  X86_FEATURE_XMM,
61462306a36Sopenharmony_ci			  "m" (*(const char *)x));
61562306a36Sopenharmony_ci}
61662306a36Sopenharmony_ci
61762306a36Sopenharmony_ci/*
61862306a36Sopenharmony_ci * 3dnow prefetch to get an exclusive cache line.
61962306a36Sopenharmony_ci * Useful for spinlocks to avoid one state transition in the
62062306a36Sopenharmony_ci * cache coherency protocol:
62162306a36Sopenharmony_ci */
62262306a36Sopenharmony_cistatic __always_inline void prefetchw(const void *x)
62362306a36Sopenharmony_ci{
62462306a36Sopenharmony_ci	alternative_input(BASE_PREFETCH, "prefetchw %P1",
62562306a36Sopenharmony_ci			  X86_FEATURE_3DNOWPREFETCH,
62662306a36Sopenharmony_ci			  "m" (*(const char *)x));
62762306a36Sopenharmony_ci}
62862306a36Sopenharmony_ci
62962306a36Sopenharmony_ci#define TOP_OF_INIT_STACK ((unsigned long)&init_stack + sizeof(init_stack) - \
63062306a36Sopenharmony_ci			   TOP_OF_KERNEL_STACK_PADDING)
63162306a36Sopenharmony_ci
63262306a36Sopenharmony_ci#define task_top_of_stack(task) ((unsigned long)(task_pt_regs(task) + 1))
63362306a36Sopenharmony_ci
63462306a36Sopenharmony_ci#define task_pt_regs(task) \
63562306a36Sopenharmony_ci({									\
63662306a36Sopenharmony_ci	unsigned long __ptr = (unsigned long)task_stack_page(task);	\
63762306a36Sopenharmony_ci	__ptr += THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING;		\
63862306a36Sopenharmony_ci	((struct pt_regs *)__ptr) - 1;					\
63962306a36Sopenharmony_ci})
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_ci#ifdef CONFIG_X86_32
64262306a36Sopenharmony_ci#define INIT_THREAD  {							  \
64362306a36Sopenharmony_ci	.sp0			= TOP_OF_INIT_STACK,			  \
64462306a36Sopenharmony_ci	.sysenter_cs		= __KERNEL_CS,				  \
64562306a36Sopenharmony_ci}
64662306a36Sopenharmony_ci
64762306a36Sopenharmony_ci#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci#else
65062306a36Sopenharmony_ciextern unsigned long __end_init_task[];
65162306a36Sopenharmony_ci
65262306a36Sopenharmony_ci#define INIT_THREAD {							    \
65362306a36Sopenharmony_ci	.sp	= (unsigned long)&__end_init_task - sizeof(struct pt_regs), \
65462306a36Sopenharmony_ci}
65562306a36Sopenharmony_ci
65662306a36Sopenharmony_ciextern unsigned long KSTK_ESP(struct task_struct *task);
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci#endif /* CONFIG_X86_64 */
65962306a36Sopenharmony_ci
66062306a36Sopenharmony_ciextern void start_thread(struct pt_regs *regs, unsigned long new_ip,
66162306a36Sopenharmony_ci					       unsigned long new_sp);
66262306a36Sopenharmony_ci
66362306a36Sopenharmony_ci/*
66462306a36Sopenharmony_ci * This decides where the kernel will search for a free chunk of vm
66562306a36Sopenharmony_ci * space during mmap's.
66662306a36Sopenharmony_ci */
66762306a36Sopenharmony_ci#define __TASK_UNMAPPED_BASE(task_size)	(PAGE_ALIGN(task_size / 3))
66862306a36Sopenharmony_ci#define TASK_UNMAPPED_BASE		__TASK_UNMAPPED_BASE(TASK_SIZE_LOW)
66962306a36Sopenharmony_ci
67062306a36Sopenharmony_ci#define KSTK_EIP(task)		(task_pt_regs(task)->ip)
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_ci/* Get/set a process' ability to use the timestamp counter instruction */
67362306a36Sopenharmony_ci#define GET_TSC_CTL(adr)	get_tsc_mode((adr))
67462306a36Sopenharmony_ci#define SET_TSC_CTL(val)	set_tsc_mode((val))
67562306a36Sopenharmony_ci
67662306a36Sopenharmony_ciextern int get_tsc_mode(unsigned long adr);
67762306a36Sopenharmony_ciextern int set_tsc_mode(unsigned int val);
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_ciDECLARE_PER_CPU(u64, msr_misc_features_shadow);
68062306a36Sopenharmony_ci
68162306a36Sopenharmony_ciextern u16 get_llc_id(unsigned int cpu);
68262306a36Sopenharmony_ci
68362306a36Sopenharmony_ci#ifdef CONFIG_CPU_SUP_AMD
68462306a36Sopenharmony_ciextern u32 amd_get_nodes_per_socket(void);
68562306a36Sopenharmony_ciextern u32 amd_get_highest_perf(void);
68662306a36Sopenharmony_ciextern void amd_clear_divider(void);
68762306a36Sopenharmony_ciextern void amd_check_microcode(void);
68862306a36Sopenharmony_ci#else
68962306a36Sopenharmony_cistatic inline u32 amd_get_nodes_per_socket(void)	{ return 0; }
69062306a36Sopenharmony_cistatic inline u32 amd_get_highest_perf(void)		{ return 0; }
69162306a36Sopenharmony_cistatic inline void amd_clear_divider(void)		{ }
69262306a36Sopenharmony_cistatic inline void amd_check_microcode(void)		{ }
69362306a36Sopenharmony_ci#endif
69462306a36Sopenharmony_ci
69562306a36Sopenharmony_ciextern unsigned long arch_align_stack(unsigned long sp);
69662306a36Sopenharmony_civoid free_init_pages(const char *what, unsigned long begin, unsigned long end);
69762306a36Sopenharmony_ciextern void free_kernel_image_pages(const char *what, void *begin, void *end);
69862306a36Sopenharmony_ci
69962306a36Sopenharmony_civoid default_idle(void);
70062306a36Sopenharmony_ci#ifdef	CONFIG_XEN
70162306a36Sopenharmony_cibool xen_set_default_idle(void);
70262306a36Sopenharmony_ci#else
70362306a36Sopenharmony_ci#define xen_set_default_idle 0
70462306a36Sopenharmony_ci#endif
70562306a36Sopenharmony_ci
70662306a36Sopenharmony_civoid __noreturn stop_this_cpu(void *dummy);
70762306a36Sopenharmony_civoid microcode_check(struct cpuinfo_x86 *prev_info);
70862306a36Sopenharmony_civoid store_cpu_caps(struct cpuinfo_x86 *info);
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_cienum l1tf_mitigations {
71162306a36Sopenharmony_ci	L1TF_MITIGATION_OFF,
71262306a36Sopenharmony_ci	L1TF_MITIGATION_FLUSH_NOWARN,
71362306a36Sopenharmony_ci	L1TF_MITIGATION_FLUSH,
71462306a36Sopenharmony_ci	L1TF_MITIGATION_FLUSH_NOSMT,
71562306a36Sopenharmony_ci	L1TF_MITIGATION_FULL,
71662306a36Sopenharmony_ci	L1TF_MITIGATION_FULL_FORCE
71762306a36Sopenharmony_ci};
71862306a36Sopenharmony_ci
71962306a36Sopenharmony_ciextern enum l1tf_mitigations l1tf_mitigation;
72062306a36Sopenharmony_ci
72162306a36Sopenharmony_cienum mds_mitigations {
72262306a36Sopenharmony_ci	MDS_MITIGATION_OFF,
72362306a36Sopenharmony_ci	MDS_MITIGATION_FULL,
72462306a36Sopenharmony_ci	MDS_MITIGATION_VMWERV,
72562306a36Sopenharmony_ci};
72662306a36Sopenharmony_ci
72762306a36Sopenharmony_ci#ifdef CONFIG_X86_SGX
72862306a36Sopenharmony_ciint arch_memory_failure(unsigned long pfn, int flags);
72962306a36Sopenharmony_ci#define arch_memory_failure arch_memory_failure
73062306a36Sopenharmony_ci
73162306a36Sopenharmony_cibool arch_is_platform_page(u64 paddr);
73262306a36Sopenharmony_ci#define arch_is_platform_page arch_is_platform_page
73362306a36Sopenharmony_ci#endif
73462306a36Sopenharmony_ci
73562306a36Sopenharmony_ciextern bool gds_ucode_mitigated(void);
73662306a36Sopenharmony_ci
73762306a36Sopenharmony_ci/*
73862306a36Sopenharmony_ci * Make previous memory operations globally visible before
73962306a36Sopenharmony_ci * a WRMSR.
74062306a36Sopenharmony_ci *
74162306a36Sopenharmony_ci * MFENCE makes writes visible, but only affects load/store
74262306a36Sopenharmony_ci * instructions.  WRMSR is unfortunately not a load/store
74362306a36Sopenharmony_ci * instruction and is unaffected by MFENCE.  The LFENCE ensures
74462306a36Sopenharmony_ci * that the WRMSR is not reordered.
74562306a36Sopenharmony_ci *
74662306a36Sopenharmony_ci * Most WRMSRs are full serializing instructions themselves and
74762306a36Sopenharmony_ci * do not require this barrier.  This is only required for the
74862306a36Sopenharmony_ci * IA32_TSC_DEADLINE and X2APIC MSRs.
74962306a36Sopenharmony_ci */
75062306a36Sopenharmony_cistatic inline void weak_wrmsr_fence(void)
75162306a36Sopenharmony_ci{
75262306a36Sopenharmony_ci	alternative("mfence; lfence", "", ALT_NOT(X86_FEATURE_APIC_MSRS_FENCE));
75362306a36Sopenharmony_ci}
75462306a36Sopenharmony_ci
75562306a36Sopenharmony_ci#endif /* _ASM_X86_PROCESSOR_H */
756