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 8*68ae7c7bSSean Christopherson #include <asm/hyperv-tlfs.h> 9*68ae7c7bSSean 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 */ 166*68ae7c7bSSean Christopherson union { 167*68ae7c7bSSean Christopherson struct hv_enlightenments hv_enlightenments; 16859d21d67SVineeth Pillai u8 reserved_sw[32]; 169c2cedf7bSEduardo Habkost }; 170*68ae7c7bSSean 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 2644d1d7942SSuravee Suthikulpanit #define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(9, 0) 26539150352SMaxim Levitsky 26639150352SMaxim Levitsky /* 267d2fe6bf5SSuravee Suthikulpanit * For AVIC, the max index allowed for physical APIC ID 268d2fe6bf5SSuravee Suthikulpanit * table is 0xff (255). 26939150352SMaxim Levitsky */ 270d2fe6bf5SSuravee Suthikulpanit #define AVIC_MAX_PHYSICAL_ID 0XFEULL 271d2fe6bf5SSuravee Suthikulpanit 272d2fe6bf5SSuravee Suthikulpanit /* 273d2fe6bf5SSuravee Suthikulpanit * For x2AVIC, the max index allowed for physical APIC ID 274d2fe6bf5SSuravee Suthikulpanit * table is 0x1ff (511). 275d2fe6bf5SSuravee Suthikulpanit */ 276d2fe6bf5SSuravee Suthikulpanit #define X2AVIC_MAX_PHYSICAL_ID 0x1FFUL 27739150352SMaxim Levitsky 27839150352SMaxim Levitsky #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) 27939150352SMaxim Levitsky #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL 28039150352SMaxim Levitsky 28139150352SMaxim Levitsky 282976bc5e2SBorislav Petkov struct vmcb_seg { 283c2cedf7bSEduardo Habkost u16 selector; 284c2cedf7bSEduardo Habkost u16 attrib; 285c2cedf7bSEduardo Habkost u32 limit; 286c2cedf7bSEduardo Habkost u64 base; 287976bc5e2SBorislav Petkov } __packed; 288c2cedf7bSEduardo Habkost 2893dd2775bSTom Lendacky /* Save area definition for legacy and SEV-MEM guests */ 290976bc5e2SBorislav Petkov struct vmcb_save_area { 291c2cedf7bSEduardo Habkost struct vmcb_seg es; 292c2cedf7bSEduardo Habkost struct vmcb_seg cs; 293c2cedf7bSEduardo Habkost struct vmcb_seg ss; 294c2cedf7bSEduardo Habkost struct vmcb_seg ds; 295c2cedf7bSEduardo Habkost struct vmcb_seg fs; 296c2cedf7bSEduardo Habkost struct vmcb_seg gs; 297c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 298c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 299c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 300c2cedf7bSEduardo Habkost struct vmcb_seg tr; 301d08b4858SCarlos Bilbao /* Reserved fields are named following their struct offset */ 302d08b4858SCarlos Bilbao u8 reserved_0xa0[42]; 303046f773bSBrijesh Singh u8 vmpl; 304c2cedf7bSEduardo Habkost u8 cpl; 305d08b4858SCarlos Bilbao u8 reserved_0xcc[4]; 306c2cedf7bSEduardo Habkost u64 efer; 307d08b4858SCarlos Bilbao u8 reserved_0xd8[112]; 3083dd2775bSTom Lendacky u64 cr4; 3093dd2775bSTom Lendacky u64 cr3; 3103dd2775bSTom Lendacky u64 cr0; 3113dd2775bSTom Lendacky u64 dr7; 3123dd2775bSTom Lendacky u64 dr6; 3133dd2775bSTom Lendacky u64 rflags; 3143dd2775bSTom Lendacky u64 rip; 315d08b4858SCarlos Bilbao u8 reserved_0x180[88]; 3163dd2775bSTom Lendacky u64 rsp; 3173dd2775bSTom Lendacky u64 s_cet; 3183dd2775bSTom Lendacky u64 ssp; 3193dd2775bSTom Lendacky u64 isst_addr; 3203dd2775bSTom Lendacky u64 rax; 3213dd2775bSTom Lendacky u64 star; 3223dd2775bSTom Lendacky u64 lstar; 3233dd2775bSTom Lendacky u64 cstar; 3243dd2775bSTom Lendacky u64 sfmask; 3253dd2775bSTom Lendacky u64 kernel_gs_base; 3263dd2775bSTom Lendacky u64 sysenter_cs; 3273dd2775bSTom Lendacky u64 sysenter_esp; 3283dd2775bSTom Lendacky u64 sysenter_eip; 3293dd2775bSTom Lendacky u64 cr2; 330d08b4858SCarlos Bilbao u8 reserved_0x248[32]; 3313dd2775bSTom Lendacky u64 g_pat; 3323dd2775bSTom Lendacky u64 dbgctl; 3333dd2775bSTom Lendacky u64 br_from; 3343dd2775bSTom Lendacky u64 br_to; 3353dd2775bSTom Lendacky u64 last_excp_from; 3363dd2775bSTom Lendacky u64 last_excp_to; 337d08b4858SCarlos Bilbao u8 reserved_0x298[72]; 3383dd2775bSTom Lendacky u32 spec_ctrl; /* Guest version of SPEC_CTRL at 0x2E0 */ 3393dd2775bSTom Lendacky } __packed; 3403dd2775bSTom Lendacky 3413dd2775bSTom Lendacky /* Save area definition for SEV-ES and SEV-SNP guests */ 3423dd2775bSTom Lendacky struct sev_es_save_area { 3433dd2775bSTom Lendacky struct vmcb_seg es; 3443dd2775bSTom Lendacky struct vmcb_seg cs; 3453dd2775bSTom Lendacky struct vmcb_seg ss; 3463dd2775bSTom Lendacky struct vmcb_seg ds; 3473dd2775bSTom Lendacky struct vmcb_seg fs; 3483dd2775bSTom Lendacky struct vmcb_seg gs; 3493dd2775bSTom Lendacky struct vmcb_seg gdtr; 3503dd2775bSTom Lendacky struct vmcb_seg ldtr; 3513dd2775bSTom Lendacky struct vmcb_seg idtr; 3523dd2775bSTom Lendacky struct vmcb_seg tr; 3536d3b3d34STom Lendacky u64 vmpl0_ssp; 3546d3b3d34STom Lendacky u64 vmpl1_ssp; 3556d3b3d34STom Lendacky u64 vmpl2_ssp; 3566d3b3d34STom Lendacky u64 vmpl3_ssp; 3576d3b3d34STom Lendacky u64 u_cet; 358d08b4858SCarlos Bilbao u8 reserved_0xc8[2]; 3596d3b3d34STom Lendacky u8 vmpl; 3603dd2775bSTom Lendacky u8 cpl; 361d08b4858SCarlos Bilbao u8 reserved_0xcc[4]; 3623dd2775bSTom Lendacky u64 efer; 363d08b4858SCarlos Bilbao u8 reserved_0xd8[104]; 3643dd2775bSTom Lendacky u64 xss; 365c2cedf7bSEduardo Habkost u64 cr4; 366c2cedf7bSEduardo Habkost u64 cr3; 367c2cedf7bSEduardo Habkost u64 cr0; 368c2cedf7bSEduardo Habkost u64 dr7; 369c2cedf7bSEduardo Habkost u64 dr6; 370c2cedf7bSEduardo Habkost u64 rflags; 371c2cedf7bSEduardo Habkost u64 rip; 3726d3b3d34STom Lendacky u64 dr0; 3736d3b3d34STom Lendacky u64 dr1; 3746d3b3d34STom Lendacky u64 dr2; 3756d3b3d34STom Lendacky u64 dr3; 3766d3b3d34STom Lendacky u64 dr0_addr_mask; 3776d3b3d34STom Lendacky u64 dr1_addr_mask; 3786d3b3d34STom Lendacky u64 dr2_addr_mask; 3796d3b3d34STom Lendacky u64 dr3_addr_mask; 380d08b4858SCarlos Bilbao u8 reserved_0x1c0[24]; 381c2cedf7bSEduardo Habkost u64 rsp; 3826d3b3d34STom Lendacky u64 s_cet; 3836d3b3d34STom Lendacky u64 ssp; 3846d3b3d34STom Lendacky u64 isst_addr; 385c2cedf7bSEduardo Habkost u64 rax; 386c2cedf7bSEduardo Habkost u64 star; 387c2cedf7bSEduardo Habkost u64 lstar; 388c2cedf7bSEduardo Habkost u64 cstar; 389c2cedf7bSEduardo Habkost u64 sfmask; 390c2cedf7bSEduardo Habkost u64 kernel_gs_base; 391c2cedf7bSEduardo Habkost u64 sysenter_cs; 392c2cedf7bSEduardo Habkost u64 sysenter_esp; 393c2cedf7bSEduardo Habkost u64 sysenter_eip; 394c2cedf7bSEduardo Habkost u64 cr2; 395d08b4858SCarlos Bilbao u8 reserved_0x248[32]; 396c2cedf7bSEduardo Habkost u64 g_pat; 397c2cedf7bSEduardo Habkost u64 dbgctl; 398c2cedf7bSEduardo Habkost u64 br_from; 399c2cedf7bSEduardo Habkost u64 br_to; 400c2cedf7bSEduardo Habkost u64 last_excp_from; 401c2cedf7bSEduardo Habkost u64 last_excp_to; 402d08b4858SCarlos Bilbao u8 reserved_0x298[80]; 40386137773STom Lendacky u32 pkru; 404d08b4858SCarlos Bilbao u32 tsc_aux; 405d08b4858SCarlos Bilbao u8 reserved_0x2f0[24]; 406d07f46f9STom Lendacky u64 rcx; 407d07f46f9STom Lendacky u64 rdx; 408d07f46f9STom Lendacky u64 rbx; 409d08b4858SCarlos Bilbao u64 reserved_0x320; /* rsp already available at 0x01d8 */ 410d07f46f9STom Lendacky u64 rbp; 411d07f46f9STom Lendacky u64 rsi; 412d07f46f9STom Lendacky u64 rdi; 413d07f46f9STom Lendacky u64 r8; 414d07f46f9STom Lendacky u64 r9; 415d07f46f9STom Lendacky u64 r10; 416d07f46f9STom Lendacky u64 r11; 417d07f46f9STom Lendacky u64 r12; 418d07f46f9STom Lendacky u64 r13; 419d07f46f9STom Lendacky u64 r14; 420d07f46f9STom Lendacky u64 r15; 421d08b4858SCarlos Bilbao u8 reserved_0x380[16]; 4226d3b3d34STom Lendacky u64 guest_exit_info_1; 4236d3b3d34STom Lendacky u64 guest_exit_info_2; 4246d3b3d34STom Lendacky u64 guest_exit_int_info; 4256d3b3d34STom Lendacky u64 guest_nrip; 426046f773bSBrijesh Singh u64 sev_features; 4276d3b3d34STom Lendacky u64 vintr_ctrl; 4286d3b3d34STom Lendacky u64 guest_exit_code; 4296d3b3d34STom Lendacky u64 virtual_tom; 4306d3b3d34STom Lendacky u64 tlb_id; 4316d3b3d34STom Lendacky u64 pcpu_id; 4326d3b3d34STom Lendacky u64 event_inj; 433d07f46f9STom Lendacky u64 xcr0; 434d08b4858SCarlos Bilbao u8 reserved_0x3f0[16]; 4356d3b3d34STom Lendacky 4366d3b3d34STom Lendacky /* Floating point area */ 4376d3b3d34STom Lendacky u64 x87_dp; 4386d3b3d34STom Lendacky u32 mxcsr; 4396d3b3d34STom Lendacky u16 x87_ftw; 4406d3b3d34STom Lendacky u16 x87_fsw; 4416d3b3d34STom Lendacky u16 x87_fcw; 4426d3b3d34STom Lendacky u16 x87_fop; 4436d3b3d34STom Lendacky u16 x87_ds; 4446d3b3d34STom Lendacky u16 x87_cs; 4456d3b3d34STom Lendacky u64 x87_rip; 4466d3b3d34STom Lendacky u8 fpreg_x87[80]; 4476d3b3d34STom Lendacky u8 fpreg_xmm[256]; 4486d3b3d34STom Lendacky u8 fpreg_ymm[256]; 449976bc5e2SBorislav Petkov } __packed; 450c2cedf7bSEduardo Habkost 451a4690359STom Lendacky struct ghcb_save_area { 452d08b4858SCarlos Bilbao u8 reserved_0x0[203]; 453a4690359STom Lendacky u8 cpl; 454d08b4858SCarlos Bilbao u8 reserved_0xcc[116]; 455a4690359STom Lendacky u64 xss; 456d08b4858SCarlos Bilbao u8 reserved_0x148[24]; 457a4690359STom Lendacky u64 dr7; 458d08b4858SCarlos Bilbao u8 reserved_0x168[16]; 459a4690359STom Lendacky u64 rip; 460d08b4858SCarlos Bilbao u8 reserved_0x180[88]; 461a4690359STom Lendacky u64 rsp; 462d08b4858SCarlos Bilbao u8 reserved_0x1e0[24]; 463a4690359STom Lendacky u64 rax; 464d08b4858SCarlos Bilbao u8 reserved_0x200[264]; 465a4690359STom Lendacky u64 rcx; 466a4690359STom Lendacky u64 rdx; 467a4690359STom Lendacky u64 rbx; 468d08b4858SCarlos Bilbao u8 reserved_0x320[8]; 469a4690359STom Lendacky u64 rbp; 470a4690359STom Lendacky u64 rsi; 471a4690359STom Lendacky u64 rdi; 472a4690359STom Lendacky u64 r8; 473a4690359STom Lendacky u64 r9; 474a4690359STom Lendacky u64 r10; 475a4690359STom Lendacky u64 r11; 476a4690359STom Lendacky u64 r12; 477a4690359STom Lendacky u64 r13; 478a4690359STom Lendacky u64 r14; 479a4690359STom Lendacky u64 r15; 480d08b4858SCarlos Bilbao u8 reserved_0x380[16]; 481a4690359STom Lendacky u64 sw_exit_code; 482a4690359STom Lendacky u64 sw_exit_info_1; 483a4690359STom Lendacky u64 sw_exit_info_2; 484a4690359STom Lendacky u64 sw_scratch; 485d08b4858SCarlos Bilbao u8 reserved_0x3b0[56]; 486a4690359STom Lendacky u64 xcr0; 487a4690359STom Lendacky u8 valid_bitmap[16]; 488a4690359STom Lendacky u64 x87_state_gpa; 489a4690359STom Lendacky } __packed; 490a4690359STom Lendacky 4913dd2775bSTom Lendacky #define GHCB_SHARED_BUF_SIZE 2032 492d07f46f9STom Lendacky 4933dd2775bSTom Lendacky struct ghcb { 494a4690359STom Lendacky struct ghcb_save_area save; 495a4690359STom Lendacky u8 reserved_save[2048 - sizeof(struct ghcb_save_area)]; 4963dd2775bSTom Lendacky 4973dd2775bSTom Lendacky u8 shared_buffer[GHCB_SHARED_BUF_SIZE]; 498d07f46f9STom Lendacky 499d08b4858SCarlos Bilbao u8 reserved_0xff0[10]; 500d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ 501d07f46f9STom Lendacky u32 ghcb_usage; 502d07f46f9STom Lendacky } __packed; 503d07f46f9STom Lendacky 504d07f46f9STom Lendacky 5053dd2775bSTom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE 740 506a4690359STom Lendacky #define EXPECTED_GHCB_SAVE_AREA_SIZE 1032 5076d3b3d34STom Lendacky #define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1648 50859d21d67SVineeth Pillai #define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024 509d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE 5107923ef4fSPaolo Bonzini 511d08b4858SCarlos Bilbao #define BUILD_BUG_RESERVED_OFFSET(x, y) \ 512d08b4858SCarlos Bilbao ASSERT_STRUCT_OFFSET(struct x, reserved ## _ ## y, y) 513d08b4858SCarlos Bilbao 5147923ef4fSPaolo Bonzini static inline void __unused_size_checks(void) 5157923ef4fSPaolo Bonzini { 516d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); 517a4690359STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb_save_area) != EXPECTED_GHCB_SAVE_AREA_SIZE); 5183dd2775bSTom Lendacky BUILD_BUG_ON(sizeof(struct sev_es_save_area) != EXPECTED_SEV_ES_SAVE_AREA_SIZE); 519d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); 520d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); 521d08b4858SCarlos Bilbao 522d08b4858SCarlos Bilbao /* Check offsets of reserved fields */ 523d08b4858SCarlos Bilbao 524d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xa0); 525d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xcc); 526d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0xd8); 527d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x180); 528d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x248); 529d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(vmcb_save_area, 0x298); 530d08b4858SCarlos Bilbao 531d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xc8); 532d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xcc); 533d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xd8); 534d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0); 535d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248); 536d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298); 537d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2f0); 538d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320); 539d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380); 540d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x3f0); 541d08b4858SCarlos Bilbao 542d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x0); 543d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0xcc); 544d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x148); 545d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x168); 546d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x180); 547d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x1e0); 548d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x200); 549d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x320); 550d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x380); 551d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb_save_area, 0x3b0); 552d08b4858SCarlos Bilbao 553d08b4858SCarlos Bilbao BUILD_BUG_RESERVED_OFFSET(ghcb, 0xff0); 5547923ef4fSPaolo Bonzini } 5557923ef4fSPaolo Bonzini 556976bc5e2SBorislav Petkov struct vmcb { 557c2cedf7bSEduardo Habkost struct vmcb_control_area control; 558c2cedf7bSEduardo Habkost struct vmcb_save_area save; 559976bc5e2SBorislav Petkov } __packed; 560c2cedf7bSEduardo Habkost 561c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 562c2cedf7bSEduardo Habkost 563c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 564c2cedf7bSEduardo Habkost 565c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 566c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 567c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 568c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 569c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 570c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 571c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 572c2cedf7bSEduardo Habkost 573c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 574c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 575c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 576c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 577c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 578c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 579c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 580c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 581c2cedf7bSEduardo Habkost 582c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 583c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 584c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 585c2cedf7bSEduardo Habkost 586c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 587c2cedf7bSEduardo Habkost 588c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 589c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 590c2cedf7bSEduardo Habkost 591c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 592c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 593c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 594c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 595c2cedf7bSEduardo Habkost 596c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 597c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 598c2cedf7bSEduardo Habkost 599c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 60064a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 601c2cedf7bSEduardo Habkost 602c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 603c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 604c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 605c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 606c2cedf7bSEduardo Habkost 607c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 608c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 609c2cedf7bSEduardo Habkost 610c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 611c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 612e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 613c2cedf7bSEduardo Habkost 6147ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 6157ff76d58SAndre Przywara 616dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 617c2cedf7bSEduardo Habkost 6183702c2f4SJoerg Roedel /* GHCB Accessor functions */ 6193702c2f4SJoerg Roedel 6203702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \ 621a4690359STom Lendacky (offsetof(struct ghcb_save_area, field) / sizeof(u64)) 6223702c2f4SJoerg Roedel 6233702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \ 6246b91ec4aSBorislav Petkov static __always_inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ 6253702c2f4SJoerg Roedel { \ 6263702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \ 6273702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 6283702c2f4SJoerg Roedel } \ 6293702c2f4SJoerg Roedel \ 6306b91ec4aSBorislav Petkov static __always_inline u64 ghcb_get_##field(struct ghcb *ghcb) \ 6310f60bde1STom Lendacky { \ 6320f60bde1STom Lendacky return ghcb->save.field; \ 6330f60bde1STom Lendacky } \ 6340f60bde1STom Lendacky \ 6356b91ec4aSBorislav Petkov static __always_inline u64 ghcb_get_##field##_if_valid(struct ghcb *ghcb) \ 6360f60bde1STom Lendacky { \ 6370f60bde1STom Lendacky return ghcb_##field##_is_valid(ghcb) ? ghcb->save.field : 0; \ 6380f60bde1STom Lendacky } \ 6390f60bde1STom Lendacky \ 6406b91ec4aSBorislav Petkov static __always_inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ 6413702c2f4SJoerg Roedel { \ 6423702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \ 6433702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 6443702c2f4SJoerg Roedel ghcb->save.field = value; \ 6453702c2f4SJoerg Roedel } 6463702c2f4SJoerg Roedel 6473702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl) 6483702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip) 6493702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp) 6503702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax) 6513702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx) 6523702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx) 6533702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx) 6543702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp) 6553702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi) 6563702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi) 6573702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8) 6583702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9) 6593702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10) 6603702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11) 6613702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12) 6623702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13) 6633702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14) 6643702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15) 6653702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code) 6663702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1) 6673702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2) 6683702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch) 6693702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0) 6703702c2f4SJoerg Roedel 671c2cedf7bSEduardo Habkost #endif 672