From b73b94ef3f35cb18cbe9fc244cb1d8f1baac7973 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Sat, 7 Apr 2018 04:34:09 -0500 Subject: [PATCH] Reset local APIC from VCPU reset, set base and LDR --- kvm_lapic.c | 17 +++++++++-------- kvm_x86.c | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/kvm_lapic.c b/kvm_lapic.c index 6a3550d..94fab80 100644 --- a/kvm_lapic.c +++ b/kvm_lapic.c @@ -16,6 +16,7 @@ * the COPYING file in the top-level directory. * * Copyright (c) 2012 Joyent, Inc. All rights reserved. + * Copyright (c) 2018 SoftNAS, LLC */ #include #include @@ -895,6 +896,7 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic = vcpu->arch.apic; + if (apic == NULL) return; @@ -966,12 +968,11 @@ kvm_lapic_set_base(struct kvm_vcpu *vcpu, uint64_t value) void kvm_lapic_reset(struct kvm_vcpu *vcpu) { - struct kvm_lapic *apic; + struct kvm_lapic *apic = vcpu->arch.apic; int i; - ASSERT(vcpu); - apic = vcpu->arch.apic; - ASSERT(apic != NULL); + if (apic == NULL) + return; /* Stop the timer in case it's a reset to an active apic */ mutex_enter(&cpu_lock); @@ -1008,13 +1009,14 @@ kvm_lapic_reset(struct kvm_vcpu *vcpu) update_divide_count(apic); apic->lapic_timer.pending = 0; - if (kvm_vcpu_is_bsp(vcpu)) - vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP; + /* also sets APIC_LDR in x2apic mode */ + kvm_lapic_set_base(vcpu, APIC_DEFAULT_PHYS_BASE | + MSR_IA32_APICBASE_BSP); apic_update_ppr(apic); vcpu->arch.apic_arb_prio = 0; - cmn_err(CE_CONT, "!%s: vcpu=%p, id=%d, base_msr= %lx PRIx64 " + cmn_err(CE_CONT, "!%s: vcpu=%p, id=%d, base_msr=%" PRIx64 ", " "base_address=%lx\n", __func__, vcpu, kvm_apic_id(apic), vcpu->arch.apic_base, apic->base_address); } @@ -1116,7 +1118,6 @@ kvm_create_lapic(struct kvm_vcpu *vcpu) apic->base_address = APIC_DEFAULT_PHYS_BASE; vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE; - kvm_lapic_reset(vcpu); kvm_iodevice_init(&apic->dev, &apic_mmio_ops); apic->dev.lapic = apic; diff --git a/kvm_x86.c b/kvm_x86.c index c366389..ca790f1 100644 --- a/kvm_x86.c +++ b/kvm_x86.c @@ -3516,7 +3516,6 @@ __vcpu_run(struct kvm_vcpu *vcpu) if (vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED) { cmn_err(CE_CONT, "!vcpu %d received sipi with vector # %x\n", vcpu->vcpu_id, vcpu->arch.sipi_vector); - kvm_lapic_reset(vcpu); r = kvm_arch_vcpu_reset(vcpu); if (r) return (r); @@ -4690,6 +4689,7 @@ kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu) { + kvm_lapic_reset(vcpu); vcpu->arch.nmi_pending = 0; vcpu->arch.nmi_injected = 0;