From 4626d164b84dea9d2eb544118119180724c0f483 Mon Sep 17 00:00:00 2001 From: neel Date: Thu, 20 Feb 2014 01:48:25 +0000 Subject: Simplify APIC mode switching from MMIO to x2APIC. In part this is done to simplify the implementation of the x2APIC virtualization assist in VT-x. Prior to this change the vlapic allowed the guest to change its mode from xAPIC to x2APIC. We don't allow that any more and the vlapic mode is locked when the virtual machine is created. This is not very constraining because operating systems already have to deal with BIOS setting up the APIC in x2APIC mode at boot. Fix a bug in the CPUID emulation where the x2APIC capability was leaking from the host to the guest. Ignore MMIO reads and writes to the vlapic in x2APIC mode. Similarly, ignore MSR accesses to the vlapic when it is in xAPIC mode. The default configuration of the vlapic is xAPIC. The "-x" option to bhyve(8) can be used to change the mode to x2APIC instead. Discussed with: grehan@ --- sys/amd64/vmm/vmm_lapic.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'sys/amd64/vmm/vmm_lapic.c') diff --git a/sys/amd64/vmm/vmm_lapic.c b/sys/amd64/vmm/vmm_lapic.c index 47e04da..640c779 100644 --- a/sys/amd64/vmm/vmm_lapic.c +++ b/sys/amd64/vmm/vmm_lapic.c @@ -172,7 +172,7 @@ lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval, bool *retu) error = 0; } else { offset = x2apic_msr_to_regoff(msr); - error = vlapic_read(vlapic, offset, rval, retu); + error = vlapic_read(vlapic, 0, offset, rval, retu); } return (error); @@ -188,11 +188,10 @@ lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t val, bool *retu) vlapic = vm_lapic(vm, cpu); if (msr == MSR_APICBASE) { - vlapic_set_apicbase(vlapic, val); - error = 0; + error = vlapic_set_apicbase(vlapic, val); } else { offset = x2apic_msr_to_regoff(msr); - error = vlapic_write(vlapic, offset, val, retu); + error = vlapic_write(vlapic, 0, offset, val, retu); } return (error); @@ -216,7 +215,7 @@ lapic_mmio_write(void *vm, int cpu, uint64_t gpa, uint64_t wval, int size, return (EINVAL); vlapic = vm_lapic(vm, cpu); - error = vlapic_write(vlapic, off, wval, arg); + error = vlapic_write(vlapic, 1, off, wval, arg); return (error); } @@ -238,6 +237,6 @@ lapic_mmio_read(void *vm, int cpu, uint64_t gpa, uint64_t *rval, int size, return (EINVAL); vlapic = vm_lapic(vm, cpu); - error = vlapic_read(vlapic, off, rval, arg); + error = vlapic_read(vlapic, 1, off, rval, arg); return (error); } -- cgit v1.1