mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cheng Yongkang <teel4res@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [BUG] KVM: x86: INIT leaves a stale RTC pending EOI
Date: Sun, 15 Nov 2026 08:37:33 -0800	[thread overview]
Message-ID: <20261115163733.227072-1-teel4res@gmail.com> (raw)

Hi Sean, Paolo,

I hit a corner case in the in-kernel IOAPIC RTC EOI tracking. It needs
a vCPU to get INIT before it EOIs an RTC interrupt, APICv to be
inactive, and a VMM that injects GSI 8 with KVM_IRQ_LINE_STATUS, so it
may be rare in practice.

When a vCPU accepts the RTC interrupt, ioapic->rtc_status records it
in map and pending_eoi. If that vCPU then processes INIT,
kvm_lapic_reset() clears IRR and ISR but does not touch rtc_status.
The guest can no longer EOI that vector, so pending_eoi stays above 0
and rtc_irq_check_coalesced() treats every later GSI 8 injection as
coalesced. Only KVM_SET_LAPIC or KVM_SET_IRQCHIP clear it, through
kvm_rtc_eoi_tracking_restore_*(). The lazy repair in
ioapic_lazy_update_eoi() only runs with APICv active, so nothing
repairs the stale entry when APICv is inactive.

On v7.3 with kvm-amd.avic=N, running nested (the KVM under test is
inside a QEMU guest), with IOAPIC pin 8 edge-triggered, vector 0x50,
physical dest 0, and GSI 8 routed only to the IOAPIC, 6 out of 6 runs
gave:

  KVM_IRQ_LINE_STATUS(GSI 8)              -> status 1
      LAPIC: SVR=0x1ff, IRR[0x50]=1, ISR[0x50]=0
  INIT through KVM_SIGNAL_MSI, processed by KVM_RUN
      LAPIC: SVR=0xff, IRR[0x50]=0, ISR[0x50]=0
  guest re-enables the LAPIC: a stub in 32-bit protected mode
  (set with KVM_SET_SREGS/KVM_SET_REGS) writes SVR=0x1ff through the
  APIC MMIO page and exits with "out"
      LAPIC: SVR=0x1ff, IRR[0x50]=0, ISR[0x50]=0
  deassert, KVM_IRQ_LINE_STATUS(GSI 8)    -> status 0 (coalesced)
  control: KVM_SET_LAPIC with the same LAPIC state, so
  kvm_rtc_eoi_tracking_restore_one() drops the stale entry
  deassert, KVM_IRQ_LINE_STATUS(GSI 8)    -> status 1

The entry is edge-triggered, so remote_irr is not involved, and GSI 8
goes only to the IOAPIC, so the status does not come from the PIC. In
the 0 and the 1 case the LAPIC is enabled and its IRR is empty; the
only difference is the stale rtc_status entry.

The code is unchanged in next-20261113. Xiang Zheng's "KVM: x86: Fix
stale RTC pending-EOI tracking under AVIC" only changes
ioapic_lazy_update_eoi(), so it does not cover the APICv-inactive
case.

One option is to call kvm_rtc_eoi_tracking_restore_one() from the INIT
path of kvm_lapic_reset(), as kvm_apic_set_state() already does. I
have not tested that.

Thanks,
Cheng Yongkang

                 reply	other threads:[~2026-11-15 16:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261115163733.227072-1-teel4res@gmail.com \
    --to=teel4res@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /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®