Skip to content

Commit a0d7e2f

Browse files
committed
KVM: arm64: vgic-v4: Only attempt vLPI mapping for actual MSIs
Some 'creative' VMMs out there may assign a VFIO MSI eventfd to an SPI routing entry. And yes, I can already hear you shouting about possibly driving a level interrupt with an edge-sensitive one. You know who you are. This works for the most part, and interrupt injection winds up taking the software path. However, when running on GICv4-enabled hardware, KVM erroneously attempts to setup LPI forwarding, even though the KVM routing isn't an MSI. Thanks to misuse of a union, the MSI destination is unlikely to match any ITS in the VM and kvm_vgic_v4_set_forwarding() bails early. Later on when the VM is being torn down, this half-configured state triggers the WARN_ON() in kvm_vgic_v4_unset_forwarding() due to the fact that no HW IRQ was ever assigned. Avoid the whole mess by preventing SPI routing entries from getting into the LPI forwarding helpers. Reported-by: Sudheer Dantuluri <dantuluris@google.com> Tested-by: Sudheer Dantuluri <dantuluris@google.com> Fixes: 196b136 ("KVM: arm/arm64: GICv4: Wire mapping/unmapping of VLPIs in VFIO irq bypass") Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250226183124.82094-2-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 0ad2507 commit a0d7e2f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/arm64/kvm/arm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,14 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons,
27172717
{
27182718
struct kvm_kernel_irqfd *irqfd =
27192719
container_of(cons, struct kvm_kernel_irqfd, consumer);
2720+
struct kvm_kernel_irq_routing_entry *irq_entry = &irqfd->irq_entry;
2721+
2722+
/*
2723+
* The only thing we have a chance of directly-injecting is LPIs. Maybe
2724+
* one day...
2725+
*/
2726+
if (irq_entry->type != KVM_IRQ_ROUTING_MSI)
2727+
return 0;
27202728

27212729
return kvm_vgic_v4_set_forwarding(irqfd->kvm, prod->irq,
27222730
&irqfd->irq_entry);
@@ -2726,6 +2734,10 @@ void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,
27262734
{
27272735
struct kvm_kernel_irqfd *irqfd =
27282736
container_of(cons, struct kvm_kernel_irqfd, consumer);
2737+
struct kvm_kernel_irq_routing_entry *irq_entry = &irqfd->irq_entry;
2738+
2739+
if (irq_entry->type != KVM_IRQ_ROUTING_MSI)
2740+
return;
27292741

27302742
kvm_vgic_v4_unset_forwarding(irqfd->kvm, prod->irq,
27312743
&irqfd->irq_entry);

0 commit comments

Comments
 (0)