-/* $OpenBSD: vmm.c,v 1.27 2017/04/12 05:46:59 guenther Exp $ */
+/* $OpenBSD: vmm.c,v 1.28 2017/04/26 08:02:14 mlarkin Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
*
ret = vm_rwregs((struct vm_rwregs_params *)data, 1);
break;
default:
- DPRINTF("vmmioctl: unknown ioctl code 0x%lx\n", cmd);
+ DPRINTF("%s: unknown ioctl code 0x%lx\n", __func__, cmd);
ret = ENOTTY;
}
/* Not found? exit. */
if (error != 0) {
- DPRINTF("vm_resetcpu: vm id %u not found\n",
+ DPRINTF("%s: vm id %u not found\n", __func__,
vrp->vrp_vm_id);
return (error);
}
rw_exit_read(&vm->vm_vcpu_lock);
if (vcpu == NULL) {
- DPRINTF("vm_resetcpu: vcpu id %u of vm %u not found\n",
+ DPRINTF("%s: vcpu id %u of vm %u not found\n", __func__,
vrp->vrp_vcpu_id, vrp->vrp_vm_id);
return (ENOENT);
}
if (vcpu->vc_state != VCPU_STATE_STOPPED) {
- DPRINTF("vm_resetcpu: reset of vcpu %u on vm %u attempted "
- "while vcpu was in state %u (%s)\n", vrp->vrp_vcpu_id,
- vrp->vrp_vm_id, vcpu->vc_state,
+ DPRINTF("%s: reset of vcpu %u on vm %u attempted "
+ "while vcpu was in state %u (%s)\n", __func__,
+ vrp->vrp_vcpu_id, vrp->vrp_vm_id, vcpu->vc_state,
vcpu_state_decode(vcpu->vc_state));
return (EBUSY);
}
- DPRINTF("vm_resetcpu: resetting vm %d vcpu %d to power on defaults\n",
- vm->vm_id, vcpu->vc_id);
+ DPRINTF("%s: resetting vm %d vcpu %d to power on defaults\n",
+ __func__, vm->vm_id, vcpu->vc_id);
if (vcpu_reset_regs(vcpu, &vrp->vrp_init_state)) {
- printf("vm_resetcpu: failed\n");
+ printf("%s: failed\n", __func__);
#ifdef VMM_DEBUG
dump_vcpu(vcpu);
#endif /* VMM_DEBUG */
/* Create a new pmap for this VM */
pmap = pmap_create();
if (!pmap) {
- printf("vm_impl_init_vmx: pmap_create failed\n");
+ printf("%s: pmap_create failed\n", __func__);
return (ENOMEM);
}
VM_MAP_ISVMSPACE | VM_MAP_PAGEABLE);
if (!vm->vm_map) {
- printf("vm_impl_init_vmx: uvm_map_create failed\n");
+ printf("%s: uvm_map_create failed\n", __func__);
pmap_destroy(pmap);
return (ENOMEM);
}
/* Map the new map with an anon */
- DPRINTF("vm_impl_init_vmx: created vm_map @ %p\n", vm->vm_map);
+ DPRINTF("%s: created vm_map @ %p\n", __func__, vm->vm_map);
for (i = 0; i < vm->vm_nmemranges; i++) {
vmr = &vm->vm_memranges[i];
ret = uvm_share(vm->vm_map, vmr->vmr_gpa,
PROT_READ | PROT_WRITE | PROT_EXEC,
&p->p_vmspace->vm_map, vmr->vmr_va, vmr->vmr_size);
if (ret) {
- printf("vm_impl_init_vmx: uvm_share failed (%d)\n",
- ret);
+ printf("%s: uvm_share failed (%d)\n", __func__, ret);
/* uvm_map_deallocate calls pmap_destroy for us */
uvm_map_deallocate(vm->vm_map);
vm->vm_map = NULL;
/* Convert the low 512GB of the pmap to EPT */
ret = pmap_convert(pmap, PMAP_TYPE_EPT);
if (ret) {
- printf("vm_impl_init_vmx: pmap_convert failed\n");
+ printf("%s: pmap_convert failed\n", __func__);
/* uvm_map_deallocate calls pmap_destroy for us */
uvm_map_deallocate(vm->vm_map);
vm->vm_map = NULL;
/* Create a new pmap for this VM */
pmap = pmap_create();
if (!pmap) {
- printf("vm_impl_init_svm: pmap_create failed\n");
+ printf("%s: pmap_create failed\n", __func__);
return (ENOMEM);
}
VM_MAP_ISVMSPACE | VM_MAP_PAGEABLE);
if (!vm->vm_map) {
- printf("vm_impl_init_svm: uvm_map_create failed\n");
+ printf("%s: uvm_map_create failed\n", __func__);
pmap_destroy(pmap);
return (ENOMEM);
}
/* Map the new map with an anon */
- DPRINTF("vm_impl_init_svm: created vm_map @ %p\n", vm->vm_map);
+ DPRINTF("%s: created vm_map @ %p\n", __func__, vm->vm_map);
for (i = 0; i < vm->vm_nmemranges; i++) {
vmr = &vm->vm_memranges[i];
ret = uvm_share(vm->vm_map, vmr->vmr_gpa,
PROT_READ | PROT_WRITE | PROT_EXEC,
&p->p_vmspace->vm_map, vmr->vmr_va, vmr->vmr_size);
if (ret) {
- printf("vm_impl_init_svm: uvm_share failed (%d)\n",
- ret);
+ printf("%s: uvm_share failed (%d)\n", __func__, ret);
/* uvm_map_deallocate calls pmap_destroy for us */
uvm_map_deallocate(vm->vm_map);
vm->vm_map = NULL;
/* Is there an interrupt pending injection? */
if (irq != 0xFFFF) {
if (!vcpu->vc_irqready) {
- printf("vcpu_run_vmx: error - irq injected"
- " while not ready\n");
+ printf("%s: error - irq injected while not "
+ "ready\n", __func__);
ret = EINVAL;
break;
}
eii |= (1ULL << 31); /* Valid */
eii |= (0ULL << 8); /* Hardware Interrupt */
if (vmwrite(VMCS_ENTRY_INTERRUPTION_INFO, eii)) {
- printf("vcpu_run_vmx: can't vector "
- "interrupt to guest\n");
+ printf("%s: can't vector interrupt to guest\n",
+ __func__);
ret = EINVAL;
break;
}
* Disable window exiting
*/
if (vmread(VMCS_PROCBASED_CTLS, &procbased)) {
- printf("vcpu_run_vmx: can't read"
- "procbased ctls on exit\n");
+ printf("%s: can't read procbased ctls on "
+ "exit\n", __func__);
ret = EINVAL;
break;
} else {
procbased &= ~IA32_VMX_INTERRUPT_WINDOW_EXITING;
if (vmwrite(VMCS_PROCBASED_CTLS, procbased)) {
- printf("vcpu_run_vmx: can't write"
- " procbased ctls on exit\n");
+ printf("%s: can't write procbased ctls "
+ "on exit\n", __func__);
ret = EINVAL;
break;
}
&vcpu->vc_gueststate.vg_eip, &exit_reason);
if (vmread(VMCS_GUEST_IA32_RFLAGS,
&vcpu->vc_gueststate.vg_eflags)) {
- printf("vcpu_run_vmx: can't read guest rflags"
- " during exit\n");
+ printf("%s: can't read guest rflags during "
+ "exit\n", __func__);
ret = EINVAL;
break;
}
if (ret == 0) {
resume = 1;
if (!(exitinfo & VMX_EXIT_INFO_HAVE_RIP)) {
- printf("vcpu_run_vmx: cannot read guest rip\n");
+ printf("%s: cannot read guest rip\n", __func__);
ret = EINVAL;
break;
}
if (!(exitinfo & VMX_EXIT_INFO_HAVE_REASON)) {
- printf("vcpu_run_vmx: cant read exit reason\n");
+ printf("%s: cant read exit reason\n", __func__);
ret = EINVAL;
break;
}
*/
if (vcpu->vc_irqready == 0 && vcpu->vc_intr) {
if (vmread(VMCS_PROCBASED_CTLS, &procbased)) {
- printf("vcpu_run_vmx: can't read"
- " procbased ctls on intwin exit\n");
+ printf("%s: can't read procbased ctls "
+ "on intwin exit\n", __func__);
ret = EINVAL;
break;
}
procbased |= IA32_VMX_INTERRUPT_WINDOW_EXITING;
if (vmwrite(VMCS_PROCBASED_CTLS, procbased)) {
- printf("vcpu_run_vmx: can't write"
- " procbased ctls on intwin exit\n");
+ printf("%s: can't write procbased ctls "
+ "on intwin exit\n", __func__);
ret = EINVAL;
break;
}
yield();
}
} else if (ret == VMX_FAIL_LAUNCH_INVALID_VMCS) {
- printf("vcpu_run_vmx: failed launch with invalid "
- "vmcs\n");
+ printf("%s: failed launch with invalid vmcs\n",
+ __func__);
#ifdef VMM_DEBUG
vmx_vcpu_dump_regs(vcpu);
dump_vcpu(vcpu);
ret = EINVAL;
} else if (ret == VMX_FAIL_LAUNCH_VALID_VMCS) {
exit_reason = vcpu->vc_gueststate.vg_exit_reason;
- printf("vcpu_run_vmx: failed launch with valid "
- "vmcs, code=%d (%s)\n", exit_reason,
+ printf("%s: failed launch with valid vmcs, code=%d "
+ "(%s)\n", __func__, exit_reason,
vmx_instruction_error_decode(exit_reason));
if (vmread(VMCS_INSTRUCTION_ERROR, &insn_error)) {
- printf("vcpu_run_vmx: can't read"
- " insn error field\n");
+ printf("%s: can't read insn error field\n",
+ __func__);
} else
- printf("vcpu_run_vmx: insn error code = "
- "%d\n", insn_error);
+ printf("%s: insn error code = %d\n", __func__,
+ insn_error);
#ifdef VMM_DEBUG
vmx_vcpu_dump_regs(vcpu);
dump_vcpu(vcpu);
#endif /* VMM_DEBUG */
ret = EINVAL;
} else {
- printf("vcpu_run_vmx: failed launch for unknown "
- "reason %d\n", ret);
+ printf("%s: failed launch for unknown reason %d\n",
+ __func__, ret);
#ifdef VMM_DEBUG
vmx_vcpu_dump_regs(vcpu);
dump_vcpu(vcpu);
vaddr_t handler;
if (vmread(VMCS_EXIT_INTERRUPTION_INFO, &eii)) {
- printf("vmx_handle_intr: can't obtain intr info\n");
+ printf("%s: can't obtain intr info\n", __func__);
return;
}
switch (exit_reason) {
case VMX_EXIT_INT_WINDOW:
if (!(eflags & PSL_I)) {
- DPRINTF("vmx_handle_exit: impossible interrupt window"
- " exit config\n");
+ DPRINTF("%s: impossible intr window exit config\n",
+ __func__);
ret = EINVAL;
break;
}
break;
case VMX_EXIT_TRIPLE_FAULT:
#ifdef VMM_DEBUG
- DPRINTF("vmx_handle_exit: vm %d vcpu %d triple fault\n",
+ DPRINTF("%s: vm %d vcpu %d triple fault\n", __func__,
vcpu->vc_parent->vm_id, vcpu->vc_id);
vmx_vcpu_dump_regs(vcpu);
dump_vcpu(vcpu);
update_rip = 0;
break;
default:
- DPRINTF("vmx_handle_exit: unhandled exit %lld (%s)\n",
+ DPRINTF("%s: unhandled exit %lld (%s)\n", __func__,
exit_reason, vmx_exit_reason_decode(exit_reason));
return (EINVAL);
}
if (update_rip) {
if (vmwrite(VMCS_GUEST_IA32_RIP,
vcpu->vc_gueststate.vg_eip)) {
- printf("vmx_handle_exit: can't advance rip\n");
+ printf("%s: can't advance rip\n", __func__);
return (EINVAL);
}
}
vmx_get_exit_qualification(uint32_t *exit_qualification)
{
if (vmread(VMCS_GUEST_EXIT_QUALIFICATION, exit_qualification)) {
- printf("vmm_get_exit_qualification: cant extract exit qual\n");
+ printf("%s: cant extract exit qual\n", __func__);
return (EINVAL);
}
fault_type = vmx_get_guest_faulttype();
if (fault_type == -1) {
- printf("vmx_fault_page: invalid fault type\n");
+ printf("%s: invalid fault type\n", __func__);
return (EINVAL);
}
ret = uvm_fault(vcpu->vc_parent->vm_map, gpa, fault_type,
PROT_READ | PROT_WRITE | PROT_EXEC);
if (ret)
- printf("vmx_fault_page: uvm_fault returns %d\n", ret);
+ printf("%s: uvm_fault returns %d\n", __func__, ret);
return (ret);
}
ret = 0;
if (vmread(VMCS_GUEST_PHYSICAL_ADDRESS, &gpa_lo)) {
- printf("vmm_handle_np_fault: cannot extract faulting pa lo\n");
+ printf("%s: cannot extract faulting pa lo\n", __func__);
return (EINVAL);
}
if (vmread(VMCS_GUEST_PHYSICAL_ADDRESS_HI, &gpa_hi)) {
- printf("vmm_handle_np_fault: cannot extract faulting pa hi\n");
+ printf("%s: cannot extract faulting pa hi\n", __func__);
return (EINVAL);
}
int ret;
if (vmread(VMCS_INSTRUCTION_LENGTH, &insn_length)) {
- printf("vmx_handle_inout: can't obtain instruction length\n");
+ printf("%s: can't obtain instruction length\n", __func__);
return (EINVAL);
}
if (vmx_get_exit_qualification(&exit_qual)) {
- printf("vmx_handle_inout: can't get exit qual\n");
+ printf("%s: can't get exit qual\n", __func__);
return (EINVAL);
}
uint8_t crnum, dir;
if (vmread(VMCS_INSTRUCTION_LENGTH, &insn_length)) {
- printf("vmx_handle_cr: can't obtain instruction length\n");
+ printf("%s: can't obtain instruction length\n", __func__);
return (EINVAL);
}
if (vmx_get_exit_qualification(&exit_qual)) {
- printf("vmx_handle_cr: can't get exit qual\n");
+ printf("%s: can't get exit qual\n", __func__);
return (EINVAL);
}
switch (dir) {
case CR_WRITE:
- DPRINTF("vmx_handle_cr: mov to cr%d @ %x\n",
+ DPRINTF("%s: mov to cr%d @ %x\n", __func__,
crnum, vcpu->vc_gueststate.vg_eip);
break;
case CR_READ:
- DPRINTF("vmx_handle_cr: mov from cr%d @ %x\n",
+ DPRINTF("%s: mov from cr%d @ %x\n", __func__,
crnum, vcpu->vc_gueststate.vg_eip);
break;
case CR_CLTS:
- DPRINTF("vmx_handle_cr: clts instruction @ %x\n",
+ DPRINTF("%s: clts instruction @ %x\n", __func__,
vcpu->vc_gueststate.vg_eip);
break;
case CR_LMSW:
- DPRINTF("vmx_handle_cr: lmsw instruction @ %x\n",
+ DPRINTF("%s: lmsw instruction @ %x\n", __func__,
vcpu->vc_gueststate.vg_eip);
break;
default:
- DPRINTF("vmx_handle_cr: unknown cr access @ %x\n",
+ DPRINTF("%s: unknown cr access @ %x\n", __func__,
vcpu->vc_gueststate.vg_eip);
}