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.


Have unregistered hypercalls fail to guest
[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_OFF,
154     VMXASSIST_ON
155 } vmxassist_state_t;
156
157 typedef enum {
158     VMX_UNLAUNCHED,
159     VMX_LAUNCHED
160 } vmx_state_t;
161
162 struct tss_descriptor {
163     uint16_t    limit1;
164     uint16_t    base1;
165     uint_t      base2       : 8;
166     /* In IA32, type follows the form 10B1b, where B is the busy flag */
167     uint_t      type        : 4; 
168     uint_t      zero1       : 1;
169     uint_t      dpl         : 2;
170     uint_t      present     : 1;
171     uint_t      limit2      : 4;
172     uint_t      available   : 1;
173     uint_t      zero2       : 1;
174     uint_t      zero3       : 1;
175     uint_t      granularity : 1;
176     uint_t      base3       : 8;
177 #ifdef __V3_64BIT__
178     uint32_t    base4;
179     uint_t      rsvd1       : 8;
180     uint_t      zero4       : 5;
181     uint_t      rsvd2       : 19;
182 #endif
183 } __attribute__((packed));
184
185 struct vmcs_host_state {
186     struct v3_segment  gdtr;
187     struct v3_segment  idtr;
188     struct v3_segment  tr;
189 };
190
191
192 struct vmcs_msr_save_area {
193     union {
194         struct vmcs_msr_entry guest_msrs[4];
195         struct {
196             struct vmcs_msr_entry guest_star;
197             struct vmcs_msr_entry guest_lstar;
198             struct vmcs_msr_entry guest_fmask;
199             struct vmcs_msr_entry guest_kern_gs;
200         } __attribute__((packed));
201     } __attribute__((packed));
202
203     union {
204         struct vmcs_msr_entry host_msrs[4];
205         struct {
206             struct vmcs_msr_entry host_star;
207             struct vmcs_msr_entry host_lstar;
208             struct vmcs_msr_entry host_fmask;
209             struct vmcs_msr_entry host_kern_gs;
210         } __attribute__((packed));
211     } __attribute__((packed)); 
212
213 } __attribute__((packed)); 
214
215
216 struct vmx_data {
217     vmx_state_t state;
218     vmxassist_state_t assist_state;
219     struct vmcs_host_state host_state;
220
221
222
223     addr_t vmcs_ptr_phys;
224
225     v3_reg_t guest_cr4; /// corresponds to the CR4 Read shadow
226
227
228     /* VMX Control Fields */
229     struct vmx_pin_ctrls pin_ctrls;
230     struct vmx_pri_proc_ctrls pri_proc_ctrls;
231     struct vmx_sec_proc_ctrls sec_proc_ctrls;
232     struct vmx_exit_ctrls exit_ctrls;
233     struct vmx_entry_ctrls entry_ctrls;
234
235     struct vmx_exception_bitmap excp_bmap;
236
237     addr_t msr_area_paddr;
238     struct vmcs_msr_save_area * msr_area;
239 };
240
241 int v3_is_vmx_capable();
242
243 void v3_init_vmx_cpu(int cpu_id);
244 void v3_deinit_vmx_cpu(int cpu_id);
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 int v3_start_vmx_guest(struct guest_info* info);
250 int v3_reset_vmx_vm_core(struct guest_info * core, addr_t rip);
251 void v3_flush_vmx_vm_core(struct guest_info * core);
252
253 int v3_vmx_enter(struct guest_info * info);
254
255 int v3_vmx_load_core(struct guest_info * core, void * ctx);
256 int v3_vmx_save_core(struct guest_info * core, void * ctx);
257
258
259
260
261
262 #endif // ! __V3VEE__
263
264 #endif 
265
266