vmx.h revision 330713
1285303Sgshapiro/*- 290792Sgshapiro * Copyright (c) 2011 NetApp, Inc. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * Redistribution and use in source and binary forms, with or without 690792Sgshapiro * modification, are permitted provided that the following conditions 790792Sgshapiro * are met: 8266692Sgshapiro * 1. Redistributions of source code must retain the above copyright 990792Sgshapiro * notice, this list of conditions and the following disclaimer. 1090792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright 1190792Sgshapiro * notice, this list of conditions and the following disclaimer in the 1290792Sgshapiro * documentation and/or other materials provided with the distribution. 1390792Sgshapiro * 1490792Sgshapiro * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 1590792Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1690792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1790792Sgshapiro * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 1890792Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1990792Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2090792Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2190792Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2290792Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2390792Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2490792Sgshapiro * SUCH DAMAGE. 2590792Sgshapiro * 2690792Sgshapiro * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmx.h 330713 2018-03-10 00:44:33Z tychon $ 2790792Sgshapiro */ 2890792Sgshapiro 2990792Sgshapiro#ifndef _VMX_H_ 3090792Sgshapiro#define _VMX_H_ 3190792Sgshapiro 3290792Sgshapiro#include "vmcs.h" 3390792Sgshapiro 3490792Sgshapirostruct pmap; 3590792Sgshapiro 3690792Sgshapirostruct vmxctx { 3790792Sgshapiro register_t guest_rdi; /* Guest state */ 3890792Sgshapiro register_t guest_rsi; 3990792Sgshapiro register_t guest_rdx; 4090792Sgshapiro register_t guest_rcx; 4190792Sgshapiro register_t guest_r8; 42168515Sgshapiro register_t guest_r9; 4390792Sgshapiro register_t guest_rax; 4490792Sgshapiro register_t guest_rbx; 4590792Sgshapiro register_t guest_rbp; 4690792Sgshapiro register_t guest_r10; 4790792Sgshapiro register_t guest_r11; 4890792Sgshapiro register_t guest_r12; 4990792Sgshapiro register_t guest_r13; 5090792Sgshapiro register_t guest_r14; 5190792Sgshapiro register_t guest_r15; 52168515Sgshapiro register_t guest_cr2; 5390792Sgshapiro 5490792Sgshapiro register_t host_r15; /* Host state */ 5590792Sgshapiro register_t host_r14; 5690792Sgshapiro register_t host_r13; 5790792Sgshapiro register_t host_r12; 5890792Sgshapiro register_t host_rbp; 5990792Sgshapiro register_t host_rsp; 6090792Sgshapiro register_t host_rbx; 6190792Sgshapiro /* 6290792Sgshapiro * XXX todo debug registers and fpu state 6390792Sgshapiro */ 6490792Sgshapiro 6590792Sgshapiro int inst_fail_status; 6690792Sgshapiro 6790792Sgshapiro /* 6890792Sgshapiro * The pmap needs to be deactivated in vmx_enter_guest() 6990792Sgshapiro * so keep a copy of the 'pmap' in each vmxctx. 7090792Sgshapiro */ 7190792Sgshapiro struct pmap *pmap; 7290792Sgshapiro}; 7390792Sgshapiro 7490792Sgshapirostruct vmxcap { 7590792Sgshapiro int set; 7690792Sgshapiro uint32_t proc_ctls; 7790792Sgshapiro uint32_t proc_ctls2; 7890792Sgshapiro}; 79168515Sgshapiro 8090792Sgshapirostruct vmxstate { 8190792Sgshapiro uint64_t nextrip; /* next instruction to be executed by guest */ 8290792Sgshapiro int lastcpu; /* host cpu that this 'vcpu' last ran on */ 8390792Sgshapiro uint16_t vpid; 8490792Sgshapiro}; 8590792Sgshapiro 8690792Sgshapirostruct apic_page { 8790792Sgshapiro uint32_t reg[PAGE_SIZE / 4]; 8890792Sgshapiro}; 8990792SgshapiroCTASSERT(sizeof(struct apic_page) == PAGE_SIZE); 9090792Sgshapiro 9190792Sgshapiro/* Posted Interrupt Descriptor (described in section 29.6 of the Intel SDM) */ 9290792Sgshapirostruct pir_desc { 9390792Sgshapiro uint64_t pir[4]; 9490792Sgshapiro uint64_t pending; 9590792Sgshapiro uint64_t unused[3]; 9690792Sgshapiro} __aligned(64); 9790792SgshapiroCTASSERT(sizeof(struct pir_desc) == 64); 98168515Sgshapiro 9990792Sgshapiro/* Index into the 'guest_msrs[]' array */ 10090792Sgshapiroenum { 10190792Sgshapiro IDX_MSR_LSTAR, 10290792Sgshapiro IDX_MSR_CSTAR, 10390792Sgshapiro IDX_MSR_STAR, 10490792Sgshapiro IDX_MSR_SF_MASK, 10590792Sgshapiro IDX_MSR_KGSBASE, 10690792Sgshapiro IDX_MSR_PAT, 10790792Sgshapiro GUEST_MSR_NUM /* must be the last enumeration */ 10890792Sgshapiro}; 10990792Sgshapiro 11090792Sgshapiro/* virtual machine softc */ 11190792Sgshapirostruct vmx { 11290792Sgshapiro struct vmcs vmcs[VM_MAXCPU]; /* one vmcs per virtual cpu */ 11390792Sgshapiro struct apic_page apic_page[VM_MAXCPU]; /* one apic page per vcpu */ 11490792Sgshapiro char msr_bitmap[PAGE_SIZE]; 11590792Sgshapiro struct pir_desc pir_desc[VM_MAXCPU]; 11690792Sgshapiro uint64_t guest_msrs[VM_MAXCPU][GUEST_MSR_NUM]; 11790792Sgshapiro struct vmxctx ctx[VM_MAXCPU]; 11890792Sgshapiro struct vmxcap cap[VM_MAXCPU]; 11990792Sgshapiro struct vmxstate state[VM_MAXCPU]; 12090792Sgshapiro uint64_t eptp; 12190792Sgshapiro struct vm *vm; 12290792Sgshapiro long eptgen[MAXCPU]; /* cached pmap->pm_eptgen */ 12390792Sgshapiro}; 12490792SgshapiroCTASSERT((offsetof(struct vmx, vmcs) & PAGE_MASK) == 0); 12590792SgshapiroCTASSERT((offsetof(struct vmx, msr_bitmap) & PAGE_MASK) == 0); 12690792SgshapiroCTASSERT((offsetof(struct vmx, pir_desc[0]) & 63) == 0); 12790792Sgshapiro 12890792Sgshapiro#define VMX_GUEST_VMEXIT 0 12990792Sgshapiro#define VMX_VMRESUME_ERROR 1 13090792Sgshapiro#define VMX_VMLAUNCH_ERROR 2 13190792Sgshapiro#define VMX_INVEPT_ERROR 3 13290792Sgshapiroint vmx_enter_guest(struct vmxctx *ctx, struct vmx *vmx, int launched); 13390792Sgshapirovoid vmx_call_isr(uintptr_t entry); 13490792Sgshapiro 13590792Sgshapirou_long vmx_fix_cr0(u_long cr0); 13690792Sgshapirou_long vmx_fix_cr4(u_long cr4); 13790792Sgshapiro 138285303Sgshapiroint vmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset); 139285303Sgshapiro 140285303Sgshapiroextern char vmx_exit_guest[]; 141285303Sgshapiroextern char vmx_exit_guest_flush_rsb[]; 142285303Sgshapiro 143285303Sgshapiro#endif 144285303Sgshapiro