Skip to content

Commit 4bf3693

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Unmap vLPIs affected by changes to GSI routing information
KVM's interrupt infrastructure is dodgy at best, allowing for some ugly 'off label' usage of the various UAPIs. In one example, userspace can change the routing entry of a particular "GSI" after configuring irqbypass with KVM_IRQFD. KVM/arm64 is oblivious to this, and winds up preserving the stale translation in cases where vLPIs are configured. Honor userspace's intentions and tear down the vLPI mapping if affected by a "GSI" routing change. Make no attempt to reconstruct vLPIs if the new target is an MSI and just fall back to software injection. Tested-by: Sweet Tea Dorminy <[email protected]> Signed-off-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 05b9405 commit 4bf3693

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

arch/arm64/kvm/arm.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,7 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons,
27902790
return kvm_vgic_v4_set_forwarding(irqfd->kvm, prod->irq,
27912791
&irqfd->irq_entry);
27922792
}
2793+
27932794
void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,
27942795
struct irq_bypass_producer *prod)
27952796
{
@@ -2803,6 +2804,28 @@ void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,
28032804
kvm_vgic_v4_unset_forwarding(irqfd->kvm, prod->irq);
28042805
}
28052806

2807+
bool kvm_arch_irqfd_route_changed(struct kvm_kernel_irq_routing_entry *old,
2808+
struct kvm_kernel_irq_routing_entry *new)
2809+
{
2810+
if (new->type != KVM_IRQ_ROUTING_MSI)
2811+
return true;
2812+
2813+
return memcmp(&old->msi, &new->msi, sizeof(new->msi));
2814+
}
2815+
2816+
int kvm_arch_update_irqfd_routing(struct kvm *kvm, unsigned int host_irq,
2817+
uint32_t guest_irq, bool set)
2818+
{
2819+
/*
2820+
* Remapping the vLPI requires taking the its_lock mutex to resolve
2821+
* the new translation. We're in spinlock land at this point, so no
2822+
* chance of resolving the translation.
2823+
*
2824+
* Unmap the vLPI and fall back to software LPI injection.
2825+
*/
2826+
return kvm_vgic_v4_unset_forwarding(kvm, host_irq);
2827+
}
2828+
28062829
void kvm_arch_irq_bypass_stop(struct irq_bypass_consumer *cons)
28072830
{
28082831
struct kvm_kernel_irqfd *irqfd =

0 commit comments

Comments
 (0)