Skip to contentSkip to conversation

genirq/core: Fall back to a static default affinity mask

PATCH In review Avi Weiss 2 participants 2 messages Oct 31 – Nov 2 IRQ

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 genirq/core: Fall back to a static default affinity mask

With CONFIG_CPUMASK_OFFSTACK=y, init_irq_default_affinity() does not check whether zalloc_cpumask_var() succeeds. If the GFP_NOWAIT allocation fails, cpumask_empty() dereferences a NULL mask during early boot.

Use a private static cpumask when allocation fails, keeping the default IRQ affinity mask available and writable.

In a QEMU guest, a test-only allocation failure triggered the boot fault without this change. The patched kernel booted with the same injected failure and allowed the default affinity mask to be read and written. Normal and irqaffinity=0 boots also passed.

Fixes d036e67b40f5 ("cpumask: convert kernel/irq")
---
 kernel/irq/irqdesc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/irq/irqdesc.c +9 -2
index 3a818f07a101..1ea020425381 100644
@@ -25,6 +25,9 @@
 static struct lock_class_key irq_desc_lock_class;
 
 #if defined(CONFIG_SMP)
+#ifdef CONFIG_CPUMASK_OFFSTACK
+static cpumask_t irq_default_affinity_fallback;
+#endif
 static int __init irq_affinity_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&irq_default_affinity);
@@ -40,8 +43,12 @@ __setup("irqaffinity=", irq_affinity_setup);
 
 static void __init init_irq_default_affinity(void)
 {
-	if (!cpumask_available(irq_default_affinity))
-		zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
+	if (!cpumask_available(irq_default_affinity) &&
+	    !zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT)) {
+#ifdef CONFIG_CPUMASK_OFFSTACK
+		irq_default_affinity = &irq_default_affinity_fallback;
+#endif
+	}
 	if (cpumask_empty(irq_default_affinity))
 		cpumask_setall(irq_default_affinity);
 }
maintainer
#1 lore raw
Quoted 11 lines · Avi Weiss

With CONFIG_CPUMASK_OFFSTACK=y, init_irq_default_affinity() does not check whether zalloc_cpumask_var() succeeds. If the GFP_NOWAIT allocation fails, cpumask_empty() dereferences a NULL mask during early boot.

Use a private static cpumask when allocation fails, keeping the default IRQ affinity mask available and writable.

In a QEMU guest, a test-only allocation failure triggered the boot fault without this change. The patched kernel booted with the same injected failure and allowed the default affinity mask to be read and written. Normal and irqaffinity=0 boots also passed.

If that allocation fails the kernel won't boot at all.

Aside of that the fallback mask defeats the whole purpose of allocating the mask at runtime.

I'm all for defensive programming, but this is just trying to "fix" a problem which does not exist to begin with.

If you really want to do something when that allocation theoretically fails then panic the machine because it is going to die on the next allocation anyway.

Thanks,

tglx