KVM: x86: Always sync PIR to IRR prior to scanning I/O APIC routes
authorSean Christopherson <seanjc@google.com>
Tue, 11 Jun 2024 01:48:45 +0000 (18:48 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 20 Jun 2024 18:18:02 +0000 (14:18 -0400)
commitf3ced000a2df53f4b12849e121769045a81a3b22
treefdf579eb23b4659e1b5255c6cfa556c5d6adecbb
parentdb574f2f96d0c9a245a9e787e3d9ec288fb2b445
KVM: x86: Always sync PIR to IRR prior to scanning I/O APIC routes

Sync pending posted interrupts to the IRR prior to re-scanning I/O APIC
routes, irrespective of whether the I/O APIC is emulated by userspace or
by KVM.  If a level-triggered interrupt routed through the I/O APIC is
pending or in-service for a vCPU, KVM needs to intercept EOIs on said
vCPU even if the vCPU isn't the destination for the new routing, e.g. if
servicing an interrupt using the old routing races with I/O APIC
reconfiguration.

Commit fceb3a36c29a ("KVM: x86: ioapic: Fix level-triggered EOI and
userspace I/OAPIC reconfigure race") fixed the common cases, but
kvm_apic_pending_eoi() only checks if an interrupt is in the local
APIC's IRR or ISR, i.e. misses the uncommon case where an interrupt is
pending in the PIR.

Failure to intercept EOI can manifest as guest hangs with Windows 11 if
the guest uses the RTC as its timekeeping source, e.g. if the VMM doesn't
expose a more modern form of time to the guest.

Cc: stable@vger.kernel.org
Cc: Adamos Ttofari <attofari@amazon.de>
Cc: Raghavendra Rao Ananta <rananta@google.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20240611014845.82795-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c