2 * Copyright (c) 2011 NetApp, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #define GUEST_MSR_MAX_ENTRIES 64 /* arbitrary */
39 register_t guest_rdi; /* Guest state */
56 register_t host_r15; /* Host state */
64 * XXX todo debug registers and fpu state
70 * The pmap needs to be deactivated in vmx_enter_guest()
71 * so keep a copy of the 'pmap' in each vmxctx.
83 int lastcpu; /* host cpu that this 'vcpu' last ran on */
88 uint32_t reg[PAGE_SIZE / 4];
90 CTASSERT(sizeof(struct apic_page) == PAGE_SIZE);
92 /* Posted Interrupt Descriptor (described in section 29.6 of the Intel SDM) */
98 CTASSERT(sizeof(struct pir_desc) == 64);
100 /* virtual machine softc */
102 struct vmcs vmcs[VM_MAXCPU]; /* one vmcs per virtual cpu */
103 struct apic_page apic_page[VM_MAXCPU]; /* one apic page per vcpu */
104 char msr_bitmap[PAGE_SIZE];
105 struct pir_desc pir_desc[VM_MAXCPU];
106 struct msr_entry guest_msrs[VM_MAXCPU][GUEST_MSR_MAX_ENTRIES];
107 struct vmxctx ctx[VM_MAXCPU];
108 struct vmxcap cap[VM_MAXCPU];
109 struct vmxstate state[VM_MAXCPU];
112 long eptgen[MAXCPU]; /* cached pmap->pm_eptgen */
114 CTASSERT((offsetof(struct vmx, vmcs) & PAGE_MASK) == 0);
115 CTASSERT((offsetof(struct vmx, msr_bitmap) & PAGE_MASK) == 0);
116 CTASSERT((offsetof(struct vmx, guest_msrs) & 15) == 0);
117 CTASSERT((offsetof(struct vmx, pir_desc[0]) & 63) == 0);
119 #define VMX_GUEST_VMEXIT 0
120 #define VMX_VMRESUME_ERROR 1
121 #define VMX_VMLAUNCH_ERROR 2
122 #define VMX_INVEPT_ERROR 3
123 int vmx_enter_guest(struct vmxctx *ctx, struct vmx *vmx, int launched);
124 void vmx_call_isr(uintptr_t entry);
126 u_long vmx_fix_cr0(u_long cr0);
127 u_long vmx_fix_cr4(u_long cr4);
129 extern char vmx_exit_guest[];