From ed5c57ef2c58e34c0fab10d2123208efb9a212c0 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Sun, 22 Nov 2026 18:26:41 -0300 Subject: [PATCH] irqchip/apple-aic: Keep a concurrent smp_affinity write on a CPU set change aic_irq_cpus_update() copied each IRQ's affinity mask into a static cpumask and then passed the copy to irq_set_affinity(). The copy was taken without the descriptor lock, so a /proc/irq/N/smp_affinity write (irqbalance, say) that lands between the copy and irq_set_affinity() was overwritten with the stale mask, and the user's setting was lost. Pass irq_get_affinity_mask() to irq_set_affinity() directly. The mask is then read under the descriptor lock, so the set change applies whatever affinity is current. genirq does the same when it restores a managed IRQ's affinity on CPU online (irq_restore_affinity_of_irq()). The static cpumask goes with it. If the IRQ's descriptor is gone by the time its mask is looked up, irq_get_affinity_mask() returns NULL. Skip that IRQ instead of passing NULL on to irq_set_affinity(). aic_irq_cpus_update() runs only on AICv2 and AICv3 at EL2, where aic2_routed_chip is used. There it changes the stored and effective affinity that is reported. It doesn't touch AICv1, or how the hardware delivers IRQs (SIQ_CFG decides that). Fixes: d3d404c0e448 ("irqchip/apple-aic: Keep the routed IRQ affinity across CPU hotplug") Signed-off-by: Jonathan Goyvaerts --- drivers/irqchip/irq-apple-aic.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index 52a892164c3a4..dbd1292031442 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -1107,8 +1107,8 @@ static int aic_init_cpu(unsigned int cpu) */ static void aic_irq_cpus_update(unsigned int cpu, bool accepts) { - static struct cpumask aff; /* CPU hotplug is serialized */ struct aic_irq_chip *ic = aic_irqc; + const struct cpumask *aff; unsigned int die, i, virq; if (accepts == cpumask_test_cpu(cpu, &aic_irq_cpus)) @@ -1120,8 +1120,11 @@ static void aic_irq_cpus_update(unsigned int cpu, bool accepts) virq = irq_find_mapping(ic->hw_domain, AIC_IRQ_HWIRQ(die, i)); if (!virq || !irq_has_action(virq)) continue; - cpumask_copy(&aff, irq_get_affinity_mask(virq)); - irq_set_affinity(virq, &aff); + aff = irq_get_affinity_mask(virq); + if (!aff) + continue; + /* Read under the desc lock, so a concurrent smp_affinity write is kept */ + irq_set_affinity(virq, aff); } } }