[PATCH 11/28] selftests/rcutorture: Add hazptr torture test script
From: Kunwu Chan
Date: Wed Nov 04 2026 - 12:25:47 EST
Add hazptr.sh: runs the NOPREEMPT/PREEMPT/READERS0/READERS4 basic
scenarios, the LOCKDEP (PROVE_LOCKING + wq_churn) and SLOWPATH
(forced slow path) combinations, the CPU-scaling sweep, and the
HOTADDR/LONGHOLD staged scenarios, checking each console log for
the module verdict (End of test: FAILURE), lockdep splats, and
unexpected stall-detector reports. Also adds the torture configs
to CFLIST.
Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
---
.../selftests/rcutorture/bin/hazptr.sh | 319 ++++++++++++++++++
.../rcutorture/configs/hazptr/CFLIST | 6 +
2 files changed, 325 insertions(+)
create mode 100755 tools/testing/selftests/rcutorture/bin/hazptr.sh
diff --git a/tools/testing/selftests/rcutorture/bin/hazptr.sh b/tools/testing/selftests/rcutorture/bin/hazptr.sh
new file mode 100755
index 000000000000..4e30ea51d9fc
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/hazptr.sh
@@ -0,0 +1,319 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Run hazptr torture tests and report any that fail.
+#
+# Usage: hazptr.sh [ --cpus N ] [ --allcpus ] [ --datestamp string ]
+#
+# Copyright (C) 2026 Kunwu Chan
+#
+# Authors: Kunwu Chan <kunwu.chan@xxxxxxxxx>
+
+usage () {
+ echo "Usage: $scriptname optional arguments:"
+ echo " --cpus N override CPU count (default: auto-detect)"
+ echo " --allcpus test at CPU counts 8,16,32,...,256"
+ echo " --datestamp string"
+ exit 1
+}
+
+ds=`date +%Y.%m.%d-%H.%M.%S`-hazptr
+scriptname="$0"
+
+RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
+PATH=${RCUTORTURE}/bin:$PATH; export PATH
+. functions.sh
+
+cpus="" # empty = let kvm.sh auto-detect
+allcpus=0
+
+while test $# -gt 0
+do
+ case "$1" in
+ --datestamp)
+ checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'
+ ds=$2
+ shift
+ ;;
+ --cpus)
+ checkarg --cpus "(number)" "$#" "$2" '^[0-9]\+$' '^--'
+ cpus="$2"
+ shift
+ ;;
+ --allcpus)
+ allcpus=1
+ ;;
+ *)
+ echo Unknown argument $1
+ usage
+ ;;
+ esac
+ shift
+done
+
+nerrs=0
+
+run_kvm () {
+ local ds_suffix="$1"
+ local configs="$2"
+ local cpu_arg="$3"
+ local kconfig="$4"
+ local duration="${5:-5s}"
+ local resdir="$RCUTORTURE/res/$ds/$ds_suffix"
+
+ mkdir -p "$resdir"
+
+ tools/testing/selftests/rcutorture/bin/kvm.sh \
+ --torture hazptr \
+ --duration "$duration" \
+ --configs "$configs" \
+ ${cpu_arg:+--cpus "$cpu_arg"} \
+ ${kconfig:+--kconfig "$kconfig"} \
+ --trust-make \
+ --datestamp "$ds/$ds_suffix" > "$resdir/kvm.sh.out" 2>&1
+ return $?
+}
+
+check_lockdep () {
+ local ds_suffix="$1" config_dir="$2" label="$3"
+ local resdir="$RCUTORTURE/res/$ds/$ds_suffix"
+ local console="$resdir/$config_dir/console.log"
+
+ if ! test -f "$console"
+ then
+ echo "Missing console.log for $label ($ds_suffix)" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ if grep -qE "WARNING: possible (recursive locking|circular locking dependency)" "$console"
+ then
+ echo "Lockdep warning in $label" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ return 0
+}
+
+# The stall detector must not fire in normal scenarios: a splat here is
+# either a detector false positive (deadline arithmetic, too-aggressive
+# timeout) or a genuine kernel bug making legitimate waits exceed the
+# timeout. Either way, fail the test. (HOTADDR is the positive case
+# and is checked separately.)
+check_stall () {
+ local ds_suffix="$1" config_dir="$2" label="$3"
+ local resdir="$RCUTORTURE/res/$ds/$ds_suffix"
+ local console="$resdir/$config_dir/console.log"
+
+ if ! test -f "$console"
+ then
+ echo "Missing console.log for $label ($ds_suffix)" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ if grep -q "hazptr: waiter stall" "$console"
+ then
+ echo "Unexpected hazptr stall splat in $label" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ return 0
+}
+
+# Classify the in-kernel torture verdict from the console log:
+# FAILURE -- the module explicitly reported failure
+# INCOMPLETE -- no module verdict reached (e.g. external limit hit)
+# SUCCESS -- the module explicitly reported success
+# Only SUCCESS passes. kvm.sh does not propagate the per-run exit
+# status of its background kvm-test-1-run.sh jobs, so grep the
+# console directly.
+check_verdict () {
+ local ds_suffix="$1" config_dir="$2" label="$3"
+ local resdir="$RCUTORTURE/res/$ds/$ds_suffix"
+ local console="$resdir/$config_dir/console.log"
+
+ if ! test -f "$console"
+ then
+ echo "Missing console.log for $label ($ds_suffix)" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ if grep -q "End of test: FAILURE" "$console"
+ then
+ echo "Module verdict FAILURE in $label: $(grep -m1 "End of test: FAILURE" "$console" | cut -c1-160)" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ if ! grep -q "End of test: SUCCESS" "$console"
+ then
+ echo "No module verdict in $label (INCOMPLETE): $(grep -m1 "MAX_LOCKDEP_KEYS\|BUG:\|hung\|Killed" "$console" 2>/dev/null | cut -c1-120)" > "$resdir/kvm.sh.err"
+ return 1
+ fi
+ return 0
+}
+
+# Basic torture: all hazptr configs, CPU count auto-detected
+echo "--- hazptr basic torture${cpus:+ ($cpus CPUs)} ---"
+if run_kvm basic "NOPREEMPT PREEMPT READERS0 READERS4" "$cpus"
+then
+ for cfg in NOPREEMPT PREEMPT READERS0 READERS4
+ do
+ check_verdict basic "$cfg" "basic/$cfg" ||
+ nerrs=$((nerrs+1))
+ check_stall basic "$cfg" "basic/$cfg" ||
+ nerrs=$((nerrs+1))
+ done
+else
+ nerrs=$((nerrs+1))
+fi
+
+# LOCKDEP: verify no lockdep splats with PROVE_LOCKING + wq_churn
+
+echo "--- hazptr lockdep + wq_churn ---"
+if run_kvm lockdep-wq LOCKDEP "$cpus"
+then
+ check_verdict lockdep-wq LOCKDEP "LOCKDEP wq_churn" ||
+ nerrs=$((nerrs+1))
+ check_lockdep lockdep-wq LOCKDEP "LOCKDEP wq_churn" ||
+ nerrs=$((nerrs+1))
+ check_stall lockdep-wq LOCKDEP "LOCKDEP wq_churn" ||
+ nerrs=$((nerrs+1))
+else
+ nerrs=$((nerrs+1))
+fi
+
+# SLOWPATH + PROVE_LOCKING: verify forced-slowpath does not deadlock
+
+echo "--- hazptr SLOWPATH + lockdep ---"
+if run_kvm slowpath-lockdep SLOWPATH "$cpus" \
+ "CONFIG_PROVE_LOCKING=y"
+then
+ check_verdict slowpath-lockdep SLOWPATH \
+ "SLOWPATH+PROVE_LOCKING" ||
+ nerrs=$((nerrs+1))
+ check_lockdep slowpath-lockdep SLOWPATH \
+ "SLOWPATH+PROVE_LOCKING" ||
+ nerrs=$((nerrs+1))
+ check_stall slowpath-lockdep SLOWPATH \
+ "SLOWPATH+PROVE_LOCKING" ||
+ nerrs=$((nerrs+1))
+else
+ nerrs=$((nerrs+1))
+fi
+
+# HOTADDR: Lai-scenario documenting mode. Starvation episodes and
+# stall-detector splats are EXPECTED here (baseline behavior); the
+# check verifies the scenario ran and the machinery stayed sane.
+
+echo "--- hazptr HOTADDR (Lai-scenario documenting) ---"
+if run_kvm hotaddr HOTADDR "$cpus" "" "30s"
+then
+ resdir="$RCUTORTURE/res/$ds/hotaddr/HOTADDR"
+ console="$resdir/console.log"
+ hotaddr_err=""
+ if ! test -f "$console"
+ then
+ echo "Missing console.log for HOTADDR" > "$RCUTORTURE/res/$ds/hotaddr/kvm.sh.err"
+ hotaddr_err=1
+ elif ! grep -q "End of test: SUCCESS" "$console"
+ then
+ echo "HOTADDR: module verdict not SUCCESS" > "$resdir/kvm.sh.err"
+ hotaddr_err=1
+ elif ! grep -q "hot r" "$console"
+ then
+ echo "HOTADDR: staged rounds not found" > "$resdir/kvm.sh.err"
+ hotaddr_err=1
+ fi
+ # Independent checks: a failure must not be masked by an earlier
+ # elif taking the note branch.
+ if grep -q "positive control timed out" "$console" 2>/dev/null
+ then
+ echo "HOTADDR: positive control failure (machinery fault)" >> "$resdir/kvm.sh.err"
+ hotaddr_err=1
+ fi
+ if [ -z "$hotaddr_err" ]
+ then
+ if ! grep -q "hazptr: waiter stall" "$console"
+ then
+ echo "HOTADDR note: no stall splats observed (record as not-reproduced, investigate interleaving)" > "$resdir/kvm.sh.note"
+ else
+ echo "HOTADDR: starvation reproduced, stall detector confirmed, drain verified"
+ fi
+ else
+ nerrs=$((nerrs+1))
+ fi
+else
+ nerrs=$((nerrs+1))
+fi
+
+# LONGHOLD: legitimate long-lived references. The stall detector must
+# fire (observation), the holder must release, and the waiter must drain
+# normally afterwards: diagnostics without interruption, module verdict
+# stays SUCCESS.
+
+echo "--- hazptr LONGHOLD (legitimate long-held reference) ---"
+if run_kvm longhold LONGHOLD "$cpus" "" "60s"
+then
+ resdir="$RCUTORTURE/res/$ds/longhold/LONGHOLD"
+ console="$resdir/console.log"
+ longhold_err=""
+ if ! test -f "$console"
+ then
+ echo "Missing console.log for LONGHOLD" > "$RCUTORTURE/res/$ds/longhold/kvm.sh.err"
+ longhold_err=1
+ elif ! grep -q "End of test: SUCCESS" "$console"
+ then
+ echo "LONGHOLD: module verdict not SUCCESS" > "$resdir/kvm.sh.err"
+ longhold_err=1
+ elif ! grep -q "longhold drain=1" "$console"
+ then
+ echo "LONGHOLD: drain after release not observed" > "$resdir/kvm.sh.err"
+ longhold_err=1
+ fi
+ # Independent check: the sync must drain after release; this
+ # must not be masked by the stall-report note branch.
+ if grep -q "longhold: sync did not drain" "$console" 2>/dev/null
+ then
+ echo "LONGHOLD: sync failed to drain after release" >> "$resdir/kvm.sh.err"
+ longhold_err=1
+ fi
+ if [ -z "$longhold_err" ]
+ then
+ if ! grep -q "hazptr: waiter stall" "$console"
+ then
+ echo "LONGHOLD note: stall detector did not fire on a legitimate long hold" > "$resdir/kvm.sh.note"
+ else
+ echo "LONGHOLD: detector fired on legitimate hold, drain verified, no interruption"
+ fi
+ else
+ nerrs=$((nerrs+1))
+ fi
+else
+ nerrs=$((nerrs+1))
+fi
+
+# CPU scaling: optionally test at multiple CPU counts
+
+if test "$allcpus" -ne 0
+then
+ max_cpus=`grep '^processor' /proc/cpuinfo 2>/dev/null | wc -l`
+ for n in 8 16 32 64 128 256
+ do
+ if test "$n" -le "$max_cpus"
+ then
+ echo "--- hazptr CPU=$n ---"
+ if run_kvm "cpu$n" "PREEMPT" "$n" "CONFIG_NR_CPUS=$n"
+ then
+ check_verdict "cpu$n" PREEMPT "cpu$n/PREEMPT" ||
+ nerrs=$((nerrs+1))
+ check_stall "cpu$n" PREEMPT "cpu$n/PREEMPT" ||
+ nerrs=$((nerrs+1))
+ else
+ nerrs=$((nerrs+1))
+ fi
+ fi
+ done
+fi
+
+# Report
+
+if test "$nerrs" -ne 0
+then
+ echo "hazptr.sh: $nerrs test(s) failed"
+ exit 1
+fi
+echo "hazptr.sh: all tests passed"
+exit 0
diff --git a/tools/testing/selftests/rcutorture/configs/hazptr/CFLIST b/tools/testing/selftests/rcutorture/configs/hazptr/CFLIST
index 4d62eb4a39f9..90ef09b0e654 100644
--- a/tools/testing/selftests/rcutorture/configs/hazptr/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/hazptr/CFLIST
@@ -1,2 +1,8 @@
NOPREEMPT
PREEMPT
+READERS0
+READERS4
+SLOWPATH
+LOCKDEP
+CPU128
+CPU256
--
2.43.0