]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Trigger I/O APIC route rescan in kvm_arch_irq_routing_update()
authorSean Christopherson <seanjc@google.com>
Wed, 11 Jun 2025 21:35:40 +0000 (14:35 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:52:41 +0000 (13:52 -0700)
Trigger the I/O APIC route rescan that's performed for a split IRQ chip
after userspace updates IRQ routes in kvm_arch_irq_routing_update(), i.e.
before dropping kvm->irq_lock.  Calling kvm_make_all_cpus_request() under
a mutex is perfectly safe, and the smp_wmb()+smp_mb__after_atomic() pair
in __kvm_make_request()+kvm_check_request() ensures the new routing is
visible to vCPUs prior to the request being visible to vCPUs.

In all likelihood, commit b053b2aef25d ("KVM: x86: Add EOI exit bitmap
inference") somewhat arbitrarily made the request outside of irq_lock to
avoid holding irq_lock any longer than is strictly necessary.  And then
commit abdb080f7ac8 ("kvm/irqchip: kvm_arch_irq_routing_update renaming
split") took the easy route of adding another arch hook instead of risking
a functional change.

Note, the call to synchronize_srcu_expedited() does NOT provide ordering
guarantees with respect to vCPUs scanning the new routing; as above, the
request infrastructure provides the necessary ordering.  I.e. there's no
need to wait for kvm_scan_ioapic_routes() to complete if it's actively
running, because regardless of whether it grabs the old or new table, the
vCPU will have another KVM_REQ_SCAN_IOAPIC pending, i.e. will rescan again
and see the new mappings.

Acked-by: Kai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/r/20250611213557.294358-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/irq_comm.c
include/linux/kvm_host.h
virt/kvm/irqchip.c

index d6d792b5d1bdb0db2af560c62ec3ce6b514bc900..e2ae62ff9cc2e6e1885b5a51aa0d0ec7a3a4af44 100644 (file)
@@ -395,13 +395,6 @@ int kvm_setup_default_irq_routing(struct kvm *kvm)
                                   ARRAY_SIZE(default_routing), 0);
 }
 
-void kvm_arch_post_irq_routing_update(struct kvm *kvm)
-{
-       if (!irqchip_split(kvm))
-               return;
-       kvm_make_scan_ioapic_request(kvm);
-}
-
 void kvm_scan_ioapic_irq(struct kvm_vcpu *vcpu, u32 dest_id, u16 dest_mode,
                         u8 vector, unsigned long *ioapic_handled_vectors)
 {
@@ -466,4 +459,7 @@ void kvm_arch_irq_routing_update(struct kvm *kvm)
 #ifdef CONFIG_KVM_HYPERV
        kvm_hv_irq_routing_update(kvm);
 #endif
+
+       if (irqchip_split(kvm))
+               kvm_make_scan_ioapic_request(kvm);
 }
index 3bde4fb5c6aa4055638f37c064e41978c9cf2079..9461517b4e62533d2761d4cba0ef6763e1e3b158 100644 (file)
@@ -1024,14 +1024,10 @@ void vcpu_put(struct kvm_vcpu *vcpu);
 
 #ifdef __KVM_HAVE_IOAPIC
 void kvm_arch_post_irq_ack_notifier_list_update(struct kvm *kvm);
-void kvm_arch_post_irq_routing_update(struct kvm *kvm);
 #else
 static inline void kvm_arch_post_irq_ack_notifier_list_update(struct kvm *kvm)
 {
 }
-static inline void kvm_arch_post_irq_routing_update(struct kvm *kvm)
-{
-}
 #endif
 
 #ifdef CONFIG_HAVE_KVM_IRQCHIP
index 162d8ed889f215b0735ea90a53abff7d40bcfb8a..6ccabfd32287e75d2c882c747569c63a377c293a 100644 (file)
@@ -222,8 +222,6 @@ int kvm_set_irq_routing(struct kvm *kvm,
        kvm_arch_irq_routing_update(kvm);
        mutex_unlock(&kvm->irq_lock);
 
-       kvm_arch_post_irq_routing_update(kvm);
-
        synchronize_srcu_expedited(&kvm->irq_srcu);
 
        new = old;