Skip to content

Commit cd7764f

Browse files
committed
KVM: x86: latch INITs while in system management mode
Do not process INITs immediately while in system management mode, keep it instead in apic->pending_events. Tell userspace if an INIT is pending when they issue GET_VCPU_EVENTS, and similarly handle the new field in SET_VCPU_EVENTS. Note that the same treatment should be done while in VMX non-root mode. Reviewed-by: Radim Krčmář <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 64d6067 commit cd7764f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

arch/x86/kvm/lapic.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,8 +2057,19 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
20572057
if (!kvm_vcpu_has_lapic(vcpu) || !apic->pending_events)
20582058
return;
20592059

2060-
pe = xchg(&apic->pending_events, 0);
2060+
/*
2061+
* INITs are latched while in SMM. Because an SMM CPU cannot
2062+
* be in KVM_MP_STATE_INIT_RECEIVED state, just eat SIPIs
2063+
* and delay processing of INIT until the next RSM.
2064+
*/
2065+
if (is_smm(vcpu)) {
2066+
WARN_ON_ONCE(vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED);
2067+
if (test_bit(KVM_APIC_SIPI, &apic->pending_events))
2068+
clear_bit(KVM_APIC_SIPI, &apic->pending_events);
2069+
return;
2070+
}
20612071

2072+
pe = xchg(&apic->pending_events, 0);
20622073
if (test_bit(KVM_APIC_INIT, &pe)) {
20632074
kvm_lapic_reset(vcpu, true);
20642075
kvm_vcpu_reset(vcpu, true);

arch/x86/kvm/x86.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,6 +5482,9 @@ static void kvm_smm_changed(struct kvm_vcpu *vcpu)
54825482
if (unlikely(vcpu->arch.smi_pending)) {
54835483
kvm_make_request(KVM_REQ_SMI, vcpu);
54845484
vcpu->arch.smi_pending = 0;
5485+
} else {
5486+
/* Process a latched INIT, if any. */
5487+
kvm_make_request(KVM_REQ_EVENT, vcpu);
54855488
}
54865489
}
54875490
}

0 commit comments

Comments
 (0)