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, 55c2cedf7bSEduardo Habkost }; 56c2cedf7bSEduardo Habkost 57c2cedf7bSEduardo Habkost 58c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area { 594ee546b4SRoedel, Joerg u32 intercept_cr; 603aed041aSJoerg Roedel u32 intercept_dr; 61c2cedf7bSEduardo Habkost u32 intercept_exceptions; 62c2cedf7bSEduardo Habkost u64 intercept; 63565d0998SMark Langsdorf u8 reserved_1[42]; 64565d0998SMark Langsdorf u16 pause_filter_count; 65c2cedf7bSEduardo Habkost u64 iopm_base_pa; 66c2cedf7bSEduardo Habkost u64 msrpm_base_pa; 67c2cedf7bSEduardo Habkost u64 tsc_offset; 68c2cedf7bSEduardo Habkost u32 asid; 69c2cedf7bSEduardo Habkost u8 tlb_ctl; 70c2cedf7bSEduardo Habkost u8 reserved_2[3]; 71c2cedf7bSEduardo Habkost u32 int_ctl; 72c2cedf7bSEduardo Habkost u32 int_vector; 73c2cedf7bSEduardo Habkost u32 int_state; 74c2cedf7bSEduardo Habkost u8 reserved_3[4]; 75c2cedf7bSEduardo Habkost u32 exit_code; 76c2cedf7bSEduardo Habkost u32 exit_code_hi; 77c2cedf7bSEduardo Habkost u64 exit_info_1; 78c2cedf7bSEduardo Habkost u64 exit_info_2; 79c2cedf7bSEduardo Habkost u32 exit_int_info; 80c2cedf7bSEduardo Habkost u32 exit_int_info_err; 81c2cedf7bSEduardo Habkost u64 nested_ctl; 823d5615e5SSuravee Suthikulpanit u64 avic_vapic_bar; 833d5615e5SSuravee Suthikulpanit u8 reserved_4[8]; 84c2cedf7bSEduardo Habkost u32 event_inj; 85c2cedf7bSEduardo Habkost u32 event_inj_err; 86c2cedf7bSEduardo Habkost u64 nested_cr3; 870dc92119SJanakarajan Natarajan u64 virt_ext; 888d28fec4SRoedel, Joerg u32 clean; 898d28fec4SRoedel, Joerg u32 reserved_5; 906bc31bdcSAndre Przywara u64 next_rip; 91dc25e89eSAndre Przywara u8 insn_len; 92dc25e89eSAndre Przywara u8 insn_bytes[15]; 933d5615e5SSuravee Suthikulpanit u64 avic_backing_page; /* Offset 0xe0 */ 943d5615e5SSuravee Suthikulpanit u8 reserved_6[8]; /* Offset 0xe8 */ 953d5615e5SSuravee Suthikulpanit u64 avic_logical_id; /* Offset 0xf0 */ 963d5615e5SSuravee Suthikulpanit u64 avic_physical_id; /* Offset 0xf8 */ 973d5615e5SSuravee Suthikulpanit u8 reserved_7[768]; 98c2cedf7bSEduardo Habkost }; 99c2cedf7bSEduardo Habkost 100c2cedf7bSEduardo Habkost 101c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0 102c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1 10338e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3 10438e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7 105c2cedf7bSEduardo Habkost 106c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f 107c2cedf7bSEduardo Habkost 108c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8 109c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT) 110c2cedf7bSEduardo Habkost 111640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9 112640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT) 113640bd6e5SJanakarajan Natarajan 114c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 115c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 116c2cedf7bSEduardo Habkost 117c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 118c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 119c2cedf7bSEduardo Habkost 120c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 121c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 122c2cedf7bSEduardo Habkost 123640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25 124640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT) 125640bd6e5SJanakarajan Natarajan 12644a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 12744a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 12844a95daeSSuravee Suthikulpanit 1298a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 13089c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1318a77e909SJanakarajan Natarajan 132c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 133c2cedf7bSEduardo Habkost 134c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 135c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 136c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 137c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 138c2cedf7bSEduardo Habkost 139c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 140c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 141c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 142c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 143c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 144c2cedf7bSEduardo Habkost 1454a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1464a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1474a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1484a810181SJoerg Roedel 149cea3a19bSTom Lendacky #define SVM_NESTED_CTL_NP_ENABLE BIT(0) 150*ba7c3398STom Lendacky #define SVM_NESTED_CTL_SEV_ENABLE BIT(1) 151cea3a19bSTom Lendacky 152c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_seg { 153c2cedf7bSEduardo Habkost u16 selector; 154c2cedf7bSEduardo Habkost u16 attrib; 155c2cedf7bSEduardo Habkost u32 limit; 156c2cedf7bSEduardo Habkost u64 base; 157c2cedf7bSEduardo Habkost }; 158c2cedf7bSEduardo Habkost 159c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_save_area { 160c2cedf7bSEduardo Habkost struct vmcb_seg es; 161c2cedf7bSEduardo Habkost struct vmcb_seg cs; 162c2cedf7bSEduardo Habkost struct vmcb_seg ss; 163c2cedf7bSEduardo Habkost struct vmcb_seg ds; 164c2cedf7bSEduardo Habkost struct vmcb_seg fs; 165c2cedf7bSEduardo Habkost struct vmcb_seg gs; 166c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 167c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 168c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 169c2cedf7bSEduardo Habkost struct vmcb_seg tr; 170c2cedf7bSEduardo Habkost u8 reserved_1[43]; 171c2cedf7bSEduardo Habkost u8 cpl; 172c2cedf7bSEduardo Habkost u8 reserved_2[4]; 173c2cedf7bSEduardo Habkost u64 efer; 174c2cedf7bSEduardo Habkost u8 reserved_3[112]; 175c2cedf7bSEduardo Habkost u64 cr4; 176c2cedf7bSEduardo Habkost u64 cr3; 177c2cedf7bSEduardo Habkost u64 cr0; 178c2cedf7bSEduardo Habkost u64 dr7; 179c2cedf7bSEduardo Habkost u64 dr6; 180c2cedf7bSEduardo Habkost u64 rflags; 181c2cedf7bSEduardo Habkost u64 rip; 182c2cedf7bSEduardo Habkost u8 reserved_4[88]; 183c2cedf7bSEduardo Habkost u64 rsp; 184c2cedf7bSEduardo Habkost u8 reserved_5[24]; 185c2cedf7bSEduardo Habkost u64 rax; 186c2cedf7bSEduardo Habkost u64 star; 187c2cedf7bSEduardo Habkost u64 lstar; 188c2cedf7bSEduardo Habkost u64 cstar; 189c2cedf7bSEduardo Habkost u64 sfmask; 190c2cedf7bSEduardo Habkost u64 kernel_gs_base; 191c2cedf7bSEduardo Habkost u64 sysenter_cs; 192c2cedf7bSEduardo Habkost u64 sysenter_esp; 193c2cedf7bSEduardo Habkost u64 sysenter_eip; 194c2cedf7bSEduardo Habkost u64 cr2; 195c2cedf7bSEduardo Habkost u8 reserved_6[32]; 196c2cedf7bSEduardo Habkost u64 g_pat; 197c2cedf7bSEduardo Habkost u64 dbgctl; 198c2cedf7bSEduardo Habkost u64 br_from; 199c2cedf7bSEduardo Habkost u64 br_to; 200c2cedf7bSEduardo Habkost u64 last_excp_from; 201c2cedf7bSEduardo Habkost u64 last_excp_to; 202c2cedf7bSEduardo Habkost }; 203c2cedf7bSEduardo Habkost 204c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb { 205c2cedf7bSEduardo Habkost struct vmcb_control_area control; 206c2cedf7bSEduardo Habkost struct vmcb_save_area save; 207c2cedf7bSEduardo Habkost }; 208c2cedf7bSEduardo Habkost 209c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 210c2cedf7bSEduardo Habkost 211c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 212c2cedf7bSEduardo Habkost 213c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 214c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 215c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 216c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 217c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 218c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 219c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 220c2cedf7bSEduardo Habkost 221c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 222c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 223c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 224c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 225c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 226c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 227c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 228c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 229c2cedf7bSEduardo Habkost 230c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 231c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 232c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 233c2cedf7bSEduardo Habkost 2344ee546b4SRoedel, Joerg #define INTERCEPT_CR0_READ 0 2354ee546b4SRoedel, Joerg #define INTERCEPT_CR3_READ 3 2364ee546b4SRoedel, Joerg #define INTERCEPT_CR4_READ 4 2374ee546b4SRoedel, Joerg #define INTERCEPT_CR8_READ 8 2384ee546b4SRoedel, Joerg #define INTERCEPT_CR0_WRITE (16 + 0) 2394ee546b4SRoedel, Joerg #define INTERCEPT_CR3_WRITE (16 + 3) 2404ee546b4SRoedel, Joerg #define INTERCEPT_CR4_WRITE (16 + 4) 2414ee546b4SRoedel, Joerg #define INTERCEPT_CR8_WRITE (16 + 8) 242c2cedf7bSEduardo Habkost 2433aed041aSJoerg Roedel #define INTERCEPT_DR0_READ 0 2443aed041aSJoerg Roedel #define INTERCEPT_DR1_READ 1 2453aed041aSJoerg Roedel #define INTERCEPT_DR2_READ 2 2463aed041aSJoerg Roedel #define INTERCEPT_DR3_READ 3 2473aed041aSJoerg Roedel #define INTERCEPT_DR4_READ 4 2483aed041aSJoerg Roedel #define INTERCEPT_DR5_READ 5 2493aed041aSJoerg Roedel #define INTERCEPT_DR6_READ 6 2503aed041aSJoerg Roedel #define INTERCEPT_DR7_READ 7 2513aed041aSJoerg Roedel #define INTERCEPT_DR0_WRITE (16 + 0) 2523aed041aSJoerg Roedel #define INTERCEPT_DR1_WRITE (16 + 1) 2533aed041aSJoerg Roedel #define INTERCEPT_DR2_WRITE (16 + 2) 2543aed041aSJoerg Roedel #define INTERCEPT_DR3_WRITE (16 + 3) 2553aed041aSJoerg Roedel #define INTERCEPT_DR4_WRITE (16 + 4) 2563aed041aSJoerg Roedel #define INTERCEPT_DR5_WRITE (16 + 5) 2573aed041aSJoerg Roedel #define INTERCEPT_DR6_WRITE (16 + 6) 2583aed041aSJoerg Roedel #define INTERCEPT_DR7_WRITE (16 + 7) 259c2cedf7bSEduardo Habkost 260c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 261c2cedf7bSEduardo Habkost 262c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 263c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 264c2cedf7bSEduardo Habkost 265c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 266c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 267c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 268c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 269c2cedf7bSEduardo Habkost 270c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 271c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 272c2cedf7bSEduardo Habkost 273c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 27464a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 275c2cedf7bSEduardo Habkost 276c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 277c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 278c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 279c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 280c2cedf7bSEduardo Habkost 281c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 282c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 283c2cedf7bSEduardo Habkost 284c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 285c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 286e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 287c2cedf7bSEduardo Habkost 2887ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 2897ff76d58SAndre Przywara 290dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 291c2cedf7bSEduardo Habkost 292c2cedf7bSEduardo Habkost #define SVM_VMLOAD ".byte 0x0f, 0x01, 0xda" 293c2cedf7bSEduardo Habkost #define SVM_VMRUN ".byte 0x0f, 0x01, 0xd8" 294c2cedf7bSEduardo Habkost #define SVM_VMSAVE ".byte 0x0f, 0x01, 0xdb" 295c2cedf7bSEduardo Habkost #define SVM_CLGI ".byte 0x0f, 0x01, 0xdd" 296c2cedf7bSEduardo Habkost #define SVM_STGI ".byte 0x0f, 0x01, 0xdc" 297c2cedf7bSEduardo Habkost #define SVM_INVLPGA ".byte 0x0f, 0x01, 0xdf" 298c2cedf7bSEduardo Habkost 299c2cedf7bSEduardo Habkost #endif 300