[BUG] KVM: x86: IOAPIC EOI can race with KVM_SET_IRQCHIP

From: Cheng Yongkang

Date: Sun Nov 15 2026 - 11:38:23 EST


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