tracing: reject invalid preemptirq_delay_test CPU affinity
PATCH 1/1 tracing: reject invalid preemptirq_delay_test CPU affinity
preemptirq_delay_test accepts cpu_affinity as a module parameter and, when it is non-negative, writes that CPU directly into a temporary cpumask from the worker thread. Values outside nr_cpu_ids can set a bit outside the allocated cpumask before the test reports a normal affinity error.
Validate the requested CPU before starting the worker thread, and return -EINVAL for invalid affinity requests.
--- kernel/trace/preemptirq_delay_test.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/trace/preemptirq_delay_test.c +10 -0
@@ -14,6 +14,7 @@#include <linux/kthread.h> #include <linux/module.h> #include <linux/printk.h> +#include <linux/cpumask.h> #include <linux/string.h> #include <linux/sysfs.h> #include <linux/completion.h>
@@ -152,6 +153,15 @@ static int preemptirq_run_test(void)struct task_struct *task;char task_name[50 ]; +if (cpu_affinity >-1 ) { +unsigned int cpu = cpu_affinity; + +if (cpu >= nr_cpu_ids || !cpu_possible (cpu)) { +pr_err ("cpu_affinity:%d, invalid CPU\n" , cpu_affinity); +return -EINVAL ; + } + } +init_completion (&done);snprintf (task_name,sizeof (task_name),"%s_test" , test_mode);
Signature · 1 line
2.43.0
Steven Rostedt
maintainerQuoted 28 lines · On Fri, 5 Jun 2026 00:40:06 +0000 Samuel Moelius…
preemptirq_delay_testacceptscpu_affinityas a module parameter and, when it is non-negative, writes that CPU directly into a temporary cpumask from the worker thread. Values outsidenr_cpu_idscan set a bit outside the allocated cpumask before the test reports a normal affinity error.Validate the requested CPU before starting the worker thread, and return
-EINVALfor invalid affinity requests.Assisted-by Codex:gpt-5.5-cyber-previewSigned-off-by Samuel Moelius <[email protected]>--- kernel/trace/preemptirq_delay_test.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/trace/preemptirq_delay_test.c +1
-0@@ -14,6 +14,7 @@#include <linux/kthread.h> #include <linux/module.h> #include <linux/printk.h> +#include <linux/cpumask.h> #include <linux/string.h> #include <linux/sysfs.h> #include <linux/completion.h>
kernel/trace/preemptirq_delay_test.c static int preemptirq_run_test(void) · line 161
Quoted 9 lines
kernel/trace/preemptirq_delay_test.c +6
-0@@ -152,6 +153,15 @@ static int preemptirq_run_test(void)struct task_struct *task;char task_name[50 ]; +if (cpu_affinity >-1 ) { +unsigned int cpu = cpu_affinity; + +if (cpu >= nr_cpu_ids || !cpu_possible (cpu)) { +pr_err ("cpu_affinity:%d, invalid CPU\n" , cpu_affinity); +return -EINVAL ;
Just add the check to the preemptirq_delay_run() function where it tests affinity. Who cares if it created the thread or not. It's just a test.
-- Steve
Quoted 6 lines
kernel/trace/preemptirq_delay_test.c +3
-0+ } + } +init_completion (&done);snprintf (task_name,sizeof (task_name),"%s_test" , test_mode);
Quoted 35 lines · Steven Rostedt
Quoted 31 lines · On Fri, 5 Jun 2026 00:40:06 +0000 Samuel Moelius…
preemptirq_delay_testacceptscpu_affinityas a module parameter and, when it is non-negative, writes that CPU directly into a temporary cpumask from the worker thread. Values outsidenr_cpu_idscan set a bit outside the allocated cpumask before the test reports a normal affinity error.Validate the requested CPU before starting the worker thread, and return
-EINVALfor invalid affinity requests.Assisted-by Codex:gpt-5.5-cyber-previewSigned-off-by Samuel Moelius <[email protected]>--- kernel/trace/preemptirq_delay_test.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/trace/preemptirq_delay_test.c +1
-0@@ -14,6 +14,7 @@#include <linux/kthread.h> #include <linux/module.h> #include <linux/printk.h> +#include <linux/cpumask.h> #include <linux/string.h> #include <linux/sysfs.h> #include <linux/completion.h> @@ -152,6 +153,15 @@ static int preemptirq_run_test(void)struct task_struct *task;char task_name[50 ];
Quoted 10 lines
kernel/trace/preemptirq_delay_test.c static int preemptirq_run_test(void) · line 161
Quoted 6 lines
kernel/trace/preemptirq_delay_test.c +6
-0+if (cpu_affinity >-1 ) { +unsigned int cpu = cpu_affinity; + +if (cpu >= nr_cpu_ids || !cpu_possible (cpu)) { +pr_err ("cpu_affinity:%d, invalid CPU\n" , cpu_affinity); +return -EINVAL ;Just add the check to the
preemptirq_delay_run()function where it tests affinity. Who cares if it created the thread or not. It's just a test.
I am getting ready to travel and I will address this when I return in about two weeks. Thank you for understanding.