2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011 NetApp, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 register_t guest_rdi; /* Guest state */
61 register_t host_r15; /* Host state */
74 uint64_t host_debugctl;
80 * The pmap needs to be deactivated in vmx_enter_guest()
81 * so keep a copy of the 'pmap' in each vmxctx.
94 uint64_t nextrip; /* next instruction to be executed by guest */
95 int lastcpu; /* host cpu that this 'vcpu' last ran on */
100 uint32_t reg[PAGE_SIZE / 4];
102 CTASSERT(sizeof(struct apic_page) == PAGE_SIZE);
104 /* Posted Interrupt Descriptor (described in section 29.6 of the Intel SDM) */
110 CTASSERT(sizeof(struct pir_desc) == 64);
112 /* Index into the 'guest_msrs[]' array */
120 GUEST_MSR_NUM /* must be the last enumeration */
123 /* virtual machine softc */
125 struct vmcs vmcs[VM_MAXCPU]; /* one vmcs per virtual cpu */
126 struct apic_page apic_page[VM_MAXCPU]; /* one apic page per vcpu */
127 char msr_bitmap[PAGE_SIZE];
128 struct pir_desc pir_desc[VM_MAXCPU];
129 uint64_t guest_msrs[VM_MAXCPU][GUEST_MSR_NUM];
130 struct vmxctx ctx[VM_MAXCPU];
131 struct vmxcap cap[VM_MAXCPU];
132 struct vmxstate state[VM_MAXCPU];
135 long eptgen[MAXCPU]; /* cached pmap->pm_eptgen */
137 CTASSERT((offsetof(struct vmx, vmcs) & PAGE_MASK) == 0);
138 CTASSERT((offsetof(struct vmx, msr_bitmap) & PAGE_MASK) == 0);
139 CTASSERT((offsetof(struct vmx, pir_desc[0]) & 63) == 0);
141 #define VMX_GUEST_VMEXIT 0
142 #define VMX_VMRESUME_ERROR 1
143 #define VMX_VMLAUNCH_ERROR 2
144 #define VMX_INVEPT_ERROR 3
145 int vmx_enter_guest(struct vmxctx *ctx, struct vmx *vmx, int launched);
146 void vmx_call_isr(uintptr_t entry);
148 u_long vmx_fix_cr0(u_long cr0);
149 u_long vmx_fix_cr4(u_long cr4);
151 int vmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset);
153 extern char vmx_exit_guest[];
154 extern char vmx_exit_guest_flush_rsb[];