arm/gicv3: Fix deadlock in gicv3_set_affinity()
PATCH 1/1 arm/gicv3: Fix deadlock in gicv3_set_affinity()
gicv3_irq_set_affinity() acquires the gicv3 lock with a bare spin_lock() with IRQs on from arch_move_irqs(). This happens when a vCPU with physical IRQs routed to it changes pCPU. The same function is called with IRQs off from vgic_migrate_irq().
If the wrong interrupt arrives while moving IRQs, Xen would re-lock the mutex, but it'll never succeed because it's already locked in the interrupted thread of that very pCPU.
Have gicv3_irq_set_affinity() use spin_lock_irqsave() instead to avoid the deadly embrace.
--- xen/arch/arm/gic-v3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v3.c +3 -2
@@ -1463,6 +1463,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)unsigned int cpu;uint64_t affinity;void __iomem *addr; +unsigned long flags;if ( desc->irq <NR_GIC_LOCAL_IRQS )return ;
@@ -1473,7 +1474,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)ASSERT (!cpumask_empty (mask)); -spin_lock (&gicv3.lock); +spin_lock_irqsave (&gicv3.lock, flags); cpu =gicv3_get_cpu_from_mask (mask); affinity =gicv3_mpidr_to_affinity (cpu);
@@ -1481,7 +1482,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask) affinity &= ~GICD_IROUTER_SPI_MODE_ANY ;writeq_relaxed_non_atomic (affinity, addr); -spin_unlock (&gicv3.lock); +spin_unlock_irqrestore (&gicv3.lock, flags); } static int gicv3_make_hwdom_dt_node(const struct domain *d,
base-commit: 1208df803530bb885419627ab36a43313b98ce5c
Signature · 1 line
2.43.0
Quoted 49 lines · Alejandro Vallejo
gicv3_irq_set_affinity()acquires the gicv3 lock with a barespin_lock()with IRQs on fromarch_move_irqs(). This happens when a vCPU with physical IRQs routed to it changes pCPU. The same function is called with IRQs off fromvgic_migrate_irq().If the wrong interrupt arrives while moving IRQs, Xen would re-lock the mutex, but it'll never succeed because it's already locked in the interrupted thread of that very pCPU.
Have
gicv3_irq_set_affinity()usespin_lock_irqsave()instead to avoid the deadly embrace.Fixes bc183a0235e0 ("xen/arm: Add support for GIC v3")Signed-off-by Alejandro Vallejo <[email protected]>--- xen/arch/arm/gic-v3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/arch/arm/gic-v3.c +3
-2@@ -1463,6 +1463,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)unsigned int cpu;uint64_t affinity;void __iomem *addr; +unsigned long flags;if ( desc->irq <NR_GIC_LOCAL_IRQS )return ;@@ -1473,7 +1474,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)ASSERT (!cpumask_empty (mask)); -spin_lock (&gicv3.lock); +spin_lock_irqsave (&gicv3.lock, flags); cpu =gicv3_get_cpu_from_mask (mask); affinity =gicv3_mpidr_to_affinity (cpu);@@ -1481,7 +1482,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask) affinity &= ~GICD_IROUTER_SPI_MODE_ANY ;writeq_relaxed_non_atomic (affinity, addr); -spin_unlock (&gicv3.lock); +spin_unlock_irqrestore (&gicv3.lock, flags); } static int gicv3_make_hwdom_dt_node(const struct domain *d,
Quoted 1 line
base-commit:
1208df803530bb885419627ab36a43313b98ce5c
gicv2_irq_set_affinity() has the same problem.
Shouldn't arch_move_irqs() be fixed instead? It is the only irq_set_affinity() caller running with IRQs on. All the others hold a lock taken with irqsave. Fixing the caller would cover both GICs.
~Michal
Quoted 50 lines · Michal
Quoted 47 lines · Alejandro Vallejo
gicv3_irq_set_affinity()acquires the gicv3 lock with a barespin_lock()with IRQs on fromarch_move_irqs(). This happens when a vCPU with physical IRQs routed to it changes pCPU. The same function is called with IRQs off fromvgic_migrate_irq().If the wrong interrupt arrives while moving IRQs, Xen would re-lock the mutex, but it'll never succeed because it's already locked in the interrupted thread of that very pCPU.
Have
gicv3_irq_set_affinity()usespin_lock_irqsave()instead to avoid the deadly embrace.Fixes bc183a0235e0 ("xen/arm: Add support for GIC v3")Signed-off-by Alejandro Vallejo <[email protected]>--- xen/arch/arm/gic-v3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/arch/arm/gic-v3.c +3
-2@@ -1463,6 +1463,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)unsigned int cpu;uint64_t affinity;void __iomem *addr; +unsigned long flags;if ( desc->irq <NR_GIC_LOCAL_IRQS )return ;@@ -1473,7 +1474,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)ASSERT (!cpumask_empty (mask)); -spin_lock (&gicv3.lock); +spin_lock_irqsave (&gicv3.lock, flags); cpu =gicv3_get_cpu_from_mask (mask); affinity =gicv3_mpidr_to_affinity (cpu);@@ -1481,7 +1482,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask) affinity &= ~GICD_IROUTER_SPI_MODE_ANY ;writeq_relaxed_non_atomic (affinity, addr); -spin_unlock (&gicv3.lock); +spin_unlock_irqrestore (&gicv3.lock, flags); }
Quoted 5 lines
Quoted 3 lines
xen/arch/arm/gic-v3.c +0
-0static int gicv3_make_hwdom_dt_node(const struct domain *d,base-commit:
1208df803530bb885419627ab36a43313b98ce5c
gicv2_irq_set_affinity()has the same problem.
True, I only looked at v3.
Quoted 4 lines
Shouldn't
arch_move_irqs()be fixed instead? It is the onlyirq_set_affinity()caller running with IRQs on. All the others hold a lock taken with irqsave. Fixing the caller would cover both GICs.
Works for me. Let me send a v2.
Cheers,
Alejandro