Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


build fixes and cleanup code to handle VMM shutdown
[palacios.git] / palacios / include / palacios / vmx.h
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Peter Dinda <pdinda@northwestern.edu> 
11  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Peter Dinda <pdinda@northwestern.edu>
16  * Author: Jack Lange <jarusl@cs.northwestern.edu>
17  *
18  * This is free software.  You are permitted to use,
19  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20  */
21
22
23 #ifndef __VMX_H__
24 #define __VMX_H__
25
26 #ifdef __V3VEE__
27
28 #include <palacios/vmm_types.h>
29 #include <palacios/vmcs.h>
30 #include <palacios/vmm.h>
31 #include <palacios/vm_guest.h>
32
33 // Intel VMX Specific MSRs
34 #define VMX_FEATURE_CONTROL_MSR     0x0000003a
35 #define VMX_BASIC_MSR               0x00000480
36 #define VMX_PINBASED_CTLS_MSR       0x00000481
37 #define VMX_PROCBASED_CTLS_MSR      0x00000482
38 #define VMX_EXIT_CTLS_MSR           0x00000483
39 #define VMX_ENTRY_CTLS_MSR          0x00000484
40 #define VMX_MISC_MSR                0x00000485
41 #define VMX_CR0_FIXED0_MSR          0x00000486
42 #define VMX_CR0_FIXED1_MSR          0x00000487
43 #define VMX_CR4_FIXED0_MSR          0x00000488
44 #define VMX_CR4_FIXED1_MSR          0x00000489
45 #define VMX_VMCS_ENUM_MSR           0x0000048A
46
47 #define VMX_SUCCESS        0
48 #define VMX_FAIL_INVALID   1
49 #define VMX_FAIL_VALID     2
50 #define VMM_ERROR          3
51
52 #define FEATURE_CONTROL_LOCK  0x00000001
53 #define FEATURE_CONTROL_VMXON 0x00000004
54 #define FEATURE_CONTROL_VALID ( FEATURE_CONTROL_LOCK | FEATURE_CONTROL_VMXON )
55
56
57 #define CPUID_1_ECX_VTXFLAG 0x00000020
58
59
60 struct vmx_pin_ctrls {
61     union {
62         uint32_t value;
63         struct {
64             uint_t ext_int_exit            : 1;
65             uint_t rsvd1                   : 2; 
66             uint_t nmi_exit                : 1;
67             uint_t rsvd2                   : 1;
68             uint_t virt_nmi                : 1;
69             uint_t active_preempt_timer    : 1;
70             uint_t rsvd3                   : 25;
71         } __attribute__((packed));
72     } __attribute__((packed));
73 } __attribute__((packed));
74
75
76 struct vmx_pri_proc_ctrls {
77     union {
78         uint32_t value;
79         struct {
80             uint_t rsvd1           : 2;
81             uint_t int_wndw_exit   : 1;
82             uint_t tsc_offset      : 1;
83             uint_t rsvd2           : 3;
84             uint_t hlt_exit        : 1;
85             uint_t rsvd3           : 1;
86             uint_t invlpg_exit     : 1;
87             uint_t mwait_exit      : 1;
88             uint_t rdpmc_exit      : 1;
89             uint_t rdtsc_exit      : 1;
90             uint_t rsvd4           : 2;
91             uint_t cr3_ld_exit     : 1;
92             uint_t cr3_str_exit    : 1;
93             uint_t rsvd5           : 2;
94             uint_t cr8_ld_exit     : 1;
95             uint_t cr8_str_exit    : 1;
96             uint_t tpr_shdw        : 1;
97             uint_t nmi_wndw_exit   : 1;
98             uint_t mov_dr_exit     : 1;
99             uint_t uncon_io_exit   : 1;
100             uint_t use_io_bitmap   : 1;
101             uint_t rsvd6           : 1;
102             uint_t monitor_trap    : 1;
103             uint_t use_msr_bitmap  : 1;
104             uint_t monitor_exit    : 1;
105             uint_t pause_exit      : 1;
106             uint_t sec_ctrls       : 1;
107         } __attribute__((packed));
108     } __attribute__((packed));
109 } __attribute__((packed));
110
111 struct vmx_sec_proc_ctrls {
112     union {
113         uint32_t value;
114         struct {
115             uint_t virt_apic_acc   : 1;
116             uint_t enable_ept      : 1;
117             uint_t desc_table_exit : 1;
118             uint_t enable_rdtscp   : 1;
119             uint_t virt_x2apic     : 1;
120             uint_t enable_vpid     : 1;
121             uint_t unrstrct_guest  : 1;
122             uint_t rsvd1           : 2;
123             uint_t pause_loop_exit : 1;
124             uint_t rsvd2           : 21;
125         } __attribute__((packed));
126     } __attribute__((packed));
127 } __attribute__((packed));
128
129 struct vmx_exit_ctrls {
130     union {
131         uint32_t value;
132         struct {
133             uint_t rsvd1                : 2;
134             uint_t save_dbg_ctrls       : 1;
135             uint_t rsvd2                : 6;
136             uint_t host_64_on           : 1;
137             uint_t rsvd3                : 2;
138             uint_t ld_perf_glbl_ctrl    : 1;
139             uint_t rsvd4                : 2;
140             uint_t ack_int_on_exit      : 1;
141             uint_t rsvd5                : 2;
142             uint_t save_pat             : 1;
143             uint_t ld_pat               : 1;
144             uint_t save_efer            : 1;
145             uint_t ld_efer              : 1;
146             uint_t save_preempt_timer   : 1;
147             uint_t rsvd6                : 9;
148         } __attribute__((packed));
149     } __attribute__((packed));
150 } __attribute__((packed));
151
152 struct vmx_entry_ctrls {
153     union {
154         uint32_t value;
155         struct {
156             uint_t rsvd1                : 2;
157             uint_t ld_dbg_ctrls         : 1;
158             uint_t rsvd2                : 6;
159             uint_t guest_ia32e          : 1;
160             uint_t smm_entry            : 1;
161             uint_t no_dual_monitor      : 1;
162             uint_t rsvd3                : 1;
163             uint_t ld_perf_glbl_ctrl    : 1;
164             uint_t ld_pat               : 1;
165             uint_t ld_efer              : 1;
166             uint_t rsvd4                : 16;
167         } __attribute__((packed));
168     } __attribute__((packed));
169 } __attribute__((packed));
170
171 struct vmx_basic_msr {
172     uint32_t revision;
173     uint_t regionSize   : 13;
174     uint_t rsvd1        : 4; // Always 0
175     uint_t physWidth    : 1;
176     uint_t smm          : 1; // Always 1
177     uint_t memType      : 4;
178     uint_t rsvd2        : 10; // Always 0
179 }  __attribute__((packed));
180
181 typedef enum { 
182     VMXASSIST_DISABLED,
183     VMXASSIST_ENABLED
184 } vmx_state_t;
185
186 struct tss_descriptor {
187     uint16_t    limit1;
188     uint16_t    base1;
189     uint_t      base2       : 8;
190     /* In IA32, type follows the form 10B1b, where B is the busy flag */
191     uint_t      type        : 4; 
192     uint_t      zero1       : 1;
193     uint_t      dpl         : 2;
194     uint_t      present     : 1;
195     uint_t      limit2      : 4;
196     uint_t      available   : 1;
197     uint_t      zero2       : 1;
198     uint_t      zero3       : 1;
199     uint_t      granularity : 1;
200     uint_t      base3       : 8;
201 #ifdef __V3_64BIT__
202     uint32_t    base4;
203     uint_t      rsvd1       : 8;
204     uint_t      zero4       : 5;
205     uint_t      rsvd2       : 19;
206 #endif
207 }__attribute__((packed));
208
209 struct vmcs_host_state {
210     struct v3_segment  gdtr;
211     struct v3_segment  idtr;
212     struct v3_segment  tr;
213 };
214
215
216
217
218
219 struct vmx_data {
220     vmx_state_t state;
221     struct vmcs_host_state host_state;
222
223     addr_t vmcs_ptr_phys;
224
225     uint8_t ia32e_avail;
226
227     v3_reg_t guest_cr4; /// corresponds to the CR4 Read shadow
228
229
230     /* VMX Control Fields */
231     struct vmx_pin_ctrls pin_ctrls;
232     struct vmx_pri_proc_ctrls pri_proc_ctrls;
233     struct vmx_sec_proc_ctrls sec_proc_ctrls;
234     struct vmx_exit_ctrls exit_ctrls;
235     struct vmx_entry_ctrls entry_ctrls;
236 };
237
238 int v3_is_vmx_capable();
239
240 void v3_init_vmx_cpu(int cpu_id);
241 void v3_deinit_vmx_cpu(int cpu_id);
242
243 int v3_start_vmx_guest(struct guest_info* info);
244 int v3_vmx_enter(struct guest_info * info);
245
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);
248
249 #endif // ! __V3VEE__
250
251 #endif 
252
253