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.


a34cd46ca5a7eaf6980e34bc5a96c59d542355b1
[palacios.git] / palacios / include / palacios / vmx.h
1
2
3 /* 
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.  
7  *
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
11  *
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.
16  *
17  * Author: Peter Dinda <pdinda@northwestern.edu>
18  * Author: Jack Lange <jarusl@cs.northwestern.edu>
19  *
20  * This is free software.  You are permitted to use,
21  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
22  */
23
24
25 #ifndef __VMX_H__
26 #define __VMX_H__
27
28 #ifdef __V3VEE__
29
30 #include <palacios/vmm_types.h>
31 #include <palacios/vmcs.h>
32 #include <palacios/vmm.h>
33 #include <palacios/vm_guest.h>
34
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
48
49 #define VMX_SUCCESS        0
50 #define VMX_FAIL_INVALID   1
51 #define VMX_FAIL_VALID     2
52 #define VMM_ERROR          3
53
54 #define FEATURE_CONTROL_LOCK  0x00000001
55 #define FEATURE_CONTROL_VMXON 0x00000004
56 #define FEATURE_CONTROL_VALID ( FEATURE_CONTROL_LOCK | FEATURE_CONTROL_VMXON )
57
58
59 #define CPUID_1_ECX_VTXFLAG 0x00000020
60
61
62 struct vmx_pin_ctrls {
63     union {
64         uint32_t value;
65         struct {
66             uint_t ext_int_exit            : 1;
67             uint_t rsvd1                   : 2; 
68             uint_t nmi_exit                : 1;
69             uint_t rsvd2                   : 1;
70             uint_t virt_nmi                : 1;
71             uint_t active_preempt_timer    : 1;
72             uint_t rsvd3                   : 25;
73         } __attribute__((packed));
74     } __attribute__((packed));
75 } __attribute__((packed));
76
77
78 struct vmx_pri_proc_ctrls {
79     union {
80         uint32_t value;
81         struct {
82             uint_t rsvd1           : 2;
83             uint_t int_wndw_exit   : 1;
84             uint_t tsc_offset      : 1;
85             uint_t rsvd2           : 3;
86             uint_t hlt_exit        : 1;
87             uint_t rsvd3           : 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;
92             uint_t rsvd4           : 2;
93             uint_t cr3_ld_exit     : 1;
94             uint_t cr3_str_exit    : 1;
95             uint_t rsvd5           : 2;
96             uint_t cr8_ld_exit     : 1;
97             uint_t cr8_str_exit    : 1;
98             uint_t tpr_shdw        : 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;
103             uint_t rsvd6           : 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));
112
113 struct vmx_sec_proc_ctrls {
114     union {
115         uint32_t value;
116         struct {
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;
124             uint_t rsvd1           : 2;
125             uint_t pause_loop_exit : 1;
126             uint_t rsvd2           : 21;
127         } __attribute__((packed));
128     } __attribute__((packed));
129 } __attribute__((packed));
130
131 struct vmx_exit_ctrls {
132     union {
133         uint32_t value;
134         struct {
135             uint_t rsvd1                : 2;
136             uint_t save_dbg_ctrls       : 1;
137             uint_t rsvd2                : 6;
138             uint_t host_64_on           : 1;
139             uint_t rsvd3                : 2;
140             uint_t ld_perf_glbl_ctrl    : 1;
141             uint_t rsvd4                : 2;
142             uint_t ack_int_on_exit      : 1;
143             uint_t rsvd5                : 2;
144             uint_t save_pat             : 1;
145             uint_t ld_pat               : 1;
146             uint_t save_efer            : 1;
147             uint_t ld_efer              : 1;
148             uint_t save_preempt_timer   : 1;
149             uint_t rsvd6                : 9;
150         } __attribute__((packed));
151     } __attribute__((packed));
152 } __attribute__((packed));
153
154 struct vmx_entry_ctrls {
155     union {
156         uint32_t value;
157         struct {
158             uint_t rsvd1                : 2;
159             uint_t ld_dbg_ctrls         : 1;
160             uint_t rsvd2                : 6;
161             uint_t guest_ia32e          : 1;
162             uint_t smm_entry            : 1;
163             uint_t no_dual_monitor      : 1;
164             uint_t rsvd3                : 1;
165             uint_t ld_perf_glbl_ctrl    : 1;
166             uint_t ld_pat               : 1;
167             uint_t ld_efer              : 1;
168             uint_t rsvd4                : 16;
169         } __attribute__((packed));
170     } __attribute__((packed));
171 } __attribute__((packed));
172
173 struct vmx_basic_msr {
174     uint32_t revision;
175     uint_t regionSize   : 13;
176     uint_t rsvd1        : 4; // Always 0
177     uint_t physWidth    : 1;
178     uint_t smm          : 1; // Always 1
179     uint_t memType      : 4;
180     uint_t rsvd2        : 10; // Always 0
181 }  __attribute__((packed));
182
183 typedef enum { 
184     VMXASSIST_DISABLED,
185     VMXASSIST_ENABLED
186 } vmx_state_t;
187
188 struct tss_descriptor {
189     uint16_t    limit1;
190     uint16_t    base1;
191     uint_t      base2       : 8;
192     /* In IA32, type follows the form 10B1b, where B is the busy flag */
193     uint_t      type        : 4; 
194     uint_t      zero1       : 1;
195     uint_t      dpl         : 2;
196     uint_t      present     : 1;
197     uint_t      limit2      : 4;
198     uint_t      available   : 1;
199     uint_t      zero2       : 1;
200     uint_t      zero3       : 1;
201     uint_t      granularity : 1;
202     uint_t      base3       : 8;
203 #ifdef __V3_64BIT__
204     uint32_t    base4;
205     uint_t      rsvd1       : 8;
206     uint_t      zero4       : 5;
207     uint_t      rsvd2       : 19;
208 #endif
209 }__attribute__((packed));
210
211 struct vmcs_host_state {
212     struct v3_segment  gdtr;
213     struct v3_segment  idtr;
214     struct v3_segment  tr;
215 };
216
217 struct vmx_data {
218     vmx_state_t state;
219     struct vmcs_host_state host_state;
220
221     addr_t vmcs_ptr_phys;
222
223     uint8_t ia32e_avail;
224
225     /* VMX Control Fields */
226     struct vmx_pin_ctrls pin_ctrls;
227     struct vmx_pri_proc_ctrls pri_proc_ctrls;
228     struct vmx_sec_proc_ctrls sec_proc_ctrls;
229     struct vmx_exit_ctrls exit_ctrls;
230     struct vmx_entry_ctrls entry_ctrls;
231 };
232
233 int v3_is_vmx_capable();
234 void v3_init_vmx_cpu(int cpu_id);
235
236
237 #endif // ! __V3VEE__
238
239 #endif 
240
241