2011-05-13 04:54:01 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2011 NetApp, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2013-01-20 03:42:49 +00:00
|
|
|
* $FreeBSD$
|
2011-05-13 04:54:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _VMM_H_
|
|
|
|
#define _VMM_H_
|
|
|
|
|
2014-04-28 22:06:40 +00:00
|
|
|
enum vm_suspend_how {
|
|
|
|
VM_SUSPEND_NONE,
|
|
|
|
VM_SUSPEND_RESET,
|
|
|
|
VM_SUSPEND_POWEROFF,
|
2014-05-02 00:33:56 +00:00
|
|
|
VM_SUSPEND_HALT,
|
2014-04-28 22:06:40 +00:00
|
|
|
VM_SUSPEND_LAST
|
|
|
|
};
|
|
|
|
|
2014-06-10 18:46:00 +00:00
|
|
|
/*
|
|
|
|
* Identifiers for architecturally defined registers.
|
|
|
|
*/
|
|
|
|
enum vm_reg_name {
|
|
|
|
VM_REG_GUEST_RAX,
|
|
|
|
VM_REG_GUEST_RBX,
|
|
|
|
VM_REG_GUEST_RCX,
|
|
|
|
VM_REG_GUEST_RDX,
|
|
|
|
VM_REG_GUEST_RSI,
|
|
|
|
VM_REG_GUEST_RDI,
|
|
|
|
VM_REG_GUEST_RBP,
|
|
|
|
VM_REG_GUEST_R8,
|
|
|
|
VM_REG_GUEST_R9,
|
|
|
|
VM_REG_GUEST_R10,
|
|
|
|
VM_REG_GUEST_R11,
|
|
|
|
VM_REG_GUEST_R12,
|
|
|
|
VM_REG_GUEST_R13,
|
|
|
|
VM_REG_GUEST_R14,
|
|
|
|
VM_REG_GUEST_R15,
|
|
|
|
VM_REG_GUEST_CR0,
|
|
|
|
VM_REG_GUEST_CR3,
|
|
|
|
VM_REG_GUEST_CR4,
|
|
|
|
VM_REG_GUEST_DR7,
|
|
|
|
VM_REG_GUEST_RSP,
|
|
|
|
VM_REG_GUEST_RIP,
|
|
|
|
VM_REG_GUEST_RFLAGS,
|
|
|
|
VM_REG_GUEST_ES,
|
|
|
|
VM_REG_GUEST_CS,
|
|
|
|
VM_REG_GUEST_SS,
|
|
|
|
VM_REG_GUEST_DS,
|
|
|
|
VM_REG_GUEST_FS,
|
|
|
|
VM_REG_GUEST_GS,
|
|
|
|
VM_REG_GUEST_LDTR,
|
|
|
|
VM_REG_GUEST_TR,
|
|
|
|
VM_REG_GUEST_IDTR,
|
|
|
|
VM_REG_GUEST_GDTR,
|
|
|
|
VM_REG_GUEST_EFER,
|
|
|
|
VM_REG_GUEST_CR2,
|
2014-07-16 21:26:26 +00:00
|
|
|
VM_REG_GUEST_PDPTE0,
|
|
|
|
VM_REG_GUEST_PDPTE1,
|
|
|
|
VM_REG_GUEST_PDPTE2,
|
|
|
|
VM_REG_GUEST_PDPTE3,
|
2014-06-10 18:46:00 +00:00
|
|
|
VM_REG_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
enum x2apic_state {
|
|
|
|
X2APIC_DISABLED,
|
|
|
|
X2APIC_ENABLED,
|
|
|
|
X2APIC_STATE_LAST
|
|
|
|
};
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
|
|
|
|
#define VM_MAX_NAMELEN 32
|
|
|
|
|
|
|
|
struct vm;
|
2014-02-26 00:52:05 +00:00
|
|
|
struct vm_exception;
|
2011-05-13 04:54:01 +00:00
|
|
|
struct vm_memory_segment;
|
|
|
|
struct seg_desc;
|
|
|
|
struct vm_exit;
|
|
|
|
struct vm_run;
|
2013-11-25 19:04:51 +00:00
|
|
|
struct vhpet;
|
2013-11-12 22:51:03 +00:00
|
|
|
struct vioapic;
|
2011-05-13 04:54:01 +00:00
|
|
|
struct vlapic;
|
2013-10-05 21:22:35 +00:00
|
|
|
struct vmspace;
|
|
|
|
struct vm_object;
|
|
|
|
struct pmap;
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2014-01-09 03:25:54 +00:00
|
|
|
typedef int (*vmm_init_func_t)(int ipinum);
|
2011-05-13 04:54:01 +00:00
|
|
|
typedef int (*vmm_cleanup_func_t)(void);
|
2013-12-23 19:48:22 +00:00
|
|
|
typedef void (*vmm_resume_func_t)(void);
|
2013-10-05 21:22:35 +00:00
|
|
|
typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap);
|
|
|
|
typedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip,
|
2014-03-26 23:34:27 +00:00
|
|
|
struct pmap *pmap, void *rendezvous_cookie,
|
|
|
|
void *suspend_cookie);
|
2011-05-13 04:54:01 +00:00
|
|
|
typedef void (*vmi_cleanup_func_t)(void *vmi);
|
|
|
|
typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num,
|
|
|
|
uint64_t *retval);
|
|
|
|
typedef int (*vmi_set_register_t)(void *vmi, int vcpu, int num,
|
|
|
|
uint64_t val);
|
|
|
|
typedef int (*vmi_get_desc_t)(void *vmi, int vcpu, int num,
|
|
|
|
struct seg_desc *desc);
|
|
|
|
typedef int (*vmi_set_desc_t)(void *vmi, int vcpu, int num,
|
|
|
|
struct seg_desc *desc);
|
|
|
|
typedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval);
|
|
|
|
typedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val);
|
2013-10-05 21:22:35 +00:00
|
|
|
typedef struct vmspace * (*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max);
|
|
|
|
typedef void (*vmi_vmspace_free)(struct vmspace *vmspace);
|
2013-12-25 06:46:31 +00:00
|
|
|
typedef struct vlapic * (*vmi_vlapic_init)(void *vmi, int vcpu);
|
|
|
|
typedef void (*vmi_vlapic_cleanup)(void *vmi, struct vlapic *vlapic);
|
2011-05-13 04:54:01 +00:00
|
|
|
|
|
|
|
struct vmm_ops {
|
|
|
|
vmm_init_func_t init; /* module wide initialization */
|
|
|
|
vmm_cleanup_func_t cleanup;
|
2013-12-23 19:48:22 +00:00
|
|
|
vmm_resume_func_t resume;
|
2011-05-13 04:54:01 +00:00
|
|
|
|
|
|
|
vmi_init_func_t vminit; /* vm-specific initialization */
|
|
|
|
vmi_run_func_t vmrun;
|
|
|
|
vmi_cleanup_func_t vmcleanup;
|
|
|
|
vmi_get_register_t vmgetreg;
|
|
|
|
vmi_set_register_t vmsetreg;
|
|
|
|
vmi_get_desc_t vmgetdesc;
|
|
|
|
vmi_set_desc_t vmsetdesc;
|
|
|
|
vmi_get_cap_t vmgetcap;
|
|
|
|
vmi_set_cap_t vmsetcap;
|
2013-10-05 21:22:35 +00:00
|
|
|
vmi_vmspace_alloc vmspace_alloc;
|
|
|
|
vmi_vmspace_free vmspace_free;
|
2013-12-25 06:46:31 +00:00
|
|
|
vmi_vlapic_init vlapic_init;
|
|
|
|
vmi_vlapic_cleanup vlapic_cleanup;
|
2011-05-13 04:54:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct vmm_ops vmm_ops_intel;
|
|
|
|
extern struct vmm_ops vmm_ops_amd;
|
|
|
|
|
2013-04-12 01:16:52 +00:00
|
|
|
int vm_create(const char *name, struct vm **retvm);
|
2011-05-13 04:54:01 +00:00
|
|
|
void vm_destroy(struct vm *vm);
|
2014-06-07 21:36:52 +00:00
|
|
|
int vm_reinit(struct vm *vm);
|
2011-05-13 04:54:01 +00:00
|
|
|
const char *vm_name(struct vm *vm);
|
2012-09-29 01:15:45 +00:00
|
|
|
int vm_malloc(struct vm *vm, vm_paddr_t gpa, size_t len);
|
2011-05-13 04:54:01 +00:00
|
|
|
int vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
|
|
|
|
int vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len);
|
2013-10-05 21:22:35 +00:00
|
|
|
void *vm_gpa_hold(struct vm *, vm_paddr_t gpa, size_t len, int prot,
|
|
|
|
void **cookie);
|
|
|
|
void vm_gpa_release(void *cookie);
|
2011-05-13 04:54:01 +00:00
|
|
|
int vm_gpabase2memseg(struct vm *vm, vm_paddr_t gpabase,
|
|
|
|
struct vm_memory_segment *seg);
|
2013-10-05 21:22:35 +00:00
|
|
|
int vm_get_memobj(struct vm *vm, vm_paddr_t gpa, size_t len,
|
|
|
|
vm_offset_t *offset, struct vm_object **object);
|
|
|
|
boolean_t vm_mem_allocated(struct vm *vm, vm_paddr_t gpa);
|
2011-05-13 04:54:01 +00:00
|
|
|
int vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval);
|
|
|
|
int vm_set_register(struct vm *vm, int vcpu, int reg, uint64_t val);
|
|
|
|
int vm_get_seg_desc(struct vm *vm, int vcpu, int reg,
|
|
|
|
struct seg_desc *ret_desc);
|
|
|
|
int vm_set_seg_desc(struct vm *vm, int vcpu, int reg,
|
|
|
|
struct seg_desc *desc);
|
|
|
|
int vm_run(struct vm *vm, struct vm_run *vmrun);
|
2014-04-28 22:06:40 +00:00
|
|
|
int vm_suspend(struct vm *vm, enum vm_suspend_how how);
|
2011-05-13 04:54:01 +00:00
|
|
|
int vm_inject_nmi(struct vm *vm, int vcpu);
|
2012-10-24 02:54:21 +00:00
|
|
|
int vm_nmi_pending(struct vm *vm, int vcpuid);
|
|
|
|
void vm_nmi_clear(struct vm *vm, int vcpuid);
|
2014-03-15 23:09:34 +00:00
|
|
|
int vm_inject_extint(struct vm *vm, int vcpu);
|
|
|
|
int vm_extint_pending(struct vm *vm, int vcpuid);
|
|
|
|
void vm_extint_clear(struct vm *vm, int vcpuid);
|
2011-05-13 04:54:01 +00:00
|
|
|
uint64_t *vm_guest_msrs(struct vm *vm, int cpu);
|
|
|
|
struct vlapic *vm_lapic(struct vm *vm, int cpu);
|
2013-11-12 22:51:03 +00:00
|
|
|
struct vioapic *vm_ioapic(struct vm *vm);
|
2013-11-25 19:04:51 +00:00
|
|
|
struct vhpet *vm_hpet(struct vm *vm);
|
2011-05-13 04:54:01 +00:00
|
|
|
int vm_get_capability(struct vm *vm, int vcpu, int type, int *val);
|
|
|
|
int vm_set_capability(struct vm *vm, int vcpu, int type, int val);
|
2012-09-25 19:08:51 +00:00
|
|
|
int vm_get_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state *state);
|
|
|
|
int vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state);
|
2013-11-12 22:51:03 +00:00
|
|
|
int vm_apicid2vcpuid(struct vm *vm, int apicid);
|
2014-05-31 23:37:34 +00:00
|
|
|
int vm_activate_cpu(struct vm *vm, int vcpu);
|
2011-06-28 06:26:03 +00:00
|
|
|
cpuset_t vm_active_cpus(struct vm *vm);
|
2014-05-31 23:37:34 +00:00
|
|
|
cpuset_t vm_suspended_cpus(struct vm *vm);
|
2012-09-24 19:32:24 +00:00
|
|
|
struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid);
|
2014-04-28 22:06:40 +00:00
|
|
|
void vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip);
|
2014-06-10 16:45:58 +00:00
|
|
|
void vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip);
|
|
|
|
void vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip);
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2014-01-14 01:55:58 +00:00
|
|
|
/*
|
|
|
|
* Rendezvous all vcpus specified in 'dest' and execute 'func(arg)'.
|
|
|
|
* The rendezvous 'func(arg)' is not allowed to do anything that will
|
|
|
|
* cause the thread to be put to sleep.
|
|
|
|
*
|
|
|
|
* If the rendezvous is being initiated from a vcpu context then the
|
|
|
|
* 'vcpuid' must refer to that vcpu, otherwise it should be set to -1.
|
|
|
|
*
|
|
|
|
* The caller cannot hold any locks when initiating the rendezvous.
|
|
|
|
*
|
|
|
|
* The implementation of this API may cause vcpus other than those specified
|
|
|
|
* by 'dest' to be stalled. The caller should not rely on any vcpus making
|
|
|
|
* forward progress when the rendezvous is in progress.
|
|
|
|
*/
|
|
|
|
typedef void (*vm_rendezvous_func_t)(struct vm *vm, int vcpuid, void *arg);
|
|
|
|
void vm_smp_rendezvous(struct vm *vm, int vcpuid, cpuset_t dest,
|
|
|
|
vm_rendezvous_func_t func, void *arg);
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
vcpu_rendezvous_pending(void *rendezvous_cookie)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (*(uintptr_t *)rendezvous_cookie != 0);
|
|
|
|
}
|
|
|
|
|
2014-03-26 23:34:27 +00:00
|
|
|
static __inline int
|
|
|
|
vcpu_suspended(void *suspend_cookie)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (*(int *)suspend_cookie);
|
|
|
|
}
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
/*
|
|
|
|
* Return 1 if device indicated by bus/slot/func is supposed to be a
|
|
|
|
* pci passthrough device.
|
|
|
|
*
|
|
|
|
* Return 0 otherwise.
|
|
|
|
*/
|
|
|
|
int vmm_is_pptdev(int bus, int slot, int func);
|
|
|
|
|
|
|
|
void *vm_iommu_domain(struct vm *vm);
|
|
|
|
|
2012-10-12 18:32:44 +00:00
|
|
|
enum vcpu_state {
|
|
|
|
VCPU_IDLE,
|
2013-10-05 21:22:35 +00:00
|
|
|
VCPU_FROZEN,
|
2012-10-12 18:32:44 +00:00
|
|
|
VCPU_RUNNING,
|
2013-10-05 21:22:35 +00:00
|
|
|
VCPU_SLEEPING,
|
2012-10-12 18:32:44 +00:00
|
|
|
};
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2013-12-22 20:29:59 +00:00
|
|
|
int vcpu_set_state(struct vm *vm, int vcpu, enum vcpu_state state,
|
|
|
|
bool from_idle);
|
2013-04-25 04:56:43 +00:00
|
|
|
enum vcpu_state vcpu_get_state(struct vm *vm, int vcpu, int *hostcpu);
|
2011-05-13 04:54:01 +00:00
|
|
|
|
|
|
|
static int __inline
|
2013-04-25 04:56:43 +00:00
|
|
|
vcpu_is_running(struct vm *vm, int vcpu, int *hostcpu)
|
2011-05-13 04:54:01 +00:00
|
|
|
{
|
2013-04-25 04:56:43 +00:00
|
|
|
return (vcpu_get_state(vm, vcpu, hostcpu) == VCPU_RUNNING);
|
2011-05-13 04:54:01 +00:00
|
|
|
}
|
|
|
|
|
2012-10-12 18:32:44 +00:00
|
|
|
void *vcpu_stats(struct vm *vm, int vcpu);
|
2013-12-25 06:46:31 +00:00
|
|
|
void vcpu_notify_event(struct vm *vm, int vcpuid, bool lapic_intr);
|
2013-10-05 21:22:35 +00:00
|
|
|
struct vmspace *vm_get_vmspace(struct vm *vm);
|
|
|
|
int vm_assign_pptdev(struct vm *vm, int bus, int slot, int func);
|
|
|
|
int vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func);
|
2014-03-11 16:56:00 +00:00
|
|
|
struct vatpic *vm_atpic(struct vm *vm);
|
2014-03-25 19:20:34 +00:00
|
|
|
struct vatpit *vm_atpit(struct vm *vm);
|
2014-02-26 00:52:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inject exception 'vme' into the guest vcpu. This function returns 0 on
|
|
|
|
* success and non-zero on failure.
|
|
|
|
*
|
|
|
|
* Wrapper functions like 'vm_inject_gp()' should be preferred to calling
|
|
|
|
* this function directly because they enforce the trap-like or fault-like
|
|
|
|
* behavior of an exception.
|
|
|
|
*
|
|
|
|
* This function should only be called in the context of the thread that is
|
|
|
|
* executing this vcpu.
|
|
|
|
*/
|
|
|
|
int vm_inject_exception(struct vm *vm, int vcpuid, struct vm_exception *vme);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns 0 if there is no exception pending for this vcpu. Returns 1 if an
|
|
|
|
* exception is pending and also updates 'vme'. The pending exception is
|
|
|
|
* cleared when this function returns.
|
|
|
|
*
|
|
|
|
* This function should only be called in the context of the thread that is
|
|
|
|
* executing this vcpu.
|
|
|
|
*/
|
|
|
|
int vm_exception_pending(struct vm *vm, int vcpuid, struct vm_exception *vme);
|
|
|
|
|
|
|
|
void vm_inject_gp(struct vm *vm, int vcpuid); /* general protection fault */
|
|
|
|
void vm_inject_ud(struct vm *vm, int vcpuid); /* undefined instruction fault */
|
2014-05-24 19:13:25 +00:00
|
|
|
void vm_inject_pf(struct vm *vm, int vcpuid, int error_code, uint64_t cr2);
|
2014-02-26 00:52:05 +00:00
|
|
|
|
2014-05-23 05:15:17 +00:00
|
|
|
enum vm_reg_name vm_segment_name(int seg_encoding);
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
#endif /* KERNEL */
|
|
|
|
|
2013-09-10 03:48:18 +00:00
|
|
|
#define VM_MAXCPU 16 /* maximum virtual cpus */
|
2011-05-13 04:54:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Identifiers for optional vmm capabilities
|
|
|
|
*/
|
|
|
|
enum vm_cap_type {
|
|
|
|
VM_CAP_HALT_EXIT,
|
|
|
|
VM_CAP_MTRAP_EXIT,
|
|
|
|
VM_CAP_PAUSE_EXIT,
|
|
|
|
VM_CAP_UNRESTRICTED_GUEST,
|
2013-10-16 18:20:27 +00:00
|
|
|
VM_CAP_ENABLE_INVPCID,
|
2011-05-13 04:54:01 +00:00
|
|
|
VM_CAP_MAX
|
|
|
|
};
|
|
|
|
|
2014-05-15 14:16:55 +00:00
|
|
|
enum vm_intr_trigger {
|
|
|
|
EDGE_TRIGGER,
|
|
|
|
LEVEL_TRIGGER
|
|
|
|
};
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
/*
|
|
|
|
* The 'access' field has the format specified in Table 21-2 of the Intel
|
|
|
|
* Architecture Manual vol 3b.
|
|
|
|
*
|
|
|
|
* XXX The contents of the 'access' field are architecturally defined except
|
|
|
|
* bit 16 - Segment Unusable.
|
|
|
|
*/
|
|
|
|
struct seg_desc {
|
|
|
|
uint64_t base;
|
|
|
|
uint32_t limit;
|
|
|
|
uint32_t access;
|
|
|
|
};
|
2014-07-15 17:37:17 +00:00
|
|
|
#define SEG_DESC_TYPE(access) ((access) & 0x001f)
|
2014-07-16 21:26:26 +00:00
|
|
|
#define SEG_DESC_DPL(access) (((access) >> 5) & 0x3)
|
2014-07-15 17:37:17 +00:00
|
|
|
#define SEG_DESC_PRESENT(access) (((access) & 0x0080) ? 1 : 0)
|
|
|
|
#define SEG_DESC_DEF32(access) (((access) & 0x4000) ? 1 : 0)
|
|
|
|
#define SEG_DESC_GRANULARITY(access) (((access) & 0x8000) ? 1 : 0)
|
|
|
|
#define SEG_DESC_UNUSABLE(access) (((access) & 0x10000) ? 1 : 0)
|
2011-05-13 04:54:01 +00:00
|
|
|
|
2014-05-24 20:26:57 +00:00
|
|
|
enum vm_cpu_mode {
|
2014-07-08 21:48:57 +00:00
|
|
|
CPU_MODE_REAL,
|
|
|
|
CPU_MODE_PROTECTED,
|
2014-05-24 20:26:57 +00:00
|
|
|
CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */
|
|
|
|
CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum vm_paging_mode {
|
|
|
|
PAGING_MODE_FLAT,
|
|
|
|
PAGING_MODE_32,
|
|
|
|
PAGING_MODE_PAE,
|
|
|
|
PAGING_MODE_64,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vm_guest_paging {
|
|
|
|
uint64_t cr3;
|
|
|
|
int cpl;
|
|
|
|
enum vm_cpu_mode cpu_mode;
|
|
|
|
enum vm_paging_mode paging_mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The data structures 'vie' and 'vie_op' are meant to be opaque to the
|
|
|
|
* consumers of instruction decoding. The only reason why their contents
|
|
|
|
* need to be exposed is because they are part of the 'vm_exit' structure.
|
|
|
|
*/
|
|
|
|
struct vie_op {
|
|
|
|
uint8_t op_byte; /* actual opcode byte */
|
|
|
|
uint8_t op_type; /* type of operation (e.g. MOV) */
|
|
|
|
uint16_t op_flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VIE_INST_SIZE 15
|
|
|
|
struct vie {
|
|
|
|
uint8_t inst[VIE_INST_SIZE]; /* instruction bytes */
|
|
|
|
uint8_t num_valid; /* size of the instruction */
|
|
|
|
uint8_t num_processed;
|
|
|
|
|
2014-07-15 17:37:17 +00:00
|
|
|
uint8_t addrsize:4, opsize:4; /* address and operand sizes */
|
2014-05-24 20:26:57 +00:00
|
|
|
uint8_t rex_w:1, /* REX prefix */
|
|
|
|
rex_r:1,
|
|
|
|
rex_x:1,
|
|
|
|
rex_b:1,
|
2014-07-15 17:37:17 +00:00
|
|
|
rex_present:1,
|
|
|
|
opsize_override:1, /* Operand size override */
|
|
|
|
addrsize_override:1; /* Address size override */
|
2014-05-24 20:26:57 +00:00
|
|
|
|
|
|
|
uint8_t mod:2, /* ModRM byte */
|
|
|
|
reg:4,
|
|
|
|
rm:4;
|
|
|
|
|
|
|
|
uint8_t ss:2, /* SIB byte */
|
|
|
|
index:4,
|
|
|
|
base:4;
|
|
|
|
|
|
|
|
uint8_t disp_bytes;
|
|
|
|
uint8_t imm_bytes;
|
|
|
|
|
|
|
|
uint8_t scale;
|
|
|
|
int base_register; /* VM_REG_GUEST_xyz */
|
|
|
|
int index_register; /* VM_REG_GUEST_xyz */
|
|
|
|
|
|
|
|
int64_t displacement; /* optional addr displacement */
|
|
|
|
int64_t immediate; /* optional immediate operand */
|
|
|
|
|
|
|
|
uint8_t decoded; /* set to 1 if successfully decoded */
|
|
|
|
|
|
|
|
struct vie_op op; /* opcode description */
|
|
|
|
};
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
enum vm_exitcode {
|
|
|
|
VM_EXITCODE_INOUT,
|
|
|
|
VM_EXITCODE_VMX,
|
|
|
|
VM_EXITCODE_BOGUS,
|
|
|
|
VM_EXITCODE_RDMSR,
|
|
|
|
VM_EXITCODE_WRMSR,
|
|
|
|
VM_EXITCODE_HLT,
|
|
|
|
VM_EXITCODE_MTRAP,
|
|
|
|
VM_EXITCODE_PAUSE,
|
2012-04-28 16:28:00 +00:00
|
|
|
VM_EXITCODE_PAGING,
|
2013-10-05 21:22:35 +00:00
|
|
|
VM_EXITCODE_INST_EMUL,
|
2012-09-25 02:33:25 +00:00
|
|
|
VM_EXITCODE_SPINUP_AP,
|
2014-04-29 18:42:56 +00:00
|
|
|
VM_EXITCODE_DEPRECATED1, /* used to be SPINDOWN_CPU */
|
2014-01-14 01:55:58 +00:00
|
|
|
VM_EXITCODE_RENDEZVOUS,
|
2014-01-25 20:58:05 +00:00
|
|
|
VM_EXITCODE_IOAPIC_EOI,
|
2014-03-26 23:34:27 +00:00
|
|
|
VM_EXITCODE_SUSPENDED,
|
2014-05-23 05:15:17 +00:00
|
|
|
VM_EXITCODE_INOUT_STR,
|
2014-07-16 21:26:26 +00:00
|
|
|
VM_EXITCODE_TASK_SWITCH,
|
2012-04-28 16:28:00 +00:00
|
|
|
VM_EXITCODE_MAX
|
2011-05-13 04:54:01 +00:00
|
|
|
};
|
|
|
|
|
2014-05-23 05:15:17 +00:00
|
|
|
struct vm_inout {
|
|
|
|
uint16_t bytes:3; /* 1 or 2 or 4 */
|
|
|
|
uint16_t in:1;
|
|
|
|
uint16_t string:1;
|
|
|
|
uint16_t rep:1;
|
|
|
|
uint16_t port;
|
|
|
|
uint32_t eax; /* valid for out */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vm_inout_str {
|
|
|
|
struct vm_inout inout; /* must be the first element */
|
2014-05-24 20:26:57 +00:00
|
|
|
struct vm_guest_paging paging;
|
2014-05-23 05:15:17 +00:00
|
|
|
uint64_t rflags;
|
|
|
|
uint64_t cr0;
|
|
|
|
uint64_t index;
|
|
|
|
uint64_t count; /* rep=1 (%rcx), rep=0 (1) */
|
|
|
|
int addrsize;
|
|
|
|
enum vm_reg_name seg_name;
|
|
|
|
struct seg_desc seg_desc;
|
|
|
|
};
|
|
|
|
|
2014-07-16 21:26:26 +00:00
|
|
|
enum task_switch_reason {
|
|
|
|
TSR_CALL,
|
|
|
|
TSR_IRET,
|
|
|
|
TSR_JMP,
|
|
|
|
TSR_IDT_GATE, /* task gate in IDT */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vm_task_switch {
|
|
|
|
uint16_t tsssel; /* new TSS selector */
|
|
|
|
int ext; /* task switch due to external event */
|
|
|
|
uint32_t errcode;
|
|
|
|
int errcode_valid; /* push 'errcode' on the new stack */
|
|
|
|
enum task_switch_reason reason;
|
|
|
|
struct vm_guest_paging paging;
|
|
|
|
};
|
|
|
|
|
2011-05-13 04:54:01 +00:00
|
|
|
struct vm_exit {
|
|
|
|
enum vm_exitcode exitcode;
|
|
|
|
int inst_length; /* 0 means unknown */
|
|
|
|
uint64_t rip;
|
|
|
|
union {
|
2014-05-23 05:15:17 +00:00
|
|
|
struct vm_inout inout;
|
|
|
|
struct vm_inout_str inout_str;
|
2012-04-28 16:28:00 +00:00
|
|
|
struct {
|
2012-10-12 23:12:19 +00:00
|
|
|
uint64_t gpa;
|
2013-10-05 21:22:35 +00:00
|
|
|
int fault_type;
|
2012-04-28 16:28:00 +00:00
|
|
|
} paging;
|
2013-10-05 21:22:35 +00:00
|
|
|
struct {
|
|
|
|
uint64_t gpa;
|
|
|
|
uint64_t gla;
|
2014-07-15 17:37:17 +00:00
|
|
|
int cs_d; /* CS.D */
|
2014-05-24 20:26:57 +00:00
|
|
|
struct vm_guest_paging paging;
|
2013-10-05 21:22:35 +00:00
|
|
|
struct vie vie;
|
|
|
|
} inst_emul;
|
2011-05-13 04:54:01 +00:00
|
|
|
/*
|
|
|
|
* VMX specific payload. Used when there is no "better"
|
|
|
|
* exitcode to represent the VM-exit.
|
|
|
|
*/
|
|
|
|
struct {
|
2014-01-01 21:17:08 +00:00
|
|
|
int status; /* vmx inst status */
|
|
|
|
/*
|
|
|
|
* 'exit_reason' and 'exit_qualification' are valid
|
|
|
|
* only if 'status' is zero.
|
|
|
|
*/
|
2011-05-13 04:54:01 +00:00
|
|
|
uint32_t exit_reason;
|
|
|
|
uint64_t exit_qualification;
|
2014-01-01 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* 'inst_error' and 'inst_type' are valid
|
|
|
|
* only if 'status' is non-zero.
|
|
|
|
*/
|
|
|
|
int inst_type;
|
|
|
|
int inst_error;
|
2011-05-13 04:54:01 +00:00
|
|
|
} vmx;
|
|
|
|
struct {
|
|
|
|
uint32_t code; /* ecx value */
|
|
|
|
uint64_t wval;
|
|
|
|
} msr;
|
2012-09-25 02:33:25 +00:00
|
|
|
struct {
|
|
|
|
int vcpu;
|
|
|
|
uint64_t rip;
|
|
|
|
} spinup_ap;
|
2013-12-07 22:18:36 +00:00
|
|
|
struct {
|
|
|
|
uint64_t rflags;
|
|
|
|
} hlt;
|
2014-01-25 20:58:05 +00:00
|
|
|
struct {
|
|
|
|
int vector;
|
|
|
|
} ioapic_eoi;
|
2014-04-28 22:06:40 +00:00
|
|
|
struct {
|
|
|
|
enum vm_suspend_how how;
|
|
|
|
} suspended;
|
2014-07-16 21:26:26 +00:00
|
|
|
struct vm_task_switch task_switch;
|
2011-05-13 04:54:01 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _VMM_H_ */
|