Skip to contentSkip to conversation

genirq: Discard cpumask of irqaffinity= boot parameter if parsing fails

PATCH Applied Lukas Beckmann 3 participants 3 messages Aug 22 – Sep 4 IRQ

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 genirq: Discard cpumask of irqaffinity= boot parameter if parsing fails

irq_affinity_setup() ignores the return value of cpulist_parse(). This can result in using a "half parsed" cpulist. E.g. on a system with 8 cores, the parameter "irqaffinity=0,1,6-10,4" would result in using only CPU 0 and 1, since the parsing fails at 6-10. Other boot parameters which take a cpulist (e.g. isolcpus=, workqueue.unbound_cpus=) already handle this by falling back to a default.

Check the return value of cpulist_parse() and let init_irq_default_affinity() set the default in early_irq_init() later, if parsing fails.

---
 kernel/irq/irqdesc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/irq/irqdesc.c +9 -1
index 3a818f07a101..7cbcc3fb9e6d 100644
@@ -28,7 +28,15 @@ static struct lock_class_key irq_desc_lock_class;
 static int __init irq_affinity_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&irq_default_affinity);
-	cpulist_parse(str, irq_default_affinity);
+	if (cpulist_parse(str, irq_default_affinity) < 0) {
+		/*
+		 * Clear the mask so that init_irq_default_affinity()
+		 * defaults it later.
+		 */
+		cpumask_clear(irq_default_affinity);
+		pr_warn("irqaffinity: incorrect CPU range, using default\n");
+		return 1;
+	}
 	/*
 	 * Set at least the boot cpu. We don't want to end up with
 	 * bugreports caused by random commandline masks

base-commit: 1ad6d4a722f509128038f9c85c6a122a382179fe

Signature · 1 line
2.55.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · Lukas Beckmann

irq_affinity_setup() ignores the return value of cpulist_parse(). This can result in using a "half parsed" cpulist. E.g. on a system with 8 cores, the parameter "irqaffinity=0,1,6-10,4" would result in using only CPU 0 and 1, since the parsing fails at 6-10. Other boot parameters which take a cpulist (e.g. isolcpus=, workqueue.unbound_cpus=) already handle this by falling back to a default.

Check the return value of cpulist_parse() and let init_irq_default_affinity() set the default in early_irq_init() later, if parsing fails.

---
 kernel/irq/irqdesc.c | 10 +++++++++-

 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/irq/irqdesc.c +9 -1
index 3a818f07a101..7cbcc3fb9e6d 100644
@@ -28,7 +28,15 @@ static struct lock_class_key irq_desc_lock_class;
  static int __init irq_affinity_setup(char *str)
  {
  	alloc_bootmem_cpumask_var(&irq_default_affinity);
-	cpulist_parse(str, irq_default_affinity);
+	if (cpulist_parse(str, irq_default_affinity) < 0) {
+		/*
+		 * Clear the mask so that init_irq_default_affinity()
+		 * defaults it later.
+		 */
+		cpumask_clear(irq_default_affinity);
+		pr_warn("irqaffinity: incorrect CPU range, using default\n");
+		return 1;
+	}
  	/*
  	 * Set at least the boot cpu. We don't want to end up with
  	 * bugreports caused by random commandline masks
Quoted 1 line

base-commit: 1ad6d4a722f509128038f9c85c6a122a382179fe

merge bot Applied
#2 lore raw
In reply to Lukas Beckmann
The following commit has been merged into the irq/core branch of tip:

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     94235414a0568f260b60b89ec584ff4829d5e8c9
Gitweb:        https://git.kernel.org/tip/94235414a0568f260b60b89ec584ff4829d5e8c9
Author:        Lukas Beckmann <[email protected]>
AuthorDate:    Sat, 22 Aug 2026 18:05:00 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 04 Sep 2026 08:44:17 +02:00

genirq: Discard cpumask of irqaffinity= boot parameter if parsing fails

irq_affinity_setup() ignores the return value of cpulist_parse(). This can result in using a "half parsed" cpulist. E.g. on a system with 8 cores, the parameter "irqaffinity=0,1,6-10,4" would result in using only CPU 0 and 1, since the parsing fails at 6-10. Other boot parameters which take a cpulist (e.g. isolcpus=, workqueue.unbound_cpus=) already handle this by falling back to a default.

Check the return value of cpulist_parse() and let init_irq_default_affinity() set the default in early_irq_init() later, if parsing fails.

---
 kernel/irq/irqdesc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/irq/irqdesc.c +9 -1
index 3a818f0..7cbcc3f 100644
@@ -28,7 +28,15 @@ static struct lock_class_key irq_desc_lock_class;
 static int __init irq_affinity_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&irq_default_affinity);
-	cpulist_parse(str, irq_default_affinity);
+	if (cpulist_parse(str, irq_default_affinity) < 0) {
+		/*
+		 * Clear the mask so that init_irq_default_affinity()
+		 * defaults it later.
+		 */
+		cpumask_clear(irq_default_affinity);
+		pr_warn("irqaffinity: incorrect CPU range, using default\n");
+		return 1;
+	}
 	/*
 	 * Set at least the boot cpu. We don't want to end up with
 	 * bugreports caused by random commandline masks