mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiang Zheng <xiang.zheng@linux.alibaba.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Shuah Khan <shuah@kernel.org>
Cc: Shannon Zhao <shannon.zhao@linux.alibaba.com>,
	kvm@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH 1/2] KVM: x86: ioapic: Clear stale RTC pending EOIs using the delivery record
Date: Tue, 20 Oct 2026 14:00:52 +0800	[thread overview]
Message-ID: <20261020060053.25011-2-xiang.zheng@linux.alibaba.com> (raw)
In-Reply-To: <20261020060053.25011-1-xiang.zheng@linux.alibaba.com>

Use the vCPU/vector pairs recorded in rtc_status to clear completed RTC
pending EOIs instead of consulting the current redirection entry.

AVIC completes EOIs of edge-triggered interrupts in hardware, without a
VM exit, so KVM cannot decrement the RTC pending-EOI count from an EOI
exit.  ioapic_lazy_update_eoi() compensates at the next injection by
clearing the pending EOI of any vCPU that no longer has the vector in
IRR/ISR, but it identifies those vCPUs with the current redirection
entry instead of the delivery record kept in rtc_status.

If the guest rewrites the RTC redirection entry after an interrupt was
delivered and EOI'd without an exit, e.g. because the guest moves the
RTC to another processor, the new route no longer matches the recorded
delivery, so the pending EOI is left set and every later RTC interrupt
is reported as coalesced and dropped.  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.

Walk the vCPUs present in rtc_status and test the vector stored at
delivery.  While at it, clear every completed record instead of bailing
out after the first one, and skip pins other than the RTC, the only pin
with delivery tracking.

Fixes: f458d039db7e ("kvm: ioapic: Lazy update IOAPIC EOI")
Signed-off-by: Xiang Zheng <xiang.zheng@linux.alibaba.com>
---
 arch/x86/kvm/ioapic.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 0d59b9c758c2..803fda172db5 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -167,21 +167,18 @@ static void ioapic_lazy_update_eoi(struct kvm_ioapic *ioapic, int irq)
 {
 	unsigned long i;
 	struct kvm_vcpu *vcpu;
-	union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];
+	struct rtc_status *status = &ioapic->rtc_status;
+
+	if (irq != RTC_GSI || !status->pending_eoi)
+		return;
 
+	/* Use the target recorded at delivery; the entry may have changed. */
 	kvm_for_each_vcpu(i, vcpu, ioapic->kvm) {
-		if (!kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT,
-					 entry->fields.dest_id,
-					 entry->fields.dest_mode) ||
-		    kvm_apic_pending_eoi(vcpu, entry->fields.vector))
+		if (!test_bit(vcpu->vcpu_id, status->map) ||
+		    kvm_apic_pending_eoi(vcpu, status->vectors[vcpu->vcpu_id]))
 			continue;
 
-		/*
-		 * If no longer has pending EOI in LAPICs, update
-		 * EOI for this vector.
-		 */
-		rtc_irq_eoi(ioapic, vcpu, entry->fields.vector);
-		break;
+		rtc_irq_eoi(ioapic, vcpu, status->vectors[vcpu->vcpu_id]);
 	}
 }
 
-- 
2.50.1 (Apple Git-155)


  reply	other threads:[~2026-10-20  6:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20  6:00 [PATCH 0/2] KVM: x86: Fix stale RTC pending-EOI tracking under AVIC Xiang Zheng
2026-10-20  6:00 ` Xiang Zheng [this message]
2026-10-20  6:00 ` [PATCH 2/2] KVM: selftests: x86: Add RTC EOI retargeting regression test Xiang Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261020060053.25011-2-xiang.zheng@linux.alibaba.com \
    --to=xiang.zheng@linux.alibaba.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shannon.zhao@linux.alibaba.com \
    --cc=shuah@kernel.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®