Skip to contentSkip to conversation

scftorture: reject zero worker threads

PATCH Superseded Samuel Moelius 2 participants 2 messages Jun 5 – Jun 10

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scftorture: reject zero worker threads

scftorture accepts nthreads=0. That value skips worker creation, but module initialization can still create the stats thread when stat_interval is positive.

Cleanup then tests "nthreads && scf_stats_p" before stopping the stats task. With nthreads=0, cleanup jumps to the end and leaves the stats task running after rmmod has returned.

Reject nthreads=0 before allocating state or creating helper threads. Negative values still retain the existing default-to-online-CPUs behavior.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 kernel/scftorture.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/scftorture.c +5 -0
index 327c315f411c..b190d9ff5157 100644
@@ -661,6 +661,11 @@ static int __init scf_torture_init(void)
 	// Worker tasks invoking smp_call_function().
 	if (nthreads < 0)
 		nthreads = num_online_cpus();
+	if (nthreads == 0) {
+		SCFTORTOUT_ERRSTRING("nthreads must be positive");
+		firsterr = -EINVAL;
+		goto unwind;
+	}
 	scf_stats_p = kzalloc_objs(scf_stats_p[0], nthreads);
 	if (!scf_stats_p) {
 		SCFTORTOUT_ERRSTRING("out of memory");
Signature · 1 line
2.43.0
#1 lore raw
Quoted 23 lines · Samuel Moelius

scftorture accepts nthreads=0. That value skips worker creation, but module initialization can still create the stats thread when stat_interval is positive.

Cleanup then tests "nthreads && scf_stats_p" before stopping the stats task. With nthreads=0, cleanup jumps to the end and leaves the stats task running after rmmod has returned.

Reject nthreads=0 before allocating state or creating helper threads. Negative values still retain the existing default-to-online-CPUs behavior.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 kernel/scftorture.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/scftorture.c +0 -0
index 327c315f411c..b190d9ff5157 100644

kernel/scftorture.c static int __init scf_torture_init(void) · line 665

Quoted 5 lines
kernel/scftorture.c +2 -0
@@ -661,6 +661,11 @@ static int __init scf_torture_init(void)
 	// Worker tasks invoking smp_call_function().
 	if (nthreads < 0)
 		nthreads = num_online_cpus();
+	if (nthreads == 0) {
+		SCFTORTOUT_ERRSTRING("nthreads must be positive");

Maybe "cannot be zero"? (Negative is a valid option...)

Quoted 9 lines
kernel/scftorture.c +3 -0
+		firsterr = -EINVAL;
+		goto unwind;
+	}
 	scf_stats_p = kzalloc_objs(scf_stats_p[0], nthreads);
 	if (!scf_stats_p) {
 		SCFTORTOUT_ERRSTRING("out of memory");
Signature · 1 line
2.43.0
Signature · 1 line
Kees Cook