Skip to contentSkip to conversation

Fix for a recent regression in kvm/queue (guest using 100% cpu time)

PATCH In review Maxim Levitsky 2 participants 3 messages Dec 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Fix for a recent regression in kvm/queue (guest using 100% cpu time)

I did a quick bisect yesterday after noticing that my VMs started to take 100% cpu time.

Looks like we don't ignore SIPIs that are received while the CPU isn't waiting for them, and that makes KVM think that CPU always has pending events which makes it never enter an idle state.

Best regards,
Maxim Levitsky

Maxim Levitsky (1):
KVM: x86: ignore SIPIs that are received while not in wait-for-sipi
state

 arch/x86/kvm/lapic.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/1 KVM: x86: ignore SIPIs that are received while not in wait-for-sipi state

In the commit 1c96dcceaeb3
("KVM: x86: fix apic_accept_events vs check_nested_events"),

we accidently started latching SIPIs that are received while the cpu is not waiting for them.

This causes vCPUs to never enter a halted state.

Fixes 1c96dcceaeb3 ("KVM: x86: fix apic_accept_events vs check_nested_events")
---
 arch/x86/kvm/lapic.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
arch/x86/kvm/lapic.c +8 -7
index e3ee597ff5404..6a87623aa578e 100644
@@ -2892,14 +2892,15 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
 		else
 			vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED;
 	}
-	if (test_bit(KVM_APIC_SIPI, &pe) &&
-	    vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) {
+	if (test_bit(KVM_APIC_SIPI, &pe)) {
 		clear_bit(KVM_APIC_SIPI, &apic->pending_events);
-		/* evaluate pending_events before reading the vector */
-		smp_rmb();
-		sipi_vector = apic->sipi_vector;
-		kvm_vcpu_deliver_sipi_vector(vcpu, sipi_vector);
-		vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+		if (vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) {
+			/* evaluate pending_events before reading the vector */
+			smp_rmb();
+			sipi_vector = apic->sipi_vector;
+			kvm_vcpu_deliver_sipi_vector(vcpu, sipi_vector);
+			vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+		}
 	}
 }
 
Signature · 1 line
2.26.2
maintainer
#2 lore raw

Re: [PATCH 1/1] KVM: x86: ignore SIPIs that are received while not in wait-for-sipi state

Quoted 6 lines · Maxim Levitsky

In the commit 1c96dcceaeb3
("KVM: x86: fix apic_accept_events vs check_nested_events"),

we accidently started latching SIPIs that are received while the cpu is not waiting for them.

Quoted 6 lines

This causes vCPUs to never enter a halted state.

Fixes 1c96dcceaeb3 ("KVM: x86: fix apic_accept_events vs check_nested_events")
---
 arch/x86/kvm/lapic.c | 15 ++++++++-------

Indeed, it was done by the xchg before that commit, even if vcpu->arch.mp_state != KVM_MP_STATE_INIT_RECEIVED.

Paolo