Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/vmm/intel/vmx.c
Show First 20 Lines • Show All 1,023 Lines • ▼ Show 20 Lines | vmx_setup_cr_shadow(int which, struct vmcs *vmcs, uint32_t initial) | ||||
return (0); | return (0); | ||||
} | } | ||||
#define vmx_setup_cr0_shadow(vmcs,init) vmx_setup_cr_shadow(0, (vmcs), (init)) | #define vmx_setup_cr0_shadow(vmcs,init) vmx_setup_cr_shadow(0, (vmcs), (init)) | ||||
#define vmx_setup_cr4_shadow(vmcs,init) vmx_setup_cr_shadow(4, (vmcs), (init)) | #define vmx_setup_cr4_shadow(vmcs,init) vmx_setup_cr_shadow(4, (vmcs), (init)) | ||||
static void * | static void * | ||||
vmx_init(struct vm *vm, pmap_t pmap) | vmx_init(struct vm *vm, pmap_t pmap) | ||||
{ | { | ||||
uint16_t vpid[VM_MAXCPU]; | |||||
int i, error; | int i, error; | ||||
struct vmx *vmx; | struct vmx *vmx; | ||||
struct vmcs *vmcs; | struct vmcs *vmcs; | ||||
uint32_t exc_bitmap; | uint32_t exc_bitmap; | ||||
uint16_t maxcpus; | uint16_t maxcpus = vm_get_maxcpus(vm); | ||||
uint16_t vpid[maxcpus]; | |||||
markj: I'd just allocate this dynamically, it doesn't seem too painful to do so? | |||||
Done Inline ActionsIt goes away in later commits in this series. jhb: It goes away in later commits in this series. | |||||
vmx = malloc(sizeof(struct vmx), M_VMX, M_WAITOK | M_ZERO); | vmx = malloc(sizeof(struct vmx), M_VMX, M_WAITOK | M_ZERO); | ||||
if ((uintptr_t)vmx & PAGE_MASK) { | if ((uintptr_t)vmx & PAGE_MASK) { | ||||
panic("malloc of struct vmx not aligned on %d byte boundary", | panic("malloc of struct vmx not aligned on %d byte boundary", | ||||
PAGE_SIZE); | PAGE_SIZE); | ||||
} | } | ||||
vmx->vm = vm; | vmx->vm = vm; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (guest_msr_rw(vmx, MSR_GSBASE) || | ||||
guest_msr_rw(vmx, MSR_SYSENTER_CS_MSR) || | guest_msr_rw(vmx, MSR_SYSENTER_CS_MSR) || | ||||
guest_msr_rw(vmx, MSR_SYSENTER_ESP_MSR) || | guest_msr_rw(vmx, MSR_SYSENTER_ESP_MSR) || | ||||
guest_msr_rw(vmx, MSR_SYSENTER_EIP_MSR) || | guest_msr_rw(vmx, MSR_SYSENTER_EIP_MSR) || | ||||
guest_msr_rw(vmx, MSR_EFER) || | guest_msr_rw(vmx, MSR_EFER) || | ||||
guest_msr_ro(vmx, MSR_TSC) || | guest_msr_ro(vmx, MSR_TSC) || | ||||
((cap_rdpid || cap_rdtscp) && guest_msr_ro(vmx, MSR_TSC_AUX))) | ((cap_rdpid || cap_rdtscp) && guest_msr_ro(vmx, MSR_TSC_AUX))) | ||||
panic("vmx_init: error setting guest msr access"); | panic("vmx_init: error setting guest msr access"); | ||||
vpid_alloc(vpid, VM_MAXCPU); | vpid_alloc(vpid, maxcpus); | ||||
if (virtual_interrupt_delivery) { | if (virtual_interrupt_delivery) { | ||||
error = vm_map_mmio(vm, DEFAULT_APIC_BASE, PAGE_SIZE, | error = vm_map_mmio(vm, DEFAULT_APIC_BASE, PAGE_SIZE, | ||||
APIC_ACCESS_ADDRESS); | APIC_ACCESS_ADDRESS); | ||||
/* XXX this should really return an error to the caller */ | /* XXX this should really return an error to the caller */ | ||||
KASSERT(error == 0, ("vm_map_mmio(apicbase) error %d", error)); | KASSERT(error == 0, ("vm_map_mmio(apicbase) error %d", error)); | ||||
} | } | ||||
maxcpus = vm_get_maxcpus(vm); | |||||
for (i = 0; i < maxcpus; i++) { | for (i = 0; i < maxcpus; i++) { | ||||
vmcs = &vmx->vmcs[i]; | vmcs = &vmx->vmcs[i]; | ||||
vmcs->identifier = vmx_revision(); | vmcs->identifier = vmx_revision(); | ||||
error = vmclear(vmcs); | error = vmclear(vmcs); | ||||
if (error != 0) { | if (error != 0) { | ||||
panic("vmx_init: vmclear error %d on vcpu %d\n", | panic("vmx_init: vmclear error %d on vcpu %d\n", | ||||
error, i); | error, i); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,951 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
static int | static int | ||||
vmx_snapshot(void *arg, struct vm_snapshot_meta *meta) | vmx_snapshot(void *arg, struct vm_snapshot_meta *meta) | ||||
{ | { | ||||
struct vmx *vmx; | struct vmx *vmx; | ||||
struct vmxctx *vmxctx; | struct vmxctx *vmxctx; | ||||
int i; | |||||
int ret; | int ret; | ||||
uint16_t i, maxcpus; | |||||
vmx = arg; | vmx = arg; | ||||
KASSERT(vmx != NULL, ("%s: arg was NULL", __func__)); | KASSERT(vmx != NULL, ("%s: arg was NULL", __func__)); | ||||
for (i = 0; i < VM_MAXCPU; i++) { | maxcpus = vm_get_maxcpus(vmx->vm); | ||||
for (i = 0; i < maxcpus; i++) { | |||||
SNAPSHOT_BUF_OR_LEAVE(vmx->guest_msrs[i], | SNAPSHOT_BUF_OR_LEAVE(vmx->guest_msrs[i], | ||||
sizeof(vmx->guest_msrs[i]), meta, ret, done); | sizeof(vmx->guest_msrs[i]), meta, ret, done); | ||||
vmxctx = &vmx->ctx[i]; | vmxctx = &vmx->ctx[i]; | ||||
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rdi, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rdi, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rsi, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rsi, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rdx, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rdx, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rcx, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rcx, meta, ret, done); | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |
I'd just allocate this dynamically, it doesn't seem too painful to do so?