Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset local APIC from VCPU reset, set base and LDR #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions kvm_lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/types.h>
#include <sys/atomic.h>
Expand Down Expand Up @@ -895,6 +896,7 @@ void
kvm_free_lapic(struct kvm_vcpu *vcpu)
{
struct kvm_lapic *apic = vcpu->arch.apic;

if (apic == NULL)
return;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion kvm_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down