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.


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