diff mbox series

[v2] KVM: x86: ioapic: Fix level-triggered EOI and userspace I/OAPIC reconfigure race

Message ID 20221208094415.12723-1-attofari@amazon.de (mailing list archive)
State New, archived
Headers show
Series [v2] KVM: x86: ioapic: Fix level-triggered EOI and userspace I/OAPIC reconfigure race | expand

Commit Message

Adamos Ttofari Dec. 8, 2022, 9:44 a.m. UTC
When scanning userspace I/OAPIC entries, intercept EOI for level-triggered
IRQs if the current vCPU has a pending and/or in-service IRQ for the
vector in its local API, even if the vCPU doesn't match the new entry's
destination.  This fixes a race between userspace I/OAPIC reconfiguration
and IRQ delivery that results in the vector's bit being left set in the
remote IRR due to the eventual EOI not being forwarded to the userspace
I/OAPIC.

Commit 0fc5a36dd6b3 ("KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC
reconfigure race") fixed the in-kernel IOAPIC, but not the userspace
IOAPIC configuration, which has a similar race.

Fixes: 0fc5a36dd6b3 ("KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC reconfigure race")

Signed-off-by: Adamos Ttofari <attofari@amazon.de>
---
 arch/x86/kvm/irq_comm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Sean Christopherson Dec. 9, 2022, 1:34 a.m. UTC | #1
On Thu, Dec 08, 2022, Adamos Ttofari wrote:
> When scanning userspace I/OAPIC entries, intercept EOI for level-triggered
> IRQs if the current vCPU has a pending and/or in-service IRQ for the
> vector in its local API, even if the vCPU doesn't match the new entry's
> destination.  This fixes a race between userspace I/OAPIC reconfiguration
> and IRQ delivery that results in the vector's bit being left set in the
> remote IRR due to the eventual EOI not being forwarded to the userspace
> I/OAPIC.
> 
> Commit 0fc5a36dd6b3 ("KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC
> reconfigure race") fixed the in-kernel IOAPIC, but not the userspace
> IOAPIC configuration, which has a similar race.
> 
> Fixes: 0fc5a36dd6b3 ("KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC reconfigure race")
> 
> Signed-off-by: Adamos Ttofari <attofari@amazon.de>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>
diff mbox series

Patch

diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
index 0687162c4f22..3742d9adacfc 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -426,8 +426,9 @@  void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
 			kvm_set_msi_irq(vcpu->kvm, entry, &irq);
 
 			if (irq.trig_mode &&
-			    kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT,
-						irq.dest_id, irq.dest_mode))
+			    (kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT,
+						 irq.dest_id, irq.dest_mode) ||
+			     kvm_apic_pending_eoi(vcpu, irq.vector)))
 				__set_bit(irq.vector, ioapic_handled_vectors);
 		}
 	}