vmcs.h revision 222605
127958Ssteve/*- 21556Srgrimes * Copyright (c) 2011 NetApp, Inc. 31556Srgrimes * All rights reserved. 41556Srgrimes * 51556Srgrimes * Redistribution and use in source and binary forms, with or without 61556Srgrimes * modification, are permitted provided that the following conditions 71556Srgrimes * are met: 81556Srgrimes * 1. Redistributions of source code must retain the above copyright 91556Srgrimes * notice, this list of conditions and the following disclaimer. 101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111556Srgrimes * notice, this list of conditions and the following disclaimer in the 121556Srgrimes * documentation and/or other materials provided with the distribution. 131556Srgrimes * 141556Srgrimes * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 151556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 171556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 181556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 191556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 201556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 211556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 221556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 231556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 241556Srgrimes * SUCH DAMAGE. 251556Srgrimes * 261556Srgrimes * $FreeBSD$ 271556Srgrimes */ 281556Srgrimes 291556Srgrimes#ifndef _VMCS_H_ 301556Srgrimes#define _VMCS_H_ 311556Srgrimes 321556Srgrimes#ifdef _KERNEL 331556Srgrimesstruct vmcs { 341556Srgrimes uint32_t identifier; 351556Srgrimes uint32_t abort_code; 361556Srgrimes char _impl_specific[PAGE_SIZE - sizeof(uint32_t) * 2]; 3727958Ssteve}; 3850471SpeterCTASSERT(sizeof(struct vmcs) == PAGE_SIZE); 391556Srgrimes 401556Srgrimes/* MSR save region is composed of an array of 'struct msr_entry' */ 411556Srgrimesstruct msr_entry { 421556Srgrimes uint32_t index; 431556Srgrimes uint32_t reserved; 441556Srgrimes uint64_t val; 451556Srgrimes 461556Srgrimes}; 471556Srgrimes 481556Srgrimesint vmcs_set_msr_save(struct vmcs *vmcs, u_long g_area, u_int g_count); 4935373Sdesint vmcs_set_defaults(struct vmcs *vmcs, u_long host_rip, u_long host_rsp, 5035417Sdes u_long ept_pml4, 511556Srgrimes uint32_t pinbased_ctls, uint32_t procbased_ctls, 521556Srgrimes uint32_t procbased_ctls2, uint32_t exit_ctls, 531556Srgrimes uint32_t entry_ctls, u_long msr_bitmap, 5437932Shoek uint16_t vpid); 551556Srgrimesint vmcs_getreg(struct vmcs *vmcs, int ident, uint64_t *retval); 561556Srgrimesint vmcs_setreg(struct vmcs *vmcs, int ident, uint64_t val); 571556Srgrimesint vmcs_getdesc(struct vmcs *vmcs, int ident, 581556Srgrimes struct seg_desc *desc); 591556Srgrimesint vmcs_setdesc(struct vmcs *vmcs, int ident, 601556Srgrimes struct seg_desc *desc); 611556Srgrimesuint64_t vmcs_read(uint32_t encoding); 621556Srgrimes 631556Srgrimes#define vmexit_instruction_length() vmcs_read(VMCS_EXIT_INSTRUCTION_LENGTH) 641556Srgrimes#define vmcs_guest_rip() vmcs_read(VMCS_GUEST_RIP) 651556Srgrimes#define vmcs_instruction_error() vmcs_read(VMCS_INSTRUCTION_ERROR) 661556Srgrimes#define vmcs_exit_reason() (vmcs_read(VMCS_EXIT_REASON) & 0xffff) 671556Srgrimes#define vmcs_exit_qualification() vmcs_read(VMCS_EXIT_QUALIFICATION) 681556Srgrimes 691556Srgrimes#endif /* _KERNEL */ 701556Srgrimes 711556Srgrimes#define VMCS_INITIAL 0xffffffffffffffff 721556Srgrimes 731556Srgrimes#define VMCS_IDENT(encoding) ((encoding) | 0x80000000) 741556Srgrimes/* 751556Srgrimes * VMCS field encodings from Appendix H, Intel Architecture Manual Vol3B. 761556Srgrimes */ 771556Srgrimes#define VMCS_INVALID_ENCODING 0xffffffff 78 79/* 16-bit control fields */ 80#define VMCS_VPID 0x00000000 81 82/* 16-bit guest-state fields */ 83#define VMCS_GUEST_ES_SELECTOR 0x00000800 84#define VMCS_GUEST_CS_SELECTOR 0x00000802 85#define VMCS_GUEST_SS_SELECTOR 0x00000804 86#define VMCS_GUEST_DS_SELECTOR 0x00000806 87#define VMCS_GUEST_FS_SELECTOR 0x00000808 88#define VMCS_GUEST_GS_SELECTOR 0x0000080A 89#define VMCS_GUEST_LDTR_SELECTOR 0x0000080C 90#define VMCS_GUEST_TR_SELECTOR 0x0000080E 91 92/* 16-bit host-state fields */ 93#define VMCS_HOST_ES_SELECTOR 0x00000C00 94#define VMCS_HOST_CS_SELECTOR 0x00000C02 95#define VMCS_HOST_SS_SELECTOR 0x00000C04 96#define VMCS_HOST_DS_SELECTOR 0x00000C06 97#define VMCS_HOST_FS_SELECTOR 0x00000C08 98#define VMCS_HOST_GS_SELECTOR 0x00000C0A 99#define VMCS_HOST_TR_SELECTOR 0x00000C0C 100 101/* 64-bit control fields */ 102#define VMCS_IO_BITMAP_A 0x00002000 103#define VMCS_IO_BITMAP_B 0x00002002 104#define VMCS_MSR_BITMAP 0x00002004 105#define VMCS_EXIT_MSR_STORE 0x00002006 106#define VMCS_EXIT_MSR_LOAD 0x00002008 107#define VMCS_ENTRY_MSR_LOAD 0x0000200A 108#define VMCS_EXECUTIVE_VMCS 0x0000200C 109#define VMCS_TSC_OFFSET 0x00002010 110#define VMCS_VIRTUAL_APIC 0x00002012 111#define VMCS_APIC_ACCESS 0x00002014 112#define VMCS_EPTP 0x0000201A 113 114/* 64-bit read-only fields */ 115#define VMCS_GUEST_PHYSICAL_ADDRESS 0x00002400 116 117/* 64-bit guest-state fields */ 118#define VMCS_LINK_POINTER 0x00002800 119#define VMCS_GUEST_IA32_DEBUGCTL 0x00002802 120#define VMCS_GUEST_IA32_PAT 0x00002804 121#define VMCS_GUEST_IA32_EFER 0x00002806 122#define VMCS_GUEST_IA32_PERF_GLOBAL_CTRL 0x00002808 123#define VMCS_GUEST_PDPTE0 0x0000280A 124#define VMCS_GUEST_PDPTE1 0x0000280C 125#define VMCS_GUEST_PDPTE2 0x0000280E 126#define VMCS_GUEST_PDPTE3 0x00002810 127 128/* 64-bit host-state fields */ 129#define VMCS_HOST_IA32_PAT 0x00002C00 130#define VMCS_HOST_IA32_EFER 0x00002C02 131#define VMCS_HOST_IA32_PERF_GLOBAL_CTRL 0x00002C04 132 133/* 32-bit control fields */ 134#define VMCS_PIN_BASED_CTLS 0x00004000 135#define VMCS_PRI_PROC_BASED_CTLS 0x00004002 136#define VMCS_EXCEPTION_BITMAP 0x00004004 137#define VMCS_PF_ERROR_MASK 0x00004006 138#define VMCS_PF_ERROR_MATCH 0x00004008 139#define VMCS_CR3_TARGET_COUNT 0x0000400A 140#define VMCS_EXIT_CTLS 0x0000400C 141#define VMCS_EXIT_MSR_STORE_COUNT 0x0000400E 142#define VMCS_EXIT_MSR_LOAD_COUNT 0x00004010 143#define VMCS_ENTRY_CTLS 0x00004012 144#define VMCS_ENTRY_MSR_LOAD_COUNT 0x00004014 145#define VMCS_ENTRY_INTR_INFO 0x00004016 146#define VMCS_ENTRY_EXCEPTION_ERROR 0x00004018 147#define VMCS_ENTRY_INST_LENGTH 0x0000401A 148#define VMCS_TPR_THRESHOLD 0x0000401C 149#define VMCS_SEC_PROC_BASED_CTLS 0x0000401E 150#define VMCS_PLE_GAP 0x00004020 151#define VMCS_PLE_WINDOW 0x00004022 152 153/* 32-bit read-only data fields */ 154#define VMCS_INSTRUCTION_ERROR 0x00004400 155#define VMCS_EXIT_REASON 0x00004402 156#define VMCS_EXIT_INTERRUPTION_INFO 0x00004404 157#define VMCS_EXIT_INTERRUPTION_ERROR 0x00004406 158#define VMCS_IDT_VECTORING_INFO 0x00004408 159#define VMCS_IDT_VECTORING_ERROR 0x0000440A 160#define VMCS_EXIT_INSTRUCTION_LENGTH 0x0000440C 161#define VMCS_EXIT_INSTRUCTION_INFO 0x0000440E 162 163/* 32-bit guest-state fields */ 164#define VMCS_GUEST_ES_LIMIT 0x00004800 165#define VMCS_GUEST_CS_LIMIT 0x00004802 166#define VMCS_GUEST_SS_LIMIT 0x00004804 167#define VMCS_GUEST_DS_LIMIT 0x00004806 168#define VMCS_GUEST_FS_LIMIT 0x00004808 169#define VMCS_GUEST_GS_LIMIT 0x0000480A 170#define VMCS_GUEST_LDTR_LIMIT 0x0000480C 171#define VMCS_GUEST_TR_LIMIT 0x0000480E 172#define VMCS_GUEST_GDTR_LIMIT 0x00004810 173#define VMCS_GUEST_IDTR_LIMIT 0x00004812 174#define VMCS_GUEST_ES_ACCESS_RIGHTS 0x00004814 175#define VMCS_GUEST_CS_ACCESS_RIGHTS 0x00004816 176#define VMCS_GUEST_SS_ACCESS_RIGHTS 0x00004818 177#define VMCS_GUEST_DS_ACCESS_RIGHTS 0x0000481A 178#define VMCS_GUEST_FS_ACCESS_RIGHTS 0x0000481C 179#define VMCS_GUEST_GS_ACCESS_RIGHTS 0x0000481E 180#define VMCS_GUEST_LDTR_ACCESS_RIGHTS 0x00004820 181#define VMCS_GUEST_TR_ACCESS_RIGHTS 0x00004822 182#define VMCS_GUEST_INTERRUPTIBILITY 0x00004824 183#define VMCS_GUEST_ACTIVITY 0x00004826 184#define VMCS_GUEST_SMBASE 0x00004828 185#define VMCS_GUEST_IA32_SYSENTER_CS 0x0000482A 186#define VMCS_PREEMPTION_TIMER_VALUE 0x0000482E 187 188/* 32-bit host state fields */ 189#define VMCS_HOST_IA32_SYSENTER_CS 0x00004C00 190 191/* Natural Width control fields */ 192#define VMCS_CR0_MASK 0x00006000 193#define VMCS_CR4_MASK 0x00006002 194#define VMCS_CR0_SHADOW 0x00006004 195#define VMCS_CR4_SHADOW 0x00006006 196#define VMCS_CR3_TARGET0 0x00006008 197#define VMCS_CR3_TARGET1 0x0000600A 198#define VMCS_CR3_TARGET2 0x0000600C 199#define VMCS_CR3_TARGET3 0x0000600E 200 201/* Natural Width read-only fields */ 202#define VMCS_EXIT_QUALIFICATION 0x00006400 203#define VMCS_IO_RCX 0x00006402 204#define VMCS_IO_RSI 0x00006404 205#define VMCS_IO_RDI 0x00006406 206#define VMCS_IO_RIP 0x00006408 207#define VMCS_GUEST_LINEAR_ADDRESS 0x0000640A 208 209/* Natural Width guest-state fields */ 210#define VMCS_GUEST_CR0 0x00006800 211#define VMCS_GUEST_CR3 0x00006802 212#define VMCS_GUEST_CR4 0x00006804 213#define VMCS_GUEST_ES_BASE 0x00006806 214#define VMCS_GUEST_CS_BASE 0x00006808 215#define VMCS_GUEST_SS_BASE 0x0000680A 216#define VMCS_GUEST_DS_BASE 0x0000680C 217#define VMCS_GUEST_FS_BASE 0x0000680E 218#define VMCS_GUEST_GS_BASE 0x00006810 219#define VMCS_GUEST_LDTR_BASE 0x00006812 220#define VMCS_GUEST_TR_BASE 0x00006814 221#define VMCS_GUEST_GDTR_BASE 0x00006816 222#define VMCS_GUEST_IDTR_BASE 0x00006818 223#define VMCS_GUEST_DR7 0x0000681A 224#define VMCS_GUEST_RSP 0x0000681C 225#define VMCS_GUEST_RIP 0x0000681E 226#define VMCS_GUEST_RFLAGS 0x00006820 227#define VMCS_GUEST_PENDING_DBG_EXCEPTIONS 0x00006822 228#define VMCS_GUEST_IA32_SYSENTER_ESP 0x00006824 229#define VMCS_GUEST_IA32_SYSENTER_EIP 0x00006826 230 231/* Natural Width host-state fields */ 232#define VMCS_HOST_CR0 0x00006C00 233#define VMCS_HOST_CR3 0x00006C02 234#define VMCS_HOST_CR4 0x00006C04 235#define VMCS_HOST_FS_BASE 0x00006C06 236#define VMCS_HOST_GS_BASE 0x00006C08 237#define VMCS_HOST_TR_BASE 0x00006C0A 238#define VMCS_HOST_GDTR_BASE 0x00006C0C 239#define VMCS_HOST_IDTR_BASE 0x00006C0E 240#define VMCS_HOST_IA32_SYSENTER_ESP 0x00006C10 241#define VMCS_HOST_IA32_SYSENTER_EIP 0x00006C12 242#define VMCS_HOST_RSP 0x00006C14 243#define VMCS_HOST_RIP 0x00006c16 244 245/* 246 * VM instruction error numbers 247 */ 248#define VMRESUME_WITH_NON_LAUNCHED_VMCS 5 249 250/* 251 * VMCS exit reasons 252 */ 253#define EXIT_REASON_EXCEPTION 0 254#define EXIT_REASON_EXT_INTR 1 255#define EXIT_REASON_TRIPLE_FAULT 2 256#define EXIT_REASON_INIT 3 257#define EXIT_REASON_SIPI 4 258#define EXIT_REASON_IO_SMI 5 259#define EXIT_REASON_SMI 6 260#define EXIT_REASON_INTR_WINDOW 7 261#define EXIT_REASON_NMI_WINDOW 8 262#define EXIT_REASON_TASK_SWITCH 9 263#define EXIT_REASON_CPUID 10 264#define EXIT_REASON_GETSEC 11 265#define EXIT_REASON_HLT 12 266#define EXIT_REASON_INVD 13 267#define EXIT_REASON_INVLPG 14 268#define EXIT_REASON_RDPMC 15 269#define EXIT_REASON_RDTSC 16 270#define EXIT_REASON_RSM 17 271#define EXIT_REASON_VMCALL 18 272#define EXIT_REASON_VMCLEAR 19 273#define EXIT_REASON_VMLAUNCH 20 274#define EXIT_REASON_VMPTRLD 21 275#define EXIT_REASON_VMPTRST 22 276#define EXIT_REASON_VMREAD 23 277#define EXIT_REASON_VMRESUME 24 278#define EXIT_REASON_VMWRITE 25 279#define EXIT_REASON_VMXOFF 26 280#define EXIT_REASON_VMXON 27 281#define EXIT_REASON_CR_ACCESS 28 282#define EXIT_REASON_DR_ACCESS 29 283#define EXIT_REASON_INOUT 30 284#define EXIT_REASON_RDMSR 31 285#define EXIT_REASON_WRMSR 32 286#define EXIT_REASON_INVAL_VMCS 33 287#define EXIT_REASON_INVAL_MSR 34 288#define EXIT_REASON_MWAIT 36 289#define EXIT_REASON_MTF 37 290#define EXIT_REASON_MONITOR 39 291#define EXIT_REASON_PAUSE 40 292#define EXIT_REASON_MCE 41 293#define EXIT_REASON_TPR 43 294#define EXIT_REASON_APIC 44 295#define EXIT_REASON_GDTR_IDTR 46 296#define EXIT_REASON_LDTR_TR 47 297#define EXIT_REASON_EPT_FAULT 48 298#define EXIT_REASON_EPT_MISCONFIG 49 299#define EXIT_REASON_INVEPT 50 300#define EXIT_REASON_RDTSCP 51 301#define EXIT_REASON_VMX_PREEMPT 52 302#define EXIT_REASON_INVVPID 53 303#define EXIT_REASON_WBINVD 54 304#define EXIT_REASON_XSETBV 55 305 306/* 307 * VMCS interrupt information fields 308 */ 309#define VMCS_INTERRUPTION_INFO_VALID (1U << 31) 310#define VMCS_INTERRUPTION_INFO_HW_INTR (0 << 8) 311#define VMCS_INTERRUPTION_INFO_NMI (2 << 8) 312 313/* 314 * VMCS Guest interruptibility field 315 */ 316#define VMCS_INTERRUPTIBILITY_STI_BLOCKING (1 << 0) 317#define VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING (1 << 1) 318#define VMCS_INTERRUPTIBILITY_SMI_BLOCKING (1 << 2) 319#define VMCS_INTERRUPTIBILITY_NMI_BLOCKING (1 << 3) 320 321/* 322 * Exit qualification for EXIT_REASON_INVAL_VMCS 323 */ 324#define EXIT_QUAL_NMI_WHILE_STI_BLOCKING 3 325 326#endif 327