vmm.h revision 267330
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 267330 2014-06-10 16:45:58Z 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 40221828Sgrehan#ifdef _KERNEL 41221828Sgrehan 42221828Sgrehan#define VM_MAX_NAMELEN 32 43221828Sgrehan 44221828Sgrehanstruct vm; 45262506Sneelstruct vm_exception; 46221828Sgrehanstruct vm_memory_segment; 47221828Sgrehanstruct seg_desc; 48221828Sgrehanstruct vm_exit; 49221828Sgrehanstruct vm_run; 50258579Sneelstruct vhpet; 51258075Sneelstruct vioapic; 52221828Sgrehanstruct vlapic; 53256072Sneelstruct vmspace; 54256072Sneelstruct vm_object; 55256072Sneelstruct pmap; 56221828Sgrehan 57266573Sneelenum vm_reg_name; 58240922Sneelenum x2apic_state; 59240922Sneel 60260466Sneeltypedef int (*vmm_init_func_t)(int ipinum); 61221828Sgrehantypedef int (*vmm_cleanup_func_t)(void); 62259782Sjhbtypedef void (*vmm_resume_func_t)(void); 63256072Sneeltypedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap); 64256072Sneeltypedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip, 65263780Sneel struct pmap *pmap, void *rendezvous_cookie, 66263780Sneel void *suspend_cookie); 67221828Sgrehantypedef void (*vmi_cleanup_func_t)(void *vmi); 68221828Sgrehantypedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num, 69221828Sgrehan uint64_t *retval); 70221828Sgrehantypedef int (*vmi_set_register_t)(void *vmi, int vcpu, int num, 71221828Sgrehan uint64_t val); 72221828Sgrehantypedef int (*vmi_get_desc_t)(void *vmi, int vcpu, int num, 73221828Sgrehan struct seg_desc *desc); 74221828Sgrehantypedef int (*vmi_set_desc_t)(void *vmi, int vcpu, int num, 75221828Sgrehan struct seg_desc *desc); 76221828Sgrehantypedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval); 77221828Sgrehantypedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val); 78256072Sneeltypedef struct vmspace * (*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max); 79256072Sneeltypedef void (*vmi_vmspace_free)(struct vmspace *vmspace); 80259863Sneeltypedef struct vlapic * (*vmi_vlapic_init)(void *vmi, int vcpu); 81259863Sneeltypedef void (*vmi_vlapic_cleanup)(void *vmi, struct vlapic *vlapic); 82221828Sgrehan 83221828Sgrehanstruct vmm_ops { 84221828Sgrehan vmm_init_func_t init; /* module wide initialization */ 85221828Sgrehan vmm_cleanup_func_t cleanup; 86259782Sjhb vmm_resume_func_t resume; 87221828Sgrehan 88221828Sgrehan vmi_init_func_t vminit; /* vm-specific initialization */ 89221828Sgrehan vmi_run_func_t vmrun; 90221828Sgrehan vmi_cleanup_func_t vmcleanup; 91221828Sgrehan vmi_get_register_t vmgetreg; 92221828Sgrehan vmi_set_register_t vmsetreg; 93221828Sgrehan vmi_get_desc_t vmgetdesc; 94221828Sgrehan vmi_set_desc_t vmsetdesc; 95221828Sgrehan vmi_get_cap_t vmgetcap; 96221828Sgrehan vmi_set_cap_t vmsetcap; 97256072Sneel vmi_vmspace_alloc vmspace_alloc; 98256072Sneel vmi_vmspace_free vmspace_free; 99259863Sneel vmi_vlapic_init vlapic_init; 100259863Sneel vmi_vlapic_cleanup vlapic_cleanup; 101221828Sgrehan}; 102221828Sgrehan 103221828Sgrehanextern struct vmm_ops vmm_ops_intel; 104221828Sgrehanextern struct vmm_ops vmm_ops_amd; 105221828Sgrehan 106249396Sneelint vm_create(const char *name, struct vm **retvm); 107221828Sgrehanvoid vm_destroy(struct vm *vm); 108267216Sneelint vm_reinit(struct vm *vm); 109221828Sgrehanconst char *vm_name(struct vm *vm); 110241041Sneelint vm_malloc(struct vm *vm, vm_paddr_t gpa, size_t len); 111221828Sgrehanint vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa); 112221828Sgrehanint vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len); 113256072Sneelvoid *vm_gpa_hold(struct vm *, vm_paddr_t gpa, size_t len, int prot, 114256072Sneel void **cookie); 115256072Sneelvoid vm_gpa_release(void *cookie); 116221828Sgrehanint vm_gpabase2memseg(struct vm *vm, vm_paddr_t gpabase, 117221828Sgrehan struct vm_memory_segment *seg); 118256072Sneelint vm_get_memobj(struct vm *vm, vm_paddr_t gpa, size_t len, 119256072Sneel vm_offset_t *offset, struct vm_object **object); 120256072Sneelboolean_t vm_mem_allocated(struct vm *vm, vm_paddr_t gpa); 121221828Sgrehanint vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval); 122221828Sgrehanint vm_set_register(struct vm *vm, int vcpu, int reg, uint64_t val); 123221828Sgrehanint vm_get_seg_desc(struct vm *vm, int vcpu, int reg, 124221828Sgrehan struct seg_desc *ret_desc); 125221828Sgrehanint vm_set_seg_desc(struct vm *vm, int vcpu, int reg, 126221828Sgrehan struct seg_desc *desc); 127221828Sgrehanint vm_run(struct vm *vm, struct vm_run *vmrun); 128265062Sneelint vm_suspend(struct vm *vm, enum vm_suspend_how how); 129221828Sgrehanint vm_inject_nmi(struct vm *vm, int vcpu); 130241982Sneelint vm_nmi_pending(struct vm *vm, int vcpuid); 131241982Sneelvoid vm_nmi_clear(struct vm *vm, int vcpuid); 132263211Stychonint vm_inject_extint(struct vm *vm, int vcpu); 133263211Stychonint vm_extint_pending(struct vm *vm, int vcpuid); 134263211Stychonvoid vm_extint_clear(struct vm *vm, int vcpuid); 135221828Sgrehanuint64_t *vm_guest_msrs(struct vm *vm, int cpu); 136221828Sgrehanstruct vlapic *vm_lapic(struct vm *vm, int cpu); 137258075Sneelstruct vioapic *vm_ioapic(struct vm *vm); 138258579Sneelstruct vhpet *vm_hpet(struct vm *vm); 139221828Sgrehanint vm_get_capability(struct vm *vm, int vcpu, int type, int *val); 140221828Sgrehanint vm_set_capability(struct vm *vm, int vcpu, int type, int val); 141240922Sneelint vm_get_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state *state); 142240922Sneelint vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state); 143258075Sneelint vm_apicid2vcpuid(struct vm *vm, int apicid); 144266933Sneelint vm_activate_cpu(struct vm *vm, int vcpu); 145223621Sgrehancpuset_t vm_active_cpus(struct vm *vm); 146266933Sneelcpuset_t vm_suspended_cpus(struct vm *vm); 147240894Sneelstruct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid); 148265062Sneelvoid vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip); 149267330Sneelvoid vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip); 150267330Sneelvoid vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip); 151221828Sgrehan 152221828Sgrehan/* 153260619Sneel * Rendezvous all vcpus specified in 'dest' and execute 'func(arg)'. 154260619Sneel * The rendezvous 'func(arg)' is not allowed to do anything that will 155260619Sneel * cause the thread to be put to sleep. 156260619Sneel * 157260619Sneel * If the rendezvous is being initiated from a vcpu context then the 158260619Sneel * 'vcpuid' must refer to that vcpu, otherwise it should be set to -1. 159260619Sneel * 160260619Sneel * The caller cannot hold any locks when initiating the rendezvous. 161260619Sneel * 162260619Sneel * The implementation of this API may cause vcpus other than those specified 163260619Sneel * by 'dest' to be stalled. The caller should not rely on any vcpus making 164260619Sneel * forward progress when the rendezvous is in progress. 165260619Sneel */ 166260619Sneeltypedef void (*vm_rendezvous_func_t)(struct vm *vm, int vcpuid, void *arg); 167260619Sneelvoid vm_smp_rendezvous(struct vm *vm, int vcpuid, cpuset_t dest, 168260619Sneel vm_rendezvous_func_t func, void *arg); 169260619Sneel 170260619Sneelstatic __inline int 171260619Sneelvcpu_rendezvous_pending(void *rendezvous_cookie) 172260619Sneel{ 173260619Sneel 174260619Sneel return (*(uintptr_t *)rendezvous_cookie != 0); 175260619Sneel} 176260619Sneel 177263780Sneelstatic __inline int 178263780Sneelvcpu_suspended(void *suspend_cookie) 179263780Sneel{ 180263780Sneel 181263780Sneel return (*(int *)suspend_cookie); 182263780Sneel} 183263780Sneel 184260619Sneel/* 185221828Sgrehan * Return 1 if device indicated by bus/slot/func is supposed to be a 186221828Sgrehan * pci passthrough device. 187221828Sgrehan * 188221828Sgrehan * Return 0 otherwise. 189221828Sgrehan */ 190221828Sgrehanint vmm_is_pptdev(int bus, int slot, int func); 191221828Sgrehan 192221828Sgrehanvoid *vm_iommu_domain(struct vm *vm); 193221828Sgrehan 194241489Sneelenum vcpu_state { 195241489Sneel VCPU_IDLE, 196256072Sneel VCPU_FROZEN, 197241489Sneel VCPU_RUNNING, 198256072Sneel VCPU_SLEEPING, 199241489Sneel}; 200221828Sgrehan 201259737Sneelint vcpu_set_state(struct vm *vm, int vcpu, enum vcpu_state state, 202259737Sneel bool from_idle); 203249879Sgrehanenum vcpu_state vcpu_get_state(struct vm *vm, int vcpu, int *hostcpu); 204221828Sgrehan 205221828Sgrehanstatic int __inline 206249879Sgrehanvcpu_is_running(struct vm *vm, int vcpu, int *hostcpu) 207221828Sgrehan{ 208249879Sgrehan return (vcpu_get_state(vm, vcpu, hostcpu) == VCPU_RUNNING); 209221828Sgrehan} 210221828Sgrehan 211241489Sneelvoid *vcpu_stats(struct vm *vm, int vcpu); 212259863Sneelvoid vcpu_notify_event(struct vm *vm, int vcpuid, bool lapic_intr); 213256072Sneelstruct vmspace *vm_get_vmspace(struct vm *vm); 214256072Sneelint vm_assign_pptdev(struct vm *vm, int bus, int slot, int func); 215256072Sneelint vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func); 216263035Stychonstruct vatpic *vm_atpic(struct vm *vm); 217263744Stychonstruct vatpit *vm_atpit(struct vm *vm); 218262506Sneel 219262506Sneel/* 220262506Sneel * Inject exception 'vme' into the guest vcpu. This function returns 0 on 221262506Sneel * success and non-zero on failure. 222262506Sneel * 223262506Sneel * Wrapper functions like 'vm_inject_gp()' should be preferred to calling 224262506Sneel * this function directly because they enforce the trap-like or fault-like 225262506Sneel * behavior of an exception. 226262506Sneel * 227262506Sneel * This function should only be called in the context of the thread that is 228262506Sneel * executing this vcpu. 229262506Sneel */ 230262506Sneelint vm_inject_exception(struct vm *vm, int vcpuid, struct vm_exception *vme); 231262506Sneel 232262506Sneel/* 233262506Sneel * Returns 0 if there is no exception pending for this vcpu. Returns 1 if an 234262506Sneel * exception is pending and also updates 'vme'. The pending exception is 235262506Sneel * cleared when this function returns. 236262506Sneel * 237262506Sneel * This function should only be called in the context of the thread that is 238262506Sneel * executing this vcpu. 239262506Sneel */ 240262506Sneelint vm_exception_pending(struct vm *vm, int vcpuid, struct vm_exception *vme); 241262506Sneel 242262506Sneelvoid vm_inject_gp(struct vm *vm, int vcpuid); /* general protection fault */ 243262506Sneelvoid vm_inject_ud(struct vm *vm, int vcpuid); /* undefined instruction fault */ 244266626Sneelvoid vm_inject_pf(struct vm *vm, int vcpuid, int error_code, uint64_t cr2); 245262506Sneel 246266573Sneelenum vm_reg_name vm_segment_name(int seg_encoding); 247266573Sneel 248221828Sgrehan#endif /* KERNEL */ 249221828Sgrehan 250255438Sgrehan#define VM_MAXCPU 16 /* maximum virtual cpus */ 251221828Sgrehan 252221828Sgrehan/* 253221828Sgrehan * Identifiers for architecturally defined registers. 254221828Sgrehan */ 255221828Sgrehanenum vm_reg_name { 256221828Sgrehan VM_REG_GUEST_RAX, 257221828Sgrehan VM_REG_GUEST_RBX, 258221828Sgrehan VM_REG_GUEST_RCX, 259221828Sgrehan VM_REG_GUEST_RDX, 260221828Sgrehan VM_REG_GUEST_RSI, 261221828Sgrehan VM_REG_GUEST_RDI, 262221828Sgrehan VM_REG_GUEST_RBP, 263221828Sgrehan VM_REG_GUEST_R8, 264221828Sgrehan VM_REG_GUEST_R9, 265221828Sgrehan VM_REG_GUEST_R10, 266221828Sgrehan VM_REG_GUEST_R11, 267221828Sgrehan VM_REG_GUEST_R12, 268221828Sgrehan VM_REG_GUEST_R13, 269221828Sgrehan VM_REG_GUEST_R14, 270221828Sgrehan VM_REG_GUEST_R15, 271221828Sgrehan VM_REG_GUEST_CR0, 272221828Sgrehan VM_REG_GUEST_CR3, 273221828Sgrehan VM_REG_GUEST_CR4, 274221828Sgrehan VM_REG_GUEST_DR7, 275221828Sgrehan VM_REG_GUEST_RSP, 276221828Sgrehan VM_REG_GUEST_RIP, 277221828Sgrehan VM_REG_GUEST_RFLAGS, 278221828Sgrehan VM_REG_GUEST_ES, 279221828Sgrehan VM_REG_GUEST_CS, 280221828Sgrehan VM_REG_GUEST_SS, 281221828Sgrehan VM_REG_GUEST_DS, 282221828Sgrehan VM_REG_GUEST_FS, 283221828Sgrehan VM_REG_GUEST_GS, 284221828Sgrehan VM_REG_GUEST_LDTR, 285221828Sgrehan VM_REG_GUEST_TR, 286221828Sgrehan VM_REG_GUEST_IDTR, 287221828Sgrehan VM_REG_GUEST_GDTR, 288221828Sgrehan VM_REG_GUEST_EFER, 289266626Sneel VM_REG_GUEST_CR2, 290221828Sgrehan VM_REG_LAST 291221828Sgrehan}; 292221828Sgrehan 293221828Sgrehan/* 294221828Sgrehan * Identifiers for optional vmm capabilities 295221828Sgrehan */ 296221828Sgrehanenum vm_cap_type { 297221828Sgrehan VM_CAP_HALT_EXIT, 298221828Sgrehan VM_CAP_MTRAP_EXIT, 299221828Sgrehan VM_CAP_PAUSE_EXIT, 300221828Sgrehan VM_CAP_UNRESTRICTED_GUEST, 301256645Sneel VM_CAP_ENABLE_INVPCID, 302221828Sgrehan VM_CAP_MAX 303221828Sgrehan}; 304221828Sgrehan 305240922Sneelenum x2apic_state { 306262236Sneel X2APIC_DISABLED, 307240922Sneel X2APIC_ENABLED, 308240922Sneel X2APIC_STATE_LAST 309240922Sneel}; 310240922Sneel 311266125Sjhbenum vm_intr_trigger { 312266125Sjhb EDGE_TRIGGER, 313266125Sjhb LEVEL_TRIGGER 314266125Sjhb}; 315266125Sjhb 316221828Sgrehan/* 317221828Sgrehan * The 'access' field has the format specified in Table 21-2 of the Intel 318221828Sgrehan * Architecture Manual vol 3b. 319221828Sgrehan * 320221828Sgrehan * XXX The contents of the 'access' field are architecturally defined except 321221828Sgrehan * bit 16 - Segment Unusable. 322221828Sgrehan */ 323221828Sgrehanstruct seg_desc { 324221828Sgrehan uint64_t base; 325221828Sgrehan uint32_t limit; 326221828Sgrehan uint32_t access; 327221828Sgrehan}; 328266724Sneel#define SEG_DESC_TYPE(desc) ((desc)->access & 0x001f) 329266724Sneel#define SEG_DESC_PRESENT(desc) ((desc)->access & 0x0080) 330266724Sneel#define SEG_DESC_DEF32(desc) ((desc)->access & 0x4000) 331266724Sneel#define SEG_DESC_GRANULARITY(desc) ((desc)->access & 0x8000) 332266724Sneel#define SEG_DESC_UNUSABLE(desc) ((desc)->access & 0x10000) 333221828Sgrehan 334266627Sneelenum vm_cpu_mode { 335266627Sneel CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */ 336266627Sneel CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */ 337266627Sneel}; 338266627Sneel 339266627Sneelenum vm_paging_mode { 340266627Sneel PAGING_MODE_FLAT, 341266627Sneel PAGING_MODE_32, 342266627Sneel PAGING_MODE_PAE, 343266627Sneel PAGING_MODE_64, 344266627Sneel}; 345266627Sneel 346266627Sneelstruct vm_guest_paging { 347266627Sneel uint64_t cr3; 348266627Sneel int cpl; 349266627Sneel enum vm_cpu_mode cpu_mode; 350266627Sneel enum vm_paging_mode paging_mode; 351266627Sneel}; 352266627Sneel 353266627Sneel/* 354266627Sneel * The data structures 'vie' and 'vie_op' are meant to be opaque to the 355266627Sneel * consumers of instruction decoding. The only reason why their contents 356266627Sneel * need to be exposed is because they are part of the 'vm_exit' structure. 357266627Sneel */ 358266627Sneelstruct vie_op { 359266627Sneel uint8_t op_byte; /* actual opcode byte */ 360266627Sneel uint8_t op_type; /* type of operation (e.g. MOV) */ 361266627Sneel uint16_t op_flags; 362266627Sneel}; 363266627Sneel 364266627Sneel#define VIE_INST_SIZE 15 365266627Sneelstruct vie { 366266627Sneel uint8_t inst[VIE_INST_SIZE]; /* instruction bytes */ 367266627Sneel uint8_t num_valid; /* size of the instruction */ 368266627Sneel uint8_t num_processed; 369266627Sneel 370266627Sneel uint8_t rex_w:1, /* REX prefix */ 371266627Sneel rex_r:1, 372266627Sneel rex_x:1, 373266627Sneel rex_b:1, 374266627Sneel rex_present:1; 375266627Sneel 376266627Sneel uint8_t mod:2, /* ModRM byte */ 377266627Sneel reg:4, 378266627Sneel rm:4; 379266627Sneel 380266627Sneel uint8_t ss:2, /* SIB byte */ 381266627Sneel index:4, 382266627Sneel base:4; 383266627Sneel 384266627Sneel uint8_t disp_bytes; 385266627Sneel uint8_t imm_bytes; 386266627Sneel 387266627Sneel uint8_t scale; 388266627Sneel int base_register; /* VM_REG_GUEST_xyz */ 389266627Sneel int index_register; /* VM_REG_GUEST_xyz */ 390266627Sneel 391266627Sneel int64_t displacement; /* optional addr displacement */ 392266627Sneel int64_t immediate; /* optional immediate operand */ 393266627Sneel 394266627Sneel uint8_t decoded; /* set to 1 if successfully decoded */ 395266627Sneel 396266627Sneel struct vie_op op; /* opcode description */ 397266627Sneel}; 398266627Sneel 399221828Sgrehanenum vm_exitcode { 400221828Sgrehan VM_EXITCODE_INOUT, 401221828Sgrehan VM_EXITCODE_VMX, 402221828Sgrehan VM_EXITCODE_BOGUS, 403221828Sgrehan VM_EXITCODE_RDMSR, 404221828Sgrehan VM_EXITCODE_WRMSR, 405221828Sgrehan VM_EXITCODE_HLT, 406221828Sgrehan VM_EXITCODE_MTRAP, 407221828Sgrehan VM_EXITCODE_PAUSE, 408234761Sgrehan VM_EXITCODE_PAGING, 409256072Sneel VM_EXITCODE_INST_EMUL, 410240912Sneel VM_EXITCODE_SPINUP_AP, 411265101Sneel VM_EXITCODE_DEPRECATED1, /* used to be SPINDOWN_CPU */ 412260619Sneel VM_EXITCODE_RENDEZVOUS, 413261170Sneel VM_EXITCODE_IOAPIC_EOI, 414263780Sneel VM_EXITCODE_SUSPENDED, 415266573Sneel VM_EXITCODE_INOUT_STR, 416234761Sgrehan VM_EXITCODE_MAX 417221828Sgrehan}; 418221828Sgrehan 419266573Sneelstruct vm_inout { 420266573Sneel uint16_t bytes:3; /* 1 or 2 or 4 */ 421266573Sneel uint16_t in:1; 422266573Sneel uint16_t string:1; 423266573Sneel uint16_t rep:1; 424266573Sneel uint16_t port; 425266573Sneel uint32_t eax; /* valid for out */ 426266573Sneel}; 427266573Sneel 428266573Sneelstruct vm_inout_str { 429266573Sneel struct vm_inout inout; /* must be the first element */ 430266627Sneel struct vm_guest_paging paging; 431266573Sneel uint64_t rflags; 432266573Sneel uint64_t cr0; 433266573Sneel uint64_t index; 434266573Sneel uint64_t count; /* rep=1 (%rcx), rep=0 (1) */ 435266573Sneel int addrsize; 436266573Sneel enum vm_reg_name seg_name; 437266573Sneel struct seg_desc seg_desc; 438266573Sneel}; 439266573Sneel 440221828Sgrehanstruct vm_exit { 441221828Sgrehan enum vm_exitcode exitcode; 442221828Sgrehan int inst_length; /* 0 means unknown */ 443221828Sgrehan uint64_t rip; 444221828Sgrehan union { 445266573Sneel struct vm_inout inout; 446266573Sneel struct vm_inout_str inout_str; 447221828Sgrehan struct { 448241497Sgrehan uint64_t gpa; 449256072Sneel int fault_type; 450256072Sneel } paging; 451256072Sneel struct { 452256072Sneel uint64_t gpa; 453256072Sneel uint64_t gla; 454266627Sneel struct vm_guest_paging paging; 455243640Sneel struct vie vie; 456256072Sneel } inst_emul; 457221828Sgrehan /* 458221828Sgrehan * VMX specific payload. Used when there is no "better" 459221828Sgrehan * exitcode to represent the VM-exit. 460221828Sgrehan */ 461221828Sgrehan struct { 462260167Sneel int status; /* vmx inst status */ 463260167Sneel /* 464260167Sneel * 'exit_reason' and 'exit_qualification' are valid 465260167Sneel * only if 'status' is zero. 466260167Sneel */ 467221828Sgrehan uint32_t exit_reason; 468221828Sgrehan uint64_t exit_qualification; 469260167Sneel /* 470260167Sneel * 'inst_error' and 'inst_type' are valid 471260167Sneel * only if 'status' is non-zero. 472260167Sneel */ 473260167Sneel int inst_type; 474260167Sneel int inst_error; 475221828Sgrehan } vmx; 476221828Sgrehan struct { 477221828Sgrehan uint32_t code; /* ecx value */ 478221828Sgrehan uint64_t wval; 479221828Sgrehan } msr; 480240912Sneel struct { 481240912Sneel int vcpu; 482240912Sneel uint64_t rip; 483240912Sneel } spinup_ap; 484259081Sneel struct { 485259081Sneel uint64_t rflags; 486259081Sneel } hlt; 487261170Sneel struct { 488261170Sneel int vector; 489261170Sneel } ioapic_eoi; 490265062Sneel struct { 491265062Sneel enum vm_suspend_how how; 492265062Sneel } suspended; 493221828Sgrehan } u; 494221828Sgrehan}; 495221828Sgrehan 496221828Sgrehan#endif /* _VMM_H_ */ 497