public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Fix lapic timer interrupt lost after loading a snapshot.
@ 2023-09-12 16:15 Haitao Shan
  2023-09-12 16:53 ` Brett Creeley
  2023-09-12 17:07 ` Sean Christopherson
  0 siblings, 2 replies; 5+ messages in thread
From: Haitao Shan @ 2023-09-12 16:15 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, kvm
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, linux-kernel, Haitao Shan

This issue exists in kernel version 6.3-rc1 or above. The issue is
introduced by the commit 8e6ed96cdd50 ("KVM: x86: fire timer when it is
migrated and expired, and in oneshot mode"). The issue occurs on Intel
platform which APIC virtualization and posted interrupt processing.

The issue is first discovered when running the Android Emulator which
is based on QEMU 2.12. I can reproduce the issue with QEMU 8.0.4 in
Debian 12.

With the above commit, the timer gets fired immediately inside the
KVM_SET_LAPIC call when loading the snapshot. On such Intel platforms,
this eventually leads to setting the corresponding PIR bit. However,
the whole PIR bits get cleared later in the same KVM_SET_LAPIC call.
Missing lapic timer interrupt freeze the guest kernel.

Signed-off-by: Haitao Shan <hshan@google.com>
---
 arch/x86/kvm/lapic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index a983a16163b1..6f73406b875a 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2977,14 +2977,14 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s)
 	apic_update_lvtt(apic);
 	apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0));
 	update_divide_count(apic);
-	__start_apic_timer(apic, APIC_TMCCT);
-	kvm_lapic_set_reg(apic, APIC_TMCCT, 0);
 	kvm_apic_update_apicv(vcpu);
 	if (apic->apicv_active) {
 		static_call_cond(kvm_x86_apicv_post_state_restore)(vcpu);
 		static_call_cond(kvm_x86_hwapic_irr_update)(vcpu, apic_find_highest_irr(apic));
 		static_call_cond(kvm_x86_hwapic_isr_update)(apic_find_highest_isr(apic));
 	}
+	__start_apic_timer(apic, APIC_TMCCT);
+	kvm_lapic_set_reg(apic, APIC_TMCCT, 0);
 	kvm_make_request(KVM_REQ_EVENT, vcpu);
 	if (ioapic_in_kernel(vcpu->kvm))
 		kvm_rtc_eoi_tracking_restore_one(vcpu);
-- 
2.42.0.283.g2d96d420d3-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-12 18:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12 16:15 [PATCH] KVM: x86: Fix lapic timer interrupt lost after loading a snapshot Haitao Shan
2023-09-12 16:53 ` Brett Creeley
2023-09-12 17:07 ` Sean Christopherson
     [not found]   ` <CAGD3tSzxgSmuC8MOt_Wek3rkO4gjT908x0bF2MNYot1W=FBcow@mail.gmail.com>
2023-09-12 18:14     ` Sean Christopherson
2023-09-12 18:16   ` Haitao Shan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox