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 7c45ad722SBabu Moger /* 8c45ad722SBabu Moger * 32-bit intercept words in the VMCB Control Area, starting 9c45ad722SBabu Moger * at Byte offset 000h. 10c45ad722SBabu Moger */ 11c45ad722SBabu Moger 12c45ad722SBabu Moger enum intercept_words { 1303bfeeb9SBabu Moger INTERCEPT_CR = 0, 14*30abaa88SBabu Moger INTERCEPT_DR, 15c45ad722SBabu Moger MAX_INTERCEPT, 16c45ad722SBabu Moger }; 1726bf264eSXiao Guangrong 18c2cedf7bSEduardo Habkost enum { 1903bfeeb9SBabu Moger /* Byte offset 000h (word 0) */ 2003bfeeb9SBabu Moger INTERCEPT_CR0_READ = 0, 2103bfeeb9SBabu Moger INTERCEPT_CR3_READ = 3, 2203bfeeb9SBabu Moger INTERCEPT_CR4_READ = 4, 2303bfeeb9SBabu Moger INTERCEPT_CR8_READ = 8, 2403bfeeb9SBabu Moger INTERCEPT_CR0_WRITE = 16, 2503bfeeb9SBabu Moger INTERCEPT_CR3_WRITE = 16 + 3, 2603bfeeb9SBabu Moger INTERCEPT_CR4_WRITE = 16 + 4, 2703bfeeb9SBabu Moger INTERCEPT_CR8_WRITE = 16 + 8, 28*30abaa88SBabu Moger /* Byte offset 004h (word 1) */ 29*30abaa88SBabu Moger INTERCEPT_DR0_READ = 32, 30*30abaa88SBabu Moger INTERCEPT_DR1_READ, 31*30abaa88SBabu Moger INTERCEPT_DR2_READ, 32*30abaa88SBabu Moger INTERCEPT_DR3_READ, 33*30abaa88SBabu Moger INTERCEPT_DR4_READ, 34*30abaa88SBabu Moger INTERCEPT_DR5_READ, 35*30abaa88SBabu Moger INTERCEPT_DR6_READ, 36*30abaa88SBabu Moger INTERCEPT_DR7_READ, 37*30abaa88SBabu Moger INTERCEPT_DR0_WRITE = 48, 38*30abaa88SBabu Moger INTERCEPT_DR1_WRITE, 39*30abaa88SBabu Moger INTERCEPT_DR2_WRITE, 40*30abaa88SBabu Moger INTERCEPT_DR3_WRITE, 41*30abaa88SBabu Moger INTERCEPT_DR4_WRITE, 42*30abaa88SBabu Moger INTERCEPT_DR5_WRITE, 43*30abaa88SBabu Moger INTERCEPT_DR6_WRITE, 44*30abaa88SBabu Moger INTERCEPT_DR7_WRITE, 4503bfeeb9SBabu Moger }; 4603bfeeb9SBabu Moger 4703bfeeb9SBabu Moger enum { 48c2cedf7bSEduardo Habkost INTERCEPT_INTR, 49c2cedf7bSEduardo Habkost INTERCEPT_NMI, 50c2cedf7bSEduardo Habkost INTERCEPT_SMI, 51c2cedf7bSEduardo Habkost INTERCEPT_INIT, 52c2cedf7bSEduardo Habkost INTERCEPT_VINTR, 53c2cedf7bSEduardo Habkost INTERCEPT_SELECTIVE_CR0, 54c2cedf7bSEduardo Habkost INTERCEPT_STORE_IDTR, 55c2cedf7bSEduardo Habkost INTERCEPT_STORE_GDTR, 56c2cedf7bSEduardo Habkost INTERCEPT_STORE_LDTR, 57c2cedf7bSEduardo Habkost INTERCEPT_STORE_TR, 58c2cedf7bSEduardo Habkost INTERCEPT_LOAD_IDTR, 59c2cedf7bSEduardo Habkost INTERCEPT_LOAD_GDTR, 60c2cedf7bSEduardo Habkost INTERCEPT_LOAD_LDTR, 61c2cedf7bSEduardo Habkost INTERCEPT_LOAD_TR, 62c2cedf7bSEduardo Habkost INTERCEPT_RDTSC, 63c2cedf7bSEduardo Habkost INTERCEPT_RDPMC, 64c2cedf7bSEduardo Habkost INTERCEPT_PUSHF, 65c2cedf7bSEduardo Habkost INTERCEPT_POPF, 66c2cedf7bSEduardo Habkost INTERCEPT_CPUID, 67c2cedf7bSEduardo Habkost INTERCEPT_RSM, 68c2cedf7bSEduardo Habkost INTERCEPT_IRET, 69c2cedf7bSEduardo Habkost INTERCEPT_INTn, 70c2cedf7bSEduardo Habkost INTERCEPT_INVD, 71c2cedf7bSEduardo Habkost INTERCEPT_PAUSE, 72c2cedf7bSEduardo Habkost INTERCEPT_HLT, 73c2cedf7bSEduardo Habkost INTERCEPT_INVLPG, 74c2cedf7bSEduardo Habkost INTERCEPT_INVLPGA, 75c2cedf7bSEduardo Habkost INTERCEPT_IOIO_PROT, 76c2cedf7bSEduardo Habkost INTERCEPT_MSR_PROT, 77c2cedf7bSEduardo Habkost INTERCEPT_TASK_SWITCH, 78c2cedf7bSEduardo Habkost INTERCEPT_FERR_FREEZE, 79c2cedf7bSEduardo Habkost INTERCEPT_SHUTDOWN, 80c2cedf7bSEduardo Habkost INTERCEPT_VMRUN, 81c2cedf7bSEduardo Habkost INTERCEPT_VMMCALL, 82c2cedf7bSEduardo Habkost INTERCEPT_VMLOAD, 83c2cedf7bSEduardo Habkost INTERCEPT_VMSAVE, 84c2cedf7bSEduardo Habkost INTERCEPT_STGI, 85c2cedf7bSEduardo Habkost INTERCEPT_CLGI, 86c2cedf7bSEduardo Habkost INTERCEPT_SKINIT, 87c2cedf7bSEduardo Habkost INTERCEPT_RDTSCP, 88c2cedf7bSEduardo Habkost INTERCEPT_ICEBP, 89c2cedf7bSEduardo Habkost INTERCEPT_WBINVD, 90c2cedf7bSEduardo Habkost INTERCEPT_MONITOR, 91c2cedf7bSEduardo Habkost INTERCEPT_MWAIT, 92c2cedf7bSEduardo Habkost INTERCEPT_MWAIT_COND, 9381dd35d4SJoerg Roedel INTERCEPT_XSETBV, 940cb8410bSJim Mattson INTERCEPT_RDPRU, 95c2cedf7bSEduardo Habkost }; 96c2cedf7bSEduardo Habkost 97c2cedf7bSEduardo Habkost 98c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area { 99c45ad722SBabu Moger u32 intercepts[MAX_INTERCEPT]; 100c2cedf7bSEduardo Habkost u32 intercept_exceptions; 101c2cedf7bSEduardo Habkost u64 intercept; 1021d8fb44aSBabu Moger u8 reserved_1[40]; 1031d8fb44aSBabu Moger u16 pause_filter_thresh; 104565d0998SMark Langsdorf u16 pause_filter_count; 105c2cedf7bSEduardo Habkost u64 iopm_base_pa; 106c2cedf7bSEduardo Habkost u64 msrpm_base_pa; 107c2cedf7bSEduardo Habkost u64 tsc_offset; 108c2cedf7bSEduardo Habkost u32 asid; 109c2cedf7bSEduardo Habkost u8 tlb_ctl; 110c2cedf7bSEduardo Habkost u8 reserved_2[3]; 111c2cedf7bSEduardo Habkost u32 int_ctl; 112c2cedf7bSEduardo Habkost u32 int_vector; 113c2cedf7bSEduardo Habkost u32 int_state; 114c2cedf7bSEduardo Habkost u8 reserved_3[4]; 115c2cedf7bSEduardo Habkost u32 exit_code; 116c2cedf7bSEduardo Habkost u32 exit_code_hi; 117c2cedf7bSEduardo Habkost u64 exit_info_1; 118c2cedf7bSEduardo Habkost u64 exit_info_2; 119c2cedf7bSEduardo Habkost u32 exit_int_info; 120c2cedf7bSEduardo Habkost u32 exit_int_info_err; 121c2cedf7bSEduardo Habkost u64 nested_ctl; 1223d5615e5SSuravee Suthikulpanit u64 avic_vapic_bar; 1233d5615e5SSuravee Suthikulpanit u8 reserved_4[8]; 124c2cedf7bSEduardo Habkost u32 event_inj; 125c2cedf7bSEduardo Habkost u32 event_inj_err; 126c2cedf7bSEduardo Habkost u64 nested_cr3; 1270dc92119SJanakarajan Natarajan u64 virt_ext; 1288d28fec4SRoedel, Joerg u32 clean; 1298d28fec4SRoedel, Joerg u32 reserved_5; 1306bc31bdcSAndre Przywara u64 next_rip; 131dc25e89eSAndre Przywara u8 insn_len; 132dc25e89eSAndre Przywara u8 insn_bytes[15]; 1333d5615e5SSuravee Suthikulpanit u64 avic_backing_page; /* Offset 0xe0 */ 1343d5615e5SSuravee Suthikulpanit u8 reserved_6[8]; /* Offset 0xe8 */ 1353d5615e5SSuravee Suthikulpanit u64 avic_logical_id; /* Offset 0xf0 */ 1363d5615e5SSuravee Suthikulpanit u64 avic_physical_id; /* Offset 0xf8 */ 137c2cedf7bSEduardo Habkost }; 138c2cedf7bSEduardo Habkost 139c2cedf7bSEduardo Habkost 140c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0 141c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1 14238e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3 14338e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7 144c2cedf7bSEduardo Habkost 145c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f 146c2cedf7bSEduardo Habkost 147c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8 148c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT) 149c2cedf7bSEduardo Habkost 150640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9 151640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT) 152640bd6e5SJanakarajan Natarajan 153c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 154c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 155c2cedf7bSEduardo Habkost 156c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 157c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 158c2cedf7bSEduardo Habkost 159c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 160c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 161c2cedf7bSEduardo Habkost 162640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25 163640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT) 164640bd6e5SJanakarajan Natarajan 16544a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 16644a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 16744a95daeSSuravee Suthikulpanit 1688a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 16989c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1708a77e909SJanakarajan Natarajan 171c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 172c2cedf7bSEduardo Habkost 173c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 174c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 175c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 176c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 177c2cedf7bSEduardo Habkost 178c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 179c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 180c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 181c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 182c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 183c2cedf7bSEduardo Habkost 1844a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1854a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1864a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1874a810181SJoerg Roedel 188cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0) 189ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1) 190cea3a19bSTom Lendacky 191976bc5e2SBorislav Petkov struct vmcb_seg { 192c2cedf7bSEduardo Habkost u16 selector; 193c2cedf7bSEduardo Habkost u16 attrib; 194c2cedf7bSEduardo Habkost u32 limit; 195c2cedf7bSEduardo Habkost u64 base; 196976bc5e2SBorislav Petkov } __packed; 197c2cedf7bSEduardo Habkost 198976bc5e2SBorislav Petkov struct vmcb_save_area { 199c2cedf7bSEduardo Habkost struct vmcb_seg es; 200c2cedf7bSEduardo Habkost struct vmcb_seg cs; 201c2cedf7bSEduardo Habkost struct vmcb_seg ss; 202c2cedf7bSEduardo Habkost struct vmcb_seg ds; 203c2cedf7bSEduardo Habkost struct vmcb_seg fs; 204c2cedf7bSEduardo Habkost struct vmcb_seg gs; 205c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 206c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 207c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 208c2cedf7bSEduardo Habkost struct vmcb_seg tr; 209c2cedf7bSEduardo Habkost u8 reserved_1[43]; 210c2cedf7bSEduardo Habkost u8 cpl; 211c2cedf7bSEduardo Habkost u8 reserved_2[4]; 212c2cedf7bSEduardo Habkost u64 efer; 213c2cedf7bSEduardo Habkost u8 reserved_3[112]; 214c2cedf7bSEduardo Habkost u64 cr4; 215c2cedf7bSEduardo Habkost u64 cr3; 216c2cedf7bSEduardo Habkost u64 cr0; 217c2cedf7bSEduardo Habkost u64 dr7; 218c2cedf7bSEduardo Habkost u64 dr6; 219c2cedf7bSEduardo Habkost u64 rflags; 220c2cedf7bSEduardo Habkost u64 rip; 221c2cedf7bSEduardo Habkost u8 reserved_4[88]; 222c2cedf7bSEduardo Habkost u64 rsp; 223c2cedf7bSEduardo Habkost u8 reserved_5[24]; 224c2cedf7bSEduardo Habkost u64 rax; 225c2cedf7bSEduardo Habkost u64 star; 226c2cedf7bSEduardo Habkost u64 lstar; 227c2cedf7bSEduardo Habkost u64 cstar; 228c2cedf7bSEduardo Habkost u64 sfmask; 229c2cedf7bSEduardo Habkost u64 kernel_gs_base; 230c2cedf7bSEduardo Habkost u64 sysenter_cs; 231c2cedf7bSEduardo Habkost u64 sysenter_esp; 232c2cedf7bSEduardo Habkost u64 sysenter_eip; 233c2cedf7bSEduardo Habkost u64 cr2; 234c2cedf7bSEduardo Habkost u8 reserved_6[32]; 235c2cedf7bSEduardo Habkost u64 g_pat; 236c2cedf7bSEduardo Habkost u64 dbgctl; 237c2cedf7bSEduardo Habkost u64 br_from; 238c2cedf7bSEduardo Habkost u64 br_to; 239c2cedf7bSEduardo Habkost u64 last_excp_from; 240c2cedf7bSEduardo Habkost u64 last_excp_to; 241d07f46f9STom Lendacky 242d07f46f9STom Lendacky /* 243d07f46f9STom Lendacky * The following part of the save area is valid only for 244d07f46f9STom Lendacky * SEV-ES guests when referenced through the GHCB. 245d07f46f9STom Lendacky */ 246d07f46f9STom Lendacky u8 reserved_7[104]; 247d07f46f9STom Lendacky u64 reserved_8; /* rax already available at 0x01f8 */ 248d07f46f9STom Lendacky u64 rcx; 249d07f46f9STom Lendacky u64 rdx; 250d07f46f9STom Lendacky u64 rbx; 251d07f46f9STom Lendacky u64 reserved_9; /* rsp already available at 0x01d8 */ 252d07f46f9STom Lendacky u64 rbp; 253d07f46f9STom Lendacky u64 rsi; 254d07f46f9STom Lendacky u64 rdi; 255d07f46f9STom Lendacky u64 r8; 256d07f46f9STom Lendacky u64 r9; 257d07f46f9STom Lendacky u64 r10; 258d07f46f9STom Lendacky u64 r11; 259d07f46f9STom Lendacky u64 r12; 260d07f46f9STom Lendacky u64 r13; 261d07f46f9STom Lendacky u64 r14; 262d07f46f9STom Lendacky u64 r15; 263d07f46f9STom Lendacky u8 reserved_10[16]; 264d07f46f9STom Lendacky u64 sw_exit_code; 265d07f46f9STom Lendacky u64 sw_exit_info_1; 266d07f46f9STom Lendacky u64 sw_exit_info_2; 267d07f46f9STom Lendacky u64 sw_scratch; 268d07f46f9STom Lendacky u8 reserved_11[56]; 269d07f46f9STom Lendacky u64 xcr0; 270d07f46f9STom Lendacky u8 valid_bitmap[16]; 271d07f46f9STom Lendacky u64 x87_state_gpa; 272976bc5e2SBorislav Petkov } __packed; 273c2cedf7bSEduardo Habkost 274d07f46f9STom Lendacky struct ghcb { 275d07f46f9STom Lendacky struct vmcb_save_area save; 276d07f46f9STom Lendacky u8 reserved_save[2048 - sizeof(struct vmcb_save_area)]; 277d07f46f9STom Lendacky 278d07f46f9STom Lendacky u8 shared_buffer[2032]; 279d07f46f9STom Lendacky 280d07f46f9STom Lendacky u8 reserved_1[10]; 281d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ 282d07f46f9STom Lendacky u32 ghcb_usage; 283d07f46f9STom Lendacky } __packed; 284d07f46f9STom Lendacky 285d07f46f9STom Lendacky 286d07f46f9STom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE 1032 287d07f46f9STom Lendacky #define EXPECTED_VMCB_CONTROL_AREA_SIZE 256 288d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE 2897923ef4fSPaolo Bonzini 2907923ef4fSPaolo Bonzini static inline void __unused_size_checks(void) 2917923ef4fSPaolo Bonzini { 292d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); 293d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); 294d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); 2957923ef4fSPaolo Bonzini } 2967923ef4fSPaolo Bonzini 297976bc5e2SBorislav Petkov struct vmcb { 298c2cedf7bSEduardo Habkost struct vmcb_control_area control; 2997923ef4fSPaolo Bonzini u8 reserved_control[1024 - sizeof(struct vmcb_control_area)]; 300c2cedf7bSEduardo Habkost struct vmcb_save_area save; 301976bc5e2SBorislav Petkov } __packed; 302c2cedf7bSEduardo Habkost 303c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 304c2cedf7bSEduardo Habkost 305c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 306c2cedf7bSEduardo Habkost 307c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 308c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 309c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 310c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 311c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 312c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 313c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 314c2cedf7bSEduardo Habkost 315c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 316c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 317c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 318c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 319c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 320c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 321c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 322c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 323c2cedf7bSEduardo Habkost 324c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 325c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 326c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 327c2cedf7bSEduardo Habkost 328c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 329c2cedf7bSEduardo Habkost 330c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 331c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 332c2cedf7bSEduardo Habkost 333c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 334c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 335c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 336c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 337c2cedf7bSEduardo Habkost 338c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 339c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 340c2cedf7bSEduardo Habkost 341c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 34264a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 343c2cedf7bSEduardo Habkost 344c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 345c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 346c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 347c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 348c2cedf7bSEduardo Habkost 349c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 350c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 351c2cedf7bSEduardo Habkost 352c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 353c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 354e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 355c2cedf7bSEduardo Habkost 3567ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 3577ff76d58SAndre Przywara 358dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 359c2cedf7bSEduardo Habkost 3603702c2f4SJoerg Roedel /* GHCB Accessor functions */ 3613702c2f4SJoerg Roedel 3623702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \ 3633702c2f4SJoerg Roedel (offsetof(struct vmcb_save_area, field) / sizeof(u64)) 3643702c2f4SJoerg Roedel 3653702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \ 3663702c2f4SJoerg Roedel static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ 3673702c2f4SJoerg Roedel { \ 3683702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \ 3693702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3703702c2f4SJoerg Roedel } \ 3713702c2f4SJoerg Roedel \ 3723702c2f4SJoerg Roedel static inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ 3733702c2f4SJoerg Roedel { \ 3743702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \ 3753702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3763702c2f4SJoerg Roedel ghcb->save.field = value; \ 3773702c2f4SJoerg Roedel } 3783702c2f4SJoerg Roedel 3793702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl) 3803702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip) 3813702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp) 3823702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax) 3833702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx) 3843702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx) 3853702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx) 3863702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp) 3873702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi) 3883702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi) 3893702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8) 3903702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9) 3913702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10) 3923702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11) 3933702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12) 3943702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13) 3953702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14) 3963702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15) 3973702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code) 3983702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1) 3993702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2) 4003702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch) 4013702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0) 4023702c2f4SJoerg Roedel 403c2cedf7bSEduardo Habkost #endif 404