mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] KVM: x86: IOAPIC EOI can race with KVM_SET_IRQCHIP
@ 2026-11-15 16:37 Cheng Yongkang
  0 siblings, 0 replies; only message in thread
From: Cheng Yongkang @ 2026-11-15 16:37 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-15 16:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 16:37 [BUG] KVM: x86: IOAPIC EOI can race with KVM_SET_IRQCHIP Cheng Yongkang

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®