1c2cedf7bSEduardo Habkost #ifndef __SVM_H 2c2cedf7bSEduardo Habkost #define __SVM_H 3c2cedf7bSEduardo Habkost 4af170c50SDavid Howells #include <uapi/asm/svm.h> 526bf264eSXiao Guangrong 626bf264eSXiao Guangrong 7c2cedf7bSEduardo Habkost enum { 8c2cedf7bSEduardo Habkost INTERCEPT_INTR, 9c2cedf7bSEduardo Habkost INTERCEPT_NMI, 10c2cedf7bSEduardo Habkost INTERCEPT_SMI, 11c2cedf7bSEduardo Habkost INTERCEPT_INIT, 12c2cedf7bSEduardo Habkost INTERCEPT_VINTR, 13c2cedf7bSEduardo Habkost INTERCEPT_SELECTIVE_CR0, 14c2cedf7bSEduardo Habkost INTERCEPT_STORE_IDTR, 15c2cedf7bSEduardo Habkost INTERCEPT_STORE_GDTR, 16c2cedf7bSEduardo Habkost INTERCEPT_STORE_LDTR, 17c2cedf7bSEduardo Habkost INTERCEPT_STORE_TR, 18c2cedf7bSEduardo Habkost INTERCEPT_LOAD_IDTR, 19c2cedf7bSEduardo Habkost INTERCEPT_LOAD_GDTR, 20c2cedf7bSEduardo Habkost INTERCEPT_LOAD_LDTR, 21c2cedf7bSEduardo Habkost INTERCEPT_LOAD_TR, 22c2cedf7bSEduardo Habkost INTERCEPT_RDTSC, 23c2cedf7bSEduardo Habkost INTERCEPT_RDPMC, 24c2cedf7bSEduardo Habkost INTERCEPT_PUSHF, 25c2cedf7bSEduardo Habkost INTERCEPT_POPF, 26c2cedf7bSEduardo Habkost INTERCEPT_CPUID, 27c2cedf7bSEduardo Habkost INTERCEPT_RSM, 28c2cedf7bSEduardo Habkost INTERCEPT_IRET, 29c2cedf7bSEduardo Habkost INTERCEPT_INTn, 30c2cedf7bSEduardo Habkost INTERCEPT_INVD, 31c2cedf7bSEduardo Habkost INTERCEPT_PAUSE, 32c2cedf7bSEduardo Habkost INTERCEPT_HLT, 33c2cedf7bSEduardo Habkost INTERCEPT_INVLPG, 34c2cedf7bSEduardo Habkost INTERCEPT_INVLPGA, 35c2cedf7bSEduardo Habkost INTERCEPT_IOIO_PROT, 36c2cedf7bSEduardo Habkost INTERCEPT_MSR_PROT, 37c2cedf7bSEduardo Habkost INTERCEPT_TASK_SWITCH, 38c2cedf7bSEduardo Habkost INTERCEPT_FERR_FREEZE, 39c2cedf7bSEduardo Habkost INTERCEPT_SHUTDOWN, 40c2cedf7bSEduardo Habkost INTERCEPT_VMRUN, 41c2cedf7bSEduardo Habkost INTERCEPT_VMMCALL, 42c2cedf7bSEduardo Habkost INTERCEPT_VMLOAD, 43c2cedf7bSEduardo Habkost INTERCEPT_VMSAVE, 44c2cedf7bSEduardo Habkost INTERCEPT_STGI, 45c2cedf7bSEduardo Habkost INTERCEPT_CLGI, 46c2cedf7bSEduardo Habkost INTERCEPT_SKINIT, 47c2cedf7bSEduardo Habkost INTERCEPT_RDTSCP, 48c2cedf7bSEduardo Habkost INTERCEPT_ICEBP, 49c2cedf7bSEduardo Habkost INTERCEPT_WBINVD, 50c2cedf7bSEduardo Habkost INTERCEPT_MONITOR, 51c2cedf7bSEduardo Habkost INTERCEPT_MWAIT, 52c2cedf7bSEduardo Habkost INTERCEPT_MWAIT_COND, 5381dd35d4SJoerg Roedel INTERCEPT_XSETBV, 54c2cedf7bSEduardo Habkost }; 55c2cedf7bSEduardo Habkost 56c2cedf7bSEduardo Habkost 57c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_control_area { 584ee546b4SRoedel, Joerg u32 intercept_cr; 593aed041aSJoerg Roedel u32 intercept_dr; 60c2cedf7bSEduardo Habkost u32 intercept_exceptions; 61c2cedf7bSEduardo Habkost u64 intercept; 62565d0998SMark Langsdorf u8 reserved_1[42]; 63565d0998SMark Langsdorf u16 pause_filter_count; 64c2cedf7bSEduardo Habkost u64 iopm_base_pa; 65c2cedf7bSEduardo Habkost u64 msrpm_base_pa; 66c2cedf7bSEduardo Habkost u64 tsc_offset; 67c2cedf7bSEduardo Habkost u32 asid; 68c2cedf7bSEduardo Habkost u8 tlb_ctl; 69c2cedf7bSEduardo Habkost u8 reserved_2[3]; 70c2cedf7bSEduardo Habkost u32 int_ctl; 71c2cedf7bSEduardo Habkost u32 int_vector; 72c2cedf7bSEduardo Habkost u32 int_state; 73c2cedf7bSEduardo Habkost u8 reserved_3[4]; 74c2cedf7bSEduardo Habkost u32 exit_code; 75c2cedf7bSEduardo Habkost u32 exit_code_hi; 76c2cedf7bSEduardo Habkost u64 exit_info_1; 77c2cedf7bSEduardo Habkost u64 exit_info_2; 78c2cedf7bSEduardo Habkost u32 exit_int_info; 79c2cedf7bSEduardo Habkost u32 exit_int_info_err; 80c2cedf7bSEduardo Habkost u64 nested_ctl; 813d5615e5SSuravee Suthikulpanit u64 avic_vapic_bar; 823d5615e5SSuravee Suthikulpanit u8 reserved_4[8]; 83c2cedf7bSEduardo Habkost u32 event_inj; 84c2cedf7bSEduardo Habkost u32 event_inj_err; 85c2cedf7bSEduardo Habkost u64 nested_cr3; 860dc92119SJanakarajan Natarajan u64 virt_ext; 878d28fec4SRoedel, Joerg u32 clean; 888d28fec4SRoedel, Joerg u32 reserved_5; 896bc31bdcSAndre Przywara u64 next_rip; 90dc25e89eSAndre Przywara u8 insn_len; 91dc25e89eSAndre Przywara u8 insn_bytes[15]; 923d5615e5SSuravee Suthikulpanit u64 avic_backing_page; /* Offset 0xe0 */ 933d5615e5SSuravee Suthikulpanit u8 reserved_6[8]; /* Offset 0xe8 */ 943d5615e5SSuravee Suthikulpanit u64 avic_logical_id; /* Offset 0xf0 */ 953d5615e5SSuravee Suthikulpanit u64 avic_physical_id; /* Offset 0xf8 */ 963d5615e5SSuravee Suthikulpanit u8 reserved_7[768]; 97c2cedf7bSEduardo Habkost }; 98c2cedf7bSEduardo Habkost 99c2cedf7bSEduardo Habkost 100c2cedf7bSEduardo Habkost #define TLB_CONTROL_DO_NOTHING 0 101c2cedf7bSEduardo Habkost #define TLB_CONTROL_FLUSH_ALL_ASID 1 10238e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID 3 10338e5e92fSJoerg Roedel #define TLB_CONTROL_FLUSH_ASID_LOCAL 7 104c2cedf7bSEduardo Habkost 105c2cedf7bSEduardo Habkost #define V_TPR_MASK 0x0f 106c2cedf7bSEduardo Habkost 107c2cedf7bSEduardo Habkost #define V_IRQ_SHIFT 8 108c2cedf7bSEduardo Habkost #define V_IRQ_MASK (1 << V_IRQ_SHIFT) 109c2cedf7bSEduardo Habkost 110c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 111c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 112c2cedf7bSEduardo Habkost 113c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 114c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 115c2cedf7bSEduardo Habkost 116c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 117c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 118c2cedf7bSEduardo Habkost 11944a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 12044a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 12144a95daeSSuravee Suthikulpanit 1228a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 123*89c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1248a77e909SJanakarajan Natarajan 125c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 126c2cedf7bSEduardo Habkost 127c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 128c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 129c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 130c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 131c2cedf7bSEduardo Habkost 132c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 133c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 134c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 135c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 136c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 137c2cedf7bSEduardo Habkost 1384a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1394a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1404a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1414a810181SJoerg Roedel 142c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_seg { 143c2cedf7bSEduardo Habkost u16 selector; 144c2cedf7bSEduardo Habkost u16 attrib; 145c2cedf7bSEduardo Habkost u32 limit; 146c2cedf7bSEduardo Habkost u64 base; 147c2cedf7bSEduardo Habkost }; 148c2cedf7bSEduardo Habkost 149c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_save_area { 150c2cedf7bSEduardo Habkost struct vmcb_seg es; 151c2cedf7bSEduardo Habkost struct vmcb_seg cs; 152c2cedf7bSEduardo Habkost struct vmcb_seg ss; 153c2cedf7bSEduardo Habkost struct vmcb_seg ds; 154c2cedf7bSEduardo Habkost struct vmcb_seg fs; 155c2cedf7bSEduardo Habkost struct vmcb_seg gs; 156c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 157c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 158c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 159c2cedf7bSEduardo Habkost struct vmcb_seg tr; 160c2cedf7bSEduardo Habkost u8 reserved_1[43]; 161c2cedf7bSEduardo Habkost u8 cpl; 162c2cedf7bSEduardo Habkost u8 reserved_2[4]; 163c2cedf7bSEduardo Habkost u64 efer; 164c2cedf7bSEduardo Habkost u8 reserved_3[112]; 165c2cedf7bSEduardo Habkost u64 cr4; 166c2cedf7bSEduardo Habkost u64 cr3; 167c2cedf7bSEduardo Habkost u64 cr0; 168c2cedf7bSEduardo Habkost u64 dr7; 169c2cedf7bSEduardo Habkost u64 dr6; 170c2cedf7bSEduardo Habkost u64 rflags; 171c2cedf7bSEduardo Habkost u64 rip; 172c2cedf7bSEduardo Habkost u8 reserved_4[88]; 173c2cedf7bSEduardo Habkost u64 rsp; 174c2cedf7bSEduardo Habkost u8 reserved_5[24]; 175c2cedf7bSEduardo Habkost u64 rax; 176c2cedf7bSEduardo Habkost u64 star; 177c2cedf7bSEduardo Habkost u64 lstar; 178c2cedf7bSEduardo Habkost u64 cstar; 179c2cedf7bSEduardo Habkost u64 sfmask; 180c2cedf7bSEduardo Habkost u64 kernel_gs_base; 181c2cedf7bSEduardo Habkost u64 sysenter_cs; 182c2cedf7bSEduardo Habkost u64 sysenter_esp; 183c2cedf7bSEduardo Habkost u64 sysenter_eip; 184c2cedf7bSEduardo Habkost u64 cr2; 185c2cedf7bSEduardo Habkost u8 reserved_6[32]; 186c2cedf7bSEduardo Habkost u64 g_pat; 187c2cedf7bSEduardo Habkost u64 dbgctl; 188c2cedf7bSEduardo Habkost u64 br_from; 189c2cedf7bSEduardo Habkost u64 br_to; 190c2cedf7bSEduardo Habkost u64 last_excp_from; 191c2cedf7bSEduardo Habkost u64 last_excp_to; 192c2cedf7bSEduardo Habkost }; 193c2cedf7bSEduardo Habkost 194c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb { 195c2cedf7bSEduardo Habkost struct vmcb_control_area control; 196c2cedf7bSEduardo Habkost struct vmcb_save_area save; 197c2cedf7bSEduardo Habkost }; 198c2cedf7bSEduardo Habkost 199c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 200c2cedf7bSEduardo Habkost 201c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 202c2cedf7bSEduardo Habkost 203c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 204c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 205c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 206c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 207c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 208c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 209c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 210c2cedf7bSEduardo Habkost 211c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 212c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 213c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 214c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 215c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 216c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 217c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 218c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 219c2cedf7bSEduardo Habkost 220c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 221c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 222c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 223c2cedf7bSEduardo Habkost 2244ee546b4SRoedel, Joerg #define INTERCEPT_CR0_READ 0 2254ee546b4SRoedel, Joerg #define INTERCEPT_CR3_READ 3 2264ee546b4SRoedel, Joerg #define INTERCEPT_CR4_READ 4 2274ee546b4SRoedel, Joerg #define INTERCEPT_CR8_READ 8 2284ee546b4SRoedel, Joerg #define INTERCEPT_CR0_WRITE (16 + 0) 2294ee546b4SRoedel, Joerg #define INTERCEPT_CR3_WRITE (16 + 3) 2304ee546b4SRoedel, Joerg #define INTERCEPT_CR4_WRITE (16 + 4) 2314ee546b4SRoedel, Joerg #define INTERCEPT_CR8_WRITE (16 + 8) 232c2cedf7bSEduardo Habkost 2333aed041aSJoerg Roedel #define INTERCEPT_DR0_READ 0 2343aed041aSJoerg Roedel #define INTERCEPT_DR1_READ 1 2353aed041aSJoerg Roedel #define INTERCEPT_DR2_READ 2 2363aed041aSJoerg Roedel #define INTERCEPT_DR3_READ 3 2373aed041aSJoerg Roedel #define INTERCEPT_DR4_READ 4 2383aed041aSJoerg Roedel #define INTERCEPT_DR5_READ 5 2393aed041aSJoerg Roedel #define INTERCEPT_DR6_READ 6 2403aed041aSJoerg Roedel #define INTERCEPT_DR7_READ 7 2413aed041aSJoerg Roedel #define INTERCEPT_DR0_WRITE (16 + 0) 2423aed041aSJoerg Roedel #define INTERCEPT_DR1_WRITE (16 + 1) 2433aed041aSJoerg Roedel #define INTERCEPT_DR2_WRITE (16 + 2) 2443aed041aSJoerg Roedel #define INTERCEPT_DR3_WRITE (16 + 3) 2453aed041aSJoerg Roedel #define INTERCEPT_DR4_WRITE (16 + 4) 2463aed041aSJoerg Roedel #define INTERCEPT_DR5_WRITE (16 + 5) 2473aed041aSJoerg Roedel #define INTERCEPT_DR6_WRITE (16 + 6) 2483aed041aSJoerg Roedel #define INTERCEPT_DR7_WRITE (16 + 7) 249c2cedf7bSEduardo Habkost 250c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 251c2cedf7bSEduardo Habkost 252c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 253c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 254c2cedf7bSEduardo Habkost 255c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 256c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 257c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 258c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 259c2cedf7bSEduardo Habkost 260c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 261c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 262c2cedf7bSEduardo Habkost 263c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 26464a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 265c2cedf7bSEduardo Habkost 266c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 267c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 268c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 269c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 270c2cedf7bSEduardo Habkost 271c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 272c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 273c2cedf7bSEduardo Habkost 274c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 275c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 276e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 277c2cedf7bSEduardo Habkost 2787ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 2797ff76d58SAndre Przywara 280dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 281c2cedf7bSEduardo Habkost 282c2cedf7bSEduardo Habkost #define SVM_VMLOAD ".byte 0x0f, 0x01, 0xda" 283c2cedf7bSEduardo Habkost #define SVM_VMRUN ".byte 0x0f, 0x01, 0xd8" 284c2cedf7bSEduardo Habkost #define SVM_VMSAVE ".byte 0x0f, 0x01, 0xdb" 285c2cedf7bSEduardo Habkost #define SVM_CLGI ".byte 0x0f, 0x01, 0xdd" 286c2cedf7bSEduardo Habkost #define SVM_STGI ".byte 0x0f, 0x01, 0xdc" 287c2cedf7bSEduardo Habkost #define SVM_INVLPGA ".byte 0x0f, 0x01, 0xdf" 288c2cedf7bSEduardo Habkost 289c2cedf7bSEduardo Habkost #endif 290