4 * This file is part of the Palacios Virtual Machine Monitor developed
5 * by the V3VEE Project with funding from the United States National
6 * Science Foundation and the Department of Energy.
8 * The V3VEE Project is a joint project between Northwestern University
9 * and the University of New Mexico. You can find out more at
10 * http://www.v3vee.org
12 * Copyright (c) 2008, Peter Dinda <pdinda@northwestern.edu>
13 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
14 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
15 * All rights reserved.
17 * Author: Peter Dinda <pdinda@northwestern.edu>
18 * Author: Jack Lange <jarusl@cs.northwestern.edu>
20 * This is free software. You are permitted to use,
21 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
30 #include <palacios/vmm_types.h>
31 #include <palacios/vmcs.h>
32 #include <palacios/vmm.h>
33 #include <palacios/vm_guest.h>
35 // Intel VMX Specific MSRs
36 #define VMX_FEATURE_CONTROL_MSR 0x0000003a
37 #define VMX_BASIC_MSR 0x00000480
38 #define VMX_PINBASED_CTLS_MSR 0x00000481
39 #define VMX_PROCBASED_CTLS_MSR 0x00000482
40 #define VMX_EXIT_CTLS_MSR 0x00000483
41 #define VMX_ENTRY_CTLS_MSR 0x00000484
42 #define VMX_MISC_MSR 0x00000485
43 #define VMX_CR0_FIXED0_MSR 0x00000486
44 #define VMX_CR0_FIXED1_MSR 0x00000487
45 #define VMX_CR4_FIXED0_MSR 0x00000488
46 #define VMX_CR4_FIXED1_MSR 0x00000489
47 #define VMX_VMCS_ENUM_MSR 0x0000048A
50 #define VMX_FAIL_INVALID 1
51 #define VMX_FAIL_VALID 2
54 #define FEATURE_CONTROL_LOCK 0x00000001
55 #define FEATURE_CONTROL_VMXON 0x00000004
56 #define FEATURE_CONTROL_VALID ( FEATURE_CONTROL_LOCK | FEATURE_CONTROL_VMXON )
59 #define CPUID_1_ECX_VTXFLAG 0x00000020
62 struct vmx_pin_ctrls {
66 uint_t ext_int_exit : 1;
71 uint_t active_preempt_timer : 1;
73 } __attribute__((packed));
74 } __attribute__((packed));
75 } __attribute__((packed));
78 struct vmx_pri_proc_ctrls {
83 uint_t int_wndw_exit : 1;
84 uint_t tsc_offset : 1;
88 uint_t invlpg_exit : 1;
89 uint_t mwait_exit : 1;
90 uint_t rdpmc_exit : 1;
91 uint_t rdtsc_exit : 1;
93 uint_t cr3_ld_exit : 1;
94 uint_t cr3_str_exit : 1;
96 uint_t cr8_ld_exit : 1;
97 uint_t cr8_str_exit : 1;
99 uint_t nmi_wndw_exit : 1;
100 uint_t mov_dr_exit : 1;
101 uint_t uncon_io_exit : 1;
102 uint_t use_io_bitmap : 1;
104 uint_t monitor_trap : 1;
105 uint_t use_msr_bitmap : 1;
106 uint_t monitor_exit : 1;
107 uint_t pause_exit : 1;
108 uint_t sec_ctrls : 1;
109 } __attribute__((packed));
110 } __attribute__((packed));
111 } __attribute__((packed));
113 struct vmx_sec_proc_ctrls {
117 uint_t virt_apic_acc : 1;
118 uint_t enable_ept : 1;
119 uint_t desc_table_exit : 1;
120 uint_t enable_rdtscp : 1;
121 uint_t virt_x2apic : 1;
122 uint_t enable_vpid : 1;
123 uint_t unrstrct_guest : 1;
125 uint_t pause_loop_exit : 1;
127 } __attribute__((packed));
128 } __attribute__((packed));
129 } __attribute__((packed));
131 struct vmx_exit_ctrls {
136 uint_t save_dbg_ctrls : 1;
138 uint_t host_64_on : 1;
140 uint_t ld_perf_glbl_ctrl : 1;
142 uint_t ack_int_on_exit : 1;
146 uint_t save_efer : 1;
148 uint_t save_preempt_timer : 1;
150 } __attribute__((packed));
151 } __attribute__((packed));
152 } __attribute__((packed));
154 struct vmx_entry_ctrls {
159 uint_t ld_dbg_ctrls : 1;
161 uint_t guest_ia32e : 1;
162 uint_t smm_entry : 1;
163 uint_t no_dual_monitor : 1;
165 uint_t ld_perf_glbl_ctrl : 1;
169 } __attribute__((packed));
170 } __attribute__((packed));
171 } __attribute__((packed));
173 struct vmx_basic_msr {
175 uint_t regionSize : 13;
176 uint_t rsvd1 : 4; // Always 0
177 uint_t physWidth : 1;
178 uint_t smm : 1; // Always 1
180 uint_t rsvd2 : 10; // Always 0
181 } __attribute__((packed));
188 struct tss_descriptor {
192 /* In IA32, type follows the form 10B1b, where B is the busy flag */
198 uint_t available : 1;
201 uint_t granularity : 1;
209 }__attribute__((packed));
211 struct vmcs_host_state {
212 struct v3_segment gdtr;
213 struct v3_segment idtr;
214 struct v3_segment tr;
223 struct vmcs_host_state host_state;
225 addr_t vmcs_ptr_phys;
229 v3_reg_t guest_cr4; /// corresponds to the CR4 Read shadow
232 /* VMX Control Fields */
233 struct vmx_pin_ctrls pin_ctrls;
234 struct vmx_pri_proc_ctrls pri_proc_ctrls;
235 struct vmx_sec_proc_ctrls sec_proc_ctrls;
236 struct vmx_exit_ctrls exit_ctrls;
237 struct vmx_entry_ctrls entry_ctrls;
240 int v3_is_vmx_capable();
241 void v3_init_vmx_cpu(int cpu_id);
243 int v3_start_vmx_guest(struct guest_info* info);
244 int v3_vmx_enter(struct guest_info * info);
246 int v3_init_vmx_vmcs(struct guest_info * info, v3_vm_class_t vm_class);
247 int v3_deinit_vmx_vmcs(struct guest_info * core);
249 #endif // ! __V3VEE__