xen-vtx-unstable

annotate xen/include/asm-x86/vmx.h @ 5615:4669354bba9a

bitkeeper revision 1.1780 (42c3a8c4tqEOpGy663gWO35k5QwZTw)

[PATCH] Infrastructure for interrupt handling.

Infrastructure for interrupt handling.

- support interruptibility
- handle interrupt window exiting control appropriately
- Add ioapic device models imported from Bochs under LGPL
- generalize the interrupt architecture to support both PIC/APIC

This patch is necessary to fix several bugs on 32 bit VMX and prepares the
ground for adding a local APIC device model in the hypervisor.

Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Eddie Dong <eddie.dong@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
author arun.sharma@intel.com[kaf24]
date Thu Jun 30 08:09:40 2005 +0000 (2005-06-30)
parents 6daf7357a9df
children 82390e707bb9
rev   line source
iap10@3290 1 /*
iap10@3290 2 * vmx.h: VMX Architecture related definitions
iap10@3290 3 * Copyright (c) 2004, Intel Corporation.
iap10@3290 4 *
iap10@3290 5 * This program is free software; you can redistribute it and/or modify it
iap10@3290 6 * under the terms and conditions of the GNU General Public License,
iap10@3290 7 * version 2, as published by the Free Software Foundation.
iap10@3290 8 *
iap10@3290 9 * This program is distributed in the hope it will be useful, but WITHOUT
iap10@3290 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iap10@3290 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
iap10@3290 12 * more details.
iap10@3290 13 *
iap10@3290 14 * You should have received a copy of the GNU General Public License along with
iap10@3290 15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
iap10@3290 16 * Place - Suite 330, Boston, MA 02111-1307 USA.
iap10@3290 17 *
iap10@3290 18 */
iap10@3290 19 #ifndef __ASM_X86_VMX_H__
iap10@3290 20 #define __ASM_X86_VMX_H__
iap10@3290 21
iap10@3290 22 #include <xen/sched.h>
iap10@3290 23 #include <asm/types.h>
iap10@3290 24 #include <asm/regs.h>
iap10@3290 25 #include <asm/processor.h>
iap10@3290 26 #include <asm/vmx_vmcs.h>
cl349@4856 27 #include <asm/i387.h>
iap10@3290 28
arun@5608 29 #include <public/io/ioreq.h>
arun@5608 30
kaf24@4683 31 extern void vmx_asm_vmexit_handler(struct cpu_user_regs);
iap10@3290 32 extern void vmx_asm_do_resume(void);
iap10@3290 33 extern void vmx_asm_do_launch(void);
kaf24@5289 34 extern void vmx_intr_assist(struct vcpu *d);
iap10@3290 35
kaf24@5289 36 extern void arch_vmx_do_launch(struct vcpu *);
kaf24@5289 37 extern void arch_vmx_do_resume(struct vcpu *);
iap10@3290 38
iap10@3290 39 extern int vmcs_size;
iap10@3290 40 extern unsigned int cpu_rev;
iap10@3290 41
iap10@3290 42 /*
iap10@3290 43 * Need fill bits for SENTER
iap10@3290 44 */
iap10@3290 45
kaf24@5414 46 #define MONITOR_PIN_BASED_EXEC_CONTROLS_RESERVED_VALUE 0x00000016
kaf24@5414 47
kaf24@5414 48 #define MONITOR_PIN_BASED_EXEC_CONTROLS \
kaf24@5414 49 MONITOR_PIN_BASED_EXEC_CONTROLS_RESERVED_VALUE | \
kaf24@5414 50 PIN_BASED_EXT_INTR_MASK | \
kaf24@5414 51 PIN_BASED_NMI_EXITING
kaf24@5414 52
kaf24@5414 53 #define MONITOR_CPU_BASED_EXEC_CONTROLS_RESERVED_VALUE 0x0401e172
iap10@3290 54
kaf24@5414 55 #define MONITOR_CPU_BASED_EXEC_CONTROLS \
kaf24@5414 56 MONITOR_CPU_BASED_EXEC_CONTROLS_RESERVED_VALUE | \
kaf24@5414 57 CPU_BASED_HLT_EXITING | \
kaf24@5414 58 CPU_BASED_INVDPG_EXITING | \
kaf24@5414 59 CPU_BASED_MWAIT_EXITING | \
kaf24@5414 60 CPU_BASED_MOV_DR_EXITING | \
kaf24@5414 61 CPU_BASED_UNCOND_IO_EXITING | \
kaf24@5414 62 CPU_BASED_CR8_LOAD_EXITING | \
kaf24@5414 63 CPU_BASED_CR8_STORE_EXITING
kaf24@5414 64
kaf24@5414 65 #define MONITOR_VM_EXIT_CONTROLS_RESERVED_VALUE 0x0003edff
kaf24@5414 66
kaf24@5414 67 #define VM_EXIT_CONTROLS_IA_32E_MODE 0x00000200
kaf24@5414 68
kaf24@5414 69 #define MONITOR_VM_EXIT_CONTROLS \
kaf24@5414 70 MONITOR_VM_EXIT_CONTROLS_RESERVED_VALUE |\
kaf24@5414 71 VM_EXIT_ACK_INTR_ON_EXIT
kaf24@5414 72
kaf24@5414 73 #define VM_ENTRY_CONTROLS_RESERVED_VALUE 0x000011ff
kaf24@5414 74 #define VM_ENTRY_CONTROLS_IA_32E_MODE 0x00000200
kaf24@5414 75 #define MONITOR_VM_ENTRY_CONTROLS VM_ENTRY_CONTROLS_RESERVED_VALUE
iap10@3290 76 /*
iap10@3290 77 * Exit Reasons
iap10@3290 78 */
iap10@3290 79 #define VMX_EXIT_REASONS_FAILED_VMENTRY 0x80000000
iap10@3290 80
iap10@3290 81 #define EXIT_REASON_EXCEPTION_NMI 0
iap10@3290 82 #define EXIT_REASON_EXTERNAL_INTERRUPT 1
iap10@3290 83
iap10@3290 84 #define EXIT_REASON_PENDING_INTERRUPT 7
iap10@3290 85
iap10@3290 86 #define EXIT_REASON_TASK_SWITCH 9
iap10@3290 87 #define EXIT_REASON_CPUID 10
iap10@3290 88 #define EXIT_REASON_HLT 12
iap10@3290 89 #define EXIT_REASON_INVLPG 14
iap10@3290 90 #define EXIT_REASON_RDPMC 15
iap10@3290 91 #define EXIT_REASON_RDTSC 16
iap10@3290 92 #define EXIT_REASON_VMCALL 18
iap10@3290 93
iap10@3290 94 #define EXIT_REASON_CR_ACCESS 28
iap10@3290 95 #define EXIT_REASON_DR_ACCESS 29
iap10@3290 96 #define EXIT_REASON_IO_INSTRUCTION 30
iap10@3290 97 #define EXIT_REASON_MSR_READ 31
iap10@3290 98 #define EXIT_REASON_MSR_WRITE 32
iap10@3290 99 #define EXIT_REASON_MWAIT_INSTRUCTION 36
iap10@3290 100
iap10@3290 101 /*
iap10@3290 102 * Interruption-information format
iap10@3290 103 */
iap10@3290 104 #define INTR_INFO_VECTOR_MASK 0xff /* 7:0 */
iap10@3290 105 #define INTR_INFO_INTR_TYPE_MASK 0x700 /* 10:8 */
iap10@3290 106 #define INTR_INFO_DELIEVER_CODE_MASK 0x800 /* 11 */
iap10@3290 107 #define INTR_INFO_VALID_MASK 0x80000000 /* 31 */
iap10@3290 108
iap10@3290 109 #define INTR_TYPE_EXT_INTR (0 << 8) /* external interrupt */
iap10@3290 110 #define INTR_TYPE_EXCEPTION (3 << 8) /* processor exception */
iap10@3290 111
iap10@3290 112 /*
iap10@3290 113 * Exit Qualifications for MOV for Control Register Access
iap10@3290 114 */
iap10@3290 115 #define CONTROL_REG_ACCESS_NUM 0x7 /* 2:0, number of control register */
iap10@3290 116 #define CONTROL_REG_ACCESS_TYPE 0x30 /* 5:4, access type */
iap10@3290 117 #define TYPE_MOV_TO_CR (0 << 4)
iap10@3290 118 #define TYPE_MOV_FROM_CR (1 << 4)
iap10@3290 119 #define TYPE_CLTS (2 << 4)
leendert@4652 120 #define TYPE_LMSW (3 << 4)
kaf24@5414 121 #define CONTROL_REG_ACCESS_REG 0xf00 /* 10:8, general purpose register */
kaf24@5414 122 #define LMSW_SOURCE_DATA (0xFFFF << 16) /* 16:31 lmsw source */
iap10@3290 123 #define REG_EAX (0 << 8)
iap10@3290 124 #define REG_ECX (1 << 8)
iap10@3290 125 #define REG_EDX (2 << 8)
iap10@3290 126 #define REG_EBX (3 << 8)
iap10@3290 127 #define REG_ESP (4 << 8)
iap10@3290 128 #define REG_EBP (5 << 8)
iap10@3290 129 #define REG_ESI (6 << 8)
iap10@3290 130 #define REG_EDI (7 << 8)
kaf24@5414 131 #define REG_R8 (8 << 8)
kaf24@5414 132 #define REG_R9 (9 << 8)
kaf24@5414 133 #define REG_R10 (10 << 8)
kaf24@5414 134 #define REG_R11 (11 << 8)
kaf24@5414 135 #define REG_R12 (12 << 8)
kaf24@5414 136 #define REG_R13 (13 << 8)
kaf24@5414 137 #define REG_R14 (14 << 8)
kaf24@5414 138 #define REG_R15 (15 << 8)
iap10@3290 139
iap10@3290 140 /*
iap10@3290 141 * Exit Qualifications for MOV for Debug Register Access
iap10@3290 142 */
iap10@3290 143 #define DEBUG_REG_ACCESS_NUM 0x7 /* 2:0, number of debug register */
iap10@3290 144 #define DEBUG_REG_ACCESS_TYPE 0x10 /* 4, direction of access */
iap10@3290 145 #define TYPE_MOV_TO_DR (0 << 4)
iap10@3290 146 #define TYPE_MOV_FROM_DR (1 << 4)
kaf24@5414 147 #define DEBUG_REG_ACCESS_REG 0xf00 /* 11:8, general purpose register */
iap10@3290 148
iap10@3290 149 #define EXCEPTION_BITMAP_DE (1 << 0) /* Divide Error */
iap10@3290 150 #define EXCEPTION_BITMAP_DB (1 << 1) /* Debug */
iap10@3290 151 #define EXCEPTION_BITMAP_NMI (1 << 2) /* NMI */
iap10@3290 152 #define EXCEPTION_BITMAP_BP (1 << 3) /* Breakpoint */
iap10@3290 153 #define EXCEPTION_BITMAP_OF (1 << 4) /* Overflow */
iap10@3290 154 #define EXCEPTION_BITMAP_BR (1 << 5) /* BOUND Range Exceeded */
iap10@3290 155 #define EXCEPTION_BITMAP_UD (1 << 6) /* Invalid Opcode */
iap10@3290 156 #define EXCEPTION_BITMAP_NM (1 << 7) /* Device Not Available */
iap10@3290 157 #define EXCEPTION_BITMAP_DF (1 << 8) /* Double Fault */
iap10@3290 158 /* reserved */
iap10@3290 159 #define EXCEPTION_BITMAP_TS (1 << 10) /* Invalid TSS */
iap10@3290 160 #define EXCEPTION_BITMAP_NP (1 << 11) /* Segment Not Present */
iap10@3290 161 #define EXCEPTION_BITMAP_SS (1 << 12) /* Stack-Segment Fault */
iap10@3290 162 #define EXCEPTION_BITMAP_GP (1 << 13) /* General Protection */
iap10@3290 163 #define EXCEPTION_BITMAP_PG (1 << 14) /* Page Fault */
iap10@3290 164 #define EXCEPTION_BITMAP_MF (1 << 16) /* x87 FPU Floating-Point Error (Math Fault) */
iap10@3290 165 #define EXCEPTION_BITMAP_AC (1 << 17) /* Alignment Check */
iap10@3290 166 #define EXCEPTION_BITMAP_MC (1 << 18) /* Machine Check */
iap10@3290 167 #define EXCEPTION_BITMAP_XF (1 << 19) /* SIMD Floating-Point Exception */
iap10@3290 168
arun@4999 169 /* Pending Debug exceptions */
arun@4999 170
arun@4999 171 #define PENDING_DEBUG_EXC_BP (1 << 12) /* break point */
arun@4999 172 #define PENDING_DEBUG_EXC_BS (1 << 14) /* Single step */
arun@4999 173
iap10@3290 174 #ifdef XEN_DEBUGGER
iap10@3290 175 #define MONITOR_DEFAULT_EXCEPTION_BITMAP \
iap10@3290 176 ( EXCEPTION_BITMAP_PG | \
iap10@3290 177 EXCEPTION_BITMAP_DB | \
iap10@3290 178 EXCEPTION_BITMAP_BP | \
iap10@3290 179 EXCEPTION_BITMAP_GP )
iap10@3290 180 #else
iap10@3290 181 #define MONITOR_DEFAULT_EXCEPTION_BITMAP \
iap10@3290 182 ( EXCEPTION_BITMAP_PG | \
iap10@3290 183 EXCEPTION_BITMAP_GP )
iap10@3290 184 #endif
iap10@3290 185
iap10@3290 186 #define VMCALL_OPCODE ".byte 0x0f,0x01,0xc1\n"
iap10@3290 187 #define VMCLEAR_OPCODE ".byte 0x66,0x0f,0xc7\n" /* reg/opcode: /6 */
iap10@3290 188 #define VMLAUNCH_OPCODE ".byte 0x0f,0x01,0xc2\n"
iap10@3290 189 #define VMPTRLD_OPCODE ".byte 0x0f,0xc7\n" /* reg/opcode: /6 */
iap10@3290 190 #define VMPTRST_OPCODE ".byte 0x0f,0xc7\n" /* reg/opcode: /7 */
iap10@3290 191 #define VMREAD_OPCODE ".byte 0x0f,0x78\n"
iap10@3290 192 #define VMRESUME_OPCODE ".byte 0x0f,0x01,0xc3\n"
iap10@3290 193 #define VMWRITE_OPCODE ".byte 0x0f,0x79\n"
iap10@3290 194 #define VMXOFF_OPCODE ".byte 0x0f,0x01,0xc4\n"
iap10@3290 195 #define VMXON_OPCODE ".byte 0xf3,0x0f,0xc7\n"
iap10@3290 196
iap10@3290 197 #define MODRM_EAX_06 ".byte 0x30\n" /* [EAX], with reg/opcode: /6 */
iap10@3290 198 #define MODRM_EAX_07 ".byte 0x38\n" /* [EAX], with reg/opcode: /7 */
iap10@3290 199 #define MODRM_EAX_ECX ".byte 0xc1\n" /* [EAX], [ECX] */
iap10@3290 200
iap10@3290 201 static inline int __vmptrld (u64 addr)
iap10@3290 202 {
iap10@3290 203 unsigned long eflags;
iap10@3290 204 __asm__ __volatile__ ( VMPTRLD_OPCODE
iap10@3290 205 MODRM_EAX_06
iap10@3290 206 :
iap10@3290 207 : "a" (&addr)
iap10@3290 208 : "memory");
iap10@3290 209
iap10@3290 210 __save_flags(eflags);
iap10@3290 211 if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
iap10@3290 212 return -1;
iap10@3290 213 return 0;
iap10@3290 214 }
iap10@3290 215
iap10@3290 216 static inline void __vmptrst (u64 addr)
iap10@3290 217 {
iap10@3290 218 __asm__ __volatile__ ( VMPTRST_OPCODE
iap10@3290 219 MODRM_EAX_07
iap10@3290 220 :
iap10@3290 221 : "a" (&addr)
iap10@3290 222 : "memory");
iap10@3290 223 }
iap10@3290 224
iap10@3290 225 static inline int __vmpclear (u64 addr)
iap10@3290 226 {
iap10@3290 227 unsigned long eflags;
iap10@3290 228
iap10@3290 229 __asm__ __volatile__ ( VMCLEAR_OPCODE
iap10@3290 230 MODRM_EAX_06
iap10@3290 231 :
iap10@3290 232 : "a" (&addr)
iap10@3290 233 : "memory");
iap10@3290 234 __save_flags(eflags);
iap10@3290 235 if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
iap10@3290 236 return -1;
iap10@3290 237 return 0;
iap10@3290 238 }
iap10@3290 239
arun@4586 240 static inline int __vmread (unsigned long field, void *value)
iap10@3290 241 {
iap10@3290 242 unsigned long eflags;
iap10@3290 243 unsigned long ecx = 0;
iap10@3290 244
iap10@3290 245 __asm__ __volatile__ ( VMREAD_OPCODE
iap10@3290 246 MODRM_EAX_ECX
iap10@3290 247 : "=c" (ecx)
iap10@3290 248 : "a" (field)
iap10@3290 249 : "memory");
iap10@3290 250
iap10@3290 251 *((long *) value) = ecx;
iap10@3290 252
iap10@3290 253 __save_flags(eflags);
iap10@3290 254 if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
iap10@3290 255 return -1;
iap10@3290 256 return 0;
iap10@3290 257 }
iap10@3290 258
arun@4586 259 static inline int __vmwrite (unsigned long field, unsigned long value)
iap10@3290 260 {
iap10@3290 261 unsigned long eflags;
iap10@3290 262
iap10@3290 263 __asm__ __volatile__ ( VMWRITE_OPCODE
iap10@3290 264 MODRM_EAX_ECX
iap10@3290 265 :
iap10@3290 266 : "a" (field) , "c" (value)
iap10@3290 267 : "memory");
iap10@3290 268 __save_flags(eflags);
iap10@3290 269 if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
iap10@3290 270 return -1;
iap10@3290 271 return 0;
iap10@3290 272 }
iap10@3290 273
arun@4999 274 static inline int __vm_set_bit(unsigned long field, unsigned long mask)
arun@4999 275 {
arun@4999 276 unsigned long tmp;
arun@4999 277 int err = 0;
arun@4999 278
arun@4999 279 err |= __vmread(field, &tmp);
arun@4999 280 tmp |= mask;
arun@4999 281 err |= __vmwrite(field, tmp);
arun@4999 282
arun@4999 283 return err;
arun@4999 284 }
arun@4999 285
arun@4999 286 static inline int __vm_clear_bit(unsigned long field, unsigned long mask)
arun@4999 287 {
arun@4999 288 unsigned long tmp;
arun@4999 289 int err = 0;
arun@4999 290
arun@4999 291 err |= __vmread(field, &tmp);
arun@4999 292 tmp &= ~mask;
arun@4999 293 err |= __vmwrite(field, tmp);
arun@4999 294
arun@4999 295 return err;
arun@4999 296 }
arun@4999 297
iap10@3290 298 static inline void __vmxoff (void)
iap10@3290 299 {
iap10@3290 300 __asm__ __volatile__ ( VMXOFF_OPCODE
iap10@3290 301 ::: "memory");
iap10@3290 302 }
iap10@3290 303
iap10@3290 304 static inline int __vmxon (u64 addr)
iap10@3290 305 {
iap10@3290 306 unsigned long eflags;
iap10@3290 307
iap10@3290 308 __asm__ __volatile__ ( VMXON_OPCODE
iap10@3290 309 MODRM_EAX_06
iap10@3290 310 :
iap10@3290 311 : "a" (&addr)
iap10@3290 312 : "memory");
iap10@3290 313 __save_flags(eflags);
iap10@3290 314 if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
iap10@3290 315 return -1;
iap10@3290 316 return 0;
iap10@3290 317 }
arun@3910 318
cl349@4856 319 /* Make sure that xen intercepts any FP accesses from current */
cl349@4856 320 static inline void vmx_stts()
cl349@4856 321 {
cl349@4856 322 unsigned long cr0;
cl349@4856 323
cl349@4856 324 __vmread(GUEST_CR0, &cr0);
cl349@4856 325 if (!(cr0 & X86_CR0_TS))
cl349@4856 326 __vmwrite(GUEST_CR0, cr0 | X86_CR0_TS);
cl349@4856 327
cl349@4856 328 __vmread(CR0_READ_SHADOW, &cr0);
cl349@4856 329 if (!(cr0 & X86_CR0_TS))
arun@4999 330 __vm_set_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_NM);
cl349@4856 331 }
arun@5186 332
arun@5186 333 /* Works only for ed == current */
kaf24@5289 334 static inline int vmx_paging_enabled(struct vcpu *v)
arun@5186 335 {
arun@5186 336 unsigned long cr0;
arun@5186 337
arun@5186 338 __vmread(CR0_READ_SHADOW, &cr0);
arun@5186 339 return (cr0 & X86_CR0_PE) && (cr0 & X86_CR0_PG);
arun@5186 340 }
arun@5186 341
arun@5615 342 static inline shared_iopage_t *get_sp(struct domain *d)
arun@5615 343 {
arun@5615 344 return (shared_iopage_t *) d->arch.vmx_platform.shared_page_va;
arun@5615 345 }
arun@5615 346
arun@5608 347 static inline vcpu_iodata_t *get_vio(struct domain *d, unsigned long cpu)
arun@5608 348 {
arun@5615 349 return &get_sp(d)->vcpu_iodata[cpu];
arun@5608 350 }
arun@5608 351
arun@5608 352 static inline int iopacket_port(struct domain *d)
arun@5608 353 {
arun@5615 354 return get_sp(d)->sp_global.eport;
arun@5608 355 }
arun@5608 356
iap10@3290 357 #endif /* __ASM_X86_VMX_H__ */