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.


Fix to MSR save/restore handling to avoid VMX ABORT errors
[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) 2011, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #ifndef __VMX_H__
22 #define __VMX_H__
23
24 #ifdef __V3VEE__
25
26 #include <palacios/vmm_types.h>
27 #include <palacios/vmcs.h>
28 #include <palacios/vmm.h>
29 #include <palacios/vm_guest.h>
30
31
32 #define VMX_SUCCESS        0
33 #define VMX_FAIL_INVALID   1
34 #define VMX_FAIL_VALID     2
35 #define VMM_ERROR          3
36
37
38 struct vmx_pin_ctrls {
39     union {
40         uint32_t value;
41         struct {
42             uint_t ext_int_exit            : 1;
43             uint_t rsvd1                   : 2; 
44             uint_t nmi_exit                : 1;
45             uint_t rsvd2                   : 1;
46             uint_t virt_nmi                : 1;
47             uint_t active_preempt_timer    : 1;
48             uint_t rsvd3                   : 25;
49         } __attribute__((packed));
50     } __attribute__((packed));
51 } __attribute__((packed));
52
53
54 struct vmx_pri_proc_ctrls {
55     union {
56         uint32_t value;
57         struct {
58             uint_t rsvd1           : 2;
59             uint_t int_wndw_exit   : 1;
60             uint_t tsc_offset      : 1;
61             uint_t rsvd2           : 3;
62             uint_t hlt_exit        : 1;
63             uint_t rsvd3           : 1;
64             uint_t invlpg_exit     : 1;
65             uint_t mwait_exit      : 1;
66             uint_t rdpmc_exit      : 1;
67             uint_t rdtsc_exit      : 1;
68             uint_t rsvd4           : 2;
69             uint_t cr3_ld_exit     : 1;
70             uint_t cr3_str_exit    : 1;
71             uint_t rsvd5           : 2;
72             uint_t cr8_ld_exit     : 1;
73             uint_t cr8_str_exit    : 1;
74             uint_t tpr_shdw        : 1;
75             uint_t nmi_wndw_exit   : 1;
76             uint_t mov_dr_exit     : 1;
77             uint_t uncon_io_exit   : 1;
78             uint_t use_io_bitmap   : 1;
79             uint_t rsvd6           : 1;
80             uint_t monitor_trap    : 1;
81             uint_t use_msr_bitmap  : 1;
82             uint_t monitor_exit    : 1;
83             uint_t pause_exit      : 1;
84             uint_t sec_ctrls       : 1;
85         } __attribute__((packed));
86     } __attribute__((packed));
87 } __attribute__((packed));
88
89 struct vmx_sec_proc_ctrls {
90     union {
91         uint32_t value;
92         struct {
93             uint_t virt_apic_acc   : 1;
94             uint_t enable_ept      : 1;
95             uint_t desc_table_exit : 1;
96             uint_t enable_rdtscp   : 1;
97             uint_t virt_x2apic     : 1;
98             uint_t enable_vpid     : 1;
99             uint_t wbinvd_exit     : 1;
100             uint_t unrstrct_guest  : 1; /* un restricted guest (CAN RUN IN REAL MODE) */
101             uint_t rsvd1           : 2;
102             uint_t pause_loop_exit : 1;
103             uint_t rsvd2           : 21;
104         } __attribute__((packed));
105     } __attribute__((packed));
106 } __attribute__((packed));
107
108 struct vmx_exit_ctrls {
109     union {
110         uint32_t value;
111         struct {
112             uint_t rsvd1                : 2;
113             uint_t save_dbg_ctrls       : 1;
114             uint_t rsvd2                : 6;
115             uint_t host_64_on           : 1;
116             uint_t rsvd3                : 2;
117             uint_t ld_perf_glbl_ctrl    : 1;
118             uint_t rsvd4                : 2;
119             uint_t ack_int_on_exit      : 1;
120             uint_t rsvd5                : 2;
121             uint_t save_pat             : 1;
122             uint_t ld_pat               : 1;
123             uint_t save_efer            : 1;
124             uint_t ld_efer              : 1;
125             uint_t save_preempt_timer   : 1;
126             uint_t rsvd6                : 9;
127         } __attribute__((packed));
128     } __attribute__((packed));
129 } __attribute__((packed));
130
131 struct vmx_entry_ctrls {
132     union {
133         uint32_t value;
134         struct {
135             uint_t rsvd1                : 2;
136             uint_t ld_dbg_ctrls         : 1;
137             uint_t rsvd2                : 6;
138             uint_t guest_ia32e          : 1;
139             uint_t smm_entry            : 1;
140             uint_t no_dual_monitor      : 1;
141             uint_t rsvd3                : 1;
142             uint_t ld_perf_glbl_ctrl    : 1;
143             uint_t ld_pat               : 1;
144             uint_t ld_efer              : 1;
145             uint_t rsvd4                : 16;
146         } __attribute__((packed));
147     } __attribute__((packed));
148 } __attribute__((packed));
149
150
151 typedef enum { 
152     VMXASSIST_DISABLED,
153     VMXASSIST_ENABLED
154 } vmxassist_state_t;
155
156 typedef enum {
157     VMX_UNLAUNCHED,
158     VMX_LAUNCHED
159 } vmx_state_t;
160
161 struct tss_descriptor {
162     uint16_t    limit1;
163     uint16_t    base1;
164     uint_t      base2       : 8;
165     /* In IA32, type follows the form 10B1b, where B is the busy flag */
166     uint_t      type        : 4; 
167     uint_t      zero1       : 1;
168     uint_t      dpl         : 2;
169     uint_t      present     : 1;
170     uint_t      limit2      : 4;
171     uint_t      available   : 1;
172     uint_t      zero2       : 1;
173     uint_t      zero3       : 1;
174     uint_t      granularity : 1;
175     uint_t      base3       : 8;
176 #ifdef __V3_64BIT__
177     uint32_t    base4;
178     uint_t      rsvd1       : 8;
179     uint_t      zero4       : 5;
180     uint_t      rsvd2       : 19;
181 #endif
182 } __attribute__((packed));
183
184 struct vmcs_host_state {
185     struct v3_segment  gdtr;
186     struct v3_segment  idtr;
187     struct v3_segment  tr;
188 };
189
190
191 struct vmcs_msr_save_area {
192     union {
193         struct vmcs_msr_entry guest_msrs[4];
194         struct {
195             struct vmcs_msr_entry guest_star;
196             struct vmcs_msr_entry guest_lstar;
197             struct vmcs_msr_entry guest_fmask;
198             struct vmcs_msr_entry guest_kern_gs;
199         } __attribute__((packed));
200     } __attribute__((packed));
201
202     union {
203         struct vmcs_msr_entry host_msrs[4];
204         struct {
205             struct vmcs_msr_entry host_star;
206             struct vmcs_msr_entry host_lstar;
207             struct vmcs_msr_entry host_fmask;
208             struct vmcs_msr_entry host_kern_gs;
209         } __attribute__((packed));
210     } __attribute__((packed)); 
211
212 } __attribute__((packed)); 
213
214
215 struct vmx_data {
216     vmx_state_t state;
217     vmxassist_state_t assist_state;
218     struct vmcs_host_state host_state;
219
220
221
222     addr_t vmcs_ptr_phys;
223
224     v3_reg_t guest_cr4; /// corresponds to the CR4 Read shadow
225
226
227     /* VMX Control Fields */
228     struct vmx_pin_ctrls pin_ctrls;
229     struct vmx_pri_proc_ctrls pri_proc_ctrls;
230     struct vmx_sec_proc_ctrls sec_proc_ctrls;
231     struct vmx_exit_ctrls exit_ctrls;
232     struct vmx_entry_ctrls entry_ctrls;
233
234     struct vmx_exception_bitmap excp_bmap;
235
236     addr_t msr_area_paddr;
237     struct vmcs_msr_save_area * msr_area;
238 };
239
240 int v3_is_vmx_capable();
241
242 void v3_init_vmx_cpu(int cpu_id);
243 void v3_deinit_vmx_cpu(int cpu_id);
244
245 int v3_init_vmx_vmcs(struct guest_info * info, v3_vm_class_t vm_class);
246 int v3_deinit_vmx_vmcs(struct guest_info * core);
247
248 int v3_start_vmx_guest(struct guest_info* info);
249 int v3_reset_vmx_vm_core(struct guest_info * core, addr_t rip);
250 void v3_flush_vmx_vm_core(struct guest_info * core);
251
252 int v3_vmx_enter(struct guest_info * info);
253
254 int v3_vmx_load_core(struct guest_info * core, void * ctx);
255 int v3_vmx_save_core(struct guest_info * core, void * ctx);
256
257
258
259
260
261 #endif // ! __V3VEE__
262
263 #endif 
264
265