[PATCH 0/2] KVM: x86: Fix stale RTC pending-EOI tracking under AVIC
From: Xiang Zheng
Date: Tue Oct 20 2026 - 02:02:29 EST
ioapic_lazy_update_eoi() exists because AVIC completes EOIs of
edge-triggered interrupts in hardware, without a VM exit. It clears
the RTC pending-EOI record of vCPUs that no longer have the vector in
IRR/ISR, but identifies those vCPUs with the current redirection entry
instead of the delivery record kept in rtc_status. A guest that
retargets the RTC after such an EOI therefore leaves the pending EOI
set, and every later RTC interrupt is dropped as coalesced. A guest
that relies on the RTC timer interrupt to advance timekeeping, e.g. a
Windows guest without HPET and with an unused APIC timer, then loses
its timer and hangs.
Patch 1 makes the lazy update consult the delivery record. Patch 2
adds a selftest that reproduces the bookkeeping failure without a
Windows guest: userspace injects GSI 8, the target vCPU handles it and
writes the EOI, the guest retargets the RTC, and the next injection
must still be reported as delivered by KVM_IRQ_LINE_STATUS.
Tested on an AMD host running Linux 7.3-rc7: with AVIC enabled, the
unpatched kernel fails the selftest at the second injection (status 0,
coalesced) and the patched kernel passes all 64 rounds; with AVIC
disabled both pass. Not tested on Intel/APICv.
Thanks,
Xiang
Xiang Zheng (2):
KVM: x86: ioapic: Clear stale RTC pending EOIs using the delivery
record
KVM: selftests: x86: Add RTC EOI retargeting regression test
arch/x86/kvm/ioapic.c | 19 +--
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/x86/rtc_eoi_retarget_test.c | 155 ++++++++++++++++++
3 files changed, 164 insertions(+), 11 deletions(-)
create mode 100644 tools/testing/selftests/kvm/x86/rtc_eoi_retarget_test.c
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
--
2.50.1 (Apple Git-155)