[PATCH] locking/locktorture: reject zero resolved worker threads

From: Samuel Moelius

Date: Fri Jun 05 2026 - 14:50:01 EST


locktorture checks for a zero-worker configuration before it resolves
the default reader count. For reader-capable lock types, a user can
pass nwriters_stress=0 and leave nreaders_stress at its default -1.
This bypasses the early check, then derives the default real reader
count from the real writer count, leaving both resolved counts at zero.

The module can then load successfully, optionally creating helper
threads such as the stats thread, but no lock-torture worker threads.

Reject the resolved zero-worker state after reader defaults have been
applied.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@xxxxxxxxxxxxxxx>
---
kernel/locking/locktorture.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index e618bcf75e2d..7d553ecd3fab 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -1320,6 +1320,13 @@ static int __init lock_torture_init(void)
cxt.nrealreaders_stress = cxt.nrealwriters_stress;
}

+ if (cxt.nrealwriters_stress == 0 &&
+ cxt.nrealreaders_stress == 0) {
+ pr_alert("lock-torture: must run at least one locking thread\n");
+ firsterr = -EINVAL;
+ goto unwind;
+ }
+
if (nreaders_stress) {
cxt.lrsa = kmalloc_objs(*cxt.lrsa,
cxt.nrealreaders_stress);
--
2.43.0