* [PATCH] genirq/core: Fall back to a static default affinity mask
@ 2026-10-31 13:38 Avi Weiss
2026-11-02 23:22 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Avi Weiss @ 2026-10-31 13:38 UTC (permalink / raw)
To: tglx; +Cc: radu, linux-kernel, 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.
Fixes: d036e67b40f5 ("cpumask: convert kernel/irq")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
kernel/irq/irqdesc.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 3a818f07a101..1ea020425381 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -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);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] genirq/core: Fall back to a static default affinity mask
2026-10-31 13:38 [PATCH] genirq/core: Fall back to a static default affinity mask Avi Weiss
@ 2026-11-02 23:22 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2026-11-02 23:22 UTC (permalink / raw)
To: Avi Weiss; +Cc: radu, linux-kernel, Avi Weiss
On Sat, Oct 31 2026 at 15:38, Avi Weiss wrote:
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-02 23:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 13:38 [PATCH] genirq/core: Fall back to a static default affinity mask Avi Weiss
2026-11-02 23:22 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®