vmm.h revision 268701
1221828Sgrehan/*- 2221828Sgrehan * Copyright (c) 2011 NetApp, Inc. 3221828Sgrehan * All rights reserved. 4221828Sgrehan * 5221828Sgrehan * Redistribution and use in source and binary forms, with or without 6221828Sgrehan * modification, are permitted provided that the following conditions 7221828Sgrehan * are met: 8221828Sgrehan * 1. Redistributions of source code must retain the above copyright 9221828Sgrehan * notice, this list of conditions and the following disclaimer. 10221828Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 11221828Sgrehan * notice, this list of conditions and the following disclaimer in the 12221828Sgrehan * documentation and/or other materials provided with the distribution. 13221828Sgrehan * 14221828Sgrehan * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 15221828Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16221828Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17221828Sgrehan * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 18221828Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19221828Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20221828Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21221828Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22221828Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23221828Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24221828Sgrehan * SUCH DAMAGE. 25221828Sgrehan * 26245678Sneel * $FreeBSD: head/sys/amd64/include/vmm.h 268701 2014-07-15 17:37:17Z neel $ 27221828Sgrehan */ 28221828Sgrehan 29221828Sgrehan#ifndef _VMM_H_ 30221828Sgrehan#define _VMM_H_ 31221828Sgrehan 32265062Sneelenum vm_suspend_how { 33265062Sneel VM_SUSPEND_NONE, 34265062Sneel VM_SUSPEND_RESET, 35265062Sneel VM_SUSPEND_POWEROFF, 36265203Sneel VM_SUSPEND_HALT, 37265062Sneel VM_SUSPEND_LAST 38265062Sneel}; 39265062Sneel 40267338Stychon/* 41267338Stychon * Identifiers for architecturally defined registers. 42267338Stychon */ 43267338Stychonenum vm_reg_name { 44267338Stychon VM_REG_GUEST_RAX, 45267338Stychon VM_REG_GUEST_RBX, 46267338Stychon VM_REG_GUEST_RCX, 47267338Stychon VM_REG_GUEST_RDX, 48267338Stychon VM_REG_GUEST_RSI, 49267338Stychon VM_REG_GUEST_RDI, 50267338Stychon VM_REG_GUEST_RBP, 51267338Stychon VM_REG_GUEST_R8, 52267338Stychon VM_REG_GUEST_R9, 53267338Stychon VM_REG_GUEST_R10, 54267338Stychon VM_REG_GUEST_R11, 55267338Stychon VM_REG_GUEST_R12, 56267338Stychon VM_REG_GUEST_R13, 57267338Stychon VM_REG_GUEST_R14, 58267338Stychon VM_REG_GUEST_R15, 59267338Stychon VM_REG_GUEST_CR0, 60267338Stychon VM_REG_GUEST_CR3, 61267338Stychon VM_REG_GUEST_CR4, 62267338Stychon VM_REG_GUEST_DR7, 63267338Stychon VM_REG_GUEST_RSP, 64267338Stychon VM_REG_GUEST_RIP, 65267338Stychon VM_REG_GUEST_RFLAGS, 66267338Stychon VM_REG_GUEST_ES, 67267338Stychon VM_REG_GUEST_CS, 68267338Stychon VM_REG_GUEST_SS, 69267338Stychon VM_REG_GUEST_DS, 70267338Stychon VM_REG_GUEST_FS, 71267338Stychon VM_REG_GUEST_GS, 72267338Stychon VM_REG_GUEST_LDTR, 73267338Stychon VM_REG_GUEST_TR, 74267338Stychon VM_REG_GUEST_IDTR, 75267338Stychon VM_REG_GUEST_GDTR, 76267338Stychon VM_REG_GUEST_EFER, 77267338Stychon VM_REG_GUEST_CR2, 78267338Stychon VM_REG_LAST 79267338Stychon}; 80267338Stychon 81267338Stychonenum x2apic_state { 82267338Stychon X2APIC_DISABLED, 83267338Stychon X2APIC_ENABLED, 84267338Stychon X2APIC_STATE_LAST 85267338Stychon}; 86267338Stychon 87221828Sgrehan#ifdef _KERNEL 88221828Sgrehan 89221828Sgrehan#define VM_MAX_NAMELEN 32 90221828Sgrehan 91221828Sgrehanstruct vm; 92262506Sneelstruct vm_exception; 93221828Sgrehanstruct vm_memory_segment; 94221828Sgrehanstruct seg_desc; 95221828Sgrehanstruct vm_exit; 96221828Sgrehanstruct vm_run; 97258579Sneelstruct vhpet; 98258075Sneelstruct vioapic; 99221828Sgrehanstruct vlapic; 100256072Sneelstruct vmspace; 101256072Sneelstruct vm_object; 102256072Sneelstruct pmap; 103221828Sgrehan 104260466Sneeltypedef int (*vmm_init_func_t)(int ipinum); 105221828Sgrehantypedef int (*vmm_cleanup_func_t)(void); 106259782Sjhbtypedef void (*vmm_resume_func_t)(void); 107256072Sneeltypedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap); 108256072Sneeltypedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip, 109263780Sneel struct pmap *pmap, void *rendezvous_cookie, 110263780Sneel void *suspend_cookie); 111221828Sgrehantypedef void (*vmi_cleanup_func_t)(void *vmi); 112221828Sgrehantypedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num, 113221828Sgrehan uint64_t *retval); 114221828Sgrehantypedef int (*vmi_set_register_t)(void *vmi, int vcpu, int num, 115221828Sgrehan uint64_t val); 116221828Sgrehantypedef int (*vmi_get_desc_t)(void *vmi, int vcpu, int num, 117221828Sgrehan struct seg_desc *desc); 118221828Sgrehantypedef int (*vmi_set_desc_t)(void *vmi, int vcpu, int num, 119221828Sgrehan struct seg_desc *desc); 120221828Sgrehantypedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval); 121221828Sgrehantypedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val); 122256072Sneeltypedef struct vmspace * (*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max); 123256072Sneeltypedef void (*vmi_vmspace_free)(struct vmspace *vmspace); 124259863Sneeltypedef struct vlapic * (*vmi_vlapic_init)(void *vmi, int vcpu); 125259863Sneeltypedef void (*vmi_vlapic_cleanup)(void *vmi, struct vlapic *vlapic); 126221828Sgrehan 127221828Sgrehanstruct vmm_ops { 128221828Sgrehan vmm_init_func_t init; /* module wide initialization */ 129221828Sgrehan vmm_cleanup_func_t cleanup; 130259782Sjhb vmm_resume_func_t resume; 131221828Sgrehan 132221828Sgrehan vmi_init_func_t vminit; /* vm-specific initialization */ 133221828Sgrehan vmi_run_func_t vmrun; 134221828Sgrehan vmi_cleanup_func_t vmcleanup; 135221828Sgrehan vmi_get_register_t vmgetreg; 136221828Sgrehan vmi_set_register_t vmsetreg; 137221828Sgrehan vmi_get_desc_t vmgetdesc; 138221828Sgrehan vmi_set_desc_t vmsetdesc; 139221828Sgrehan vmi_get_cap_t vmgetcap; 140221828Sgrehan vmi_set_cap_t vmsetcap; 141256072Sneel vmi_vmspace_alloc vmspace_alloc; 142256072Sneel vmi_vmspace_free vmspace_free; 143259863Sneel vmi_vlapic_init vlapic_init; 144259863Sneel vmi_vlapic_cleanup vlapic_cleanup; 145221828Sgrehan}; 146221828Sgrehan 147221828Sgrehanextern struct vmm_ops vmm_ops_intel; 148221828Sgrehanextern struct vmm_ops vmm_ops_amd; 149221828Sgrehan 150249396Sneelint vm_create(const char *name, struct vm **retvm); 151221828Sgrehanvoid vm_destroy(struct vm *vm); 152267216Sneelint vm_reinit(struct vm *vm); 153221828Sgrehanconst char *vm_name(struct vm *vm); 154241041Sneelint vm_malloc(struct vm *vm, vm_paddr_t gpa, size_t len); 155221828Sgrehanint vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa); 156221828Sgrehanint vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len); 157256072Sneelvoid *vm_gpa_hold(struct vm *, vm_paddr_t gpa, size_t len, int prot, 158256072Sneel void **cookie); 159256072Sneelvoid vm_gpa_release(void *cookie); 160221828Sgrehanint vm_gpabase2memseg(struct vm *vm, vm_paddr_t gpabase, 161221828Sgrehan struct vm_memory_segment *seg); 162256072Sneelint vm_get_memobj(struct vm *vm, vm_paddr_t gpa, size_t len, 163256072Sneel vm_offset_t *offset, struct vm_object **object); 164256072Sneelboolean_t vm_mem_allocated(struct vm *vm, vm_paddr_t gpa); 165221828Sgrehanint vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval); 166221828Sgrehanint vm_set_register(struct vm *vm, int vcpu, int reg, uint64_t val); 167221828Sgrehanint vm_get_seg_desc(struct vm *vm, int vcpu, int reg, 168221828Sgrehan struct seg_desc *ret_desc); 169221828Sgrehanint vm_set_seg_desc(struct vm *vm, int vcpu, int reg, 170221828Sgrehan struct seg_desc *desc); 171221828Sgrehanint vm_run(struct vm *vm, struct vm_run *vmrun); 172265062Sneelint vm_suspend(struct vm *vm, enum vm_suspend_how how); 173221828Sgrehanint vm_inject_nmi(struct vm *vm, int vcpu); 174241982Sneelint vm_nmi_pending(struct vm *vm, int vcpuid); 175241982Sneelvoid vm_nmi_clear(struct vm *vm, int vcpuid); 176263211Stychonint vm_inject_extint(struct vm *vm, int vcpu); 177263211Stychonint vm_extint_pending(struct vm *vm, int vcpuid); 178263211Stychonvoid vm_extint_clear(struct vm *vm, int vcpuid); 179221828Sgrehanuint64_t *vm_guest_msrs(struct vm *vm, int cpu); 180221828Sgrehanstruct vlapic *vm_lapic(struct vm *vm, int cpu); 181258075Sneelstruct vioapic *vm_ioapic(struct vm *vm); 182258579Sneelstruct vhpet *vm_hpet(struct vm *vm); 183221828Sgrehanint vm_get_capability(struct vm *vm, int vcpu, int type, int *val); 184221828Sgrehanint vm_set_capability(struct vm *vm, int vcpu, int type, int val); 185240922Sneelint vm_get_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state *state); 186240922Sneelint vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state); 187258075Sneelint vm_apicid2vcpuid(struct vm *vm, int apicid); 188266933Sneelint vm_activate_cpu(struct vm *vm, int vcpu); 189223621Sgrehancpuset_t vm_active_cpus(struct vm *vm); 190266933Sneelcpuset_t vm_suspended_cpus(struct vm *vm); 191240894Sneelstruct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid); 192265062Sneelvoid vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip); 193267330Sneelvoid vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip); 194267330Sneelvoid vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip); 195221828Sgrehan 196221828Sgrehan/* 197260619Sneel * Rendezvous all vcpus specified in 'dest' and execute 'func(arg)'. 198260619Sneel * The rendezvous 'func(arg)' is not allowed to do anything that will 199260619Sneel * cause the thread to be put to sleep. 200260619Sneel * 201260619Sneel * If the rendezvous is being initiated from a vcpu context then the 202260619Sneel * 'vcpuid' must refer to that vcpu, otherwise it should be set to -1. 203260619Sneel * 204260619Sneel * The caller cannot hold any locks when initiating the rendezvous. 205260619Sneel * 206260619Sneel * The implementation of this API may cause vcpus other than those specified 207260619Sneel * by 'dest' to be stalled. The caller should not rely on any vcpus making 208260619Sneel * forward progress when the rendezvous is in progress. 209260619Sneel */ 210260619Sneeltypedef void (*vm_rendezvous_func_t)(struct vm *vm, int vcpuid, void *arg); 211260619Sneelvoid vm_smp_rendezvous(struct vm *vm, int vcpuid, cpuset_t dest, 212260619Sneel vm_rendezvous_func_t func, void *arg); 213260619Sneel 214260619Sneelstatic __inline int 215260619Sneelvcpu_rendezvous_pending(void *rendezvous_cookie) 216260619Sneel{ 217260619Sneel 218260619Sneel return (*(uintptr_t *)rendezvous_cookie != 0); 219260619Sneel} 220260619Sneel 221263780Sneelstatic __inline int 222263780Sneelvcpu_suspended(void *suspend_cookie) 223263780Sneel{ 224263780Sneel 225263780Sneel return (*(int *)suspend_cookie); 226263780Sneel} 227263780Sneel 228260619Sneel/* 229221828Sgrehan * Return 1 if device indicated by bus/slot/func is supposed to be a 230221828Sgrehan * pci passthrough device. 231221828Sgrehan * 232221828Sgrehan * Return 0 otherwise. 233221828Sgrehan */ 234221828Sgrehanint vmm_is_pptdev(int bus, int slot, int func); 235221828Sgrehan 236221828Sgrehanvoid *vm_iommu_domain(struct vm *vm); 237221828Sgrehan 238241489Sneelenum vcpu_state { 239241489Sneel VCPU_IDLE, 240256072Sneel VCPU_FROZEN, 241241489Sneel VCPU_RUNNING, 242256072Sneel VCPU_SLEEPING, 243241489Sneel}; 244221828Sgrehan 245259737Sneelint vcpu_set_state(struct vm *vm, int vcpu, enum vcpu_state state, 246259737Sneel bool from_idle); 247249879Sgrehanenum vcpu_state vcpu_get_state(struct vm *vm, int vcpu, int *hostcpu); 248221828Sgrehan 249221828Sgrehanstatic int __inline 250249879Sgrehanvcpu_is_running(struct vm *vm, int vcpu, int *hostcpu) 251221828Sgrehan{ 252249879Sgrehan return (vcpu_get_state(vm, vcpu, hostcpu) == VCPU_RUNNING); 253221828Sgrehan} 254221828Sgrehan 255241489Sneelvoid *vcpu_stats(struct vm *vm, int vcpu); 256259863Sneelvoid vcpu_notify_event(struct vm *vm, int vcpuid, bool lapic_intr); 257256072Sneelstruct vmspace *vm_get_vmspace(struct vm *vm); 258256072Sneelint vm_assign_pptdev(struct vm *vm, int bus, int slot, int func); 259256072Sneelint vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func); 260263035Stychonstruct vatpic *vm_atpic(struct vm *vm); 261263744Stychonstruct vatpit *vm_atpit(struct vm *vm); 262262506Sneel 263262506Sneel/* 264262506Sneel * Inject exception 'vme' into the guest vcpu. This function returns 0 on 265262506Sneel * success and non-zero on failure. 266262506Sneel * 267262506Sneel * Wrapper functions like 'vm_inject_gp()' should be preferred to calling 268262506Sneel * this function directly because they enforce the trap-like or fault-like 269262506Sneel * behavior of an exception. 270262506Sneel * 271262506Sneel * This function should only be called in the context of the thread that is 272262506Sneel * executing this vcpu. 273262506Sneel */ 274262506Sneelint vm_inject_exception(struct vm *vm, int vcpuid, struct vm_exception *vme); 275262506Sneel 276262506Sneel/* 277262506Sneel * Returns 0 if there is no exception pending for this vcpu. Returns 1 if an 278262506Sneel * exception is pending and also updates 'vme'. The pending exception is 279262506Sneel * cleared when this function returns. 280262506Sneel * 281262506Sneel * This function should only be called in the context of the thread that is 282262506Sneel * executing this vcpu. 283262506Sneel */ 284262506Sneelint vm_exception_pending(struct vm *vm, int vcpuid, struct vm_exception *vme); 285262506Sneel 286262506Sneelvoid vm_inject_gp(struct vm *vm, int vcpuid); /* general protection fault */ 287262506Sneelvoid vm_inject_ud(struct vm *vm, int vcpuid); /* undefined instruction fault */ 288266626Sneelvoid vm_inject_pf(struct vm *vm, int vcpuid, int error_code, uint64_t cr2); 289262506Sneel 290266573Sneelenum vm_reg_name vm_segment_name(int seg_encoding); 291266573Sneel 292221828Sgrehan#endif /* KERNEL */ 293221828Sgrehan 294255438Sgrehan#define VM_MAXCPU 16 /* maximum virtual cpus */ 295221828Sgrehan 296221828Sgrehan/* 297221828Sgrehan * Identifiers for optional vmm capabilities 298221828Sgrehan */ 299221828Sgrehanenum vm_cap_type { 300221828Sgrehan VM_CAP_HALT_EXIT, 301221828Sgrehan VM_CAP_MTRAP_EXIT, 302221828Sgrehan VM_CAP_PAUSE_EXIT, 303221828Sgrehan VM_CAP_UNRESTRICTED_GUEST, 304256645Sneel VM_CAP_ENABLE_INVPCID, 305221828Sgrehan VM_CAP_MAX 306221828Sgrehan}; 307221828Sgrehan 308266125Sjhbenum vm_intr_trigger { 309266125Sjhb EDGE_TRIGGER, 310266125Sjhb LEVEL_TRIGGER 311266125Sjhb}; 312266125Sjhb 313221828Sgrehan/* 314221828Sgrehan * The 'access' field has the format specified in Table 21-2 of the Intel 315221828Sgrehan * Architecture Manual vol 3b. 316221828Sgrehan * 317221828Sgrehan * XXX The contents of the 'access' field are architecturally defined except 318221828Sgrehan * bit 16 - Segment Unusable. 319221828Sgrehan */ 320221828Sgrehanstruct seg_desc { 321221828Sgrehan uint64_t base; 322221828Sgrehan uint32_t limit; 323221828Sgrehan uint32_t access; 324221828Sgrehan}; 325268701Sneel#define SEG_DESC_TYPE(access) ((access) & 0x001f) 326268701Sneel#define SEG_DESC_PRESENT(access) (((access) & 0x0080) ? 1 : 0) 327268701Sneel#define SEG_DESC_DEF32(access) (((access) & 0x4000) ? 1 : 0) 328268701Sneel#define SEG_DESC_GRANULARITY(access) (((access) & 0x8000) ? 1 : 0) 329268701Sneel#define SEG_DESC_UNUSABLE(access) (((access) & 0x10000) ? 1 : 0) 330221828Sgrehan 331266627Sneelenum vm_cpu_mode { 332268428Sneel CPU_MODE_REAL, 333268428Sneel CPU_MODE_PROTECTED, 334266627Sneel CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */ 335266627Sneel CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */ 336266627Sneel}; 337266627Sneel 338266627Sneelenum vm_paging_mode { 339266627Sneel PAGING_MODE_FLAT, 340266627Sneel PAGING_MODE_32, 341266627Sneel PAGING_MODE_PAE, 342266627Sneel PAGING_MODE_64, 343266627Sneel}; 344266627Sneel 345266627Sneelstruct vm_guest_paging { 346266627Sneel uint64_t cr3; 347266627Sneel int cpl; 348266627Sneel enum vm_cpu_mode cpu_mode; 349266627Sneel enum vm_paging_mode paging_mode; 350266627Sneel}; 351266627Sneel 352266627Sneel/* 353266627Sneel * The data structures 'vie' and 'vie_op' are meant to be opaque to the 354266627Sneel * consumers of instruction decoding. The only reason why their contents 355266627Sneel * need to be exposed is because they are part of the 'vm_exit' structure. 356266627Sneel */ 357266627Sneelstruct vie_op { 358266627Sneel uint8_t op_byte; /* actual opcode byte */ 359266627Sneel uint8_t op_type; /* type of operation (e.g. MOV) */ 360266627Sneel uint16_t op_flags; 361266627Sneel}; 362266627Sneel 363266627Sneel#define VIE_INST_SIZE 15 364266627Sneelstruct vie { 365266627Sneel uint8_t inst[VIE_INST_SIZE]; /* instruction bytes */ 366266627Sneel uint8_t num_valid; /* size of the instruction */ 367266627Sneel uint8_t num_processed; 368266627Sneel 369268701Sneel uint8_t addrsize:4, opsize:4; /* address and operand sizes */ 370266627Sneel uint8_t rex_w:1, /* REX prefix */ 371266627Sneel rex_r:1, 372266627Sneel rex_x:1, 373266627Sneel rex_b:1, 374268701Sneel rex_present:1, 375268701Sneel opsize_override:1, /* Operand size override */ 376268701Sneel addrsize_override:1; /* Address size override */ 377266627Sneel 378266627Sneel uint8_t mod:2, /* ModRM byte */ 379266627Sneel reg:4, 380266627Sneel rm:4; 381266627Sneel 382266627Sneel uint8_t ss:2, /* SIB byte */ 383266627Sneel index:4, 384266627Sneel base:4; 385266627Sneel 386266627Sneel uint8_t disp_bytes; 387266627Sneel uint8_t imm_bytes; 388266627Sneel 389266627Sneel uint8_t scale; 390266627Sneel int base_register; /* VM_REG_GUEST_xyz */ 391266627Sneel int index_register; /* VM_REG_GUEST_xyz */ 392266627Sneel 393266627Sneel int64_t displacement; /* optional addr displacement */ 394266627Sneel int64_t immediate; /* optional immediate operand */ 395266627Sneel 396266627Sneel uint8_t decoded; /* set to 1 if successfully decoded */ 397266627Sneel 398266627Sneel struct vie_op op; /* opcode description */ 399266627Sneel}; 400266627Sneel 401221828Sgrehanenum vm_exitcode { 402221828Sgrehan VM_EXITCODE_INOUT, 403221828Sgrehan VM_EXITCODE_VMX, 404221828Sgrehan VM_EXITCODE_BOGUS, 405221828Sgrehan VM_EXITCODE_RDMSR, 406221828Sgrehan VM_EXITCODE_WRMSR, 407221828Sgrehan VM_EXITCODE_HLT, 408221828Sgrehan VM_EXITCODE_MTRAP, 409221828Sgrehan VM_EXITCODE_PAUSE, 410234761Sgrehan VM_EXITCODE_PAGING, 411256072Sneel VM_EXITCODE_INST_EMUL, 412240912Sneel VM_EXITCODE_SPINUP_AP, 413265101Sneel VM_EXITCODE_DEPRECATED1, /* used to be SPINDOWN_CPU */ 414260619Sneel VM_EXITCODE_RENDEZVOUS, 415261170Sneel VM_EXITCODE_IOAPIC_EOI, 416263780Sneel VM_EXITCODE_SUSPENDED, 417266573Sneel VM_EXITCODE_INOUT_STR, 418234761Sgrehan VM_EXITCODE_MAX 419221828Sgrehan}; 420221828Sgrehan 421266573Sneelstruct vm_inout { 422266573Sneel uint16_t bytes:3; /* 1 or 2 or 4 */ 423266573Sneel uint16_t in:1; 424266573Sneel uint16_t string:1; 425266573Sneel uint16_t rep:1; 426266573Sneel uint16_t port; 427266573Sneel uint32_t eax; /* valid for out */ 428266573Sneel}; 429266573Sneel 430266573Sneelstruct vm_inout_str { 431266573Sneel struct vm_inout inout; /* must be the first element */ 432266627Sneel struct vm_guest_paging paging; 433266573Sneel uint64_t rflags; 434266573Sneel uint64_t cr0; 435266573Sneel uint64_t index; 436266573Sneel uint64_t count; /* rep=1 (%rcx), rep=0 (1) */ 437266573Sneel int addrsize; 438266573Sneel enum vm_reg_name seg_name; 439266573Sneel struct seg_desc seg_desc; 440266573Sneel}; 441266573Sneel 442221828Sgrehanstruct vm_exit { 443221828Sgrehan enum vm_exitcode exitcode; 444221828Sgrehan int inst_length; /* 0 means unknown */ 445221828Sgrehan uint64_t rip; 446221828Sgrehan union { 447266573Sneel struct vm_inout inout; 448266573Sneel struct vm_inout_str inout_str; 449221828Sgrehan struct { 450241497Sgrehan uint64_t gpa; 451256072Sneel int fault_type; 452256072Sneel } paging; 453256072Sneel struct { 454256072Sneel uint64_t gpa; 455256072Sneel uint64_t gla; 456268701Sneel int cs_d; /* CS.D */ 457266627Sneel struct vm_guest_paging paging; 458243640Sneel struct vie vie; 459256072Sneel } inst_emul; 460221828Sgrehan /* 461221828Sgrehan * VMX specific payload. Used when there is no "better" 462221828Sgrehan * exitcode to represent the VM-exit. 463221828Sgrehan */ 464221828Sgrehan struct { 465260167Sneel int status; /* vmx inst status */ 466260167Sneel /* 467260167Sneel * 'exit_reason' and 'exit_qualification' are valid 468260167Sneel * only if 'status' is zero. 469260167Sneel */ 470221828Sgrehan uint32_t exit_reason; 471221828Sgrehan uint64_t exit_qualification; 472260167Sneel /* 473260167Sneel * 'inst_error' and 'inst_type' are valid 474260167Sneel * only if 'status' is non-zero. 475260167Sneel */ 476260167Sneel int inst_type; 477260167Sneel int inst_error; 478221828Sgrehan } vmx; 479221828Sgrehan struct { 480221828Sgrehan uint32_t code; /* ecx value */ 481221828Sgrehan uint64_t wval; 482221828Sgrehan } msr; 483240912Sneel struct { 484240912Sneel int vcpu; 485240912Sneel uint64_t rip; 486240912Sneel } spinup_ap; 487259081Sneel struct { 488259081Sneel uint64_t rflags; 489259081Sneel } hlt; 490261170Sneel struct { 491261170Sneel int vector; 492261170Sneel } ioapic_eoi; 493265062Sneel struct { 494265062Sneel enum vm_suspend_how how; 495265062Sneel } suspended; 496221828Sgrehan } u; 497221828Sgrehan}; 498221828Sgrehan 499221828Sgrehan#endif /* _VMM_H_ */ 500