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 8c45ad722SBabu Moger /* 9c45ad722SBabu Moger * 32-bit intercept words in the VMCB Control Area, starting 10c45ad722SBabu Moger * at Byte offset 000h. 11c45ad722SBabu Moger */ 12c45ad722SBabu Moger 13c45ad722SBabu Moger enum intercept_words { 1403bfeeb9SBabu Moger INTERCEPT_CR = 0, 1530abaa88SBabu Moger INTERCEPT_DR, 169780d51dSBabu Moger INTERCEPT_EXCEPTION, 17c62e2e94SBabu Moger INTERCEPT_WORD3, 18c62e2e94SBabu Moger INTERCEPT_WORD4, 19*4c44e8d6SBabu Moger INTERCEPT_WORD5, 20c45ad722SBabu Moger MAX_INTERCEPT, 21c45ad722SBabu Moger }; 2226bf264eSXiao Guangrong 23c2cedf7bSEduardo Habkost enum { 2403bfeeb9SBabu Moger /* Byte offset 000h (word 0) */ 2503bfeeb9SBabu Moger INTERCEPT_CR0_READ = 0, 2603bfeeb9SBabu Moger INTERCEPT_CR3_READ = 3, 2703bfeeb9SBabu Moger INTERCEPT_CR4_READ = 4, 2803bfeeb9SBabu Moger INTERCEPT_CR8_READ = 8, 2903bfeeb9SBabu Moger INTERCEPT_CR0_WRITE = 16, 3003bfeeb9SBabu Moger INTERCEPT_CR3_WRITE = 16 + 3, 3103bfeeb9SBabu Moger INTERCEPT_CR4_WRITE = 16 + 4, 3203bfeeb9SBabu Moger INTERCEPT_CR8_WRITE = 16 + 8, 3330abaa88SBabu Moger /* Byte offset 004h (word 1) */ 3430abaa88SBabu Moger INTERCEPT_DR0_READ = 32, 3530abaa88SBabu Moger INTERCEPT_DR1_READ, 3630abaa88SBabu Moger INTERCEPT_DR2_READ, 3730abaa88SBabu Moger INTERCEPT_DR3_READ, 3830abaa88SBabu Moger INTERCEPT_DR4_READ, 3930abaa88SBabu Moger INTERCEPT_DR5_READ, 4030abaa88SBabu Moger INTERCEPT_DR6_READ, 4130abaa88SBabu Moger INTERCEPT_DR7_READ, 4230abaa88SBabu Moger INTERCEPT_DR0_WRITE = 48, 4330abaa88SBabu Moger INTERCEPT_DR1_WRITE, 4430abaa88SBabu Moger INTERCEPT_DR2_WRITE, 4530abaa88SBabu Moger INTERCEPT_DR3_WRITE, 4630abaa88SBabu Moger INTERCEPT_DR4_WRITE, 4730abaa88SBabu Moger INTERCEPT_DR5_WRITE, 4830abaa88SBabu Moger INTERCEPT_DR6_WRITE, 4930abaa88SBabu Moger INTERCEPT_DR7_WRITE, 509780d51dSBabu Moger /* Byte offset 008h (word 2) */ 519780d51dSBabu Moger INTERCEPT_EXCEPTION_OFFSET = 64, 52c62e2e94SBabu Moger /* Byte offset 00Ch (word 3) */ 53c62e2e94SBabu Moger INTERCEPT_INTR = 96, 54c2cedf7bSEduardo Habkost INTERCEPT_NMI, 55c2cedf7bSEduardo Habkost INTERCEPT_SMI, 56c2cedf7bSEduardo Habkost INTERCEPT_INIT, 57c2cedf7bSEduardo Habkost INTERCEPT_VINTR, 58c2cedf7bSEduardo Habkost INTERCEPT_SELECTIVE_CR0, 59c2cedf7bSEduardo Habkost INTERCEPT_STORE_IDTR, 60c2cedf7bSEduardo Habkost INTERCEPT_STORE_GDTR, 61c2cedf7bSEduardo Habkost INTERCEPT_STORE_LDTR, 62c2cedf7bSEduardo Habkost INTERCEPT_STORE_TR, 63c2cedf7bSEduardo Habkost INTERCEPT_LOAD_IDTR, 64c2cedf7bSEduardo Habkost INTERCEPT_LOAD_GDTR, 65c2cedf7bSEduardo Habkost INTERCEPT_LOAD_LDTR, 66c2cedf7bSEduardo Habkost INTERCEPT_LOAD_TR, 67c2cedf7bSEduardo Habkost INTERCEPT_RDTSC, 68c2cedf7bSEduardo Habkost INTERCEPT_RDPMC, 69c2cedf7bSEduardo Habkost INTERCEPT_PUSHF, 70c2cedf7bSEduardo Habkost INTERCEPT_POPF, 71c2cedf7bSEduardo Habkost INTERCEPT_CPUID, 72c2cedf7bSEduardo Habkost INTERCEPT_RSM, 73c2cedf7bSEduardo Habkost INTERCEPT_IRET, 74c2cedf7bSEduardo Habkost INTERCEPT_INTn, 75c2cedf7bSEduardo Habkost INTERCEPT_INVD, 76c2cedf7bSEduardo Habkost INTERCEPT_PAUSE, 77c2cedf7bSEduardo Habkost INTERCEPT_HLT, 78c2cedf7bSEduardo Habkost INTERCEPT_INVLPG, 79c2cedf7bSEduardo Habkost INTERCEPT_INVLPGA, 80c2cedf7bSEduardo Habkost INTERCEPT_IOIO_PROT, 81c2cedf7bSEduardo Habkost INTERCEPT_MSR_PROT, 82c2cedf7bSEduardo Habkost INTERCEPT_TASK_SWITCH, 83c2cedf7bSEduardo Habkost INTERCEPT_FERR_FREEZE, 84c2cedf7bSEduardo Habkost INTERCEPT_SHUTDOWN, 85c62e2e94SBabu Moger /* Byte offset 010h (word 4) */ 86c62e2e94SBabu Moger INTERCEPT_VMRUN = 128, 87c2cedf7bSEduardo Habkost INTERCEPT_VMMCALL, 88c2cedf7bSEduardo Habkost INTERCEPT_VMLOAD, 89c2cedf7bSEduardo Habkost INTERCEPT_VMSAVE, 90c2cedf7bSEduardo Habkost INTERCEPT_STGI, 91c2cedf7bSEduardo Habkost INTERCEPT_CLGI, 92c2cedf7bSEduardo Habkost INTERCEPT_SKINIT, 93c2cedf7bSEduardo Habkost INTERCEPT_RDTSCP, 94c2cedf7bSEduardo Habkost INTERCEPT_ICEBP, 95c2cedf7bSEduardo Habkost INTERCEPT_WBINVD, 96c2cedf7bSEduardo Habkost INTERCEPT_MONITOR, 97c2cedf7bSEduardo Habkost INTERCEPT_MWAIT, 98c2cedf7bSEduardo Habkost INTERCEPT_MWAIT_COND, 9981dd35d4SJoerg Roedel INTERCEPT_XSETBV, 1000cb8410bSJim Mattson INTERCEPT_RDPRU, 101*4c44e8d6SBabu Moger /* Byte offset 014h (word 5) */ 102*4c44e8d6SBabu Moger INTERCEPT_INVLPGB = 160, 103*4c44e8d6SBabu Moger INTERCEPT_INVLPGB_ILLEGAL, 104*4c44e8d6SBabu Moger INTERCEPT_INVPCID, 105*4c44e8d6SBabu Moger INTERCEPT_MCOMMIT, 106*4c44e8d6SBabu Moger INTERCEPT_TLBSYNC, 107c2cedf7bSEduardo Habkost }; 108c2cedf7bSEduardo Habkost 109c2cedf7bSEduardo Habkost 110c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area { 111c45ad722SBabu Moger u32 intercepts[MAX_INTERCEPT]; 112c62e2e94SBabu Moger u32 reserved_1[15 - MAX_INTERCEPT]; 1131d8fb44aSBabu Moger u16 pause_filter_thresh; 114565d0998SMark Langsdorf u16 pause_filter_count; 115c2cedf7bSEduardo Habkost u64 iopm_base_pa; 116c2cedf7bSEduardo Habkost u64 msrpm_base_pa; 117c2cedf7bSEduardo Habkost u64 tsc_offset; 118c2cedf7bSEduardo Habkost u32 asid; 119c2cedf7bSEduardo Habkost u8 tlb_ctl; 120c2cedf7bSEduardo Habkost u8 reserved_2[3]; 121c2cedf7bSEduardo Habkost u32 int_ctl; 122c2cedf7bSEduardo Habkost u32 int_vector; 123c2cedf7bSEduardo Habkost u32 int_state; 124c2cedf7bSEduardo Habkost u8 reserved_3[4]; 125c2cedf7bSEduardo Habkost u32 exit_code; 126c2cedf7bSEduardo Habkost u32 exit_code_hi; 127c2cedf7bSEduardo Habkost u64 exit_info_1; 128c2cedf7bSEduardo Habkost u64 exit_info_2; 129c2cedf7bSEduardo Habkost u32 exit_int_info; 130c2cedf7bSEduardo Habkost u32 exit_int_info_err; 131c2cedf7bSEduardo Habkost u64 nested_ctl; 1323d5615e5SSuravee Suthikulpanit u64 avic_vapic_bar; 1333d5615e5SSuravee Suthikulpanit u8 reserved_4[8]; 134c2cedf7bSEduardo Habkost u32 event_inj; 135c2cedf7bSEduardo Habkost u32 event_inj_err; 136c2cedf7bSEduardo Habkost u64 nested_cr3; 1370dc92119SJanakarajan Natarajan u64 virt_ext; 1388d28fec4SRoedel, Joerg u32 clean; 1398d28fec4SRoedel, Joerg u32 reserved_5; 1406bc31bdcSAndre Przywara u64 next_rip; 141dc25e89eSAndre Przywara u8 insn_len; 142dc25e89eSAndre Przywara u8 insn_bytes[15]; 1433d5615e5SSuravee Suthikulpanit u64 avic_backing_page; /* Offset 0xe0 */ 1443d5615e5SSuravee Suthikulpanit u8 reserved_6[8]; /* Offset 0xe8 */ 1453d5615e5SSuravee Suthikulpanit u64 avic_logical_id; /* Offset 0xf0 */ 1463d5615e5SSuravee Suthikulpanit u64 avic_physical_id; /* Offset 0xf8 */ 147c2cedf7bSEduardo Habkost }; 148c2cedf7bSEduardo Habkost 149c2cedf7bSEduardo Habkost 150c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0 151c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1 15238e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3 15338e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7 154c2cedf7bSEduardo Habkost 155c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f 156c2cedf7bSEduardo Habkost 157c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8 158c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT) 159c2cedf7bSEduardo Habkost 160640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9 161640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT) 162640bd6e5SJanakarajan Natarajan 163c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 164c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 165c2cedf7bSEduardo Habkost 166c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 167c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 168c2cedf7bSEduardo Habkost 169c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 170c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 171c2cedf7bSEduardo Habkost 172640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25 173640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT) 174640bd6e5SJanakarajan Natarajan 17544a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 17644a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 17744a95daeSSuravee Suthikulpanit 1788a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 17989c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1808a77e909SJanakarajan Natarajan 181c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 182c2cedf7bSEduardo Habkost 183c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 184c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 185c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 186c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 187c2cedf7bSEduardo Habkost 188c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 189c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 190c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 191c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 192c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 193c2cedf7bSEduardo Habkost 1944a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1954a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1964a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1974a810181SJoerg Roedel 198cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0) 199ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1) 200cea3a19bSTom Lendacky 201976bc5e2SBorislav Petkov struct vmcb_seg { 202c2cedf7bSEduardo Habkost u16 selector; 203c2cedf7bSEduardo Habkost u16 attrib; 204c2cedf7bSEduardo Habkost u32 limit; 205c2cedf7bSEduardo Habkost u64 base; 206976bc5e2SBorislav Petkov } __packed; 207c2cedf7bSEduardo Habkost 208976bc5e2SBorislav Petkov struct vmcb_save_area { 209c2cedf7bSEduardo Habkost struct vmcb_seg es; 210c2cedf7bSEduardo Habkost struct vmcb_seg cs; 211c2cedf7bSEduardo Habkost struct vmcb_seg ss; 212c2cedf7bSEduardo Habkost struct vmcb_seg ds; 213c2cedf7bSEduardo Habkost struct vmcb_seg fs; 214c2cedf7bSEduardo Habkost struct vmcb_seg gs; 215c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 216c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 217c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 218c2cedf7bSEduardo Habkost struct vmcb_seg tr; 219c2cedf7bSEduardo Habkost u8 reserved_1[43]; 220c2cedf7bSEduardo Habkost u8 cpl; 221c2cedf7bSEduardo Habkost u8 reserved_2[4]; 222c2cedf7bSEduardo Habkost u64 efer; 223c2cedf7bSEduardo Habkost u8 reserved_3[112]; 224c2cedf7bSEduardo Habkost u64 cr4; 225c2cedf7bSEduardo Habkost u64 cr3; 226c2cedf7bSEduardo Habkost u64 cr0; 227c2cedf7bSEduardo Habkost u64 dr7; 228c2cedf7bSEduardo Habkost u64 dr6; 229c2cedf7bSEduardo Habkost u64 rflags; 230c2cedf7bSEduardo Habkost u64 rip; 231c2cedf7bSEduardo Habkost u8 reserved_4[88]; 232c2cedf7bSEduardo Habkost u64 rsp; 233c2cedf7bSEduardo Habkost u8 reserved_5[24]; 234c2cedf7bSEduardo Habkost u64 rax; 235c2cedf7bSEduardo Habkost u64 star; 236c2cedf7bSEduardo Habkost u64 lstar; 237c2cedf7bSEduardo Habkost u64 cstar; 238c2cedf7bSEduardo Habkost u64 sfmask; 239c2cedf7bSEduardo Habkost u64 kernel_gs_base; 240c2cedf7bSEduardo Habkost u64 sysenter_cs; 241c2cedf7bSEduardo Habkost u64 sysenter_esp; 242c2cedf7bSEduardo Habkost u64 sysenter_eip; 243c2cedf7bSEduardo Habkost u64 cr2; 244c2cedf7bSEduardo Habkost u8 reserved_6[32]; 245c2cedf7bSEduardo Habkost u64 g_pat; 246c2cedf7bSEduardo Habkost u64 dbgctl; 247c2cedf7bSEduardo Habkost u64 br_from; 248c2cedf7bSEduardo Habkost u64 br_to; 249c2cedf7bSEduardo Habkost u64 last_excp_from; 250c2cedf7bSEduardo Habkost u64 last_excp_to; 251d07f46f9STom Lendacky 252d07f46f9STom Lendacky /* 253d07f46f9STom Lendacky * The following part of the save area is valid only for 254d07f46f9STom Lendacky * SEV-ES guests when referenced through the GHCB. 255d07f46f9STom Lendacky */ 256d07f46f9STom Lendacky u8 reserved_7[104]; 257d07f46f9STom Lendacky u64 reserved_8; /* rax already available at 0x01f8 */ 258d07f46f9STom Lendacky u64 rcx; 259d07f46f9STom Lendacky u64 rdx; 260d07f46f9STom Lendacky u64 rbx; 261d07f46f9STom Lendacky u64 reserved_9; /* rsp already available at 0x01d8 */ 262d07f46f9STom Lendacky u64 rbp; 263d07f46f9STom Lendacky u64 rsi; 264d07f46f9STom Lendacky u64 rdi; 265d07f46f9STom Lendacky u64 r8; 266d07f46f9STom Lendacky u64 r9; 267d07f46f9STom Lendacky u64 r10; 268d07f46f9STom Lendacky u64 r11; 269d07f46f9STom Lendacky u64 r12; 270d07f46f9STom Lendacky u64 r13; 271d07f46f9STom Lendacky u64 r14; 272d07f46f9STom Lendacky u64 r15; 273d07f46f9STom Lendacky u8 reserved_10[16]; 274d07f46f9STom Lendacky u64 sw_exit_code; 275d07f46f9STom Lendacky u64 sw_exit_info_1; 276d07f46f9STom Lendacky u64 sw_exit_info_2; 277d07f46f9STom Lendacky u64 sw_scratch; 278d07f46f9STom Lendacky u8 reserved_11[56]; 279d07f46f9STom Lendacky u64 xcr0; 280d07f46f9STom Lendacky u8 valid_bitmap[16]; 281d07f46f9STom Lendacky u64 x87_state_gpa; 282976bc5e2SBorislav Petkov } __packed; 283c2cedf7bSEduardo Habkost 284d07f46f9STom Lendacky struct ghcb { 285d07f46f9STom Lendacky struct vmcb_save_area save; 286d07f46f9STom Lendacky u8 reserved_save[2048 - sizeof(struct vmcb_save_area)]; 287d07f46f9STom Lendacky 288d07f46f9STom Lendacky u8 shared_buffer[2032]; 289d07f46f9STom Lendacky 290d07f46f9STom Lendacky u8 reserved_1[10]; 291d07f46f9STom Lendacky u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ 292d07f46f9STom Lendacky u32 ghcb_usage; 293d07f46f9STom Lendacky } __packed; 294d07f46f9STom Lendacky 295d07f46f9STom Lendacky 296d07f46f9STom Lendacky #define EXPECTED_VMCB_SAVE_AREA_SIZE 1032 297d07f46f9STom Lendacky #define EXPECTED_VMCB_CONTROL_AREA_SIZE 256 298d07f46f9STom Lendacky #define EXPECTED_GHCB_SIZE PAGE_SIZE 2997923ef4fSPaolo Bonzini 3007923ef4fSPaolo Bonzini static inline void __unused_size_checks(void) 3017923ef4fSPaolo Bonzini { 302d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); 303d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); 304d07f46f9STom Lendacky BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); 3057923ef4fSPaolo Bonzini } 3067923ef4fSPaolo Bonzini 307976bc5e2SBorislav Petkov struct vmcb { 308c2cedf7bSEduardo Habkost struct vmcb_control_area control; 3097923ef4fSPaolo Bonzini u8 reserved_control[1024 - sizeof(struct vmcb_control_area)]; 310c2cedf7bSEduardo Habkost struct vmcb_save_area save; 311976bc5e2SBorislav Petkov } __packed; 312c2cedf7bSEduardo Habkost 313c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 314c2cedf7bSEduardo Habkost 315c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 316c2cedf7bSEduardo Habkost 317c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 318c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 319c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 320c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 321c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 322c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 323c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 324c2cedf7bSEduardo Habkost 325c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 326c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 327c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 328c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 329c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 330c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 331c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 332c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 333c2cedf7bSEduardo Habkost 334c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 335c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 336c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 337c2cedf7bSEduardo Habkost 338c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 339c2cedf7bSEduardo Habkost 340c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 341c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 342c2cedf7bSEduardo Habkost 343c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 344c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 345c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 346c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 347c2cedf7bSEduardo Habkost 348c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 349c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 350c2cedf7bSEduardo Habkost 351c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 35264a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 353c2cedf7bSEduardo Habkost 354c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 355c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 356c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 357c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 358c2cedf7bSEduardo Habkost 359c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 360c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 361c2cedf7bSEduardo Habkost 362c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 363c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 364e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 365c2cedf7bSEduardo Habkost 3667ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 3677ff76d58SAndre Przywara 368dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 369c2cedf7bSEduardo Habkost 3703702c2f4SJoerg Roedel /* GHCB Accessor functions */ 3713702c2f4SJoerg Roedel 3723702c2f4SJoerg Roedel #define GHCB_BITMAP_IDX(field) \ 3733702c2f4SJoerg Roedel (offsetof(struct vmcb_save_area, field) / sizeof(u64)) 3743702c2f4SJoerg Roedel 3753702c2f4SJoerg Roedel #define DEFINE_GHCB_ACCESSORS(field) \ 3763702c2f4SJoerg Roedel static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ 3773702c2f4SJoerg Roedel { \ 3783702c2f4SJoerg Roedel return test_bit(GHCB_BITMAP_IDX(field), \ 3793702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3803702c2f4SJoerg Roedel } \ 3813702c2f4SJoerg Roedel \ 3823702c2f4SJoerg Roedel static inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ 3833702c2f4SJoerg Roedel { \ 3843702c2f4SJoerg Roedel __set_bit(GHCB_BITMAP_IDX(field), \ 3853702c2f4SJoerg Roedel (unsigned long *)&ghcb->save.valid_bitmap); \ 3863702c2f4SJoerg Roedel ghcb->save.field = value; \ 3873702c2f4SJoerg Roedel } 3883702c2f4SJoerg Roedel 3893702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(cpl) 3903702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rip) 3913702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsp) 3923702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rax) 3933702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rcx) 3943702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdx) 3953702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbx) 3963702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rbp) 3973702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rsi) 3983702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(rdi) 3993702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r8) 4003702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r9) 4013702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r10) 4023702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r11) 4033702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r12) 4043702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r13) 4053702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r14) 4063702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(r15) 4073702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_code) 4083702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_1) 4093702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_exit_info_2) 4103702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(sw_scratch) 4113702c2f4SJoerg Roedel DEFINE_GHCB_ACCESSORS(xcr0) 4123702c2f4SJoerg Roedel 413c2cedf7bSEduardo Habkost #endif 414