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 726bf264eSXiao Guangrong 8c2cedf7bSEduardo Habkost enum { 9c2cedf7bSEduardo Habkost INTERCEPT_INTR, 10c2cedf7bSEduardo Habkost INTERCEPT_NMI, 11c2cedf7bSEduardo Habkost INTERCEPT_SMI, 12c2cedf7bSEduardo Habkost INTERCEPT_INIT, 13c2cedf7bSEduardo Habkost INTERCEPT_VINTR, 14c2cedf7bSEduardo Habkost INTERCEPT_SELECTIVE_CR0, 15c2cedf7bSEduardo Habkost INTERCEPT_STORE_IDTR, 16c2cedf7bSEduardo Habkost INTERCEPT_STORE_GDTR, 17c2cedf7bSEduardo Habkost INTERCEPT_STORE_LDTR, 18c2cedf7bSEduardo Habkost INTERCEPT_STORE_TR, 19c2cedf7bSEduardo Habkost INTERCEPT_LOAD_IDTR, 20c2cedf7bSEduardo Habkost INTERCEPT_LOAD_GDTR, 21c2cedf7bSEduardo Habkost INTERCEPT_LOAD_LDTR, 22c2cedf7bSEduardo Habkost INTERCEPT_LOAD_TR, 23c2cedf7bSEduardo Habkost INTERCEPT_RDTSC, 24c2cedf7bSEduardo Habkost INTERCEPT_RDPMC, 25c2cedf7bSEduardo Habkost INTERCEPT_PUSHF, 26c2cedf7bSEduardo Habkost INTERCEPT_POPF, 27c2cedf7bSEduardo Habkost INTERCEPT_CPUID, 28c2cedf7bSEduardo Habkost INTERCEPT_RSM, 29c2cedf7bSEduardo Habkost INTERCEPT_IRET, 30c2cedf7bSEduardo Habkost INTERCEPT_INTn, 31c2cedf7bSEduardo Habkost INTERCEPT_INVD, 32c2cedf7bSEduardo Habkost INTERCEPT_PAUSE, 33c2cedf7bSEduardo Habkost INTERCEPT_HLT, 34c2cedf7bSEduardo Habkost INTERCEPT_INVLPG, 35c2cedf7bSEduardo Habkost INTERCEPT_INVLPGA, 36c2cedf7bSEduardo Habkost INTERCEPT_IOIO_PROT, 37c2cedf7bSEduardo Habkost INTERCEPT_MSR_PROT, 38c2cedf7bSEduardo Habkost INTERCEPT_TASK_SWITCH, 39c2cedf7bSEduardo Habkost INTERCEPT_FERR_FREEZE, 40c2cedf7bSEduardo Habkost INTERCEPT_SHUTDOWN, 41c2cedf7bSEduardo Habkost INTERCEPT_VMRUN, 42c2cedf7bSEduardo Habkost INTERCEPT_VMMCALL, 43c2cedf7bSEduardo Habkost INTERCEPT_VMLOAD, 44c2cedf7bSEduardo Habkost INTERCEPT_VMSAVE, 45c2cedf7bSEduardo Habkost INTERCEPT_STGI, 46c2cedf7bSEduardo Habkost INTERCEPT_CLGI, 47c2cedf7bSEduardo Habkost INTERCEPT_SKINIT, 48c2cedf7bSEduardo Habkost INTERCEPT_RDTSCP, 49c2cedf7bSEduardo Habkost INTERCEPT_ICEBP, 50c2cedf7bSEduardo Habkost INTERCEPT_WBINVD, 51c2cedf7bSEduardo Habkost INTERCEPT_MONITOR, 52c2cedf7bSEduardo Habkost INTERCEPT_MWAIT, 53c2cedf7bSEduardo Habkost INTERCEPT_MWAIT_COND, 5481dd35d4SJoerg Roedel INTERCEPT_XSETBV, 550cb8410bSJim Mattson INTERCEPT_RDPRU, 56c2cedf7bSEduardo Habkost }; 57c2cedf7bSEduardo Habkost 58c2cedf7bSEduardo Habkost 59c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area { 604ee546b4SRoedel, Joerg u32 intercept_cr; 613aed041aSJoerg Roedel u32 intercept_dr; 62c2cedf7bSEduardo Habkost u32 intercept_exceptions; 63c2cedf7bSEduardo Habkost u64 intercept; 641d8fb44aSBabu Moger u8 reserved_1[40]; 651d8fb44aSBabu Moger u16 pause_filter_thresh; 66565d0998SMark Langsdorf u16 pause_filter_count; 67c2cedf7bSEduardo Habkost u64 iopm_base_pa; 68c2cedf7bSEduardo Habkost u64 msrpm_base_pa; 69c2cedf7bSEduardo Habkost u64 tsc_offset; 70c2cedf7bSEduardo Habkost u32 asid; 71c2cedf7bSEduardo Habkost u8 tlb_ctl; 72c2cedf7bSEduardo Habkost u8 reserved_2[3]; 73c2cedf7bSEduardo Habkost u32 int_ctl; 74c2cedf7bSEduardo Habkost u32 int_vector; 75c2cedf7bSEduardo Habkost u32 int_state; 76c2cedf7bSEduardo Habkost u8 reserved_3[4]; 77c2cedf7bSEduardo Habkost u32 exit_code; 78c2cedf7bSEduardo Habkost u32 exit_code_hi; 79c2cedf7bSEduardo Habkost u64 exit_info_1; 80c2cedf7bSEduardo Habkost u64 exit_info_2; 81c2cedf7bSEduardo Habkost u32 exit_int_info; 82c2cedf7bSEduardo Habkost u32 exit_int_info_err; 83c2cedf7bSEduardo Habkost u64 nested_ctl; 843d5615e5SSuravee Suthikulpanit u64 avic_vapic_bar; 853d5615e5SSuravee Suthikulpanit u8 reserved_4[8]; 86c2cedf7bSEduardo Habkost u32 event_inj; 87c2cedf7bSEduardo Habkost u32 event_inj_err; 88c2cedf7bSEduardo Habkost u64 nested_cr3; 890dc92119SJanakarajan Natarajan u64 virt_ext; 908d28fec4SRoedel, Joerg u32 clean; 918d28fec4SRoedel, Joerg u32 reserved_5; 926bc31bdcSAndre Przywara u64 next_rip; 93dc25e89eSAndre Przywara u8 insn_len; 94dc25e89eSAndre Przywara u8 insn_bytes[15]; 953d5615e5SSuravee Suthikulpanit u64 avic_backing_page; /* Offset 0xe0 */ 963d5615e5SSuravee Suthikulpanit u8 reserved_6[8]; /* Offset 0xe8 */ 973d5615e5SSuravee Suthikulpanit u64 avic_logical_id; /* Offset 0xf0 */ 983d5615e5SSuravee Suthikulpanit u64 avic_physical_id; /* Offset 0xf8 */ 99c2cedf7bSEduardo Habkost }; 100c2cedf7bSEduardo Habkost 101c2cedf7bSEduardo Habkost 102c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0 103c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1 10438e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3 10538e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7 106c2cedf7bSEduardo Habkost 107c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f 108c2cedf7bSEduardo Habkost 109c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8 110c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT) 111c2cedf7bSEduardo Habkost 112640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9 113640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT) 114640bd6e5SJanakarajan Natarajan 115c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 116c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 117c2cedf7bSEduardo Habkost 118c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 119c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 120c2cedf7bSEduardo Habkost 121c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 122c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 123c2cedf7bSEduardo Habkost 124640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25 125640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT) 126640bd6e5SJanakarajan Natarajan 12744a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 12844a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 12944a95daeSSuravee Suthikulpanit 1308a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 13189c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1328a77e909SJanakarajan Natarajan 133c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 134c2cedf7bSEduardo Habkost 135c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 136c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 137c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 138c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 139c2cedf7bSEduardo Habkost 140c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 141c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 142c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 143c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 144c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 145c2cedf7bSEduardo Habkost 1464a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1474a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1484a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1494a810181SJoerg Roedel 150cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0) 151ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1) 152cea3a19bSTom Lendacky 153*976bc5e2SBorislav Petkov struct vmcb_seg { 154c2cedf7bSEduardo Habkost u16 selector; 155c2cedf7bSEduardo Habkost u16 attrib; 156c2cedf7bSEduardo Habkost u32 limit; 157c2cedf7bSEduardo Habkost u64 base; 158*976bc5e2SBorislav Petkov } __packed; 159c2cedf7bSEduardo Habkost 160*976bc5e2SBorislav Petkov struct vmcb_save_area { 161c2cedf7bSEduardo Habkost struct vmcb_seg es; 162c2cedf7bSEduardo Habkost struct vmcb_seg cs; 163c2cedf7bSEduardo Habkost struct vmcb_seg ss; 164c2cedf7bSEduardo Habkost struct vmcb_seg ds; 165c2cedf7bSEduardo Habkost struct vmcb_seg fs; 166c2cedf7bSEduardo Habkost struct vmcb_seg gs; 167c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 168c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 169c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 170c2cedf7bSEduardo Habkost struct vmcb_seg tr; 171c2cedf7bSEduardo Habkost u8 reserved_1[43]; 172c2cedf7bSEduardo Habkost u8 cpl; 173c2cedf7bSEduardo Habkost u8 reserved_2[4]; 174c2cedf7bSEduardo Habkost u64 efer; 175c2cedf7bSEduardo Habkost u8 reserved_3[112]; 176c2cedf7bSEduardo Habkost u64 cr4; 177c2cedf7bSEduardo Habkost u64 cr3; 178c2cedf7bSEduardo Habkost u64 cr0; 179c2cedf7bSEduardo Habkost u64 dr7; 180c2cedf7bSEduardo Habkost u64 dr6; 181c2cedf7bSEduardo Habkost u64 rflags; 182c2cedf7bSEduardo Habkost u64 rip; 183c2cedf7bSEduardo Habkost u8 reserved_4[88]; 184c2cedf7bSEduardo Habkost u64 rsp; 185c2cedf7bSEduardo Habkost u8 reserved_5[24]; 186c2cedf7bSEduardo Habkost u64 rax; 187c2cedf7bSEduardo Habkost u64 star; 188c2cedf7bSEduardo Habkost u64 lstar; 189c2cedf7bSEduardo Habkost u64 cstar; 190c2cedf7bSEduardo Habkost u64 sfmask; 191c2cedf7bSEduardo Habkost u64 kernel_gs_base; 192c2cedf7bSEduardo Habkost u64 sysenter_cs; 193c2cedf7bSEduardo Habkost u64 sysenter_esp; 194c2cedf7bSEduardo Habkost u64 sysenter_eip; 195c2cedf7bSEduardo Habkost u64 cr2; 196c2cedf7bSEduardo Habkost u8 reserved_6[32]; 197c2cedf7bSEduardo Habkost u64 g_pat; 198c2cedf7bSEduardo Habkost u64 dbgctl; 199c2cedf7bSEduardo Habkost u64 br_from; 200c2cedf7bSEduardo Habkost u64 br_to; 201c2cedf7bSEduardo Habkost u64 last_excp_from; 202c2cedf7bSEduardo Habkost u64 last_excp_to; 203d07f46f9STom Lendacky 204d07f46f9STom Lendacky /* 205d07f46f9STom Lendacky * The following part of the save area is valid only for 206d07f46f9STom Lendacky * SEV-ES guests when referenced through the GHCB. 207d07f46f9STom Lendacky */ 208d07f46f9STom Lendacky u8 reserved_7[104]; 209d07f46f9STom Lendacky u64 reserved_8; /* rax already available at 0x01f8 */ 210d07f46f9STom Lendacky u64 rcx; 211d07f46f9STom Lendacky u64 rdx; 212d07f46f9STom Lendacky u64 rbx; 213d07f46f9STom Lendacky u64 reserved_9; /* rsp already available at 0x01d8 */ 214d07f46f9STom Lendacky u64 rbp; 215d07f46f9STom Lendacky u64 rsi; 216d07f46f9STom Lendacky u64 rdi; 217d07f46f9STom Lendacky u64 r8; 218d07f46f9STom Lendacky u64 r9; 219d07f46f9STom Lendacky u64 r10; 220d07f46f9STom Lendacky u64 r11; 221d07f46f9STom Lendacky u64 r12; 222d07f46f9STom Lendacky u64 r13; 223d07f46f9STom Lendacky u64 r14; 224d07f46f9STom Lendacky u64 r15; 225d07f46f9STom Lendacky u8 reserved_10[16]; 226d07f46f9STom Lendacky u64 sw_exit_code; 227d07f46f9STom Lendacky u64 sw_exit_info_1; 228d07f46f9STom Lendacky u64 sw_exit_info_2; 229d07f46f9STom Lendacky u64 sw_scratch; 230d07f46f9STom Lendacky u8 reserved_11[56]; 231d07f46f9STom Lendacky u64 xcr0; 232d07f46f9STom Lendacky u8 valid_bitmap[16]; 233d07f46f9STom Lendacky u64 x87_state_gpa; 234*976bc5e2SBorislav Petkov } __packed; 235c2cedf7bSEduardo Habkost 236d07f46f9STom Lendacky struct ghcb { 237d07f46f9STom Lendacky struct vmcb_save_area save; 238d07f46f9STom Lendacky u8 reserved_save[2048 - sizeof(struct vmcb_save_area)]; 239d07f46f9STom Lendacky 240d07f46f9STom Lendacky u8 shared_buffer[2032]; 241d07f46f9STom Lendacky 242d07f46f9STom Lendacky u8 reserved_1[10]; 243d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ 244d07f46f9STom Lendacky u32 ghcb_usage; 245d07f46f9STom Lendacky } __packed; 246d07f46f9STom Lendacky 247d07f46f9STom Lendacky 248d07f46f9STom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE 1032 249d07f46f9STom Lendacky #define EXPECTED_VMCB_CONTROL_AREA_SIZE 256 250d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE 2517923ef4fSPaolo Bonzini 2527923ef4fSPaolo Bonzini static inline void __unused_size_checks(void) 2537923ef4fSPaolo Bonzini { 254d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); 255d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); 256d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); 2577923ef4fSPaolo Bonzini } 2587923ef4fSPaolo Bonzini 259*976bc5e2SBorislav Petkov struct vmcb { 260c2cedf7bSEduardo Habkost struct vmcb_control_area control; 2617923ef4fSPaolo Bonzini u8 reserved_control[1024 - sizeof(struct vmcb_control_area)]; 262c2cedf7bSEduardo Habkost struct vmcb_save_area save; 263*976bc5e2SBorislav Petkov } __packed; 264c2cedf7bSEduardo Habkost 265c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 266c2cedf7bSEduardo Habkost 267c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 268c2cedf7bSEduardo Habkost 269c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 270c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 271c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 272c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 273c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 274c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 275c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 276c2cedf7bSEduardo Habkost 277c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 278c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 279c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 280c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 281c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 282c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 283c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 284c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 285c2cedf7bSEduardo Habkost 286c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 287c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 288c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 289c2cedf7bSEduardo Habkost 2904ee546b4SRoedel, Joerg #define INTERCEPT_CR0_READ 0 2914ee546b4SRoedel, Joerg #define INTERCEPT_CR3_READ 3 2924ee546b4SRoedel, Joerg #define INTERCEPT_CR4_READ 4 2934ee546b4SRoedel, Joerg #define INTERCEPT_CR8_READ 8 2944ee546b4SRoedel, Joerg #define INTERCEPT_CR0_WRITE (16 + 0) 2954ee546b4SRoedel, Joerg #define INTERCEPT_CR3_WRITE (16 + 3) 2964ee546b4SRoedel, Joerg #define INTERCEPT_CR4_WRITE (16 + 4) 2974ee546b4SRoedel, Joerg #define INTERCEPT_CR8_WRITE (16 + 8) 298c2cedf7bSEduardo Habkost 2993aed041aSJoerg Roedel #define INTERCEPT_DR0_READ 0 3003aed041aSJoerg Roedel #define INTERCEPT_DR1_READ 1 3013aed041aSJoerg Roedel #define INTERCEPT_DR2_READ 2 3023aed041aSJoerg Roedel #define INTERCEPT_DR3_READ 3 3033aed041aSJoerg Roedel #define INTERCEPT_DR4_READ 4 3043aed041aSJoerg Roedel #define INTERCEPT_DR5_READ 5 3053aed041aSJoerg Roedel #define INTERCEPT_DR6_READ 6 3063aed041aSJoerg Roedel #define INTERCEPT_DR7_READ 7 3073aed041aSJoerg Roedel #define INTERCEPT_DR0_WRITE (16 + 0) 3083aed041aSJoerg Roedel #define INTERCEPT_DR1_WRITE (16 + 1) 3093aed041aSJoerg Roedel #define INTERCEPT_DR2_WRITE (16 + 2) 3103aed041aSJoerg Roedel #define INTERCEPT_DR3_WRITE (16 + 3) 3113aed041aSJoerg Roedel #define INTERCEPT_DR4_WRITE (16 + 4) 3123aed041aSJoerg Roedel #define INTERCEPT_DR5_WRITE (16 + 5) 3133aed041aSJoerg Roedel #define INTERCEPT_DR6_WRITE (16 + 6) 3143aed041aSJoerg Roedel #define INTERCEPT_DR7_WRITE (16 + 7) 315c2cedf7bSEduardo Habkost 316c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 317c2cedf7bSEduardo Habkost 318c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 319c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 320c2cedf7bSEduardo Habkost 321c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 322c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 323c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 324c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 325c2cedf7bSEduardo Habkost 326c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 327c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 328c2cedf7bSEduardo Habkost 329c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 33064a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 331c2cedf7bSEduardo Habkost 332c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 333c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 334c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 335c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 336c2cedf7bSEduardo Habkost 337c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 338c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 339c2cedf7bSEduardo Habkost 340c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 341c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 342e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 343c2cedf7bSEduardo Habkost 3447ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 3457ff76d58SAndre Przywara 346dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 347c2cedf7bSEduardo Habkost 3483702c2f4SJoerg Roedel /* GHCB Accessor functions */ 3493702c2f4SJoerg Roedel 3503702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \ 3513702c2f4SJoerg Roedel (offsetof(struct vmcb_save_area, field) / sizeof(u64)) 3523702c2f4SJoerg Roedel 3533702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \ 3543702c2f4SJoerg Roedel static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ 3553702c2f4SJoerg Roedel { \ 3563702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \ 3573702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3583702c2f4SJoerg Roedel } \ 3593702c2f4SJoerg Roedel \ 3603702c2f4SJoerg Roedel static inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ 3613702c2f4SJoerg Roedel { \ 3623702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \ 3633702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3643702c2f4SJoerg Roedel ghcb->save.field = value; \ 3653702c2f4SJoerg Roedel } 3663702c2f4SJoerg Roedel 3673702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl) 3683702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip) 3693702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp) 3703702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax) 3713702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx) 3723702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx) 3733702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx) 3743702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp) 3753702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi) 3763702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi) 3773702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8) 3783702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9) 3793702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10) 3803702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11) 3813702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12) 3823702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13) 3833702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14) 3843702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15) 3853702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code) 3863702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1) 3873702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2) 3883702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch) 3893702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0) 3903702c2f4SJoerg Roedel 391c2cedf7bSEduardo Habkost #endif 392