On Mon, 2025-03-03 at 17:33 -0800, Sean Christopherson wrote: > From: weizijie <zijie.wei@xxxxxxxxxxxxxxxxx> > > Rescan I/O APIC routes for a vCPU after handling an intercepted I/O APIC > EOI for an IRQ that is not targeting said vCPU, i.e. after handling what's > effectively a stale EOI VM-Exit. If a level-triggered IRQ is in-flight > when IRQ routing changes, e.g. because the guest change routing from its ^ changes ? > IRQ handler, then KVM intercepts EOIs on both the new and old target vCPUs, > so that the in-flight IRQ can be de-asserted when it's EOI'd. > > However, only the EOI for the in-flight IRQ needs to intercepted, as IRQs ^ be intercepted > on the same vector with the new routing are coincidental, i.e. occur only > if the guest is reusing the vector for multiple interrupt sources. If the > I/O APIC routes aren't rescanned, KVM will unnecessarily intercept EOIs > for the vector and negative impact the vCPU's interrupt performance. > > Note, both commit db2bdcbbbd32 ("KVM: x86: fix edge EOI and IOAPIC reconfig > race") and commit 0fc5a36dd6b3 ("KVM: x86: ioapic: Fix level-triggered EOI > and IOAPIC reconfigure race") mentioned this issue, but it was considered > a "rare" occurrence thus was not addressed. However in real environments, > this issue can happen even in a well-behaved guest. > > Cc: Kai Huang <kai.huang@xxxxxxxxx> > Co-developed-by: xuyun <xuyun_xy.xy@xxxxxxxxxxxxxxxxx> > Signed-off-by: xuyun <xuyun_xy.xy@xxxxxxxxxxxxxxxxx> > Signed-off-by: weizijie <zijie.wei@xxxxxxxxxxxxxxxxx> > [sean: massage changelog and comments, use int/-1, reset at scan] > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx> Reviewed-by: Kai Huang <kai.huang@xxxxxxxxx>