Skip to content

Commit b7e31be

Browse files
committed
KVM: x86: fix vcpu initialization with userspace lapic
Moving the code around broke this rare configuration. Use this opportunity to finally call lapic reset from vcpu reset. Reported-by: [email protected] Suggested-by: Paolo Bonzini <[email protected]> Fixes: 0b2e990 ("KVM: x86: move LAPIC initialization after VMCS creation") Cc: [email protected] Signed-off-by: Radim Krčmář <[email protected]>
1 parent 518e7b9 commit b7e31be

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

arch/x86/kvm/lapic.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,14 +2002,13 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)
20022002

20032003
void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
20042004
{
2005-
struct kvm_lapic *apic;
2005+
struct kvm_lapic *apic = vcpu->arch.apic;
20062006
int i;
20072007

2008-
apic_debug("%s\n", __func__);
2008+
if (!apic)
2009+
return;
20092010

2010-
ASSERT(vcpu);
2011-
apic = vcpu->arch.apic;
2012-
ASSERT(apic != NULL);
2011+
apic_debug("%s\n", __func__);
20132012

20142013
/* Stop the timer in case it's a reset to an active apic */
20152014
hrtimer_cancel(&apic->lapic_timer.timer);
@@ -2568,7 +2567,6 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
25682567

25692568
pe = xchg(&apic->pending_events, 0);
25702569
if (test_bit(KVM_APIC_INIT, &pe)) {
2571-
kvm_lapic_reset(vcpu, true);
25722570
kvm_vcpu_reset(vcpu, true);
25732571
if (kvm_vcpu_is_bsp(apic->vcpu))
25742572
vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;

arch/x86/kvm/x86.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8060,7 +8060,6 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
80608060
kvm_vcpu_mtrr_init(vcpu);
80618061
vcpu_load(vcpu);
80628062
kvm_vcpu_reset(vcpu, false);
8063-
kvm_lapic_reset(vcpu, false);
80648063
kvm_mmu_setup(vcpu);
80658064
vcpu_put(vcpu);
80668065
return 0;
@@ -8103,6 +8102,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
81038102

81048103
void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
81058104
{
8105+
kvm_lapic_reset(vcpu, init_event);
8106+
81068107
vcpu->arch.hflags = 0;
81078108

81088109
vcpu->arch.smi_pending = 0;

0 commit comments

Comments
 (0)