3 * This file is part of the Palacios Virtual Machine Monitor developed
4 * by the V3VEE Project with funding from the United States National
5 * Science Foundation and the Department of Energy.
7 * The V3VEE Project is a joint project between Northwestern University
8 * and the University of New Mexico. You can find out more at
11 * Copyright (c) 2008, Peter Dinda <pdinda@northwestern.edu>
12 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
13 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
14 * All rights reserved.
16 * Author: Peter Dinda <pdinda@northwestern.edu>
17 * Author: Jack Lange <jarusl@cs.northwestern.edu>
19 * This is free software. You are permitted to use,
20 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
29 #include <palacios/vmm_types.h>
30 #include <palacios/vmcs.h>
31 #include <palacios/vmm.h>
32 #include <palacios/vm_guest.h>
34 // Intel VMX Specific MSRs
35 #define VMX_FEATURE_CONTROL_MSR 0x0000003a
36 #define VMX_BASIC_MSR 0x00000480
37 #define VMX_PINBASED_CTLS_MSR 0x00000481
38 #define VMX_PROCBASED_CTLS_MSR 0x00000482
39 #define VMX_EXIT_CTLS_MSR 0x00000483
40 #define VMX_ENTRY_CTLS_MSR 0x00000484
41 #define VMX_MISC_MSR 0x00000485
42 #define VMX_CR0_FIXED0_MSR 0x00000486
43 #define VMX_CR0_FIXED1_MSR 0x00000487
44 #define VMX_CR4_FIXED0_MSR 0x00000488
45 #define VMX_CR4_FIXED1_MSR 0x00000489
46 #define VMX_VMCS_ENUM_MSR 0x0000048A
49 #define VMX_FAIL_INVALID 1
50 #define VMX_FAIL_VALID 2
53 #define FEATURE_CONTROL_LOCK 0x00000001
54 #define FEATURE_CONTROL_VMXON 0x00000004
55 #define FEATURE_CONTROL_VALID ( FEATURE_CONTROL_LOCK | FEATURE_CONTROL_VMXON )
58 #define CPUID_1_ECX_VTXFLAG 0x00000020
61 struct vmx_pin_ctrls {
65 uint_t ext_int_exit : 1;
70 uint_t active_preempt_timer : 1;
72 } __attribute__((packed));
73 } __attribute__((packed));
74 } __attribute__((packed));
77 struct vmx_pri_proc_ctrls {
82 uint_t int_wndw_exit : 1;
83 uint_t tsc_offset : 1;
87 uint_t invlpg_exit : 1;
88 uint_t mwait_exit : 1;
89 uint_t rdpmc_exit : 1;
90 uint_t rdtsc_exit : 1;
92 uint_t cr3_ld_exit : 1;
93 uint_t cr3_str_exit : 1;
95 uint_t cr8_ld_exit : 1;
96 uint_t cr8_str_exit : 1;
98 uint_t nmi_wndw_exit : 1;
99 uint_t mov_dr_exit : 1;
100 uint_t uncon_io_exit : 1;
101 uint_t use_io_bitmap : 1;
103 uint_t monitor_trap : 1;
104 uint_t use_msr_bitmap : 1;
105 uint_t monitor_exit : 1;
106 uint_t pause_exit : 1;
107 uint_t sec_ctrls : 1;
108 } __attribute__((packed));
109 } __attribute__((packed));
110 } __attribute__((packed));
112 struct vmx_sec_proc_ctrls {
116 uint_t virt_apic_acc : 1;
117 uint_t enable_ept : 1;
118 uint_t desc_table_exit : 1;
119 uint_t enable_rdtscp : 1;
120 uint_t virt_x2apic : 1;
121 uint_t enable_vpid : 1;
122 uint_t unrstrct_guest : 1;
124 uint_t pause_loop_exit : 1;
126 } __attribute__((packed));
127 } __attribute__((packed));
128 } __attribute__((packed));
130 struct vmx_exit_ctrls {
135 uint_t save_dbg_ctrls : 1;
137 uint_t host_64_on : 1;
139 uint_t ld_perf_glbl_ctrl : 1;
141 uint_t ack_int_on_exit : 1;
145 uint_t save_efer : 1;
147 uint_t save_preempt_timer : 1;
149 } __attribute__((packed));
150 } __attribute__((packed));
151 } __attribute__((packed));
153 struct vmx_entry_ctrls {
158 uint_t ld_dbg_ctrls : 1;
160 uint_t guest_ia32e : 1;
161 uint_t smm_entry : 1;
162 uint_t no_dual_monitor : 1;
164 uint_t ld_perf_glbl_ctrl : 1;
168 } __attribute__((packed));
169 } __attribute__((packed));
170 } __attribute__((packed));
172 struct vmx_basic_msr {
174 uint_t regionSize : 13;
175 uint_t rsvd1 : 4; // Always 0
176 uint_t physWidth : 1;
177 uint_t smm : 1; // Always 1
179 uint_t rsvd2 : 10; // Always 0
180 } __attribute__((packed));
187 struct tss_descriptor {
191 /* In IA32, type follows the form 10B1b, where B is the busy flag */
197 uint_t available : 1;
200 uint_t granularity : 1;
208 }__attribute__((packed));
210 struct vmcs_host_state {
211 struct v3_segment gdtr;
212 struct v3_segment idtr;
213 struct v3_segment tr;
218 struct vmcs_host_state host_state;
220 addr_t vmcs_ptr_phys;
224 /* VMX Control Fields */
225 struct vmx_pin_ctrls pin_ctrls;
226 struct vmx_pri_proc_ctrls pri_proc_ctrls;
227 struct vmx_sec_proc_ctrls sec_proc_ctrls;
228 struct vmx_exit_ctrls exit_ctrls;
229 struct vmx_entry_ctrls entry_ctrls;
232 int v3_is_vmx_capable();
233 void v3_init_vmx_hooks(struct v3_ctrl_ops * vm_ops);
234 void v3_init_vmx_cpu(int cpu_id);
237 #endif // ! __V3VEE__