vmx.h revision 264619
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmx.h 264619 2014-04-17 18:00:07Z jhb $
27 */
28
29#ifndef _VMX_H_
30#define	_VMX_H_
31
32#include "vmcs.h"
33
34struct pmap;
35
36#define	GUEST_MSR_MAX_ENTRIES	64		/* arbitrary */
37
38struct vmxctx {
39	register_t	guest_rdi;		/* Guest state */
40	register_t	guest_rsi;
41	register_t	guest_rdx;
42	register_t	guest_rcx;
43	register_t	guest_r8;
44	register_t	guest_r9;
45	register_t	guest_rax;
46	register_t	guest_rbx;
47	register_t	guest_rbp;
48	register_t	guest_r10;
49	register_t	guest_r11;
50	register_t	guest_r12;
51	register_t	guest_r13;
52	register_t	guest_r14;
53	register_t	guest_r15;
54	register_t	guest_cr2;
55
56	register_t	host_r15;		/* Host state */
57	register_t	host_r14;
58	register_t	host_r13;
59	register_t	host_r12;
60	register_t	host_rbp;
61	register_t	host_rsp;
62	register_t	host_rbx;
63	register_t	host_rip;
64	/*
65	 * XXX todo debug registers and fpu state
66	 */
67
68	int		inst_fail_status;
69
70	long		eptgen[MAXCPU];		/* cached pmap->pm_eptgen */
71
72	/*
73	 * The 'eptp' and the 'pmap' do not change during the lifetime of
74	 * the VM so it is safe to keep a copy in each vcpu's vmxctx.
75	 */
76	vm_paddr_t	eptp;
77	struct pmap	*pmap;
78};
79
80struct vmxcap {
81	int	set;
82	uint32_t proc_ctls;
83	uint32_t proc_ctls2;
84};
85
86struct vmxstate {
87	int	lastcpu;	/* host cpu that this 'vcpu' last ran on */
88	uint16_t vpid;
89};
90
91/* virtual machine softc */
92struct vmx {
93	struct vmcs	vmcs[VM_MAXCPU];	/* one vmcs per virtual cpu */
94	char		msr_bitmap[PAGE_SIZE];
95	struct msr_entry guest_msrs[VM_MAXCPU][GUEST_MSR_MAX_ENTRIES];
96	struct vmxctx	ctx[VM_MAXCPU];
97	struct vmxcap	cap[VM_MAXCPU];
98	struct vmxstate	state[VM_MAXCPU];
99	uint64_t	eptp;
100	struct vm	*vm;
101};
102CTASSERT((offsetof(struct vmx, vmcs) & PAGE_MASK) == 0);
103CTASSERT((offsetof(struct vmx, msr_bitmap) & PAGE_MASK) == 0);
104CTASSERT((offsetof(struct vmx, guest_msrs) & 15) == 0);
105
106#define	VMX_GUEST_VMEXIT	0
107#define	VMX_VMRESUME_ERROR	1
108#define	VMX_VMLAUNCH_ERROR	2
109#define	VMX_INVEPT_ERROR	3
110int	vmx_enter_guest(struct vmxctx *ctx, int launched);
111void	vmx_exit_guest(void);
112
113u_long	vmx_fix_cr0(u_long cr0);
114u_long	vmx_fix_cr4(u_long cr4);
115
116#endif
117