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 110*640bd6e5SJanakarajan Natarajan #define V_GIF_SHIFT 9 111*640bd6e5SJanakarajan Natarajan #define V_GIF_MASK (1 << V_GIF_SHIFT) 112*640bd6e5SJanakarajan Natarajan 113c2cedf7bSEduardo Habkost #define V_INTR_PRIO_SHIFT 16 114c2cedf7bSEduardo Habkost #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) 115c2cedf7bSEduardo Habkost 116c2cedf7bSEduardo Habkost #define V_IGN_TPR_SHIFT 20 117c2cedf7bSEduardo Habkost #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) 118c2cedf7bSEduardo Habkost 119c2cedf7bSEduardo Habkost #define V_INTR_MASKING_SHIFT 24 120c2cedf7bSEduardo Habkost #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) 121c2cedf7bSEduardo Habkost 122*640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_SHIFT 25 123*640bd6e5SJanakarajan Natarajan #define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT) 124*640bd6e5SJanakarajan Natarajan 12544a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_SHIFT 31 12644a95daeSSuravee Suthikulpanit #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) 12744a95daeSSuravee Suthikulpanit 1288a77e909SJanakarajan Natarajan #define LBR_CTL_ENABLE_MASK BIT_ULL(0) 12989c8a498SJanakarajan Natarajan #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) 1308a77e909SJanakarajan Natarajan 131c2cedf7bSEduardo Habkost #define SVM_INTERRUPT_SHADOW_MASK 1 132c2cedf7bSEduardo Habkost 133c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_SHIFT 2 134c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_SHIFT 3 135c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_SHIFT 4 136c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_SHIFT 7 137c2cedf7bSEduardo Habkost 138c2cedf7bSEduardo Habkost #define SVM_IOIO_TYPE_MASK 1 139c2cedf7bSEduardo Habkost #define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT) 140c2cedf7bSEduardo Habkost #define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT) 141c2cedf7bSEduardo Habkost #define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT) 142c2cedf7bSEduardo Habkost #define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT) 143c2cedf7bSEduardo Habkost 1444a810181SJoerg Roedel #define SVM_VM_CR_VALID_MASK 0x001fULL 1454a810181SJoerg Roedel #define SVM_VM_CR_SVM_LOCK_MASK 0x0008ULL 1464a810181SJoerg Roedel #define SVM_VM_CR_SVM_DIS_MASK 0x0010ULL 1474a810181SJoerg Roedel 148c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_seg { 149c2cedf7bSEduardo Habkost u16 selector; 150c2cedf7bSEduardo Habkost u16 attrib; 151c2cedf7bSEduardo Habkost u32 limit; 152c2cedf7bSEduardo Habkost u64 base; 153c2cedf7bSEduardo Habkost }; 154c2cedf7bSEduardo Habkost 155c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb_save_area { 156c2cedf7bSEduardo Habkost struct vmcb_seg es; 157c2cedf7bSEduardo Habkost struct vmcb_seg cs; 158c2cedf7bSEduardo Habkost struct vmcb_seg ss; 159c2cedf7bSEduardo Habkost struct vmcb_seg ds; 160c2cedf7bSEduardo Habkost struct vmcb_seg fs; 161c2cedf7bSEduardo Habkost struct vmcb_seg gs; 162c2cedf7bSEduardo Habkost struct vmcb_seg gdtr; 163c2cedf7bSEduardo Habkost struct vmcb_seg ldtr; 164c2cedf7bSEduardo Habkost struct vmcb_seg idtr; 165c2cedf7bSEduardo Habkost struct vmcb_seg tr; 166c2cedf7bSEduardo Habkost u8 reserved_1[43]; 167c2cedf7bSEduardo Habkost u8 cpl; 168c2cedf7bSEduardo Habkost u8 reserved_2[4]; 169c2cedf7bSEduardo Habkost u64 efer; 170c2cedf7bSEduardo Habkost u8 reserved_3[112]; 171c2cedf7bSEduardo Habkost u64 cr4; 172c2cedf7bSEduardo Habkost u64 cr3; 173c2cedf7bSEduardo Habkost u64 cr0; 174c2cedf7bSEduardo Habkost u64 dr7; 175c2cedf7bSEduardo Habkost u64 dr6; 176c2cedf7bSEduardo Habkost u64 rflags; 177c2cedf7bSEduardo Habkost u64 rip; 178c2cedf7bSEduardo Habkost u8 reserved_4[88]; 179c2cedf7bSEduardo Habkost u64 rsp; 180c2cedf7bSEduardo Habkost u8 reserved_5[24]; 181c2cedf7bSEduardo Habkost u64 rax; 182c2cedf7bSEduardo Habkost u64 star; 183c2cedf7bSEduardo Habkost u64 lstar; 184c2cedf7bSEduardo Habkost u64 cstar; 185c2cedf7bSEduardo Habkost u64 sfmask; 186c2cedf7bSEduardo Habkost u64 kernel_gs_base; 187c2cedf7bSEduardo Habkost u64 sysenter_cs; 188c2cedf7bSEduardo Habkost u64 sysenter_esp; 189c2cedf7bSEduardo Habkost u64 sysenter_eip; 190c2cedf7bSEduardo Habkost u64 cr2; 191c2cedf7bSEduardo Habkost u8 reserved_6[32]; 192c2cedf7bSEduardo Habkost u64 g_pat; 193c2cedf7bSEduardo Habkost u64 dbgctl; 194c2cedf7bSEduardo Habkost u64 br_from; 195c2cedf7bSEduardo Habkost u64 br_to; 196c2cedf7bSEduardo Habkost u64 last_excp_from; 197c2cedf7bSEduardo Habkost u64 last_excp_to; 198c2cedf7bSEduardo Habkost }; 199c2cedf7bSEduardo Habkost 200c2cedf7bSEduardo Habkost struct __attribute__ ((__packed__)) vmcb { 201c2cedf7bSEduardo Habkost struct vmcb_control_area control; 202c2cedf7bSEduardo Habkost struct vmcb_save_area save; 203c2cedf7bSEduardo Habkost }; 204c2cedf7bSEduardo Habkost 205c2cedf7bSEduardo Habkost #define SVM_CPUID_FUNC 0x8000000a 206c2cedf7bSEduardo Habkost 207c2cedf7bSEduardo Habkost #define SVM_VM_CR_SVM_DISABLE 4 208c2cedf7bSEduardo Habkost 209c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_SHIFT 4 210c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_SHIFT 5 211c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_SHIFT 7 212c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_SHIFT 8 213c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_SHIFT 9 214c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_SHIFT 10 215c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_SHIFT 11 216c2cedf7bSEduardo Habkost 217c2cedf7bSEduardo Habkost #define SVM_SELECTOR_TYPE_MASK (0xf) 218c2cedf7bSEduardo Habkost #define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT) 219c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT) 220c2cedf7bSEduardo Habkost #define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT) 221c2cedf7bSEduardo Habkost #define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT) 222c2cedf7bSEduardo Habkost #define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT) 223c2cedf7bSEduardo Habkost #define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT) 224c2cedf7bSEduardo Habkost #define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT) 225c2cedf7bSEduardo Habkost 226c2cedf7bSEduardo Habkost #define SVM_SELECTOR_WRITE_MASK (1 << 1) 227c2cedf7bSEduardo Habkost #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 228c2cedf7bSEduardo Habkost #define SVM_SELECTOR_CODE_MASK (1 << 3) 229c2cedf7bSEduardo Habkost 2304ee546b4SRoedel, Joerg #define INTERCEPT_CR0_READ 0 2314ee546b4SRoedel, Joerg #define INTERCEPT_CR3_READ 3 2324ee546b4SRoedel, Joerg #define INTERCEPT_CR4_READ 4 2334ee546b4SRoedel, Joerg #define INTERCEPT_CR8_READ 8 2344ee546b4SRoedel, Joerg #define INTERCEPT_CR0_WRITE (16 + 0) 2354ee546b4SRoedel, Joerg #define INTERCEPT_CR3_WRITE (16 + 3) 2364ee546b4SRoedel, Joerg #define INTERCEPT_CR4_WRITE (16 + 4) 2374ee546b4SRoedel, Joerg #define INTERCEPT_CR8_WRITE (16 + 8) 238c2cedf7bSEduardo Habkost 2393aed041aSJoerg Roedel #define INTERCEPT_DR0_READ 0 2403aed041aSJoerg Roedel #define INTERCEPT_DR1_READ 1 2413aed041aSJoerg Roedel #define INTERCEPT_DR2_READ 2 2423aed041aSJoerg Roedel #define INTERCEPT_DR3_READ 3 2433aed041aSJoerg Roedel #define INTERCEPT_DR4_READ 4 2443aed041aSJoerg Roedel #define INTERCEPT_DR5_READ 5 2453aed041aSJoerg Roedel #define INTERCEPT_DR6_READ 6 2463aed041aSJoerg Roedel #define INTERCEPT_DR7_READ 7 2473aed041aSJoerg Roedel #define INTERCEPT_DR0_WRITE (16 + 0) 2483aed041aSJoerg Roedel #define INTERCEPT_DR1_WRITE (16 + 1) 2493aed041aSJoerg Roedel #define INTERCEPT_DR2_WRITE (16 + 2) 2503aed041aSJoerg Roedel #define INTERCEPT_DR3_WRITE (16 + 3) 2513aed041aSJoerg Roedel #define INTERCEPT_DR4_WRITE (16 + 4) 2523aed041aSJoerg Roedel #define INTERCEPT_DR5_WRITE (16 + 5) 2533aed041aSJoerg Roedel #define INTERCEPT_DR6_WRITE (16 + 6) 2543aed041aSJoerg Roedel #define INTERCEPT_DR7_WRITE (16 + 7) 255c2cedf7bSEduardo Habkost 256c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VEC_MASK 0xff 257c2cedf7bSEduardo Habkost 258c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SHIFT 8 259c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT) 260c2cedf7bSEduardo Habkost 261c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT) 262c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT) 263c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT) 264c2cedf7bSEduardo Habkost #define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT) 265c2cedf7bSEduardo Habkost 266c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID (1 << 31) 267c2cedf7bSEduardo Habkost #define SVM_EVTINJ_VALID_ERR (1 << 11) 268c2cedf7bSEduardo Habkost 269c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 27064a7ec06SGleb Natapov #define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK 271c2cedf7bSEduardo Habkost 272c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 273c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 274c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT 275c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT 276c2cedf7bSEduardo Habkost 277c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID 278c2cedf7bSEduardo Habkost #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR 279c2cedf7bSEduardo Habkost 280c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_IRET 36 281c2cedf7bSEduardo Habkost #define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 282e269fb21SJan Kiszka #define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 283c2cedf7bSEduardo Habkost 2847ff76d58SAndre Przywara #define SVM_EXITINFO_REG_MASK 0x0F 2857ff76d58SAndre Przywara 286dc77270fSAvi Kivity #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) 287c2cedf7bSEduardo Habkost 288c2cedf7bSEduardo Habkost #define SVM_VMLOAD ".byte 0x0f, 0x01, 0xda" 289c2cedf7bSEduardo Habkost #define SVM_VMRUN ".byte 0x0f, 0x01, 0xd8" 290c2cedf7bSEduardo Habkost #define SVM_VMSAVE ".byte 0x0f, 0x01, 0xdb" 291c2cedf7bSEduardo Habkost #define SVM_CLGI ".byte 0x0f, 0x01, 0xdd" 292c2cedf7bSEduardo Habkost #define SVM_STGI ".byte 0x0f, 0x01, 0xdc" 293c2cedf7bSEduardo Habkost #define SVM_INVLPGA ".byte 0x0f, 0x01, 0xdf" 294c2cedf7bSEduardo Habkost 295c2cedf7bSEduardo Habkost #endif 296