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> 626bf264eSXiao Guangrong 7*c45ad722SBabu Moger /* 8*c45ad722SBabu Moger * 32-bit intercept words in the VMCB Control Area, starting 9*c45ad722SBabu Moger * at Byte offset 000h. 10*c45ad722SBabu Moger */ 11*c45ad722SBabu Moger 12*c45ad722SBabu Moger enum intercept_words { 13*c45ad722SBabu Moger MAX_INTERCEPT, 14*c45ad722SBabu Moger }; 1526bf264eSXiao Guangrong 16c2cedf7bSEduardo Habkost enum { 17c2cedf7bSEduardo Habkost INTERCEPT_INTR, 18c2cedf7bSEduardo Habkost INTERCEPT_NMI, 19c2cedf7bSEduardo Habkost INTERCEPT_SMI, 20c2cedf7bSEduardo Habkost INTERCEPT_INIT, 21c2cedf7bSEduardo Habkost INTERCEPT_VINTR, 22c2cedf7bSEduardo Habkost INTERCEPT_SELECTIVE_CR0, 23c2cedf7bSEduardo Habkost INTERCEPT_STORE_IDTR, 24c2cedf7bSEduardo Habkost INTERCEPT_STORE_GDTR, 25c2cedf7bSEduardo Habkost INTERCEPT_STORE_LDTR, 26c2cedf7bSEduardo Habkost INTERCEPT_STORE_TR, 27c2cedf7bSEduardo Habkost INTERCEPT_LOAD_IDTR, 28c2cedf7bSEduardo Habkost INTERCEPT_LOAD_GDTR, 29c2cedf7bSEduardo Habkost INTERCEPT_LOAD_LDTR, 30c2cedf7bSEduardo Habkost INTERCEPT_LOAD_TR, 31c2cedf7bSEduardo Habkost INTERCEPT_RDTSC, 32c2cedf7bSEduardo Habkost INTERCEPT_RDPMC, 33c2cedf7bSEduardo Habkost INTERCEPT_PUSHF, 34c2cedf7bSEduardo Habkost INTERCEPT_POPF, 35c2cedf7bSEduardo Habkost INTERCEPT_CPUID, 36c2cedf7bSEduardo Habkost INTERCEPT_RSM, 37c2cedf7bSEduardo Habkost INTERCEPT_IRET, 38c2cedf7bSEduardo Habkost INTERCEPT_INTn, 39c2cedf7bSEduardo Habkost INTERCEPT_INVD, 40c2cedf7bSEduardo Habkost INTERCEPT_PAUSE, 41c2cedf7bSEduardo Habkost INTERCEPT_HLT, 42c2cedf7bSEduardo Habkost INTERCEPT_INVLPG, 43c2cedf7bSEduardo Habkost INTERCEPT_INVLPGA, 44c2cedf7bSEduardo Habkost INTERCEPT_IOIO_PROT, 45c2cedf7bSEduardo Habkost INTERCEPT_MSR_PROT, 46c2cedf7bSEduardo Habkost INTERCEPT_TASK_SWITCH, 47c2cedf7bSEduardo Habkost INTERCEPT_FERR_FREEZE, 48c2cedf7bSEduardo Habkost INTERCEPT_SHUTDOWN, 49c2cedf7bSEduardo Habkost INTERCEPT_VMRUN, 50c2cedf7bSEduardo Habkost INTERCEPT_VMMCALL, 51c2cedf7bSEduardo Habkost INTERCEPT_VMLOAD, 52c2cedf7bSEduardo Habkost INTERCEPT_VMSAVE, 53c2cedf7bSEduardo Habkost INTERCEPT_STGI, 54c2cedf7bSEduardo Habkost INTERCEPT_CLGI, 55c2cedf7bSEduardo Habkost INTERCEPT_SKINIT, 56c2cedf7bSEduardo Habkost INTERCEPT_RDTSCP, 57c2cedf7bSEduardo Habkost INTERCEPT_ICEBP, 58c2cedf7bSEduardo Habkost INTERCEPT_WBINVD, 59c2cedf7bSEduardo Habkost INTERCEPT_MONITOR, 60c2cedf7bSEduardo Habkost INTERCEPT_MWAIT, 61c2cedf7bSEduardo Habkost INTERCEPT_MWAIT_COND, 6281dd35d4SJoerg Roedel INTERCEPT_XSETBV, 630cb8410bSJim Mattson INTERCEPT_RDPRU, 64c2cedf7bSEduardo Habkost }; 65c2cedf7bSEduardo Habkost 66c2cedf7bSEduardo Habkost 67c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area { 68*c45ad722SBabu Moger u32 intercepts[MAX_INTERCEPT]; 694ee546b4SRoedel, Joerg u32 intercept_cr; 703aed041aSJoerg Roedel u32 intercept_dr; 71c2cedf7bSEduardo Habkost u32 intercept_exceptions; 72c2cedf7bSEduardo Habkost u64 intercept; 731d8fb44aSBabu Moger u8 reserved_1[40]; 741d8fb44aSBabu Moger u16 pause_filter_thresh; 75565d0998SMark Langsdorf u16 pause_filter_count; 76c2cedf7bSEduardo Habkost u64 iopm_base_pa; 77c2cedf7bSEduardo Habkost u64 msrpm_base_pa; 78c2cedf7bSEduardo Habkost u64 tsc_offset; 79c2cedf7bSEduardo Habkost u32 asid; 80c2cedf7bSEduardo Habkost u8 tlb_ctl; 81c2cedf7bSEduardo Habkost u8 reserved_2[3]; 82c2cedf7bSEduardo Habkost u32 int_ctl; 83c2cedf7bSEduardo Habkost u32 int_vector; 84c2cedf7bSEduardo Habkost u32 int_state; 85c2cedf7bSEduardo Habkost u8 reserved_3[4]; 86c2cedf7bSEduardo Habkost u32 exit_code; 87c2cedf7bSEduardo Habkost u32 exit_code_hi; 88c2cedf7bSEduardo Habkost u64 exit_info_1; 89c2cedf7bSEduardo Habkost u64 exit_info_2; 90c2cedf7bSEduardo Habkost u32 exit_int_info; 91c2cedf7bSEduardo Habkost u32 exit_int_info_err; 92c2cedf7bSEduardo Habkost u64 nested_ctl; 933d5615e5SSuravee Suthikulpanit u64 avic_vapic_bar; 943d5615e5SSuravee Suthikulpanit u8 reserved_4[8]; 95c2cedf7bSEduardo Habkost u32 event_inj; 96c2cedf7bSEduardo Habkost u32 event_inj_err; 97c2cedf7bSEduardo Habkost u64 nested_cr3; 980dc92119SJanakarajan Natarajan u64 virt_ext; 998d28fec4SRoedel, Joerg u32 clean; 1008d28fec4SRoedel, Joerg u32 reserved_5; 1016bc31bdcSAndre Przywara u64 next_rip; 102dc25e89eSAndre Przywara u8 insn_len; 103dc25e89eSAndre Przywara u8 insn_bytes[15]; 1043d5615e5SSuravee Suthikulpanit u64 avic_backing_page; /* Offset 0xe0 */ 1053d5615e5SSuravee Suthikulpanit u8 reserved_6[8]; /* Offset 0xe8 */ 1063d5615e5SSuravee Suthikulpanit u64 avic_logical_id; /* Offset 0xf0 */ 1073d5615e5SSuravee Suthikulpanit u64 avic_physical_id; /* Offset 0xf8 */ 108c2cedf7bSEduardo Habkost }; 109c2cedf7bSEduardo Habkost 110c2cedf7bSEduardo Habkost 111c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0 112c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1 11338e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3 11438e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7 115c2cedf7bSEduardo Habkost 116c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f 117c2cedf7bSEduardo Habkost 118c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8 119c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT) 120c2cedf7bSEduardo Habkost 121640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9 122640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT) 123640bd6e5SJanakarajan Natarajan 124c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 125c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 126c2cedf7bSEduardo Habkost 127c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 128c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 129c2cedf7bSEduardo Habkost 130c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 131c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 132c2cedf7bSEduardo Habkost 133640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25 134640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT) 135640bd6e5SJanakarajan Natarajan 13644a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 13744a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 13844a95daeSSuravee Suthikulpanit 1398a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 14089c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1418a77e909SJanakarajan Natarajan 142c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 143c2cedf7bSEduardo Habkost 144c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 145c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 146c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 147c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 148c2cedf7bSEduardo Habkost 149c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 150c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 151c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 152c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 153c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 154c2cedf7bSEduardo Habkost 1554a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1564a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1574a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1584a810181SJoerg Roedel 159cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0) 160ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1) 161cea3a19bSTom Lendacky 162976bc5e2SBorislav Petkov struct vmcb_seg { 163c2cedf7bSEduardo Habkost u16 selector; 164c2cedf7bSEduardo Habkost u16 attrib; 165c2cedf7bSEduardo Habkost u32 limit; 166c2cedf7bSEduardo Habkost u64 base; 167976bc5e2SBorislav Petkov } __packed; 168c2cedf7bSEduardo Habkost 169976bc5e2SBorislav Petkov struct vmcb_save_area { 170c2cedf7bSEduardo Habkost struct vmcb_seg es; 171c2cedf7bSEduardo Habkost struct vmcb_seg cs; 172c2cedf7bSEduardo Habkost struct vmcb_seg ss; 173c2cedf7bSEduardo Habkost struct vmcb_seg ds; 174c2cedf7bSEduardo Habkost struct vmcb_seg fs; 175c2cedf7bSEduardo Habkost struct vmcb_seg gs; 176c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 177c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 178c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 179c2cedf7bSEduardo Habkost struct vmcb_seg tr; 180c2cedf7bSEduardo Habkost u8 reserved_1[43]; 181c2cedf7bSEduardo Habkost u8 cpl; 182c2cedf7bSEduardo Habkost u8 reserved_2[4]; 183c2cedf7bSEduardo Habkost u64 efer; 184c2cedf7bSEduardo Habkost u8 reserved_3[112]; 185c2cedf7bSEduardo Habkost u64 cr4; 186c2cedf7bSEduardo Habkost u64 cr3; 187c2cedf7bSEduardo Habkost u64 cr0; 188c2cedf7bSEduardo Habkost u64 dr7; 189c2cedf7bSEduardo Habkost u64 dr6; 190c2cedf7bSEduardo Habkost u64 rflags; 191c2cedf7bSEduardo Habkost u64 rip; 192c2cedf7bSEduardo Habkost u8 reserved_4[88]; 193c2cedf7bSEduardo Habkost u64 rsp; 194c2cedf7bSEduardo Habkost u8 reserved_5[24]; 195c2cedf7bSEduardo Habkost u64 rax; 196c2cedf7bSEduardo Habkost u64 star; 197c2cedf7bSEduardo Habkost u64 lstar; 198c2cedf7bSEduardo Habkost u64 cstar; 199c2cedf7bSEduardo Habkost u64 sfmask; 200c2cedf7bSEduardo Habkost u64 kernel_gs_base; 201c2cedf7bSEduardo Habkost u64 sysenter_cs; 202c2cedf7bSEduardo Habkost u64 sysenter_esp; 203c2cedf7bSEduardo Habkost u64 sysenter_eip; 204c2cedf7bSEduardo Habkost u64 cr2; 205c2cedf7bSEduardo Habkost u8 reserved_6[32]; 206c2cedf7bSEduardo Habkost u64 g_pat; 207c2cedf7bSEduardo Habkost u64 dbgctl; 208c2cedf7bSEduardo Habkost u64 br_from; 209c2cedf7bSEduardo Habkost u64 br_to; 210c2cedf7bSEduardo Habkost u64 last_excp_from; 211c2cedf7bSEduardo Habkost u64 last_excp_to; 212d07f46f9STom Lendacky 213d07f46f9STom Lendacky /* 214d07f46f9STom Lendacky * The following part of the save area is valid only for 215d07f46f9STom Lendacky * SEV-ES guests when referenced through the GHCB. 216d07f46f9STom Lendacky */ 217d07f46f9STom Lendacky u8 reserved_7[104]; 218d07f46f9STom Lendacky u64 reserved_8; /* rax already available at 0x01f8 */ 219d07f46f9STom Lendacky u64 rcx; 220d07f46f9STom Lendacky u64 rdx; 221d07f46f9STom Lendacky u64 rbx; 222d07f46f9STom Lendacky u64 reserved_9; /* rsp already available at 0x01d8 */ 223d07f46f9STom Lendacky u64 rbp; 224d07f46f9STom Lendacky u64 rsi; 225d07f46f9STom Lendacky u64 rdi; 226d07f46f9STom Lendacky u64 r8; 227d07f46f9STom Lendacky u64 r9; 228d07f46f9STom Lendacky u64 r10; 229d07f46f9STom Lendacky u64 r11; 230d07f46f9STom Lendacky u64 r12; 231d07f46f9STom Lendacky u64 r13; 232d07f46f9STom Lendacky u64 r14; 233d07f46f9STom Lendacky u64 r15; 234d07f46f9STom Lendacky u8 reserved_10[16]; 235d07f46f9STom Lendacky u64 sw_exit_code; 236d07f46f9STom Lendacky u64 sw_exit_info_1; 237d07f46f9STom Lendacky u64 sw_exit_info_2; 238d07f46f9STom Lendacky u64 sw_scratch; 239d07f46f9STom Lendacky u8 reserved_11[56]; 240d07f46f9STom Lendacky u64 xcr0; 241d07f46f9STom Lendacky u8 valid_bitmap[16]; 242d07f46f9STom Lendacky u64 x87_state_gpa; 243976bc5e2SBorislav Petkov } __packed; 244c2cedf7bSEduardo Habkost 245d07f46f9STom Lendacky struct ghcb { 246d07f46f9STom Lendacky struct vmcb_save_area save; 247d07f46f9STom Lendacky u8 reserved_save[2048 - sizeof(struct vmcb_save_area)]; 248d07f46f9STom Lendacky 249d07f46f9STom Lendacky u8 shared_buffer[2032]; 250d07f46f9STom Lendacky 251d07f46f9STom Lendacky u8 reserved_1[10]; 252d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ 253d07f46f9STom Lendacky u32 ghcb_usage; 254d07f46f9STom Lendacky } __packed; 255d07f46f9STom Lendacky 256d07f46f9STom Lendacky 257d07f46f9STom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE 1032 258d07f46f9STom Lendacky #define EXPECTED_VMCB_CONTROL_AREA_SIZE 256 259d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE 2607923ef4fSPaolo Bonzini 2617923ef4fSPaolo Bonzini static inline void __unused_size_checks(void) 2627923ef4fSPaolo Bonzini { 263d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); 264d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); 265d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); 2667923ef4fSPaolo Bonzini } 2677923ef4fSPaolo Bonzini 268976bc5e2SBorislav Petkov struct vmcb { 269c2cedf7bSEduardo Habkost struct vmcb_control_area control; 2707923ef4fSPaolo Bonzini u8 reserved_control[1024 - sizeof(struct vmcb_control_area)]; 271c2cedf7bSEduardo Habkost struct vmcb_save_area save; 272976bc5e2SBorislav Petkov } __packed; 273c2cedf7bSEduardo Habkost 274c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 275c2cedf7bSEduardo Habkost 276c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 277c2cedf7bSEduardo Habkost 278c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 279c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 280c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 281c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 282c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 283c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 284c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 285c2cedf7bSEduardo Habkost 286c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 287c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 288c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 289c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 290c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 291c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 292c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 293c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 294c2cedf7bSEduardo Habkost 295c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 296c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 297c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 298c2cedf7bSEduardo Habkost 2994ee546b4SRoedel, Joerg #define INTERCEPT_CR0_READ 0 3004ee546b4SRoedel, Joerg #define INTERCEPT_CR3_READ 3 3014ee546b4SRoedel, Joerg #define INTERCEPT_CR4_READ 4 3024ee546b4SRoedel, Joerg #define INTERCEPT_CR8_READ 8 3034ee546b4SRoedel, Joerg #define INTERCEPT_CR0_WRITE (16 + 0) 3044ee546b4SRoedel, Joerg #define INTERCEPT_CR3_WRITE (16 + 3) 3054ee546b4SRoedel, Joerg #define INTERCEPT_CR4_WRITE (16 + 4) 3064ee546b4SRoedel, Joerg #define INTERCEPT_CR8_WRITE (16 + 8) 307c2cedf7bSEduardo Habkost 3083aed041aSJoerg Roedel #define INTERCEPT_DR0_READ 0 3093aed041aSJoerg Roedel #define INTERCEPT_DR1_READ 1 3103aed041aSJoerg Roedel #define INTERCEPT_DR2_READ 2 3113aed041aSJoerg Roedel #define INTERCEPT_DR3_READ 3 3123aed041aSJoerg Roedel #define INTERCEPT_DR4_READ 4 3133aed041aSJoerg Roedel #define INTERCEPT_DR5_READ 5 3143aed041aSJoerg Roedel #define INTERCEPT_DR6_READ 6 3153aed041aSJoerg Roedel #define INTERCEPT_DR7_READ 7 3163aed041aSJoerg Roedel #define INTERCEPT_DR0_WRITE (16 + 0) 3173aed041aSJoerg Roedel #define INTERCEPT_DR1_WRITE (16 + 1) 3183aed041aSJoerg Roedel #define INTERCEPT_DR2_WRITE (16 + 2) 3193aed041aSJoerg Roedel #define INTERCEPT_DR3_WRITE (16 + 3) 3203aed041aSJoerg Roedel #define INTERCEPT_DR4_WRITE (16 + 4) 3213aed041aSJoerg Roedel #define INTERCEPT_DR5_WRITE (16 + 5) 3223aed041aSJoerg Roedel #define INTERCEPT_DR6_WRITE (16 + 6) 3233aed041aSJoerg Roedel #define INTERCEPT_DR7_WRITE (16 + 7) 324c2cedf7bSEduardo Habkost 325c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 326c2cedf7bSEduardo Habkost 327c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 328c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 329c2cedf7bSEduardo Habkost 330c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 331c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 332c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 333c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 334c2cedf7bSEduardo Habkost 335c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 336c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 337c2cedf7bSEduardo Habkost 338c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 33964a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 340c2cedf7bSEduardo Habkost 341c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 342c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 343c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 344c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 345c2cedf7bSEduardo Habkost 346c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 347c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 348c2cedf7bSEduardo Habkost 349c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 350c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 351e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 352c2cedf7bSEduardo Habkost 3537ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 3547ff76d58SAndre Przywara 355dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 356c2cedf7bSEduardo Habkost 3573702c2f4SJoerg Roedel /* GHCB Accessor functions */ 3583702c2f4SJoerg Roedel 3593702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \ 3603702c2f4SJoerg Roedel (offsetof(struct vmcb_save_area, field) / sizeof(u64)) 3613702c2f4SJoerg Roedel 3623702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \ 3633702c2f4SJoerg Roedel static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ 3643702c2f4SJoerg Roedel { \ 3653702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \ 3663702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3673702c2f4SJoerg Roedel } \ 3683702c2f4SJoerg Roedel \ 3693702c2f4SJoerg Roedel static inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ 3703702c2f4SJoerg Roedel { \ 3713702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \ 3723702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3733702c2f4SJoerg Roedel ghcb->save.field = value; \ 3743702c2f4SJoerg Roedel } 3753702c2f4SJoerg Roedel 3763702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl) 3773702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip) 3783702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp) 3793702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax) 3803702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx) 3813702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx) 3823702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx) 3833702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp) 3843702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi) 3853702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi) 3863702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8) 3873702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9) 3883702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10) 3893702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11) 3903702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12) 3913702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13) 3923702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14) 3933702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15) 3943702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code) 3953702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1) 3963702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2) 3973702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch) 3983702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0) 3993702c2f4SJoerg Roedel 400c2cedf7bSEduardo Habkost #endif 401