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.


Added shadow page handling, IO and MSR bitmap allocation, and started
[palacios.git] / palacios / include / palacios / vmcs.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  *         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 __VMCS_H__
24 #define __VMCS_H__
25
26 #ifdef __V3VEE__
27
28
29 #include <palacios/vmm_types.h>
30     /* Pin Based VM Execution Controls */
31     /* INTEL MANUAL: 20-10 vol 3B */
32 #define   EXT_INTR_EXIT                 0x00000001
33 #define   NMI_EXIT                      0x00000008
34 #define   VIRTUAL_NMIS                  0x00000020
35 /* Processor Based VM Execution Controls */
36 /* INTEL MANUAL: 20-11 vol. 3B */
37 #define   INTR_WIN_EXIT                 0x00000004
38 #define   USE_TSC_OFFSET                0x00000008
39 #define   HLT_EXIT                      0x00000080
40 #define   INVLPG_EXIT                   0x00000200
41 #define   MWAIT_EXIT                    0x00000400
42 #define   RDPMC_EXIT                    0x00000800
43 #define   RDTSC_EXIT                    0x00001000
44 #define   CR3_LOAD_EXIT                 0x00008000
45 #define   CR3_STORE_EXIT                0x00010000
46 #define   CR8_LOAD_EXIT                 0x00080000
47 #define   CR8_STORE_EXIT                0x00100000
48 #define   USE_TPR_SHADOW                0x00200000
49 #define   NMI_WINDOW_EXIT               0x00400000
50 #define   MOVDR_EXIT                    0x00800000
51 #define   UNCOND_IO_EXIT                0x01000000
52 #define   USE_IO_BITMAPS                0x02000000
53 #define   USE_MSR_BITMAPS               0x10000000
54 #define   MONITOR_EXIT                  0x20000000
55 #define   PAUSE_EXIT                    0x40000000
56 #define   ACTIVE_SEC_CTRLS              0x80000000
57 /* VM-Exit Controls */
58 /* INTEL MANUAL: 20-16 vol. 3B */
59 #define   HOST_ADDR_SPACE_SIZE          0x00000200
60 #define   ACK_IRQ_ON_EXIT               0x00008000
61
62 typedef enum {
63     VMCS_GUEST_ES_SELECTOR       = 0x00000800,
64     VMCS_GUEST_CS_SELECTOR       = 0x00000802,
65     VMCS_GUEST_SS_SELECTOR       = 0x00000804,
66     VMCS_GUEST_DS_SELECTOR       = 0x00000806,
67     VMCS_GUEST_FS_SELECTOR       = 0x00000808,
68     VMCS_GUEST_GS_SELECTOR       = 0x0000080A,
69     VMCS_GUEST_LDTR_SELECTOR     = 0x0000080C,
70     VMCS_GUEST_TR_SELECTOR       = 0x0000080E,
71     /* 16 bit host state */
72     VMCS_HOST_ES_SELECTOR        = 0x00000C00,
73     VMCS_HOST_CS_SELECTOR        = 0x00000C02,
74     VMCS_HOST_SS_SELECTOR        = 0x00000C04,
75     VMCS_HOST_DS_SELECTOR        = 0x00000C06,
76     VMCS_HOST_FS_SELECTOR        = 0x00000C08,
77     VMCS_HOST_GS_SELECTOR        = 0x00000C0A,
78     VMCS_HOST_TR_SELECTOR        = 0x00000C0C,
79     /* 64 bit control fields */
80     VMCS_IO_BITMAP_A_ADDR             = 0x00002000,
81     VMCS_IO_BITMAP_A_ADDR_HIGH        = 0x00002001,
82     VMCS_IO_BITMAP_B_ADDR             = 0x00002002,
83     VMCS_IO_BITMAP_B_ADDR_HIGH        = 0x00002003,
84     VMCS_MSR_BITMAP                   = 0x00002004,
85     VMCS_MSR_BITMAP_HIGH              = 0x00002005,
86     VMCS_EXIT_MSR_STORE_ADDR          = 0x00002006,
87     VMCS_EXIT_MSR_STORE_ADDR_HIGH     = 0x00002007,
88     VMCS_EXIT_MSR_LOAD_ADDR           = 0x00002008,
89     VMCS_EXIT_MSR_LOAD_ADDR_HIGH      = 0x00002009,
90     VMCS_ENTRY_MSR_LOAD_ADDR          = 0x0000200A,
91     VMCS_ENTRY_MSR_LOAD_ADDR_HIGH     = 0x0000200B,
92     VMCS_EXEC_PTR                     = 0x0000200C,
93     VMCS_EXEC_PTR_HIGH                = 0x0000200D,
94     VMCS_TSC_OFFSET                   = 0x00002010,
95     VMCS_TSC_OFFSET_HIGH              = 0x00002011,
96     VMCS_VAPIC_ADDR                   = 0x00002012,
97     VMCS_VAPIC_ADDR_HIGH              = 0x00002013,
98     VMCS_APIC_ACCESS_ADDR             = 0x00002014,
99     VMCS_APIC_ACCESS_ADDR_HIGH        = 0x00002015,
100     /* 64 bit guest state fields */
101     VMCS_LINK_PTR                     = 0x00002800,
102     VMCS_LINK_PTR_HIGH                = 0x00002801,
103     VMCS_GUEST_DBG_CTL               = 0x00002802,
104     VMCS_GUEST_DBG_CTL_HIGH          = 0x00002803,
105     VMCS_GUEST_PERF_GLOBAL_CTRL       = 0x00002808,
106     VMCS_GUEST_PERF_GLOBAL_CTRL_HIGH  = 0x00002809,
107
108     VMCS_HOST_PERF_GLOBAL_CTRL        = 0x00002c04,
109     VMCS_HOST_PERF_GLOBAL_CTRL_HIGH   = 0x00002c05,
110     /* 32 bit control fields */
111     VMCS_PIN_CTRLS                    = 0x00004000,
112     VMCS_PROC_CTRLS                   = 0x00004002,
113     VMCS_EXCP_BITMAP                  = 0x00004004,
114     VMCS_PG_FAULT_ERR_MASK            = 0x00004006,
115     VMCS_PG_FAULT_ERR_MATCH           = 0x00004008,
116     VMCS_CR3_TGT_CNT                  = 0x0000400A,
117     VMCS_EXIT_CTRLS                   = 0x0000400C,
118     VMCS_EXIT_MSR_STORE_CNT           = 0x0000400E,
119     VMCS_EXIT_MSR_LOAD_CNT            = 0x00004010,
120     VMCS_ENTRY_CTRLS                  = 0x00004012,
121     VMCS_ENTRY_MSR_LOAD_CNT           = 0x00004014,
122     VMCS_ENTRY_INT_INFO               = 0x00004016,
123     VMCS_ENTRY_EXCP_ERR               = 0x00004018,
124     VMCS_ENTRY_INSTR_LEN              = 0x0000401A,
125     VMCS_TPR_THRESHOLD                = 0x0000401C,
126     VMCS_SEC_PROC_CTRLS               = 0x0000401e,
127     /* 32 bit Read Only data fields */
128     VMCS_INSTR_ERR                    = 0x00004400,
129     VMCS_EXIT_REASON                  = 0x00004402,
130     VMCS_EXIT_INT_INFO                = 0x00004404,
131     VMCS_EXIT_INT_ERR                 = 0x00004406,
132     VMCS_IDT_VECTOR_INFO              = 0x00004408,
133     VMCS_IDT_VECTOR_ERR               = 0x0000440A,
134     VMCS_EXIT_INSTR_LEN               = 0x0000440C,
135     VMCS_VMX_INSTR_INFO               = 0x0000440E,
136     /* 32 bit Guest state fields */
137     VMCS_GUEST_ES_LIMIT               = 0x00004800,
138     VMCS_GUEST_CS_LIMIT               = 0x00004802,
139     VMCS_GUEST_SS_LIMIT               = 0x00004804,
140     VMCS_GUEST_DS_LIMIT               = 0x00004806,
141     VMCS_GUEST_FS_LIMIT               = 0x00004808,
142     VMCS_GUEST_GS_LIMIT               = 0x0000480A,
143     VMCS_GUEST_LDTR_LIMIT             = 0x0000480C,
144     VMCS_GUEST_TR_LIMIT               = 0x0000480E,
145     VMCS_GUEST_GDTR_LIMIT             = 0x00004810,
146     VMCS_GUEST_IDTR_LIMIT             = 0x00004812,
147     VMCS_GUEST_ES_ACCESS              = 0x00004814,
148     VMCS_GUEST_CS_ACCESS              = 0x00004816,
149     VMCS_GUEST_SS_ACCESS              = 0x00004818,
150     VMCS_GUEST_DS_ACCESS              = 0x0000481A,
151     VMCS_GUEST_FS_ACCESS              = 0x0000481C,
152     VMCS_GUEST_GS_ACCESS              = 0x0000481E,
153     VMCS_GUEST_LDTR_ACCESS            = 0x00004820,
154     VMCS_GUEST_TR_ACCESS              = 0x00004822,
155     VMCS_GUEST_INT_STATE              = 0x00004824,
156     VMCS_GUEST_ACTIVITY_STATE         = 0x00004826,
157     VMCS_GUEST_SMBASE                 = 0x00004828,
158     VMCS_GUEST_SYSENTER_CS            = 0x0000482A,
159     /* 32 bit host state field */
160     VMCS_HOST_SYSENTER_CS             = 0x00004C00,
161     /* Natural Width Control Fields */
162     VMCS_CR0_MASK                     = 0x00006000,
163     VMCS_CR4_MASK                     = 0x00006002,
164     VMCS_CR0_READ_SHDW                = 0x00006004,
165     VMCS_CR4_READ_SHDW                = 0x00006006,
166     VMCS_CR3_TGT_VAL_0                = 0x00006008,
167     VMCS_CR3_TGT_VAL_1                = 0x0000600A,
168     VMCS_CR3_TGT_VAL_2                = 0x0000600C,
169     VMCS_CR3_TGT_VAL_3                = 0x0000600E,
170     /* Natural Width Read Only Fields */
171     VMCS_EXIT_QUAL                    = 0x00006400,
172     VMCS_IO_RCX                       = 0x00006402,
173     VMCS_IO_RSI                       = 0x00006404,
174     VMCS_IO_RDI                       = 0x00006406,
175     VMCS_IO_RIP                       = 0x00006408,
176     VMCS_GUEST_LINEAR_ADDR            = 0x0000640A,
177     /* Natural Width Guest State Fields */
178     VMCS_GUEST_CR0                    = 0x00006800,
179     VMCS_GUEST_CR3                    = 0x00006802,
180     VMCS_GUEST_CR4                    = 0x00006804,
181     VMCS_GUEST_ES_BASE                = 0x00006806,
182     VMCS_GUEST_CS_BASE                = 0x00006808,
183     VMCS_GUEST_SS_BASE                = 0x0000680A,
184     VMCS_GUEST_DS_BASE                = 0x0000680C,
185     VMCS_GUEST_FS_BASE                = 0x0000680E,
186     VMCS_GUEST_GS_BASE                = 0x00006810,
187     VMCS_GUEST_LDTR_BASE              = 0x00006812,
188     VMCS_GUEST_TR_BASE                = 0x00006814,
189     VMCS_GUEST_GDTR_BASE              = 0x00006816,
190     VMCS_GUEST_IDTR_BASE              = 0x00006818,
191     VMCS_GUEST_DR7                    = 0x0000681A,
192     VMCS_GUEST_RSP                    = 0x0000681C,
193     VMCS_GUEST_RIP                    = 0x0000681E,
194     VMCS_GUEST_RFLAGS                 = 0x00006820,
195     VMCS_GUEST_PENDING_DBG_EXCP       = 0x00006822,
196     VMCS_GUEST_SYSENTER_ESP           = 0x00006824,
197     VMCS_GUEST_SYSENTER_EIP           = 0x00006826,
198     /* Natural Width Host State Fields */
199     VMCS_HOST_CR0                     = 0x00006C00,
200     VMCS_HOST_CR3                     = 0x00006C02,
201     VMCS_HOST_CR4                     = 0x00006C04,
202     VMCS_HOST_FS_BASE                 = 0x00006C06,
203     VMCS_HOST_GS_BASE                 = 0x00006C08,
204     VMCS_HOST_TR_BASE                 = 0x00006C0A,
205     VMCS_HOST_GDTR_BASE               = 0x00006C0C,
206     VMCS_HOST_IDTR_BASE               = 0x00006C0E,
207     VMCS_HOST_SYSENTER_ESP            = 0x00006C10,
208     VMCS_HOST_SYSENTER_EIP            = 0x00006C12,
209     VMCS_HOST_RSP                     = 0x00006C14,
210     VMCS_HOST_RIP                     = 0x00006C16,
211 } vmcs_field_t;
212
213 int v3_vmcs_get_field_len(vmcs_field_t field);
214 const char* v3_vmcs_field_to_str(vmcs_field_t field);
215 void v3_print_vmcs();
216
217
218
219 /* VMCS Exit QUALIFICATIONs */
220 struct vmcs_io_qual {
221     uint32_t accessSize : 3; // (0: 1 Byte ;; 1: 2 Bytes ;; 3: 4 Bytes)
222     uint32_t dir        : 1; // (0: Out ;; 1: In)
223     uint32_t string     : 1; // (0: not string ;; 1: string)
224     uint32_t REP        : 1; // (0: not REP ;; 1: REP)
225     uint32_t opEnc      : 1; // (0: DX ;; 1: immediate)
226     uint32_t rsvd       : 9; // Set to 0
227     uint32_t port       : 16; // IO Port Number
228 } __attribute__((packed));
229
230
231
232 struct VMExitDBGQual {
233     uint32_t B0         : 1; // Breakpoint 0 condition met
234     uint32_t B1         : 1; // Breakpoint 1 condition met
235     uint32_t B2         : 1; // Breakpoint 2 condition met
236     uint32_t B3         : 1; // Breakpoint 3 condition met
237     uint32_t rsvd       : 9; // reserved to 0
238     uint32_t BD         : 1; // detected DBG reg access
239     uint32_t BS         : 1; // cause either single instr or taken branch
240 } __attribute__((packed));
241
242
243 struct VMExitTSQual {
244     uint32_t selector   : 16; // selector of destination TSS 
245     uint32_t rsvd       : 14; // reserved to 0
246     uint32_t src        : 2; // (0: CALL ; 1: IRET ; 2: JMP ; 3: Task gate in IDT)
247 } __attribute__((packed));
248
249 struct VMExitCRQual {
250     uint32_t crID       : 4; // cr number (0 for CLTS and LMSW) (bit 3 always 0, on 32bit)
251     uint32_t accessType : 2; // (0: MOV to CR ; 1: MOV from CR ; 2: CLTS ; 3: LMSW)
252     uint32_t lmswOpType : 1; // (0: register ; 1: memory)
253     uint32_t rsvd1      : 1; // reserved to 0
254     uint32_t gpr        : 4; // (0:RAX+[CLTS/LMSW], 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
255     uint32_t rsvd2      : 4; // reserved to 0
256     uint32_t lmswSrc    : 16; // src data for lmsw
257 } __attribute__((packed));
258
259 struct VMExitMovDRQual {
260     uint32_t regID      : 3; // debug register number
261     uint32_t rsvd1      : 1; // reserved to 0
262     uint32_t dir        : 1; // (0: MOV to DR , 1: MOV from DR)
263     uint32_t rsvd2      : 3; // reserved to 0
264     uint32_t gpr        : 4; // (0:RAX, 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
265 } __attribute__((packed));
266
267 /* End Exit Qualifications */
268
269 /* Exit Vector Info */
270 struct VMExitIntInfo {
271     uint32_t nr         : 8; // IRQ number, exception vector, NMI = 2 
272     uint32_t type       : 3; // (0: ext. IRQ , 2: NMI , 3: hw exception , 6: sw exception
273     uint32_t errorCode  : 1; // 1: error Code present
274     uint32_t iret       : 1; // something to do with NMIs and IRETs (Intel 3B, sec. 23.2.2) 
275     uint32_t rsvd       : 18; // always 0
276     uint32_t valid      : 1; // always 1 if valid
277 } __attribute__((packed));
278
279
280
281
282 /*  End Exit Vector Info */
283
284
285
286
287 /* Segment Selector Access Rights (32 bits) */
288 /* INTEL Manual: 20-4 vol 3B */
289
290
291 struct vmcs_segment_access {
292     union {
293         uint32_t value;
294         struct {
295             uint32_t    type        : 4;
296             uint32_t    desc_type   : 1; 
297             uint32_t    dpl         : 2;
298             uint32_t    present     : 1;
299             uint32_t    rsvd1       : 4;
300             uint32_t    avail       : 1;
301             uint32_t    long_mode   : 1; // CS only (64 bit active), reserved otherwise
302             uint32_t    db          : 1; 
303             uint32_t    granularity : 1;
304             uint32_t    unusable    : 1; 
305             uint32_t    rsvd2       : 15;
306         } __attribute__((packed));
307     } __attribute__((packed));
308 }__attribute__((packed));
309
310
311 struct vmcs_interrupt_state {
312     uint32_t    sti_blocking    : 1;
313     uint32_t    mov_ss_blocking : 1;
314     uint32_t    smi_blocking    : 1;
315     uint32_t    nmi_blocking    : 1;
316     uint32_t    rsvd1           : 28;
317 } __attribute__((packed));
318
319
320
321 struct vmcs_data {
322     uint32_t revision ;
323     uint32_t abort    ;
324 } __attribute__((packed));
325
326
327 //uint_t VMCSRead(uint_t tag, void * val);
328
329
330 #endif // ! __V3VEE__
331
332
333 #endif