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 186*1c4522abSSantosh Shukla #define V_NMI_PENDING_SHIFT 11 187*1c4522abSSantosh Shukla #define V_NMI_PENDING_MASK (1 << V_NMI_PENDING_SHIFT) 188*1c4522abSSantosh Shukla 189*1c4522abSSantosh Shukla #define V_NMI_BLOCKING_SHIFT 12 190*1c4522abSSantosh Shukla #define V_NMI_BLOCKING_MASK (1 << V_NMI_BLOCKING_SHIFT) 191*1c4522abSSantosh 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 206*1c4522abSSantosh Shukla #define V_NMI_ENABLE_SHIFT 26 207*1c4522abSSantosh Shukla #define V_NMI_ENABLE_MASK (1 << V_NMI_ENABLE_SHIFT) 208*1c4522abSSantosh 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 2324a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 2334a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 2344a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 2354a810181SJoerg Roedel 236cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0) 237ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1) 238376c6d28STom Lendacky #define SVM_NESTED_CTL_SEV_ES_ENABLE BIT(2) 239cea3a19bSTom Lendacky 24039150352SMaxim Levitsky 241bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_RSVD 0xffffff0000000000ULL 242bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_MIN 0x0000000000000001ULL 243bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_MAX 0x000000ffffffffffULL 244bb2aa78eSMaxim Levitsky #define SVM_TSC_RATIO_DEFAULT 0x0100000000ULL 245bb2aa78eSMaxim Levitsky 246bb2aa78eSMaxim Levitsky 24739150352SMaxim Levitsky /* AVIC */ 2480dacc3dfSMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFFULL) 24939150352SMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 25039150352SMaxim Levitsky #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) 25139150352SMaxim Levitsky 2524a204f78SSuravee Suthikulpanit #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK GENMASK_ULL(11, 0) 25339150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12) 25439150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62) 25539150352SMaxim Levitsky #define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63) 2560dacc3dfSMaxim Levitsky #define AVIC_PHYSICAL_ID_TABLE_SIZE_MASK (0xFFULL) 25739150352SMaxim Levitsky 2580dacc3dfSMaxim Levitsky #define AVIC_DOORBELL_PHYSICAL_ID_MASK GENMASK_ULL(11, 0) 2590dacc3dfSMaxim Levitsky 2600dacc3dfSMaxim Levitsky #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL 26139150352SMaxim Levitsky 26239150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_WRITE_MASK 1 26339150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_OFFSET_MASK 0xFF0 26439150352SMaxim Levitsky #define AVIC_UNACCEL_ACCESS_VECTOR_MASK 0xFFFFFFFF 26539150352SMaxim Levitsky 26639150352SMaxim Levitsky enum avic_ipi_failure_cause { 26739150352SMaxim Levitsky AVIC_IPI_FAILURE_INVALID_INT_TYPE, 26839150352SMaxim Levitsky AVIC_IPI_FAILURE_TARGET_NOT_RUNNING, 26939150352SMaxim Levitsky AVIC_IPI_FAILURE_INVALID_TARGET, 27039150352SMaxim Levitsky AVIC_IPI_FAILURE_INVALID_BACKING_PAGE, 27139150352SMaxim Levitsky }; 27239150352SMaxim Levitsky 2733ec7a1b2SSean Christopherson #define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0) 27439150352SMaxim Levitsky 27539150352SMaxim Levitsky /* 2763ec7a1b2SSean Christopherson * For AVIC, the max index allowed for physical APIC ID table is 0xfe (254), as 2773ec7a1b2SSean Christopherson * 0xff is a broadcast to all CPUs, i.e. can't be targeted individually. 27839150352SMaxim Levitsky */ 279d2fe6bf5SSuravee Suthikulpanit #define AVIC_MAX_PHYSICAL_ID 0XFEULL 280d2fe6bf5SSuravee Suthikulpanit 281d2fe6bf5SSuravee Suthikulpanit /* 2823ec7a1b2SSean Christopherson * For x2AVIC, the max index allowed for physical APIC ID table is 0x1ff (511). 283d2fe6bf5SSuravee Suthikulpanit */ 284d2fe6bf5SSuravee Suthikulpanit #define X2AVIC_MAX_PHYSICAL_ID 0x1FFUL 28539150352SMaxim Levitsky 2863ec7a1b2SSean Christopherson static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == AVIC_MAX_PHYSICAL_ID); 2873ec7a1b2SSean Christopherson static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_MAX_PHYSICAL_ID); 2883ec7a1b2SSean Christopherson 28939150352SMaxim Levitsky #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) 29039150352SMaxim Levitsky #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL 29139150352SMaxim Levitsky 29239150352SMaxim Levitsky 293976bc5e2SBorislav Petkov struct vmcb_seg { 294c2cedf7bSEduardo Habkost u16 selector; 295c2cedf7bSEduardo Habkost u16 attrib; 296c2cedf7bSEduardo Habkost u32 limit; 297c2cedf7bSEduardo Habkost u64 base; 298976bc5e2SBorislav Petkov } __packed; 299c2cedf7bSEduardo Habkost 3003dd2775bSTom Lendacky /* Save area definition for legacy and SEV-MEM guests */ 301976bc5e2SBorislav Petkov struct vmcb_save_area { 302c2cedf7bSEduardo Habkost struct vmcb_seg es; 303c2cedf7bSEduardo Habkost struct vmcb_seg cs; 304c2cedf7bSEduardo Habkost struct vmcb_seg ss; 305c2cedf7bSEduardo Habkost struct vmcb_seg ds; 306c2cedf7bSEduardo Habkost struct vmcb_seg fs; 307c2cedf7bSEduardo Habkost struct vmcb_seg gs; 308c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 309c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 310c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 311c2cedf7bSEduardo Habkost struct vmcb_seg tr; 312d08b4858SCarlos Bilbao /* Reserved fields are named following their struct offset */ 313d08b4858SCarlos Bilbao u8 reserved_0xa0[42]; 314046f773bSBrijesh Singh u8 vmpl; 315c2cedf7bSEduardo Habkost u8 cpl; 316d08b4858SCarlos Bilbao u8 reserved_0xcc[4]; 317c2cedf7bSEduardo Habkost u64 efer; 318d08b4858SCarlos Bilbao u8 reserved_0xd8[112]; 3193dd2775bSTom Lendacky u64 cr4; 3203dd2775bSTom Lendacky u64 cr3; 3213dd2775bSTom Lendacky u64 cr0; 3223dd2775bSTom Lendacky u64 dr7; 3233dd2775bSTom Lendacky u64 dr6; 3243dd2775bSTom Lendacky u64 rflags; 3253dd2775bSTom Lendacky u64 rip; 326d08b4858SCarlos Bilbao u8 reserved_0x180[88]; 3273dd2775bSTom Lendacky u64 rsp; 3283dd2775bSTom Lendacky u64 s_cet; 3293dd2775bSTom Lendacky u64 ssp; 3303dd2775bSTom Lendacky u64 isst_addr; 3313dd2775bSTom Lendacky u64 rax; 3323dd2775bSTom Lendacky u64 star; 3333dd2775bSTom Lendacky u64 lstar; 3343dd2775bSTom Lendacky u64 cstar; 3353dd2775bSTom Lendacky u64 sfmask; 3363dd2775bSTom Lendacky u64 kernel_gs_base; 3373dd2775bSTom Lendacky u64 sysenter_cs; 3383dd2775bSTom Lendacky u64 sysenter_esp; 3393dd2775bSTom Lendacky u64 sysenter_eip; 3403dd2775bSTom Lendacky u64 cr2; 341d08b4858SCarlos Bilbao u8 reserved_0x248[32]; 3423dd2775bSTom Lendacky u64 g_pat; 3433dd2775bSTom Lendacky u64 dbgctl; 3443dd2775bSTom Lendacky u64 br_from; 3453dd2775bSTom Lendacky u64 br_to; 3463dd2775bSTom Lendacky u64 last_excp_from; 3473dd2775bSTom Lendacky u64 last_excp_to; 348d08b4858SCarlos Bilbao u8 reserved_0x298[72]; 3493dd2775bSTom Lendacky u32 spec_ctrl; /* Guest version of SPEC_CTRL at 0x2E0 */ 3503dd2775bSTom Lendacky } __packed; 3513dd2775bSTom Lendacky 3523dd2775bSTom Lendacky /* Save area definition for SEV-ES and SEV-SNP guests */ 3533dd2775bSTom Lendacky struct sev_es_save_area { 3543dd2775bSTom Lendacky struct vmcb_seg es; 3553dd2775bSTom Lendacky struct vmcb_seg cs; 3563dd2775bSTom Lendacky struct vmcb_seg ss; 3573dd2775bSTom Lendacky struct vmcb_seg ds; 3583dd2775bSTom Lendacky struct vmcb_seg fs; 3593dd2775bSTom Lendacky struct vmcb_seg gs; 3603dd2775bSTom Lendacky struct vmcb_seg gdtr; 3613dd2775bSTom Lendacky struct vmcb_seg ldtr; 3623dd2775bSTom Lendacky struct vmcb_seg idtr; 3633dd2775bSTom Lendacky struct vmcb_seg tr; 3646d3b3d34STom Lendacky u64 vmpl0_ssp; 3656d3b3d34STom Lendacky u64 vmpl1_ssp; 3666d3b3d34STom Lendacky u64 vmpl2_ssp; 3676d3b3d34STom Lendacky u64 vmpl3_ssp; 3686d3b3d34STom Lendacky u64 u_cet; 369d08b4858SCarlos Bilbao u8 reserved_0xc8[2]; 3706d3b3d34STom Lendacky u8 vmpl; 3713dd2775bSTom Lendacky u8 cpl; 372d08b4858SCarlos Bilbao u8 reserved_0xcc[4]; 3733dd2775bSTom Lendacky u64 efer; 374d08b4858SCarlos Bilbao u8 reserved_0xd8[104]; 3753dd2775bSTom Lendacky u64 xss; 376c2cedf7bSEduardo Habkost u64 cr4; 377c2cedf7bSEduardo Habkost u64 cr3; 378c2cedf7bSEduardo Habkost u64 cr0; 379c2cedf7bSEduardo Habkost u64 dr7; 380c2cedf7bSEduardo Habkost u64 dr6; 381c2cedf7bSEduardo Habkost u64 rflags; 382c2cedf7bSEduardo Habkost u64 rip; 3836d3b3d34STom Lendacky u64 dr0; 3846d3b3d34STom Lendacky u64 dr1; 3856d3b3d34STom Lendacky u64 dr2; 3866d3b3d34STom Lendacky u64 dr3; 3876d3b3d34STom Lendacky u64 dr0_addr_mask; 3886d3b3d34STom Lendacky u64 dr1_addr_mask; 3896d3b3d34STom Lendacky u64 dr2_addr_mask; 3906d3b3d34STom Lendacky u64 dr3_addr_mask; 391d08b4858SCarlos Bilbao u8 reserved_0x1c0[24]; 392c2cedf7bSEduardo Habkost u64 rsp; 3936d3b3d34STom Lendacky u64 s_cet; 3946d3b3d34STom Lendacky u64 ssp; 3956d3b3d34STom Lendacky u64 isst_addr; 396c2cedf7bSEduardo Habkost u64 rax; 397c2cedf7bSEduardo Habkost u64 star; 398c2cedf7bSEduardo Habkost u64 lstar; 399c2cedf7bSEduardo Habkost u64 cstar; 400c2cedf7bSEduardo Habkost u64 sfmask; 401c2cedf7bSEduardo Habkost u64 kernel_gs_base; 402c2cedf7bSEduardo Habkost u64 sysenter_cs; 403c2cedf7bSEduardo Habkost u64 sysenter_esp; 404c2cedf7bSEduardo Habkost u64 sysenter_eip; 405c2cedf7bSEduardo Habkost u64 cr2; 406d08b4858SCarlos Bilbao u8 reserved_0x248[32]; 407c2cedf7bSEduardo Habkost u64 g_pat; 408c2cedf7bSEduardo Habkost u64 dbgctl; 409c2cedf7bSEduardo Habkost u64 br_from; 410c2cedf7bSEduardo Habkost u64 br_to; 411c2cedf7bSEduardo Habkost u64 last_excp_from; 412c2cedf7bSEduardo Habkost u64 last_excp_to; 413d08b4858SCarlos Bilbao u8 reserved_0x298[80]; 41486137773STom Lendacky u32 pkru; 415d08b4858SCarlos Bilbao u32 tsc_aux; 416d08b4858SCarlos Bilbao u8 reserved_0x2f0[24]; 417d07f46f9STom Lendacky u64 rcx; 418d07f46f9STom Lendacky u64 rdx; 419d07f46f9STom Lendacky u64 rbx; 420d08b4858SCarlos Bilbao u64 reserved_0x320; /* rsp already available at 0x01d8 */ 421d07f46f9STom Lendacky u64 rbp; 422d07f46f9STom Lendacky u64 rsi; 423d07f46f9STom Lendacky u64 rdi; 424d07f46f9STom Lendacky u64 r8; 425d07f46f9STom Lendacky u64 r9; 426d07f46f9STom Lendacky u64 r10; 427d07f46f9STom Lendacky u64 r11; 428d07f46f9STom Lendacky u64 r12; 429d07f46f9STom Lendacky u64 r13; 430d07f46f9STom Lendacky u64 r14; 431d07f46f9STom Lendacky u64 r15; 432d08b4858SCarlos Bilbao u8 reserved_0x380[16]; 4336d3b3d34STom Lendacky u64 guest_exit_info_1; 4346d3b3d34STom Lendacky u64 guest_exit_info_2; 4356d3b3d34STom Lendacky u64 guest_exit_int_info; 4366d3b3d34STom Lendacky u64 guest_nrip; 437046f773bSBrijesh Singh u64 sev_features; 4386d3b3d34STom Lendacky u64 vintr_ctrl; 4396d3b3d34STom Lendacky u64 guest_exit_code; 4406d3b3d34STom Lendacky u64 virtual_tom; 4416d3b3d34STom Lendacky u64 tlb_id; 4426d3b3d34STom Lendacky u64 pcpu_id; 4436d3b3d34STom Lendacky u64 event_inj; 444d07f46f9STom Lendacky u64 xcr0; 445d08b4858SCarlos Bilbao u8 reserved_0x3f0[16]; 4466d3b3d34STom Lendacky 4476d3b3d34STom Lendacky /* Floating point area */ 4486d3b3d34STom Lendacky u64 x87_dp; 4496d3b3d34STom Lendacky u32 mxcsr; 4506d3b3d34STom Lendacky u16 x87_ftw; 4516d3b3d34STom Lendacky u16 x87_fsw; 4526d3b3d34STom Lendacky u16 x87_fcw; 4536d3b3d34STom Lendacky u16 x87_fop; 4546d3b3d34STom Lendacky u16 x87_ds; 4556d3b3d34STom Lendacky u16 x87_cs; 4566d3b3d34STom Lendacky u64 x87_rip; 4576d3b3d34STom Lendacky u8 fpreg_x87[80]; 4586d3b3d34STom Lendacky u8 fpreg_xmm[256]; 4596d3b3d34STom Lendacky u8 fpreg_ymm[256]; 460976bc5e2SBorislav Petkov } __packed; 461c2cedf7bSEduardo Habkost 462a4690359STom Lendacky struct ghcb_save_area { 463d08b4858SCarlos Bilbao u8 reserved_0x0[203]; 464a4690359STom Lendacky u8 cpl; 465d08b4858SCarlos Bilbao u8 reserved_0xcc[116]; 466a4690359STom Lendacky u64 xss; 467d08b4858SCarlos Bilbao u8 reserved_0x148[24]; 468a4690359STom Lendacky u64 dr7; 469d08b4858SCarlos Bilbao u8 reserved_0x168[16]; 470a4690359STom Lendacky u64 rip; 471d08b4858SCarlos Bilbao u8 reserved_0x180[88]; 472a4690359STom Lendacky u64 rsp; 473d08b4858SCarlos Bilbao u8 reserved_0x1e0[24]; 474a4690359STom Lendacky u64 rax; 475d08b4858SCarlos Bilbao u8 reserved_0x200[264]; 476a4690359STom Lendacky u64 rcx; 477a4690359STom Lendacky u64 rdx; 478a4690359STom Lendacky u64 rbx; 479d08b4858SCarlos Bilbao u8 reserved_0x320[8]; 480a4690359STom Lendacky u64 rbp; 481a4690359STom Lendacky u64 rsi; 482a4690359STom Lendacky u64 rdi; 483a4690359STom Lendacky u64 r8; 484a4690359STom Lendacky u64 r9; 485a4690359STom Lendacky u64 r10; 486a4690359STom Lendacky u64 r11; 487a4690359STom Lendacky u64 r12; 488a4690359STom Lendacky u64 r13; 489a4690359STom Lendacky u64 r14; 490a4690359STom Lendacky u64 r15; 491d08b4858SCarlos Bilbao u8 reserved_0x380[16]; 492a4690359STom Lendacky u64 sw_exit_code; 493a4690359STom Lendacky u64 sw_exit_info_1; 494a4690359STom Lendacky u64 sw_exit_info_2; 495a4690359STom Lendacky u64 sw_scratch; 496d08b4858SCarlos Bilbao u8 reserved_0x3b0[56]; 497a4690359STom Lendacky u64 xcr0; 498a4690359STom Lendacky u8 valid_bitmap[16]; 499a4690359STom Lendacky u64 x87_state_gpa; 500a4690359STom Lendacky } __packed; 501a4690359STom Lendacky 5023dd2775bSTom Lendacky #define GHCB_SHARED_BUF_SIZE 2032 503d07f46f9STom Lendacky 5043dd2775bSTom Lendacky struct ghcb { 505a4690359STom Lendacky struct ghcb_save_area save; 506a4690359STom Lendacky u8 reserved_save[2048 - sizeof(struct ghcb_save_area)]; 5073dd2775bSTom Lendacky 5083dd2775bSTom Lendacky u8 shared_buffer[GHCB_SHARED_BUF_SIZE]; 509d07f46f9STom Lendacky 510d08b4858SCarlos Bilbao u8 reserved_0xff0[10]; 511d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ 512d07f46f9STom Lendacky u32 ghcb_usage; 513d07f46f9STom Lendacky } __packed; 514d07f46f9STom Lendacky 515d07f46f9STom Lendacky 5163dd2775bSTom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE 740 517a4690359STom Lendacky #define EXPECTED_GHCB_SAVE_AREA_SIZE 1032 5186d3b3d34STom Lendacky #define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1648 51959d21d67SVineeth Pillai #define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024 520d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE 5217923ef4fSPaolo Bonzini 522d08b4858SCarlos Bilbao #define BUILD_BUG_RESERVED_OFFSET(x, y) \ 523d08b4858SCarlos Bilbao ASSERT_STRUCT_OFFSET(struct x, reserved ## _ ## y, y) 524d08b4858SCarlos Bilbao 5257923ef4fSPaolo Bonzini static inline void __unused_size_checks(void) 5267923ef4fSPaolo Bonzini { 527d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); 528a4690359STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb_save_area) != EXPECTED_GHCB_SAVE_AREA_SIZE); 5293dd2775bSTom Lendacky BUILD_BUG_ON(sizeof(struct sev_es_save_area) != EXPECTED_SEV_ES_SAVE_AREA_SIZE); 530d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); 531d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); 532d08b4858SCarlos Bilbao 533d08b4858SCarlos Bilbao /* Check offsets of reserved fields */ 534d08b4858SCarlos Bilbao 535d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xa0); 536d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xcc); 537d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xd8); 538d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x180); 539d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x248); 540d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x298); 541d08b4858SCarlos Bilbao 542d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xc8); 543d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xcc); 544d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xd8); 545d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0); 546d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248); 547d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298); 548d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2f0); 549d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320); 550d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380); 551d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x3f0); 552d08b4858SCarlos Bilbao 553d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x0); 554d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0xcc); 555d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x148); 556d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x168); 557d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x180); 558d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x1e0); 559d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x200); 560d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x320); 561d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x380); 562d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x3b0); 563d08b4858SCarlos Bilbao 564d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb, 0xff0); 5657923ef4fSPaolo Bonzini } 5667923ef4fSPaolo Bonzini 567976bc5e2SBorislav Petkov struct vmcb { 568c2cedf7bSEduardo Habkost struct vmcb_control_area control; 569c2cedf7bSEduardo Habkost struct vmcb_save_area save; 570976bc5e2SBorislav Petkov } __packed; 571c2cedf7bSEduardo Habkost 572c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 573c2cedf7bSEduardo Habkost 574c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 575c2cedf7bSEduardo Habkost 576c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 577c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 578c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 579c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 580c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 581c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 582c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 583c2cedf7bSEduardo Habkost 584c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 585c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 586c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 587c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 588c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 589c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 590c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 591c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 592c2cedf7bSEduardo Habkost 593c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 594c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 595c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 596c2cedf7bSEduardo Habkost 597c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 598c2cedf7bSEduardo Habkost 599c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 600c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 601c2cedf7bSEduardo Habkost 602c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 603c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 604c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 605c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 606c2cedf7bSEduardo Habkost 607c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 608c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 609c2cedf7bSEduardo Habkost 610c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 61164a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 612c2cedf7bSEduardo Habkost 613c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 614c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 615c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 616c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 617c2cedf7bSEduardo Habkost 618c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 619c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 620c2cedf7bSEduardo Habkost 621c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 622c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 623e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 624c2cedf7bSEduardo Habkost 6257ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 6267ff76d58SAndre Przywara 627dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 628c2cedf7bSEduardo Habkost 6293702c2f4SJoerg Roedel /* GHCB Accessor functions */ 6303702c2f4SJoerg Roedel 6313702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \ 632a4690359STom Lendacky (offsetof(struct ghcb_save_area, field) / sizeof(u64)) 6333702c2f4SJoerg Roedel 6343702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \ 6356b91ec4aSBorislav Petkov static __always_inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ 6363702c2f4SJoerg Roedel { \ 6373702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \ 6383702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 6393702c2f4SJoerg Roedel } \ 6403702c2f4SJoerg Roedel \ 6416b91ec4aSBorislav Petkov static __always_inline u64 ghcb_get_##field(struct ghcb *ghcb) \ 6420f60bde1STom Lendacky { \ 6430f60bde1STom Lendacky return ghcb->save.field; \ 6440f60bde1STom Lendacky } \ 6450f60bde1STom Lendacky \ 6466b91ec4aSBorislav Petkov static __always_inline u64 ghcb_get_##field##_if_valid(struct ghcb *ghcb) \ 6470f60bde1STom Lendacky { \ 6480f60bde1STom Lendacky return ghcb_##field##_is_valid(ghcb) ? ghcb->save.field : 0; \ 6490f60bde1STom Lendacky } \ 6500f60bde1STom Lendacky \ 6516b91ec4aSBorislav Petkov static __always_inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ 6523702c2f4SJoerg Roedel { \ 6533702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \ 6543702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 6553702c2f4SJoerg Roedel ghcb->save.field = value; \ 6563702c2f4SJoerg Roedel } 6573702c2f4SJoerg Roedel 6583702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl) 6593702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip) 6603702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp) 6613702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax) 6623702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx) 6633702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx) 6643702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx) 6653702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp) 6663702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi) 6673702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi) 6683702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8) 6693702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9) 6703702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10) 6713702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11) 6723702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12) 6733702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13) 6743702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14) 6753702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15) 6763702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code) 6773702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1) 6783702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2) 6793702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch) 6803702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0) 6813702c2f4SJoerg Roedel 682c2cedf7bSEduardo Habkost #endif 683