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
1861c4522abSSantosh Shukla #define V_NMI_PENDING_SHIFT 11
1871c4522abSSantosh Shukla #define V_NMI_PENDING_MASK (1 << V_NMI_PENDING_SHIFT)
1881c4522abSSantosh Shukla
1891c4522abSSantosh Shukla #define V_NMI_BLOCKING_SHIFT 12
1901c4522abSSantosh Shukla #define V_NMI_BLOCKING_MASK (1 << V_NMI_BLOCKING_SHIFT)
1911c4522abSSantosh Shukla
192c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16
193c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT)
194c2cedf7bSEduardo Habkost
195c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20
196c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT)
197c2cedf7bSEduardo Habkost
1980f923e07SMaxim Levitsky #define V_IRQ_INJECTION_BITS_MASK (V_IRQ_MASK | V_INTR_PRIO_MASK | V_IGN_TPR_MASK)
1990f923e07SMaxim Levitsky
200c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24
201c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT)
202c2cedf7bSEduardo Habkost
203640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25
204640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT)
205640bd6e5SJanakarajan Natarajan
2061c4522abSSantosh Shukla #define V_NMI_ENABLE_SHIFT 26
2071c4522abSSantosh Shukla #define V_NMI_ENABLE_MASK (1 << V_NMI_ENABLE_SHIFT)
2081c4522abSSantosh Shukla
20944a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31
21044a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT)
21144a95daeSSuravee Suthikulpanit
2124bdec12aSSuravee Suthikulpanit #define X2APIC_MODE_SHIFT 30
2134bdec12aSSuravee Suthikulpanit #define X2APIC_MODE_MASK (1 << X2APIC_MODE_SHIFT)
2144bdec12aSSuravee Suthikulpanit
2158a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0)
21689c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1)
2178a77e909SJanakarajan Natarajan
218f1c6366eSTom Lendacky #define SVM_INTERRUPT_SHADOW_MASK BIT_ULL(0)
219f1c6366eSTom Lendacky #define SVM_GUEST_INTERRUPT_MASK BIT_ULL(1)
220c2cedf7bSEduardo Habkost
221c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2
222c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3
223c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4
224c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7
225c2cedf7bSEduardo Habkost
226c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1
227c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT)
228c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT)
229c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT)
230c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT)
231c2cedf7bSEduardo Habkost
232cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0)
233ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1)
234376c6d28STom Lendacky #define SVM_NESTED_CTL_SEV_ES_ENABLE BIT(2)
235cea3a19bSTom Lendacky
23639150352SMaxim Levitsky
237bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_RSVD 0xffffff0000000000ULL
238bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_MIN 0x0000000000000001ULL
239bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_MAX 0x000000ffffffffffULL
240bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_DEFAULT 0x0100000000ULL
241bb2aa78eSMaxim Levitsky
242bb2aa78eSMaxim Levitsky
24339150352SMaxim Levitsky /* AVIC */
2440dacc3dfSMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFFULL)
24539150352SMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31
24639150352SMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31)
24739150352SMaxim Levitsky
2484a204f78SSuravee Suthikulpanit #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK GENMASK_ULL(11, 0)
24939150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12)
25039150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62)
25139150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63)
2520dacc3dfSMaxim Levitsky #define AVIC_PHYSICAL_ID_TABLE_SIZE_MASK (0xFFULL)
25339150352SMaxim Levitsky
2540dacc3dfSMaxim Levitsky #define AVIC_DOORBELL_PHYSICAL_ID_MASK GENMASK_ULL(11, 0)
2550dacc3dfSMaxim Levitsky
2560dacc3dfSMaxim Levitsky #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL
25739150352SMaxim Levitsky
25839150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_WRITE_MASK 1
25939150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_OFFSET_MASK 0xFF0
26039150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_VECTOR_MASK 0xFFFFFFFF
26139150352SMaxim Levitsky
26239150352SMaxim Levitsky enum avic_ipi_failure_cause {
26339150352SMaxim Levitsky AVIC_IPI_FAILURE_INVALID_INT_TYPE,
26439150352SMaxim Levitsky AVIC_IPI_FAILURE_TARGET_NOT_RUNNING,
26539150352SMaxim Levitsky AVIC_IPI_FAILURE_INVALID_TARGET,
26639150352SMaxim Levitsky AVIC_IPI_FAILURE_INVALID_BACKING_PAGE,
2672dcf37abSMaxim Levitsky AVIC_IPI_FAILURE_INVALID_IPI_VECTOR,
26839150352SMaxim Levitsky };
26939150352SMaxim Levitsky
2703ec7a1b2SSean Christopherson #define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0)
27139150352SMaxim Levitsky
27239150352SMaxim Levitsky /*
2733ec7a1b2SSean Christopherson * For AVIC, the max index allowed for physical APIC ID table is 0xfe (254), as
2743ec7a1b2SSean Christopherson * 0xff is a broadcast to all CPUs, i.e. can't be targeted individually.
27539150352SMaxim Levitsky */
276d2fe6bf5SSuravee Suthikulpanit #define AVIC_MAX_PHYSICAL_ID 0XFEULL
277d2fe6bf5SSuravee Suthikulpanit
278d2fe6bf5SSuravee Suthikulpanit /*
2793ec7a1b2SSean Christopherson * For x2AVIC, the max index allowed for physical APIC ID table is 0x1ff (511).
280d2fe6bf5SSuravee Suthikulpanit */
281d2fe6bf5SSuravee Suthikulpanit #define X2AVIC_MAX_PHYSICAL_ID 0x1FFUL
28239150352SMaxim Levitsky
2833ec7a1b2SSean Christopherson static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == AVIC_MAX_PHYSICAL_ID);
2843ec7a1b2SSean Christopherson static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_MAX_PHYSICAL_ID);
2853ec7a1b2SSean Christopherson
28639150352SMaxim Levitsky #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF)
28739150352SMaxim Levitsky
2881dfe571cSBrijesh Singh #define SVM_SEV_FEAT_SNP_ACTIVE BIT(0)
289e366f92eSTom Lendacky #define SVM_SEV_FEAT_RESTRICTED_INJECTION BIT(3)
290e366f92eSTom Lendacky #define SVM_SEV_FEAT_ALTERNATE_INJECTION BIT(4)
291d1f85fbeSAlexey Kardashevskiy #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5)
29239150352SMaxim Levitsky
293e366f92eSTom Lendacky #define SVM_SEV_FEAT_INT_INJ_MODES \
294e366f92eSTom Lendacky (SVM_SEV_FEAT_RESTRICTED_INJECTION | \
295e366f92eSTom Lendacky SVM_SEV_FEAT_ALTERNATE_INJECTION)
296e366f92eSTom Lendacky
297976bc5e2SBorislav Petkov struct vmcb_seg {
298c2cedf7bSEduardo Habkost u16 selector;
299c2cedf7bSEduardo Habkost u16 attrib;
300c2cedf7bSEduardo Habkost u32 limit;
301c2cedf7bSEduardo Habkost u64 base;
302976bc5e2SBorislav Petkov } __packed;
303c2cedf7bSEduardo Habkost
3043dd2775bSTom Lendacky /* Save area definition for legacy and SEV-MEM guests */
305976bc5e2SBorislav Petkov struct vmcb_save_area {
306c2cedf7bSEduardo Habkost struct vmcb_seg es;
307c2cedf7bSEduardo Habkost struct vmcb_seg cs;
308c2cedf7bSEduardo Habkost struct vmcb_seg ss;
309c2cedf7bSEduardo Habkost struct vmcb_seg ds;
310c2cedf7bSEduardo Habkost struct vmcb_seg fs;
311c2cedf7bSEduardo Habkost struct vmcb_seg gs;
312c2cedf7bSEduardo Habkost struct vmcb_seg gdtr;
313c2cedf7bSEduardo Habkost struct vmcb_seg ldtr;
314c2cedf7bSEduardo Habkost struct vmcb_seg idtr;
315c2cedf7bSEduardo Habkost struct vmcb_seg tr;
316d08b4858SCarlos Bilbao /* Reserved fields are named following their struct offset */
317d08b4858SCarlos Bilbao u8 reserved_0xa0[42];
318046f773bSBrijesh Singh u8 vmpl;
319c2cedf7bSEduardo Habkost u8 cpl;
320d08b4858SCarlos Bilbao u8 reserved_0xcc[4];
321c2cedf7bSEduardo Habkost u64 efer;
322d08b4858SCarlos Bilbao u8 reserved_0xd8[112];
3233dd2775bSTom Lendacky u64 cr4;
3243dd2775bSTom Lendacky u64 cr3;
3253dd2775bSTom Lendacky u64 cr0;
3263dd2775bSTom Lendacky u64 dr7;
3273dd2775bSTom Lendacky u64 dr6;
3283dd2775bSTom Lendacky u64 rflags;
3293dd2775bSTom Lendacky u64 rip;
330d08b4858SCarlos Bilbao u8 reserved_0x180[88];
3313dd2775bSTom Lendacky u64 rsp;
3323dd2775bSTom Lendacky u64 s_cet;
3333dd2775bSTom Lendacky u64 ssp;
3343dd2775bSTom Lendacky u64 isst_addr;
3353dd2775bSTom Lendacky u64 rax;
3363dd2775bSTom Lendacky u64 star;
3373dd2775bSTom Lendacky u64 lstar;
3383dd2775bSTom Lendacky u64 cstar;
3393dd2775bSTom Lendacky u64 sfmask;
3403dd2775bSTom Lendacky u64 kernel_gs_base;
3413dd2775bSTom Lendacky u64 sysenter_cs;
3423dd2775bSTom Lendacky u64 sysenter_esp;
3433dd2775bSTom Lendacky u64 sysenter_eip;
3443dd2775bSTom Lendacky u64 cr2;
345d08b4858SCarlos Bilbao u8 reserved_0x248[32];
3463dd2775bSTom Lendacky u64 g_pat;
3473dd2775bSTom Lendacky u64 dbgctl;
3483dd2775bSTom Lendacky u64 br_from;
3493dd2775bSTom Lendacky u64 br_to;
3503dd2775bSTom Lendacky u64 last_excp_from;
3513dd2775bSTom Lendacky u64 last_excp_to;
352d08b4858SCarlos Bilbao u8 reserved_0x298[72];
353f6706341SManali Shukla u64 spec_ctrl; /* Guest version of SPEC_CTRL at 0x2E0 */
3543dd2775bSTom Lendacky } __packed;
3553dd2775bSTom Lendacky
3563dd2775bSTom Lendacky /* Save area definition for SEV-ES and SEV-SNP guests */
3573dd2775bSTom Lendacky struct sev_es_save_area {
3583dd2775bSTom Lendacky struct vmcb_seg es;
3593dd2775bSTom Lendacky struct vmcb_seg cs;
3603dd2775bSTom Lendacky struct vmcb_seg ss;
3613dd2775bSTom Lendacky struct vmcb_seg ds;
3623dd2775bSTom Lendacky struct vmcb_seg fs;
3633dd2775bSTom Lendacky struct vmcb_seg gs;
3643dd2775bSTom Lendacky struct vmcb_seg gdtr;
3653dd2775bSTom Lendacky struct vmcb_seg ldtr;
3663dd2775bSTom Lendacky struct vmcb_seg idtr;
3673dd2775bSTom Lendacky struct vmcb_seg tr;
36878ccfce7SJohn Allen u64 pl0_ssp;
36978ccfce7SJohn Allen u64 pl1_ssp;
37078ccfce7SJohn Allen u64 pl2_ssp;
37178ccfce7SJohn Allen u64 pl3_ssp;
3726d3b3d34STom Lendacky u64 u_cet;
373d08b4858SCarlos Bilbao u8 reserved_0xc8[2];
3746d3b3d34STom Lendacky u8 vmpl;
3753dd2775bSTom Lendacky u8 cpl;
376d08b4858SCarlos Bilbao u8 reserved_0xcc[4];
3773dd2775bSTom Lendacky u64 efer;
378d08b4858SCarlos Bilbao u8 reserved_0xd8[104];
3793dd2775bSTom Lendacky u64 xss;
380c2cedf7bSEduardo Habkost u64 cr4;
381c2cedf7bSEduardo Habkost u64 cr3;
382c2cedf7bSEduardo Habkost u64 cr0;
383c2cedf7bSEduardo Habkost u64 dr7;
384c2cedf7bSEduardo Habkost u64 dr6;
385c2cedf7bSEduardo Habkost u64 rflags;
386c2cedf7bSEduardo Habkost u64 rip;
3876d3b3d34STom Lendacky u64 dr0;
3886d3b3d34STom Lendacky u64 dr1;
3896d3b3d34STom Lendacky u64 dr2;
3906d3b3d34STom Lendacky u64 dr3;
3916d3b3d34STom Lendacky u64 dr0_addr_mask;
3926d3b3d34STom Lendacky u64 dr1_addr_mask;
3936d3b3d34STom Lendacky u64 dr2_addr_mask;
3946d3b3d34STom Lendacky u64 dr3_addr_mask;
395d08b4858SCarlos Bilbao u8 reserved_0x1c0[24];
396c2cedf7bSEduardo Habkost u64 rsp;
3976d3b3d34STom Lendacky u64 s_cet;
3986d3b3d34STom Lendacky u64 ssp;
3996d3b3d34STom Lendacky u64 isst_addr;
400c2cedf7bSEduardo Habkost u64 rax;
401c2cedf7bSEduardo Habkost u64 star;
402c2cedf7bSEduardo Habkost u64 lstar;
403c2cedf7bSEduardo Habkost u64 cstar;
404c2cedf7bSEduardo Habkost u64 sfmask;
405c2cedf7bSEduardo Habkost u64 kernel_gs_base;
406c2cedf7bSEduardo Habkost u64 sysenter_cs;
407c2cedf7bSEduardo Habkost u64 sysenter_esp;
408c2cedf7bSEduardo Habkost u64 sysenter_eip;
409c2cedf7bSEduardo Habkost u64 cr2;
410d08b4858SCarlos Bilbao u8 reserved_0x248[32];
411c2cedf7bSEduardo Habkost u64 g_pat;
412c2cedf7bSEduardo Habkost u64 dbgctl;
413c2cedf7bSEduardo Habkost u64 br_from;
414c2cedf7bSEduardo Habkost u64 br_to;
415c2cedf7bSEduardo Habkost u64 last_excp_from;
416c2cedf7bSEduardo Habkost u64 last_excp_to;
417d08b4858SCarlos Bilbao u8 reserved_0x298[80];
41886137773STom Lendacky u32 pkru;
419d08b4858SCarlos Bilbao u32 tsc_aux;
420d08b4858SCarlos Bilbao u8 reserved_0x2f0[24];
421d07f46f9STom Lendacky u64 rcx;
422d07f46f9STom Lendacky u64 rdx;
423d07f46f9STom Lendacky u64 rbx;
424d08b4858SCarlos Bilbao u64 reserved_0x320; /* rsp already available at 0x01d8 */
425d07f46f9STom Lendacky u64 rbp;
426d07f46f9STom Lendacky u64 rsi;
427d07f46f9STom Lendacky u64 rdi;
428d07f46f9STom Lendacky u64 r8;
429d07f46f9STom Lendacky u64 r9;
430d07f46f9STom Lendacky u64 r10;
431d07f46f9STom Lendacky u64 r11;
432d07f46f9STom Lendacky u64 r12;
433d07f46f9STom Lendacky u64 r13;
434d07f46f9STom Lendacky u64 r14;
435d07f46f9STom Lendacky u64 r15;
436d08b4858SCarlos Bilbao u8 reserved_0x380[16];
4376d3b3d34STom Lendacky u64 guest_exit_info_1;
4386d3b3d34STom Lendacky u64 guest_exit_info_2;
4396d3b3d34STom Lendacky u64 guest_exit_int_info;
4406d3b3d34STom Lendacky u64 guest_nrip;
441046f773bSBrijesh Singh u64 sev_features;
4426d3b3d34STom Lendacky u64 vintr_ctrl;
4436d3b3d34STom Lendacky u64 guest_exit_code;
4446d3b3d34STom Lendacky u64 virtual_tom;
4456d3b3d34STom Lendacky u64 tlb_id;
4466d3b3d34STom Lendacky u64 pcpu_id;
4476d3b3d34STom Lendacky u64 event_inj;
448d07f46f9STom Lendacky u64 xcr0;
449d08b4858SCarlos Bilbao u8 reserved_0x3f0[16];
4506d3b3d34STom Lendacky
4516d3b3d34STom Lendacky /* Floating point area */
4526d3b3d34STom Lendacky u64 x87_dp;
4536d3b3d34STom Lendacky u32 mxcsr;
4546d3b3d34STom Lendacky u16 x87_ftw;
4556d3b3d34STom Lendacky u16 x87_fsw;
4566d3b3d34STom Lendacky u16 x87_fcw;
4576d3b3d34STom Lendacky u16 x87_fop;
4586d3b3d34STom Lendacky u16 x87_ds;
4596d3b3d34STom Lendacky u16 x87_cs;
4606d3b3d34STom Lendacky u64 x87_rip;
4616d3b3d34STom Lendacky u8 fpreg_x87[80];
4626d3b3d34STom Lendacky u8 fpreg_xmm[256];
4636d3b3d34STom Lendacky u8 fpreg_ymm[256];
464976bc5e2SBorislav Petkov } __packed;
465c2cedf7bSEduardo Habkost
466a4690359STom Lendacky struct ghcb_save_area {
467d08b4858SCarlos Bilbao u8 reserved_0x0[203];
468a4690359STom Lendacky u8 cpl;
469d08b4858SCarlos Bilbao u8 reserved_0xcc[116];
470a4690359STom Lendacky u64 xss;
471d08b4858SCarlos Bilbao u8 reserved_0x148[24];
472a4690359STom Lendacky u64 dr7;
473d08b4858SCarlos Bilbao u8 reserved_0x168[16];
474a4690359STom Lendacky u64 rip;
475d08b4858SCarlos Bilbao u8 reserved_0x180[88];
476a4690359STom Lendacky u64 rsp;
477d08b4858SCarlos Bilbao u8 reserved_0x1e0[24];
478a4690359STom Lendacky u64 rax;
479d08b4858SCarlos Bilbao u8 reserved_0x200[264];
480a4690359STom Lendacky u64 rcx;
481a4690359STom Lendacky u64 rdx;
482a4690359STom Lendacky u64 rbx;
483d08b4858SCarlos Bilbao u8 reserved_0x320[8];
484a4690359STom Lendacky u64 rbp;
485a4690359STom Lendacky u64 rsi;
486a4690359STom Lendacky u64 rdi;
487a4690359STom Lendacky u64 r8;
488a4690359STom Lendacky u64 r9;
489a4690359STom Lendacky u64 r10;
490a4690359STom Lendacky u64 r11;
491a4690359STom Lendacky u64 r12;
492a4690359STom Lendacky u64 r13;
493a4690359STom Lendacky u64 r14;
494a4690359STom Lendacky u64 r15;
495d08b4858SCarlos Bilbao u8 reserved_0x380[16];
496a4690359STom Lendacky u64 sw_exit_code;
497a4690359STom Lendacky u64 sw_exit_info_1;
498a4690359STom Lendacky u64 sw_exit_info_2;
499a4690359STom Lendacky u64 sw_scratch;
500d08b4858SCarlos Bilbao u8 reserved_0x3b0[56];
501a4690359STom Lendacky u64 xcr0;
502a4690359STom Lendacky u8 valid_bitmap[16];
503a4690359STom Lendacky u64 x87_state_gpa;
504a4690359STom Lendacky } __packed;
505a4690359STom Lendacky
5063dd2775bSTom Lendacky #define GHCB_SHARED_BUF_SIZE 2032
507d07f46f9STom Lendacky
5083dd2775bSTom Lendacky struct ghcb {
509a4690359STom Lendacky struct ghcb_save_area save;
510a4690359STom Lendacky u8 reserved_save[2048 - sizeof(struct ghcb_save_area)];
5113dd2775bSTom Lendacky
5123dd2775bSTom Lendacky u8 shared_buffer[GHCB_SHARED_BUF_SIZE];
513d07f46f9STom Lendacky
514d08b4858SCarlos Bilbao u8 reserved_0xff0[10];
515d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */
516d07f46f9STom Lendacky u32 ghcb_usage;
517d07f46f9STom Lendacky } __packed;
518d07f46f9STom Lendacky
519*1b5ef14dSSean Christopherson struct vmcb {
520*1b5ef14dSSean Christopherson struct vmcb_control_area control;
521*1b5ef14dSSean Christopherson union {
522*1b5ef14dSSean Christopherson struct vmcb_save_area save;
523*1b5ef14dSSean Christopherson
524*1b5ef14dSSean Christopherson /*
525*1b5ef14dSSean Christopherson * For SEV-ES VMs, the save area in the VMCB is used only to
526*1b5ef14dSSean Christopherson * save/load host state. Guest state resides in a separate
527*1b5ef14dSSean Christopherson * page, the aptly named VM Save Area (VMSA), that is encrypted
528*1b5ef14dSSean Christopherson * with the guest's private key.
529*1b5ef14dSSean Christopherson */
530*1b5ef14dSSean Christopherson struct sev_es_save_area host_sev_es_save;
531*1b5ef14dSSean Christopherson };
532*1b5ef14dSSean Christopherson } __packed;
533d07f46f9STom Lendacky
534f6706341SManali Shukla #define EXPECTED_VMCB_SAVE_AREA_SIZE 744
535a4690359STom Lendacky #define EXPECTED_GHCB_SAVE_AREA_SIZE 1032
5366d3b3d34STom Lendacky #define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1648
53759d21d67SVineeth Pillai #define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024
538d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE
5397923ef4fSPaolo Bonzini
540d08b4858SCarlos Bilbao #define BUILD_BUG_RESERVED_OFFSET(x, y) \
541d08b4858SCarlos Bilbao ASSERT_STRUCT_OFFSET(struct x, reserved ## _ ## y, y)
542d08b4858SCarlos Bilbao
__unused_size_checks(void)5437923ef4fSPaolo Bonzini static inline void __unused_size_checks(void)
5447923ef4fSPaolo Bonzini {
545d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE);
546a4690359STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb_save_area) != EXPECTED_GHCB_SAVE_AREA_SIZE);
5473dd2775bSTom Lendacky BUILD_BUG_ON(sizeof(struct sev_es_save_area) != EXPECTED_SEV_ES_SAVE_AREA_SIZE);
548d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE);
549*1b5ef14dSSean Christopherson BUILD_BUG_ON(offsetof(struct vmcb, save) != EXPECTED_VMCB_CONTROL_AREA_SIZE);
550d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE);
551d08b4858SCarlos Bilbao
552d08b4858SCarlos Bilbao /* Check offsets of reserved fields */
553d08b4858SCarlos Bilbao
554d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xa0);
555d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xcc);
556d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xd8);
557d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x180);
558d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x248);
559d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x298);
560d08b4858SCarlos Bilbao
561d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xc8);
562d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xcc);
563d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xd8);
564d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0);
565d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248);
566d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298);
567d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2f0);
568d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320);
569d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380);
570d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x3f0);
571d08b4858SCarlos Bilbao
572d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x0);
573d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0xcc);
574d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x148);
575d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x168);
576d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x180);
577d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x1e0);
578d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x200);
579d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x320);
580d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x380);
581d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x3b0);
582d08b4858SCarlos Bilbao
583d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb, 0xff0);
5847923ef4fSPaolo Bonzini }
5857923ef4fSPaolo Bonzini
586c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a
587c2cedf7bSEduardo Habkost
588c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4
589c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5
590c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7
591c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8
592c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9
593c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10
594c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11
595c2cedf7bSEduardo Habkost
596c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf)
597c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT)
598c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT)
599c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT)
600c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT)
601c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT)
602c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT)
603c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT)
604c2cedf7bSEduardo Habkost
605c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1)
606c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK
607c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3)
608c2cedf7bSEduardo Habkost
609c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff
610c2cedf7bSEduardo Habkost
611c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8
612c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT)
613c2cedf7bSEduardo Habkost
614c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT)
615c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT)
616c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT)
617c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT)
618c2cedf7bSEduardo Habkost
619c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31)
620c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11)
621c2cedf7bSEduardo Habkost
622c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK
62364a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK
624c2cedf7bSEduardo Habkost
625c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR
626c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI
627c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT
628c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT
629c2cedf7bSEduardo Habkost
630c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID
631c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR
632c2cedf7bSEduardo Habkost
633c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36
634c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38
635e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44
636c2cedf7bSEduardo Habkost
6377ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F
6387ff76d58SAndre Przywara
639dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP)
640c2cedf7bSEduardo Habkost
6413702c2f4SJoerg Roedel /* GHCB Accessor functions */
6423702c2f4SJoerg Roedel
6433702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \
644a4690359STom Lendacky (offsetof(struct ghcb_save_area, field) / sizeof(u64))
6453702c2f4SJoerg Roedel
6463702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \
6476b91ec4aSBorislav Petkov static __always_inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \
6483702c2f4SJoerg Roedel { \
6493702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \
6503702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \
6513702c2f4SJoerg Roedel } \
6523702c2f4SJoerg Roedel \
6536b91ec4aSBorislav Petkov static __always_inline u64 ghcb_get_##field(struct ghcb *ghcb) \
6540f60bde1STom Lendacky { \
6550f60bde1STom Lendacky return ghcb->save.field; \
6560f60bde1STom Lendacky } \
6570f60bde1STom Lendacky \
6586b91ec4aSBorislav Petkov static __always_inline u64 ghcb_get_##field##_if_valid(struct ghcb *ghcb) \
6590f60bde1STom Lendacky { \
6600f60bde1STom Lendacky return ghcb_##field##_is_valid(ghcb) ? ghcb->save.field : 0; \
6610f60bde1STom Lendacky } \
6620f60bde1STom Lendacky \
6636b91ec4aSBorislav Petkov static __always_inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \
6643702c2f4SJoerg Roedel { \
6653702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \
6663702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \
6673702c2f4SJoerg Roedel ghcb->save.field = value; \
6683702c2f4SJoerg Roedel }
6693702c2f4SJoerg Roedel
6703702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl)
6713702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip)
6723702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp)
6733702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax)
6743702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx)
6753702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx)
6763702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx)
6773702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp)
6783702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi)
6793702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi)
6803702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8)
6813702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9)
6823702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10)
6833702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11)
6843702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12)
6853702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13)
6863702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14)
6873702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15)
6883702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code)
6893702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1)
6903702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2)
6913702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch)
6923702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0)
6933702c2f4SJoerg Roedel
694c2cedf7bSEduardo Habkost #endif
695