xref: /linux/arch/x86/include/asm/svm.h (revision 3ec7a1b2743c07c45f4a0c508114f6cb410ddef3)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2c2cedf7bSEduardo Habkost #ifndef __SVM_H
3c2cedf7bSEduardo Habkost #define __SVM_H
4c2cedf7bSEduardo Habkost 
5af170c50SDavid Howells #include <uapi/asm/svm.h>
69780d51dSBabu Moger #include <uapi/asm/kvm.h>
726bf264eSXiao Guangrong 
868ae7c7bSSean Christopherson #include <asm/hyperv-tlfs.h>
968ae7c7bSSean Christopherson 
10c45ad722SBabu Moger /*
11c45ad722SBabu Moger  * 32-bit intercept words in the VMCB Control Area, starting
12c45ad722SBabu Moger  * at Byte offset 000h.
13c45ad722SBabu Moger  */
14c45ad722SBabu Moger 
15c45ad722SBabu Moger enum intercept_words {
1603bfeeb9SBabu Moger 	INTERCEPT_CR = 0,
1730abaa88SBabu Moger 	INTERCEPT_DR,
189780d51dSBabu Moger 	INTERCEPT_EXCEPTION,
19c62e2e94SBabu Moger 	INTERCEPT_WORD3,
20c62e2e94SBabu Moger 	INTERCEPT_WORD4,
214c44e8d6SBabu Moger 	INTERCEPT_WORD5,
22c45ad722SBabu Moger 	MAX_INTERCEPT,
23c45ad722SBabu Moger };
2426bf264eSXiao Guangrong 
25c2cedf7bSEduardo Habkost enum {
2603bfeeb9SBabu Moger 	/* Byte offset 000h (word 0) */
2703bfeeb9SBabu Moger 	INTERCEPT_CR0_READ = 0,
2803bfeeb9SBabu Moger 	INTERCEPT_CR3_READ = 3,
2903bfeeb9SBabu Moger 	INTERCEPT_CR4_READ = 4,
3003bfeeb9SBabu Moger 	INTERCEPT_CR8_READ = 8,
3103bfeeb9SBabu Moger 	INTERCEPT_CR0_WRITE = 16,
3203bfeeb9SBabu Moger 	INTERCEPT_CR3_WRITE = 16 + 3,
3303bfeeb9SBabu Moger 	INTERCEPT_CR4_WRITE = 16 + 4,
3403bfeeb9SBabu Moger 	INTERCEPT_CR8_WRITE = 16 + 8,
3530abaa88SBabu Moger 	/* Byte offset 004h (word 1) */
3630abaa88SBabu Moger 	INTERCEPT_DR0_READ = 32,
3730abaa88SBabu Moger 	INTERCEPT_DR1_READ,
3830abaa88SBabu Moger 	INTERCEPT_DR2_READ,
3930abaa88SBabu Moger 	INTERCEPT_DR3_READ,
4030abaa88SBabu Moger 	INTERCEPT_DR4_READ,
4130abaa88SBabu Moger 	INTERCEPT_DR5_READ,
4230abaa88SBabu Moger 	INTERCEPT_DR6_READ,
4330abaa88SBabu Moger 	INTERCEPT_DR7_READ,
4430abaa88SBabu Moger 	INTERCEPT_DR0_WRITE = 48,
4530abaa88SBabu Moger 	INTERCEPT_DR1_WRITE,
4630abaa88SBabu Moger 	INTERCEPT_DR2_WRITE,
4730abaa88SBabu Moger 	INTERCEPT_DR3_WRITE,
4830abaa88SBabu Moger 	INTERCEPT_DR4_WRITE,
4930abaa88SBabu Moger 	INTERCEPT_DR5_WRITE,
5030abaa88SBabu Moger 	INTERCEPT_DR6_WRITE,
5130abaa88SBabu Moger 	INTERCEPT_DR7_WRITE,
529780d51dSBabu Moger 	/* Byte offset 008h (word 2) */
539780d51dSBabu Moger 	INTERCEPT_EXCEPTION_OFFSET = 64,
54c62e2e94SBabu Moger 	/* Byte offset 00Ch (word 3) */
55c62e2e94SBabu Moger 	INTERCEPT_INTR = 96,
56c2cedf7bSEduardo Habkost 	INTERCEPT_NMI,
57c2cedf7bSEduardo Habkost 	INTERCEPT_SMI,
58c2cedf7bSEduardo Habkost 	INTERCEPT_INIT,
59c2cedf7bSEduardo Habkost 	INTERCEPT_VINTR,
60c2cedf7bSEduardo Habkost 	INTERCEPT_SELECTIVE_CR0,
61c2cedf7bSEduardo Habkost 	INTERCEPT_STORE_IDTR,
62c2cedf7bSEduardo Habkost 	INTERCEPT_STORE_GDTR,
63c2cedf7bSEduardo Habkost 	INTERCEPT_STORE_LDTR,
64c2cedf7bSEduardo Habkost 	INTERCEPT_STORE_TR,
65c2cedf7bSEduardo Habkost 	INTERCEPT_LOAD_IDTR,
66c2cedf7bSEduardo Habkost 	INTERCEPT_LOAD_GDTR,
67c2cedf7bSEduardo Habkost 	INTERCEPT_LOAD_LDTR,
68c2cedf7bSEduardo Habkost 	INTERCEPT_LOAD_TR,
69c2cedf7bSEduardo Habkost 	INTERCEPT_RDTSC,
70c2cedf7bSEduardo Habkost 	INTERCEPT_RDPMC,
71c2cedf7bSEduardo Habkost 	INTERCEPT_PUSHF,
72c2cedf7bSEduardo Habkost 	INTERCEPT_POPF,
73c2cedf7bSEduardo Habkost 	INTERCEPT_CPUID,
74c2cedf7bSEduardo Habkost 	INTERCEPT_RSM,
75c2cedf7bSEduardo Habkost 	INTERCEPT_IRET,
76c2cedf7bSEduardo Habkost 	INTERCEPT_INTn,
77c2cedf7bSEduardo Habkost 	INTERCEPT_INVD,
78c2cedf7bSEduardo Habkost 	INTERCEPT_PAUSE,
79c2cedf7bSEduardo Habkost 	INTERCEPT_HLT,
80c2cedf7bSEduardo Habkost 	INTERCEPT_INVLPG,
81c2cedf7bSEduardo Habkost 	INTERCEPT_INVLPGA,
82c2cedf7bSEduardo Habkost 	INTERCEPT_IOIO_PROT,
83c2cedf7bSEduardo Habkost 	INTERCEPT_MSR_PROT,
84c2cedf7bSEduardo Habkost 	INTERCEPT_TASK_SWITCH,
85c2cedf7bSEduardo Habkost 	INTERCEPT_FERR_FREEZE,
86c2cedf7bSEduardo Habkost 	INTERCEPT_SHUTDOWN,
87c62e2e94SBabu Moger 	/* Byte offset 010h (word 4) */
88c62e2e94SBabu Moger 	INTERCEPT_VMRUN = 128,
89c2cedf7bSEduardo Habkost 	INTERCEPT_VMMCALL,
90c2cedf7bSEduardo Habkost 	INTERCEPT_VMLOAD,
91c2cedf7bSEduardo Habkost 	INTERCEPT_VMSAVE,
92c2cedf7bSEduardo Habkost 	INTERCEPT_STGI,
93c2cedf7bSEduardo Habkost 	INTERCEPT_CLGI,
94c2cedf7bSEduardo Habkost 	INTERCEPT_SKINIT,
95c2cedf7bSEduardo Habkost 	INTERCEPT_RDTSCP,
96c2cedf7bSEduardo Habkost 	INTERCEPT_ICEBP,
97c2cedf7bSEduardo Habkost 	INTERCEPT_WBINVD,
98c2cedf7bSEduardo Habkost 	INTERCEPT_MONITOR,
99c2cedf7bSEduardo Habkost 	INTERCEPT_MWAIT,
100c2cedf7bSEduardo Habkost 	INTERCEPT_MWAIT_COND,
10181dd35d4SJoerg Roedel 	INTERCEPT_XSETBV,
1020cb8410bSJim Mattson 	INTERCEPT_RDPRU,
103376c6d28STom Lendacky 	TRAP_EFER_WRITE,
104376c6d28STom Lendacky 	TRAP_CR0_WRITE,
105376c6d28STom Lendacky 	TRAP_CR1_WRITE,
106376c6d28STom Lendacky 	TRAP_CR2_WRITE,
107376c6d28STom Lendacky 	TRAP_CR3_WRITE,
108376c6d28STom Lendacky 	TRAP_CR4_WRITE,
109376c6d28STom Lendacky 	TRAP_CR5_WRITE,
110376c6d28STom Lendacky 	TRAP_CR6_WRITE,
111376c6d28STom Lendacky 	TRAP_CR7_WRITE,
112376c6d28STom Lendacky 	TRAP_CR8_WRITE,
1134c44e8d6SBabu Moger 	/* Byte offset 014h (word 5) */
1144c44e8d6SBabu Moger 	INTERCEPT_INVLPGB = 160,
1154c44e8d6SBabu Moger 	INTERCEPT_INVLPGB_ILLEGAL,
1164c44e8d6SBabu Moger 	INTERCEPT_INVPCID,
1174c44e8d6SBabu Moger 	INTERCEPT_MCOMMIT,
1184c44e8d6SBabu Moger 	INTERCEPT_TLBSYNC,
119c2cedf7bSEduardo Habkost };
120c2cedf7bSEduardo Habkost 
121c2cedf7bSEduardo Habkost 
122c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area {
123c45ad722SBabu Moger 	u32 intercepts[MAX_INTERCEPT];
124c62e2e94SBabu Moger 	u32 reserved_1[15 - MAX_INTERCEPT];
1251d8fb44aSBabu Moger 	u16 pause_filter_thresh;
126565d0998SMark Langsdorf 	u16 pause_filter_count;
127c2cedf7bSEduardo Habkost 	u64 iopm_base_pa;
128c2cedf7bSEduardo Habkost 	u64 msrpm_base_pa;
129c2cedf7bSEduardo Habkost 	u64 tsc_offset;
130c2cedf7bSEduardo Habkost 	u32 asid;
131c2cedf7bSEduardo Habkost 	u8 tlb_ctl;
132c2cedf7bSEduardo Habkost 	u8 reserved_2[3];
133c2cedf7bSEduardo Habkost 	u32 int_ctl;
134c2cedf7bSEduardo Habkost 	u32 int_vector;
135c2cedf7bSEduardo Habkost 	u32 int_state;
136c2cedf7bSEduardo Habkost 	u8 reserved_3[4];
137c2cedf7bSEduardo Habkost 	u32 exit_code;
138c2cedf7bSEduardo Habkost 	u32 exit_code_hi;
139c2cedf7bSEduardo Habkost 	u64 exit_info_1;
140c2cedf7bSEduardo Habkost 	u64 exit_info_2;
141c2cedf7bSEduardo Habkost 	u32 exit_int_info;
142c2cedf7bSEduardo Habkost 	u32 exit_int_info_err;
143c2cedf7bSEduardo Habkost 	u64 nested_ctl;
1443d5615e5SSuravee Suthikulpanit 	u64 avic_vapic_bar;
145291bd20dSTom Lendacky 	u64 ghcb_gpa;
146c2cedf7bSEduardo Habkost 	u32 event_inj;
147c2cedf7bSEduardo Habkost 	u32 event_inj_err;
148c2cedf7bSEduardo Habkost 	u64 nested_cr3;
1490dc92119SJanakarajan Natarajan 	u64 virt_ext;
1508d28fec4SRoedel, Joerg 	u32 clean;
1518d28fec4SRoedel, Joerg 	u32 reserved_5;
1526bc31bdcSAndre Przywara 	u64 next_rip;
153dc25e89eSAndre Przywara 	u8 insn_len;
154dc25e89eSAndre Przywara 	u8 insn_bytes[15];
1553d5615e5SSuravee Suthikulpanit 	u64 avic_backing_page;	/* Offset 0xe0 */
1563d5615e5SSuravee Suthikulpanit 	u8 reserved_6[8];	/* Offset 0xe8 */
1573d5615e5SSuravee Suthikulpanit 	u64 avic_logical_id;	/* Offset 0xf0 */
1583d5615e5SSuravee Suthikulpanit 	u64 avic_physical_id;	/* Offset 0xf8 */
159376c6d28STom Lendacky 	u8 reserved_7[8];
160376c6d28STom Lendacky 	u64 vmsa_pa;		/* Used for an SEV-ES guest */
16159d21d67SVineeth Pillai 	u8 reserved_8[720];
16259d21d67SVineeth Pillai 	/*
16359d21d67SVineeth Pillai 	 * Offset 0x3e0, 32 bytes reserved
16459d21d67SVineeth Pillai 	 * for use by hypervisor/software.
16559d21d67SVineeth Pillai 	 */
16668ae7c7bSSean Christopherson 	union {
16726b516bbSSean Christopherson 		struct hv_vmcb_enlightenments hv_enlightenments;
16859d21d67SVineeth Pillai 		u8 reserved_sw[32];
169c2cedf7bSEduardo Habkost 	};
17068ae7c7bSSean Christopherson };
171c2cedf7bSEduardo Habkost 
172c2cedf7bSEduardo Habkost 
173c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0
174c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1
17538e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3
17638e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7
177c2cedf7bSEduardo Habkost 
178c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f
179c2cedf7bSEduardo Habkost 
180c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8
181c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT)
182c2cedf7bSEduardo Habkost 
183640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9
184640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT)
185640bd6e5SJanakarajan Natarajan 
186c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16
187c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT)
188c2cedf7bSEduardo Habkost 
189c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20
190c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT)
191c2cedf7bSEduardo Habkost 
1920f923e07SMaxim Levitsky #define V_IRQ_INJECTION_BITS_MASK (V_IRQ_MASK | V_INTR_PRIO_MASK | V_IGN_TPR_MASK)
1930f923e07SMaxim Levitsky 
194c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24
195c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT)
196c2cedf7bSEduardo Habkost 
197640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25
198640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT)
199640bd6e5SJanakarajan Natarajan 
20044a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31
20144a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT)
20244a95daeSSuravee Suthikulpanit 
2034bdec12aSSuravee Suthikulpanit #define X2APIC_MODE_SHIFT 30
2044bdec12aSSuravee Suthikulpanit #define X2APIC_MODE_MASK (1 << X2APIC_MODE_SHIFT)
2054bdec12aSSuravee Suthikulpanit 
2068a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0)
20789c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1)
2088a77e909SJanakarajan Natarajan 
209f1c6366eSTom Lendacky #define SVM_INTERRUPT_SHADOW_MASK	BIT_ULL(0)
210f1c6366eSTom Lendacky #define SVM_GUEST_INTERRUPT_MASK	BIT_ULL(1)
211c2cedf7bSEduardo Habkost 
212c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2
213c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3
214c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4
215c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7
216c2cedf7bSEduardo Habkost 
217c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1
218c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT)
219c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT)
220c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT)
221c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT)
222c2cedf7bSEduardo Habkost 
2234a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK	0x001fULL
2244a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL
2254a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK  0x0010ULL
2264a810181SJoerg Roedel 
227cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE	BIT(0)
228ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE	BIT(1)
229376c6d28STom Lendacky #define SVM_NESTED_CTL_SEV_ES_ENABLE	BIT(2)
230cea3a19bSTom Lendacky 
23139150352SMaxim Levitsky 
232bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_RSVD	0xffffff0000000000ULL
233bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_MIN	0x0000000000000001ULL
234bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_MAX	0x000000ffffffffffULL
235bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_DEFAULT	0x0100000000ULL
236bb2aa78eSMaxim Levitsky 
237bb2aa78eSMaxim Levitsky 
23839150352SMaxim Levitsky /* AVIC */
2390dacc3dfSMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK	(0xFFULL)
24039150352SMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_VALID_BIT			31
24139150352SMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK		(1 << 31)
24239150352SMaxim Levitsky 
2434a204f78SSuravee Suthikulpanit #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK	GENMASK_ULL(11, 0)
24439150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK	(0xFFFFFFFFFFULL << 12)
24539150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK		(1ULL << 62)
24639150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK		(1ULL << 63)
2470dacc3dfSMaxim Levitsky #define AVIC_PHYSICAL_ID_TABLE_SIZE_MASK		(0xFFULL)
24839150352SMaxim Levitsky 
2490dacc3dfSMaxim Levitsky #define AVIC_DOORBELL_PHYSICAL_ID_MASK			GENMASK_ULL(11, 0)
2500dacc3dfSMaxim Levitsky 
2510dacc3dfSMaxim Levitsky #define VMCB_AVIC_APIC_BAR_MASK				0xFFFFFFFFFF000ULL
25239150352SMaxim Levitsky 
25339150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_WRITE_MASK		1
25439150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_OFFSET_MASK		0xFF0
25539150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_VECTOR_MASK		0xFFFFFFFF
25639150352SMaxim Levitsky 
25739150352SMaxim Levitsky enum avic_ipi_failure_cause {
25839150352SMaxim Levitsky 	AVIC_IPI_FAILURE_INVALID_INT_TYPE,
25939150352SMaxim Levitsky 	AVIC_IPI_FAILURE_TARGET_NOT_RUNNING,
26039150352SMaxim Levitsky 	AVIC_IPI_FAILURE_INVALID_TARGET,
26139150352SMaxim Levitsky 	AVIC_IPI_FAILURE_INVALID_BACKING_PAGE,
26239150352SMaxim Levitsky };
26339150352SMaxim Levitsky 
264*3ec7a1b2SSean Christopherson #define AVIC_PHYSICAL_MAX_INDEX_MASK	GENMASK_ULL(8, 0)
26539150352SMaxim Levitsky 
26639150352SMaxim Levitsky /*
267*3ec7a1b2SSean Christopherson  * For AVIC, the max index allowed for physical APIC ID table is 0xfe (254), as
268*3ec7a1b2SSean Christopherson  * 0xff is a broadcast to all CPUs, i.e. can't be targeted individually.
26939150352SMaxim Levitsky  */
270d2fe6bf5SSuravee Suthikulpanit #define AVIC_MAX_PHYSICAL_ID		0XFEULL
271d2fe6bf5SSuravee Suthikulpanit 
272d2fe6bf5SSuravee Suthikulpanit /*
273*3ec7a1b2SSean Christopherson  * For x2AVIC, the max index allowed for physical APIC ID table is 0x1ff (511).
274d2fe6bf5SSuravee Suthikulpanit  */
275d2fe6bf5SSuravee Suthikulpanit #define X2AVIC_MAX_PHYSICAL_ID		0x1FFUL
27639150352SMaxim Levitsky 
277*3ec7a1b2SSean Christopherson static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == AVIC_MAX_PHYSICAL_ID);
278*3ec7a1b2SSean Christopherson static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_MAX_PHYSICAL_ID);
279*3ec7a1b2SSean Christopherson 
28039150352SMaxim Levitsky #define AVIC_HPA_MASK	~((0xFFFULL << 52) | 0xFFF)
28139150352SMaxim Levitsky #define VMCB_AVIC_APIC_BAR_MASK		0xFFFFFFFFFF000ULL
28239150352SMaxim Levitsky 
28339150352SMaxim Levitsky 
284976bc5e2SBorislav Petkov struct vmcb_seg {
285c2cedf7bSEduardo Habkost 	u16 selector;
286c2cedf7bSEduardo Habkost 	u16 attrib;
287c2cedf7bSEduardo Habkost 	u32 limit;
288c2cedf7bSEduardo Habkost 	u64 base;
289976bc5e2SBorislav Petkov } __packed;
290c2cedf7bSEduardo Habkost 
2913dd2775bSTom Lendacky /* Save area definition for legacy and SEV-MEM guests */
292976bc5e2SBorislav Petkov struct vmcb_save_area {
293c2cedf7bSEduardo Habkost 	struct vmcb_seg es;
294c2cedf7bSEduardo Habkost 	struct vmcb_seg cs;
295c2cedf7bSEduardo Habkost 	struct vmcb_seg ss;
296c2cedf7bSEduardo Habkost 	struct vmcb_seg ds;
297c2cedf7bSEduardo Habkost 	struct vmcb_seg fs;
298c2cedf7bSEduardo Habkost 	struct vmcb_seg gs;
299c2cedf7bSEduardo Habkost 	struct vmcb_seg gdtr;
300c2cedf7bSEduardo Habkost 	struct vmcb_seg ldtr;
301c2cedf7bSEduardo Habkost 	struct vmcb_seg idtr;
302c2cedf7bSEduardo Habkost 	struct vmcb_seg tr;
303d08b4858SCarlos Bilbao 	/* Reserved fields are named following their struct offset */
304d08b4858SCarlos Bilbao 	u8 reserved_0xa0[42];
305046f773bSBrijesh Singh 	u8 vmpl;
306c2cedf7bSEduardo Habkost 	u8 cpl;
307d08b4858SCarlos Bilbao 	u8 reserved_0xcc[4];
308c2cedf7bSEduardo Habkost 	u64 efer;
309d08b4858SCarlos Bilbao 	u8 reserved_0xd8[112];
3103dd2775bSTom Lendacky 	u64 cr4;
3113dd2775bSTom Lendacky 	u64 cr3;
3123dd2775bSTom Lendacky 	u64 cr0;
3133dd2775bSTom Lendacky 	u64 dr7;
3143dd2775bSTom Lendacky 	u64 dr6;
3153dd2775bSTom Lendacky 	u64 rflags;
3163dd2775bSTom Lendacky 	u64 rip;
317d08b4858SCarlos Bilbao 	u8 reserved_0x180[88];
3183dd2775bSTom Lendacky 	u64 rsp;
3193dd2775bSTom Lendacky 	u64 s_cet;
3203dd2775bSTom Lendacky 	u64 ssp;
3213dd2775bSTom Lendacky 	u64 isst_addr;
3223dd2775bSTom Lendacky 	u64 rax;
3233dd2775bSTom Lendacky 	u64 star;
3243dd2775bSTom Lendacky 	u64 lstar;
3253dd2775bSTom Lendacky 	u64 cstar;
3263dd2775bSTom Lendacky 	u64 sfmask;
3273dd2775bSTom Lendacky 	u64 kernel_gs_base;
3283dd2775bSTom Lendacky 	u64 sysenter_cs;
3293dd2775bSTom Lendacky 	u64 sysenter_esp;
3303dd2775bSTom Lendacky 	u64 sysenter_eip;
3313dd2775bSTom Lendacky 	u64 cr2;
332d08b4858SCarlos Bilbao 	u8 reserved_0x248[32];
3333dd2775bSTom Lendacky 	u64 g_pat;
3343dd2775bSTom Lendacky 	u64 dbgctl;
3353dd2775bSTom Lendacky 	u64 br_from;
3363dd2775bSTom Lendacky 	u64 br_to;
3373dd2775bSTom Lendacky 	u64 last_excp_from;
3383dd2775bSTom Lendacky 	u64 last_excp_to;
339d08b4858SCarlos Bilbao 	u8 reserved_0x298[72];
3403dd2775bSTom Lendacky 	u32 spec_ctrl;		/* Guest version of SPEC_CTRL at 0x2E0 */
3413dd2775bSTom Lendacky } __packed;
3423dd2775bSTom Lendacky 
3433dd2775bSTom Lendacky /* Save area definition for SEV-ES and SEV-SNP guests */
3443dd2775bSTom Lendacky struct sev_es_save_area {
3453dd2775bSTom Lendacky 	struct vmcb_seg es;
3463dd2775bSTom Lendacky 	struct vmcb_seg cs;
3473dd2775bSTom Lendacky 	struct vmcb_seg ss;
3483dd2775bSTom Lendacky 	struct vmcb_seg ds;
3493dd2775bSTom Lendacky 	struct vmcb_seg fs;
3503dd2775bSTom Lendacky 	struct vmcb_seg gs;
3513dd2775bSTom Lendacky 	struct vmcb_seg gdtr;
3523dd2775bSTom Lendacky 	struct vmcb_seg ldtr;
3533dd2775bSTom Lendacky 	struct vmcb_seg idtr;
3543dd2775bSTom Lendacky 	struct vmcb_seg tr;
3556d3b3d34STom Lendacky 	u64 vmpl0_ssp;
3566d3b3d34STom Lendacky 	u64 vmpl1_ssp;
3576d3b3d34STom Lendacky 	u64 vmpl2_ssp;
3586d3b3d34STom Lendacky 	u64 vmpl3_ssp;
3596d3b3d34STom Lendacky 	u64 u_cet;
360d08b4858SCarlos Bilbao 	u8 reserved_0xc8[2];
3616d3b3d34STom Lendacky 	u8 vmpl;
3623dd2775bSTom Lendacky 	u8 cpl;
363d08b4858SCarlos Bilbao 	u8 reserved_0xcc[4];
3643dd2775bSTom Lendacky 	u64 efer;
365d08b4858SCarlos Bilbao 	u8 reserved_0xd8[104];
3663dd2775bSTom Lendacky 	u64 xss;
367c2cedf7bSEduardo Habkost 	u64 cr4;
368c2cedf7bSEduardo Habkost 	u64 cr3;
369c2cedf7bSEduardo Habkost 	u64 cr0;
370c2cedf7bSEduardo Habkost 	u64 dr7;
371c2cedf7bSEduardo Habkost 	u64 dr6;
372c2cedf7bSEduardo Habkost 	u64 rflags;
373c2cedf7bSEduardo Habkost 	u64 rip;
3746d3b3d34STom Lendacky 	u64 dr0;
3756d3b3d34STom Lendacky 	u64 dr1;
3766d3b3d34STom Lendacky 	u64 dr2;
3776d3b3d34STom Lendacky 	u64 dr3;
3786d3b3d34STom Lendacky 	u64 dr0_addr_mask;
3796d3b3d34STom Lendacky 	u64 dr1_addr_mask;
3806d3b3d34STom Lendacky 	u64 dr2_addr_mask;
3816d3b3d34STom Lendacky 	u64 dr3_addr_mask;
382d08b4858SCarlos Bilbao 	u8 reserved_0x1c0[24];
383c2cedf7bSEduardo Habkost 	u64 rsp;
3846d3b3d34STom Lendacky 	u64 s_cet;
3856d3b3d34STom Lendacky 	u64 ssp;
3866d3b3d34STom Lendacky 	u64 isst_addr;
387c2cedf7bSEduardo Habkost 	u64 rax;
388c2cedf7bSEduardo Habkost 	u64 star;
389c2cedf7bSEduardo Habkost 	u64 lstar;
390c2cedf7bSEduardo Habkost 	u64 cstar;
391c2cedf7bSEduardo Habkost 	u64 sfmask;
392c2cedf7bSEduardo Habkost 	u64 kernel_gs_base;
393c2cedf7bSEduardo Habkost 	u64 sysenter_cs;
394c2cedf7bSEduardo Habkost 	u64 sysenter_esp;
395c2cedf7bSEduardo Habkost 	u64 sysenter_eip;
396c2cedf7bSEduardo Habkost 	u64 cr2;
397d08b4858SCarlos Bilbao 	u8 reserved_0x248[32];
398c2cedf7bSEduardo Habkost 	u64 g_pat;
399c2cedf7bSEduardo Habkost 	u64 dbgctl;
400c2cedf7bSEduardo Habkost 	u64 br_from;
401c2cedf7bSEduardo Habkost 	u64 br_to;
402c2cedf7bSEduardo Habkost 	u64 last_excp_from;
403c2cedf7bSEduardo Habkost 	u64 last_excp_to;
404d08b4858SCarlos Bilbao 	u8 reserved_0x298[80];
40586137773STom Lendacky 	u32 pkru;
406d08b4858SCarlos Bilbao 	u32 tsc_aux;
407d08b4858SCarlos Bilbao 	u8 reserved_0x2f0[24];
408d07f46f9STom Lendacky 	u64 rcx;
409d07f46f9STom Lendacky 	u64 rdx;
410d07f46f9STom Lendacky 	u64 rbx;
411d08b4858SCarlos Bilbao 	u64 reserved_0x320;	/* rsp already available at 0x01d8 */
412d07f46f9STom Lendacky 	u64 rbp;
413d07f46f9STom Lendacky 	u64 rsi;
414d07f46f9STom Lendacky 	u64 rdi;
415d07f46f9STom Lendacky 	u64 r8;
416d07f46f9STom Lendacky 	u64 r9;
417d07f46f9STom Lendacky 	u64 r10;
418d07f46f9STom Lendacky 	u64 r11;
419d07f46f9STom Lendacky 	u64 r12;
420d07f46f9STom Lendacky 	u64 r13;
421d07f46f9STom Lendacky 	u64 r14;
422d07f46f9STom Lendacky 	u64 r15;
423d08b4858SCarlos Bilbao 	u8 reserved_0x380[16];
4246d3b3d34STom Lendacky 	u64 guest_exit_info_1;
4256d3b3d34STom Lendacky 	u64 guest_exit_info_2;
4266d3b3d34STom Lendacky 	u64 guest_exit_int_info;
4276d3b3d34STom Lendacky 	u64 guest_nrip;
428046f773bSBrijesh Singh 	u64 sev_features;
4296d3b3d34STom Lendacky 	u64 vintr_ctrl;
4306d3b3d34STom Lendacky 	u64 guest_exit_code;
4316d3b3d34STom Lendacky 	u64 virtual_tom;
4326d3b3d34STom Lendacky 	u64 tlb_id;
4336d3b3d34STom Lendacky 	u64 pcpu_id;
4346d3b3d34STom Lendacky 	u64 event_inj;
435d07f46f9STom Lendacky 	u64 xcr0;
436d08b4858SCarlos Bilbao 	u8 reserved_0x3f0[16];
4376d3b3d34STom Lendacky 
4386d3b3d34STom Lendacky 	/* Floating point area */
4396d3b3d34STom Lendacky 	u64 x87_dp;
4406d3b3d34STom Lendacky 	u32 mxcsr;
4416d3b3d34STom Lendacky 	u16 x87_ftw;
4426d3b3d34STom Lendacky 	u16 x87_fsw;
4436d3b3d34STom Lendacky 	u16 x87_fcw;
4446d3b3d34STom Lendacky 	u16 x87_fop;
4456d3b3d34STom Lendacky 	u16 x87_ds;
4466d3b3d34STom Lendacky 	u16 x87_cs;
4476d3b3d34STom Lendacky 	u64 x87_rip;
4486d3b3d34STom Lendacky 	u8 fpreg_x87[80];
4496d3b3d34STom Lendacky 	u8 fpreg_xmm[256];
4506d3b3d34STom Lendacky 	u8 fpreg_ymm[256];
451976bc5e2SBorislav Petkov } __packed;
452c2cedf7bSEduardo Habkost 
453a4690359STom Lendacky struct ghcb_save_area {
454d08b4858SCarlos Bilbao 	u8 reserved_0x0[203];
455a4690359STom Lendacky 	u8 cpl;
456d08b4858SCarlos Bilbao 	u8 reserved_0xcc[116];
457a4690359STom Lendacky 	u64 xss;
458d08b4858SCarlos Bilbao 	u8 reserved_0x148[24];
459a4690359STom Lendacky 	u64 dr7;
460d08b4858SCarlos Bilbao 	u8 reserved_0x168[16];
461a4690359STom Lendacky 	u64 rip;
462d08b4858SCarlos Bilbao 	u8 reserved_0x180[88];
463a4690359STom Lendacky 	u64 rsp;
464d08b4858SCarlos Bilbao 	u8 reserved_0x1e0[24];
465a4690359STom Lendacky 	u64 rax;
466d08b4858SCarlos Bilbao 	u8 reserved_0x200[264];
467a4690359STom Lendacky 	u64 rcx;
468a4690359STom Lendacky 	u64 rdx;
469a4690359STom Lendacky 	u64 rbx;
470d08b4858SCarlos Bilbao 	u8 reserved_0x320[8];
471a4690359STom Lendacky 	u64 rbp;
472a4690359STom Lendacky 	u64 rsi;
473a4690359STom Lendacky 	u64 rdi;
474a4690359STom Lendacky 	u64 r8;
475a4690359STom Lendacky 	u64 r9;
476a4690359STom Lendacky 	u64 r10;
477a4690359STom Lendacky 	u64 r11;
478a4690359STom Lendacky 	u64 r12;
479a4690359STom Lendacky 	u64 r13;
480a4690359STom Lendacky 	u64 r14;
481a4690359STom Lendacky 	u64 r15;
482d08b4858SCarlos Bilbao 	u8 reserved_0x380[16];
483a4690359STom Lendacky 	u64 sw_exit_code;
484a4690359STom Lendacky 	u64 sw_exit_info_1;
485a4690359STom Lendacky 	u64 sw_exit_info_2;
486a4690359STom Lendacky 	u64 sw_scratch;
487d08b4858SCarlos Bilbao 	u8 reserved_0x3b0[56];
488a4690359STom Lendacky 	u64 xcr0;
489a4690359STom Lendacky 	u8 valid_bitmap[16];
490a4690359STom Lendacky 	u64 x87_state_gpa;
491a4690359STom Lendacky } __packed;
492a4690359STom Lendacky 
4933dd2775bSTom Lendacky #define GHCB_SHARED_BUF_SIZE	2032
494d07f46f9STom Lendacky 
4953dd2775bSTom Lendacky struct ghcb {
496a4690359STom Lendacky 	struct ghcb_save_area save;
497a4690359STom Lendacky 	u8 reserved_save[2048 - sizeof(struct ghcb_save_area)];
4983dd2775bSTom Lendacky 
4993dd2775bSTom Lendacky 	u8 shared_buffer[GHCB_SHARED_BUF_SIZE];
500d07f46f9STom Lendacky 
501d08b4858SCarlos Bilbao 	u8 reserved_0xff0[10];
502d07f46f9STom Lendacky 	u16 protocol_version;	/* negotiated SEV-ES/GHCB protocol version */
503d07f46f9STom Lendacky 	u32 ghcb_usage;
504d07f46f9STom Lendacky } __packed;
505d07f46f9STom Lendacky 
506d07f46f9STom Lendacky 
5073dd2775bSTom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE		740
508a4690359STom Lendacky #define EXPECTED_GHCB_SAVE_AREA_SIZE		1032
5096d3b3d34STom Lendacky #define EXPECTED_SEV_ES_SAVE_AREA_SIZE		1648
51059d21d67SVineeth Pillai #define EXPECTED_VMCB_CONTROL_AREA_SIZE		1024
511d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE			PAGE_SIZE
5127923ef4fSPaolo Bonzini 
513d08b4858SCarlos Bilbao #define BUILD_BUG_RESERVED_OFFSET(x, y) \
514d08b4858SCarlos Bilbao 	ASSERT_STRUCT_OFFSET(struct x, reserved ## _ ## y, y)
515d08b4858SCarlos Bilbao 
5167923ef4fSPaolo Bonzini static inline void __unused_size_checks(void)
5177923ef4fSPaolo Bonzini {
518d07f46f9STom Lendacky 	BUILD_BUG_ON(sizeof(struct vmcb_save_area)	!= EXPECTED_VMCB_SAVE_AREA_SIZE);
519a4690359STom Lendacky 	BUILD_BUG_ON(sizeof(struct ghcb_save_area)	!= EXPECTED_GHCB_SAVE_AREA_SIZE);
5203dd2775bSTom Lendacky 	BUILD_BUG_ON(sizeof(struct sev_es_save_area)	!= EXPECTED_SEV_ES_SAVE_AREA_SIZE);
521d07f46f9STom Lendacky 	BUILD_BUG_ON(sizeof(struct vmcb_control_area)	!= EXPECTED_VMCB_CONTROL_AREA_SIZE);
522d07f46f9STom Lendacky 	BUILD_BUG_ON(sizeof(struct ghcb)		!= EXPECTED_GHCB_SIZE);
523d08b4858SCarlos Bilbao 
524d08b4858SCarlos Bilbao 	/* Check offsets of reserved fields */
525d08b4858SCarlos Bilbao 
526d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xa0);
527d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xcc);
528d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xd8);
529d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x180);
530d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x248);
531d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x298);
532d08b4858SCarlos Bilbao 
533d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xc8);
534d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xcc);
535d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xd8);
536d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0);
537d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248);
538d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298);
539d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2f0);
540d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320);
541d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380);
542d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x3f0);
543d08b4858SCarlos Bilbao 
544d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x0);
545d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0xcc);
546d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x148);
547d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x168);
548d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x180);
549d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x1e0);
550d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x200);
551d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x320);
552d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x380);
553d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x3b0);
554d08b4858SCarlos Bilbao 
555d08b4858SCarlos Bilbao 	BUILD_BUG_RESERVED_OFFSET(ghcb, 0xff0);
5567923ef4fSPaolo Bonzini }
5577923ef4fSPaolo Bonzini 
558976bc5e2SBorislav Petkov struct vmcb {
559c2cedf7bSEduardo Habkost 	struct vmcb_control_area control;
560c2cedf7bSEduardo Habkost 	struct vmcb_save_area save;
561976bc5e2SBorislav Petkov } __packed;
562c2cedf7bSEduardo Habkost 
563c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a
564c2cedf7bSEduardo Habkost 
565c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4
566c2cedf7bSEduardo Habkost 
567c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4
568c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5
569c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7
570c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8
571c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9
572c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10
573c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11
574c2cedf7bSEduardo Habkost 
575c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf)
576c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT)
577c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT)
578c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT)
579c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT)
580c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT)
581c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT)
582c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT)
583c2cedf7bSEduardo Habkost 
584c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1)
585c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK
586c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3)
587c2cedf7bSEduardo Habkost 
588c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff
589c2cedf7bSEduardo Habkost 
590c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8
591c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT)
592c2cedf7bSEduardo Habkost 
593c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT)
594c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT)
595c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT)
596c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT)
597c2cedf7bSEduardo Habkost 
598c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31)
599c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11)
600c2cedf7bSEduardo Habkost 
601c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK
60264a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK
603c2cedf7bSEduardo Habkost 
604c2cedf7bSEduardo Habkost #define	SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR
605c2cedf7bSEduardo Habkost #define	SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI
606c2cedf7bSEduardo Habkost #define	SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT
607c2cedf7bSEduardo Habkost #define	SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT
608c2cedf7bSEduardo Habkost 
609c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID
610c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR
611c2cedf7bSEduardo Habkost 
612c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36
613c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38
614e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44
615c2cedf7bSEduardo Habkost 
6167ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F
6177ff76d58SAndre Przywara 
618dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP)
619c2cedf7bSEduardo Habkost 
6203702c2f4SJoerg Roedel /* GHCB Accessor functions */
6213702c2f4SJoerg Roedel 
6223702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field)							\
623a4690359STom Lendacky 	(offsetof(struct ghcb_save_area, field) / sizeof(u64))
6243702c2f4SJoerg Roedel 
6253702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field)						\
6266b91ec4aSBorislav Petkov 	static __always_inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \
6273702c2f4SJoerg Roedel 	{									\
6283702c2f4SJoerg Roedel 		return test_bit(GHCB_BITMAP_IDX(field),				\
6293702c2f4SJoerg Roedel 				(unsigned long *)&ghcb->save.valid_bitmap);	\
6303702c2f4SJoerg Roedel 	}									\
6313702c2f4SJoerg Roedel 										\
6326b91ec4aSBorislav Petkov 	static __always_inline u64 ghcb_get_##field(struct ghcb *ghcb)		\
6330f60bde1STom Lendacky 	{									\
6340f60bde1STom Lendacky 		return ghcb->save.field;					\
6350f60bde1STom Lendacky 	}									\
6360f60bde1STom Lendacky 										\
6376b91ec4aSBorislav Petkov 	static __always_inline u64 ghcb_get_##field##_if_valid(struct ghcb *ghcb) \
6380f60bde1STom Lendacky 	{									\
6390f60bde1STom Lendacky 		return ghcb_##field##_is_valid(ghcb) ? ghcb->save.field : 0;	\
6400f60bde1STom Lendacky 	}									\
6410f60bde1STom Lendacky 										\
6426b91ec4aSBorislav Petkov 	static __always_inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \
6433702c2f4SJoerg Roedel 	{									\
6443702c2f4SJoerg Roedel 		__set_bit(GHCB_BITMAP_IDX(field),				\
6453702c2f4SJoerg Roedel 			  (unsigned long *)&ghcb->save.valid_bitmap);		\
6463702c2f4SJoerg Roedel 		ghcb->save.field = value;					\
6473702c2f4SJoerg Roedel 	}
6483702c2f4SJoerg Roedel 
6493702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl)
6503702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip)
6513702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp)
6523702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax)
6533702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx)
6543702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx)
6553702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx)
6563702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp)
6573702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi)
6583702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi)
6593702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8)
6603702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9)
6613702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10)
6623702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11)
6633702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12)
6643702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13)
6653702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14)
6663702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15)
6673702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code)
6683702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1)
6693702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2)
6703702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch)
6713702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0)
6723702c2f4SJoerg Roedel 
673c2cedf7bSEduardo Habkost #endif
674