summaryrefslogtreecommitdiffstats
path: root/sys/amd64
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2012-11-28 13:10:18 +0000
committerneel <neel@FreeBSD.org>2012-11-28 13:10:18 +0000
commit308122a0f1279a0305554f864d6b01f9c132511a (patch)
tree5f19842a5c240b93e3f6cfbdee50f247157d04cf /sys/amd64
parent36ab9a2e1ab7d2b1884270275584f989cfd65e2b (diff)
downloadFreeBSD-src-308122a0f1279a0305554f864d6b01f9c132511a.zip
FreeBSD-src-308122a0f1279a0305554f864d6b01f9c132511a.tar.gz
Change emulate_rdmsr() and emulate_wrmsr() to return 0 on sucess and errno on
failure. The conversion from the return value to HANDLED or UNHANDLED can be done locally in vmx_exit_process(). Obtained from: NetApp
Diffstat (limited to 'sys/amd64')
-rw-r--r--sys/amd64/vmm/intel/vmx.c14
-rw-r--r--sys/amd64/vmm/vmm_lapic.c52
-rw-r--r--sys/amd64/vmm/vmm_msr.c36
3 files changed, 37 insertions, 65 deletions
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index b185c57..af4a03f 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -1214,23 +1214,25 @@ vmx_exit_process(struct vmx *vmx, int vcpu, struct vm_exit *vmexit)
break;
case EXIT_REASON_RDMSR:
ecx = vmxctx->guest_rcx;
- handled = emulate_rdmsr(vmx->vm, vcpu, ecx);
- if (!handled) {
+ error = emulate_rdmsr(vmx->vm, vcpu, ecx);
+ if (error) {
vmexit->exitcode = VM_EXITCODE_RDMSR;
vmexit->u.msr.code = ecx;
- }
+ } else
+ handled = 1;
break;
case EXIT_REASON_WRMSR:
eax = vmxctx->guest_rax;
ecx = vmxctx->guest_rcx;
edx = vmxctx->guest_rdx;
- handled = emulate_wrmsr(vmx->vm, vcpu, ecx,
+ error = emulate_wrmsr(vmx->vm, vcpu, ecx,
(uint64_t)edx << 32 | eax);
- if (!handled) {
+ if (error) {
vmexit->exitcode = VM_EXITCODE_WRMSR;
vmexit->u.msr.code = ecx;
vmexit->u.msr.wval = (uint64_t)edx << 32 | eax;
- }
+ } else
+ handled = 1;
break;
case EXIT_REASON_HLT:
vmm_stat_incr(vmx->vm, vcpu, VMEXIT_HLT, 1);
diff --git a/sys/amd64/vmm/vmm_lapic.c b/sys/amd64/vmm/vmm_lapic.c
index dabcf06..d024b71 100644
--- a/sys/amd64/vmm/vmm_lapic.c
+++ b/sys/amd64/vmm/vmm_lapic.c
@@ -41,32 +41,6 @@ __FBSDID("$FreeBSD$");
#include "vmm_lapic.h"
#include "vlapic.h"
-static int
-lapic_write(struct vlapic *vlapic, u_int offset, uint64_t val)
-{
- int handled;
-
- if (vlapic_op_mem_write(vlapic, offset, DWORD, val) == 0)
- handled = 1;
- else
- handled = 0;
-
- return (handled);
-}
-
-static int
-lapic_read(struct vlapic *vlapic, u_int offset, uint64_t *rv)
-{
- int handled;
-
- if (vlapic_op_mem_read(vlapic, offset, DWORD, rv) == 0)
- handled = 1;
- else
- handled = 0;
-
- return (handled);
-}
-
int
lapic_pending_intr(struct vm *vm, int cpu)
{
@@ -145,35 +119,41 @@ lapic_msr(u_int msr)
int
lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval)
{
- int handled;
+ int error;
+ u_int offset;
struct vlapic *vlapic;
vlapic = vm_lapic(vm, cpu);
if (msr == MSR_APICBASE) {
*rval = vlapic_get_apicbase(vlapic);
- handled = 1;
- } else
- handled = lapic_read(vlapic, x2apic_msr_to_regoff(msr), rval);
+ error = 0;
+ } else {
+ offset = x2apic_msr_to_regoff(msr);
+ error = vlapic_op_mem_read(vlapic, offset, DWORD, rval);
+ }
- return (handled);
+ return (error);
}
int
lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t val)
{
- int handled;
+ int error;
+ u_int offset;
struct vlapic *vlapic;
vlapic = vm_lapic(vm, cpu);
if (msr == MSR_APICBASE) {
vlapic_set_apicbase(vlapic, val);
- handled = 1;
- } else
- handled = lapic_write(vlapic, x2apic_msr_to_regoff(msr), val);
+ error = 0;
+ } else {
+ offset = x2apic_msr_to_regoff(msr);
+ error = vlapic_op_mem_write(vlapic, offset, DWORD, val);
+ }
- return (handled);
+ return (error);
}
int
diff --git a/sys/amd64/vmm/vmm_msr.c b/sys/amd64/vmm/vmm_msr.c
index bc67f98..d97c819 100644
--- a/sys/amd64/vmm/vmm_msr.c
+++ b/sys/amd64/vmm/vmm_msr.c
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
#define VMM_MSR_F_EMULATE 0x01
#define VMM_MSR_F_READONLY 0x02
-#define VMM_MSR_F_INVALID 0x04
+#define VMM_MSR_F_INVALID 0x04 /* guest_msr_valid() can override this */
struct vmm_msr {
int num;
@@ -137,20 +137,15 @@ msr_num_to_idx(u_int num)
int
emulate_wrmsr(struct vm *vm, int cpu, u_int num, uint64_t val)
{
- int handled, idx;
+ int idx;
uint64_t *guest_msrs;
- handled = 0;
-
if (lapic_msr(num))
return (lapic_wrmsr(vm, cpu, num, val));
idx = msr_num_to_idx(num);
- if (idx < 0)
- goto done;
-
- if (invalid_msr(idx))
- goto done;
+ if (idx < 0 || invalid_msr(idx))
+ return (EINVAL);
if (!readonly_msr(idx)) {
guest_msrs = vm_guest_msrs(vm, cpu);
@@ -163,31 +158,26 @@ emulate_wrmsr(struct vm *vm, int cpu, u_int num, uint64_t val)
wrmsr(vmm_msr[idx].num, val);
}
- handled = 1;
-done:
- return (handled);
+ return (0);
}
int
emulate_rdmsr(struct vm *vm, int cpu, u_int num)
{
- int error, handled, idx;
+ int error, idx;
uint32_t eax, edx;
uint64_t result, *guest_msrs;
- handled = 0;
-
if (lapic_msr(num)) {
- handled = lapic_rdmsr(vm, cpu, num, &result);
+ error = lapic_rdmsr(vm, cpu, num, &result);
goto done;
}
idx = msr_num_to_idx(num);
- if (idx < 0)
- goto done;
-
- if (invalid_msr(idx))
+ if (idx < 0 || invalid_msr(idx)) {
+ error = EINVAL;
goto done;
+ }
guest_msrs = vm_guest_msrs(vm, cpu);
result = guest_msrs[idx];
@@ -202,10 +192,10 @@ emulate_rdmsr(struct vm *vm, int cpu, u_int num)
result, rdmsr(num));
}
- handled = 1;
+ error = 0;
done:
- if (handled) {
+ if (error == 0) {
eax = result;
edx = result >> 32;
error = vm_set_register(vm, cpu, VM_REG_GUEST_RAX, eax);
@@ -215,7 +205,7 @@ done:
if (error)
panic("vm_set_register(rdx) error %d", error);
}
- return (handled);
+ return (error);
}
void
OpenPOWER on IntegriCloud