Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: x86: Trigger I/O APIC route rescan in kvm_arch_irq_routing_update()

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>

+3 -13
+3 -7
arch/x86/kvm/irq_comm.c
··· 395 395 ARRAY_SIZE(default_routing), 0); 396 396 } 397 397 398 - void kvm_arch_post_irq_routing_update(struct kvm *kvm) 399 - { 400 - if (!irqchip_split(kvm)) 401 - return; 402 - kvm_make_scan_ioapic_request(kvm); 403 - } 404 - 405 398 void kvm_scan_ioapic_irq(struct kvm_vcpu *vcpu, u32 dest_id, u16 dest_mode, 406 399 u8 vector, unsigned long *ioapic_handled_vectors) 407 400 { ··· 459 466 #ifdef CONFIG_KVM_HYPERV 460 467 kvm_hv_irq_routing_update(kvm); 461 468 #endif 469 + 470 + if (irqchip_split(kvm)) 471 + kvm_make_scan_ioapic_request(kvm); 462 472 }
-4
include/linux/kvm_host.h
··· 1024 1024 1025 1025 #ifdef __KVM_HAVE_IOAPIC 1026 1026 void kvm_arch_post_irq_ack_notifier_list_update(struct kvm *kvm); 1027 - void kvm_arch_post_irq_routing_update(struct kvm *kvm); 1028 1027 #else 1029 1028 static inline void kvm_arch_post_irq_ack_notifier_list_update(struct kvm *kvm) 1030 - { 1031 - } 1032 - static inline void kvm_arch_post_irq_routing_update(struct kvm *kvm) 1033 1029 { 1034 1030 } 1035 1031 #endif
-2
virt/kvm/irqchip.c
··· 222 222 kvm_arch_irq_routing_update(kvm); 223 223 mutex_unlock(&kvm->irq_lock); 224 224 225 - kvm_arch_post_irq_routing_update(kvm); 226 - 227 225 synchronize_srcu_expedited(&kvm->irq_srcu); 228 226 229 227 new = old;