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: IOAPIC EOI can race with KVM_SET_IRQCHIP
Date: Sun, 15 Nov 2026 08:37:50 -0800	[thread overview]
Message-ID: <20261115163750.227354-1-teel4res@gmail.com> (raw)

Hi Sean, Paolo,

I hit a race between a level-triggered EOI and KVM_SET_IRQCHIP. It
needs the VMM to restore the IOAPIC while vCPUs are running, which
VMMs normally avoid, so it may not matter much in practice.

kvm_ioapic_update_eoi_one() keeps ent = &ioapic->redirtbl[pin], drops
ioapic->lock to run the ack notifiers, and then takes the lock again.
It does this for every matching pin, whether or not a notifier is
registered. KVM_SET_IRQCHIP can take the lock in that window and
memcpy a new redirection table. The EOI then clears remote_irr, and
may call ioapic_service(), on an entry of the new table that the
guest never acknowledged. The outer loop also continues over the new
table. The KVM_SET_IRQCHIP documentation does not say that vCPUs must
be stopped first, so I am not sure whether this is meant to be
supported.

On v7.3 I alternated KVM_SET_IRQCHIP between two tables while the
guest EOIed a level interrupt, with no irqfd or other ack notifier
registered, and used a level entry that can never match the EOI
vector as a marker. Its remote_irr went from 1 to 0, after 81
SET_IRQCHIP calls in one run and 30 in another. The code is unchanged
in next-20261113.

One fix is a generation counter in struct kvm_ioapic, outside the
copied kvm_ioapic_state, that KVM_SET_IRQCHIP bumps under the lock.
The EOI path drops its match if the counter changed while the lock was
released. With that change I saw no such event in 247,039 SET_IRQCHIP
calls, and basic EOI tests still passed. I can send it as a patch if
you want one.

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=20261115163750.227354-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®