mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests
@ 2026-11-28 14:27 Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 1/7] rcu-tasks: Record callback enqueue stack Kunwu Chan
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan

This series records the enqueue stack for RCU Tasks callbacks and adds
rcutorture coverage for duplicate callbacks and KASAN auxiliary-stack
recording.

kasan-aux.sh runs the auxiliary-stack self-test on existing scenarios
and checks for the enqueue caller in the intentional KASAN report.
Patch 6 runs it from torture.sh when both RCU torture and KASAN testing
are enabled. The extra builds follow --configs-rcutorture. --no-kasan
disables both ordinary KASAN torture and the auxiliary-stack checks.

Changes since v2 [1]

- Rebased onto Paul's dev branch at 68dcfb0e34ee. The previous callback
  stack and duplicate-enqueue series is already in dev. Joel's Tasks
  RCU barrier debugobjects fix is included in f9857faffbb2
  ("rcu-tasks: Detect duplicate callback enqueue").
- Dropped v2 patch 4/7. Zqiang's 6abf78ac6a2c ("rcutorture: Make
  tasks-tracing support duplicate call testing") already sets
  debug_objects for Tasks Trace.
- Adjusted the torture.sh patch to keep dev's NMI boot parameters and
  QEMU arguments for ordinary RCU torture. The dedicated aux-stack run
  uses its own boot parameters.
- Added patch 7/7 to accept the expected KASAN aux-stack skip in the
  TRIVIAL-PREEMPT scenario. Codex found and helped fix the checker
  omission while comparing the rebased series with v2.

On the rebased x86-64 tree, I built the RCU objects with Generic KASAN
enabled and checked torture.sh argument handling. A 30-second QEMU
run of TRIVIAL-PREEMPT skipped the KASAN self-test and reached
SUCCESS.

[1] https://lore.kernel.org/all/20261118085147.1668598-1-kunwu.chan@gmail.com/

Kunwu Chan (7):
  rcu-tasks: Record callback enqueue stack
  rcutorture: Require debug_objects flag for debug-objects test
  rcutorture: Test duplicate call_rcu_tasks() callback enqueue
  rcutorture: Add KASAN aux-stack self-test
  rcutorture: Add kasan-aux.sh aux-stack checker
  rcutorture: Run KASAN aux-stack checks from torture.sh
  rcutorture: Accept TRIVIAL-PREEMPT skips in kasan-aux.sh

 Documentation/RCU/torture.rst                 |  46 ++++
 .../admin-guide/kernel-parameters.txt         |  11 +
 kernel/rcu/rcutorture.c                       |  54 ++++-
 kernel/rcu/tasks.h                            |   4 +
 .../rcutorture/bin/kasan-aux-check.sh         | 158 ++++++++++++
 .../selftests/rcutorture/bin/kasan-aux.sh     | 229 ++++++++++++++++++
 .../selftests/rcutorture/bin/torture.sh       |   9 +
 7 files changed, 509 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
 create mode 100755 tools/testing/selftests/rcutorture/bin/kasan-aux.sh


base-commit: 68dcfb0e34ee3a9628f6b5ce7e06931b5248bb9e
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/7] rcu-tasks: Record callback enqueue stack
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 2/7] rcutorture: Require debug_objects flag for debug-objects test Kunwu Chan
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

Tree RCU records the code path that enqueued a given callback via
kasan_record_aux_stack(), but Tasks RCU does not.  KASAN reports
involving Tasks RCU callbacks therefore lack any hint as to which
code path did the enqueueing.  This commit therefore invokes
kasan_record_aux_stack() in call_rcu_tasks_generic(), covering both
call_rcu_tasks() and call_rcu_tasks_rude().

Suggested-by: Zqiang <qiang.zhang@linux.dev>
Cc: Kunwu Chan <kunwu.chan@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 kernel/rcu/tasks.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
index c1e456e08e668..ab05131a12b18 100644
--- a/kernel/rcu/tasks.h
+++ b/kernel/rcu/tasks.h
@@ -6,6 +6,7 @@
  */
 
 #ifdef CONFIG_TASKS_RCU_GENERIC
+#include <linux/kasan.h>
 #include <linux/mm.h>
 #include <linux/ratelimit.h>
 #include "rcu_segcblist.h"
@@ -364,6 +365,9 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
 	if (WARN_ON_ONCE(!func))
 		return;
 
+	/* Record the caller: the irq_work's stack says nothing about it. */
+	kasan_record_aux_stack(rhp);
+
 	if (debug_rcu_head_queue(rhp)) {
 		if (__ratelimit(&rcu_tasks_dup_rs)) {
 			pr_err("%s(): Duplicate CB for %s, %p->%pS()\n",
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 2/7] rcutorture: Require debug_objects flag for debug-objects test
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 1/7] rcu-tasks: Record callback enqueue stack Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 3/7] rcutorture: Test duplicate call_rcu_tasks() callback enqueue Kunwu Chan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

rcu_test_debug_objects() checks for missing callback and barrier
operations only when ->debug_objects is set.  With the flag clear,
execution falls through to the test even if those operations are
missing.

With CONFIG_DEBUG_OBJECTS_RCU_HEAD=y and rcutorture.object_debug=1,
the trivial flavor can therefore call a NULL function pointer.

Skip the test for flavors that do not set ->debug_objects.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 kernel/rcu/rcutorture.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 67fc770abc102..1648e6369d809 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -4774,8 +4774,13 @@ static void rcu_test_debug_objects(void)
 		return;
 	}
 
-	if (WARN_ON_ONCE(cur_ops->debug_objects &&
-			(!cur_ops->call || !cur_ops->cb_barrier)))
+	if (!cur_ops->debug_objects) {
+		pr_alert("%s: %s does not support debug-object testing\n",
+			 KBUILD_MODNAME, cur_ops->name);
+		return;
+	}
+
+	if (WARN_ON_ONCE(!cur_ops->call || !cur_ops->cb_barrier))
 		return;
 
 	struct rcu_head *rhp = kmalloc_obj(*rhp);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 3/7] rcutorture: Test duplicate call_rcu_tasks() callback enqueue
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 1/7] rcu-tasks: Record callback enqueue stack Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 2/7] rcutorture: Require debug_objects flag for debug-objects test Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 4/7] rcutorture: Add KASAN aux-stack self-test Kunwu Chan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

Enable the existing duplicate-callback test for RCU Tasks by
setting ->debug_objects.

Suggested-by: Zqiang <qiang.zhang@linux.dev>
Cc: Kunwu Chan <kunwu.chan@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 kernel/rcu/rcutorture.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 1648e6369d809..8c264aaf1727a 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1327,6 +1327,7 @@ static struct rcu_torture_ops tasks_ops = {
 	.get_gp_data	= rcu_tasks_get_gp_data,
 	.irq_capable	= 1,
 	.slow_gps	= 1,
+	.debug_objects	= 1,
 	.name		= "tasks"
 };
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 4/7] rcutorture: Add KASAN aux-stack self-test
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
                   ` (2 preceding siblings ...)
  2026-11-28 14:27 ` [PATCH v3 3/7] rcutorture: Test duplicate call_rcu_tasks() callback enqueue Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 5/7] rcutorture: Add kasan-aux.sh aux-stack checker Kunwu Chan
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

Add rcutorture.kasan_debug to queue and drain an empty callback,
then free and read its rcu_head to trigger a KASAN report.

Check "Last potentially related work creation:" for rcu_test_kasan()
and the enqueue path. The intentional report makes kvm.sh exit 3
(runtime errors), even if rcutorture prints SUCCESS.

Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Suggested-by: Zqiang <qiang.zhang@linux.dev>
Cc: Kunwu Chan <kunwu.chan@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 .../admin-guide/kernel-parameters.txt         | 11 +++++
 kernel/rcu/rcutorture.c                       | 44 +++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a49523c52c759..6425e84194f76 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6227,6 +6227,17 @@ Kernel parameters
 			accurately, from a timer handler.  Not all RCU
 			flavors take kindly to this sort of thing.
 
+	rcutorture.kasan_debug= [KNL]
+			Enable an intentional KASAN use-after-free test of
+			callback enqueue-stack recording. Requires
+			CONFIG_KASAN_GENERIC and a torture flavor with
+			callback and barrier operations. Inspect "Last
+			potentially related work creation" in the report
+			for the enqueue stack. Disabled by default.
+			Use a dedicated test run: the report taints the
+			kernel and suppresses later KASAN reports unless
+			kasan_multi_shot is enabled.
+
 	rcutorture.leakpointer= [KNL]
 			Leak an RCU-protected pointer out of the reader.
 			This can of course result in splats, and is
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 8c264aaf1727a..f9cd90d54165a 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -113,6 +113,7 @@ torture_param(int, gp_poll_wi_exp, 128,
 		   "Wait interval for expedited polled grace periods, us (default 128 us)");
 torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
 torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
+torture_param(bool, kasan_debug, false, "Enable KASAN aux-stack call_rcu() testing");
 torture_param(int, leakpointer, 0, "Leak pointer dereferences from readers");
 torture_param(int, n_barrier_cbs, 0, "# of callbacks/kthreads for barrier testing");
 torture_param(int, n_up_down, 32, "# of concurrent up/down hrtimer-based RCU readers");
@@ -4809,6 +4810,46 @@ static void rcu_test_debug_objects(void)
 	kfree(rhp);
 }
 
+/*
+ * Trigger a KASAN use-after-free report after draining a callback. Check
+ * "Last potentially related work creation" for the callback enqueue stack.
+ */
+static noinline void rcu_test_kasan(void)
+{
+	struct rcu_head *rhp;
+
+	if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+		pr_alert("%s: !CONFIG_KASAN_GENERIC, not testing KASAN aux stack call_%s()\n",
+			 KBUILD_MODNAME, cur_ops->name);
+		return;
+	}
+
+	if (!cur_ops->call || !cur_ops->cb_barrier) {
+		pr_alert("%s: %s has no callback/barrier ops, skipping KASAN test\n",
+			 KBUILD_MODNAME, cur_ops->name);
+		return;
+	}
+
+	rhp = kmalloc_obj(*rhp);
+	if (!rhp) {
+		pr_alert("%s: KASAN aux-stack test skipped: allocation failed\n", KBUILD_MODNAME);
+		return;
+	}
+
+	pr_alert("%s: WARN: KASAN aux-stack call_%s() test starting.\n",
+		 KBUILD_MODNAME, cur_ops->name);
+
+	/* Keep the rcu_head allocated until all callbacks have completed. */
+	cur_ops->call(rhp, rcu_torture_leak_cb);
+	cur_ops->cb_barrier();
+
+	kfree(rhp);
+	/* Intentional use-after-free to display the recorded enqueue stack. */
+	(void)READ_ONCE(*(u8 *)rhp);
+	pr_alert("%s: WARN: KASAN aux-stack call_%s() test complete.\n",
+		 KBUILD_MODNAME, cur_ops->name);
+}
+
 static void rcutorture_sync(void)
 {
 	static unsigned long n;
@@ -5376,6 +5417,9 @@ rcu_torture_init(void)
 	if (object_debug)
 		rcu_test_debug_objects();
 
+	if (kasan_debug)
+		rcu_test_kasan();
+
 	if (cur_ops->gp_slow_register && !WARN_ON_ONCE(!cur_ops->gp_slow_unregister))
 		cur_ops->gp_slow_register(&rcu_fwd_cb_nodelay);
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 5/7] rcutorture: Add kasan-aux.sh aux-stack checker
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
                   ` (3 preceding siblings ...)
  2026-11-28 14:27 ` [PATCH v3 4/7] rcutorture: Add KASAN aux-stack self-test Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 6/7] rcutorture: Run KASAN aux-stack checks from torture.sh Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 7/7] rcutorture: Accept TRIVIAL-PREEMPT skips in kasan-aux.sh Kunwu Chan
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

kasan-aux.sh runs dedicated aux-stack tests with kvm.sh --kasan,
existing scenarios, and the rcutorture.kasan_debug=1 and
kasan_multi_shot boot parameters.  It then verifies the recorded
caller in each intentional report's auxiliary stack, retaining the
report body and using kvm-recheck.sh for the ordinary checks.
Flavors without callback operations are expected to skip the
self-test.  Saved results can be rechecked with --check using
their batches list and QEMU commands.

Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Suggested-by: Joel Fernandes <joelagnelf@nvidia.com>
Cc: Kunwu Chan <kunwu.chan@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 Documentation/RCU/torture.rst                 |  32 +++
 .../rcutorture/bin/kasan-aux-check.sh         | 158 ++++++++++++
 .../selftests/rcutorture/bin/kasan-aux.sh     | 228 ++++++++++++++++++
 3 files changed, 418 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
 create mode 100755 tools/testing/selftests/rcutorture/bin/kasan-aux.sh

diff --git a/Documentation/RCU/torture.rst b/Documentation/RCU/torture.rst
index 1ad5cc7938113..15a430f5111f4 100644
--- a/Documentation/RCU/torture.rst
+++ b/Documentation/RCU/torture.rst
@@ -212,6 +212,38 @@ Note that --gdb limits you to one scenario per kvm.sh run and requires
 that you have another window open from which to run ``gdb`` as instructed
 by the script.
 
+The callback enqueue-stack self-test intentionally triggers a KASAN
+use-after-free report.  Run it separately from ordinary KASAN bug hunts::
+
+	tools/testing/selftests/rcutorture/bin/kasan-aux.sh
+
+This uses ``kvm.sh --kasan``, existing scenarios, and the
+``rcutorture.kasan_debug=1`` and ``kasan_multi_shot`` boot parameters.
+The default 30-second runs cover Tree RCU, RCU Tasks, RCU Tasks Trace,
+Tree SRCU, and, except on arm64, Tiny RCU and Tiny SRCU.  Use ``--configs``
+and ``--duration`` to override the scenario list and duration.
+
+These scenarios cover the callback enqueue implementations that record
+KASAN auxiliary stacks, rather than all RCU configuration combinations.
+Flavors with no callback operations, such as Tasks Rude, are expected
+to skip the self-test, and the checker requires their skip message and
+a successful ordinary run.  Any other skip fails the check, even if
+the ordinary torture run succeeds.
+
+The script requires exactly one intentional report per supported scenario, with
+``rcu_test_kasan()`` in its "Last potentially related work creation"
+stack, followed by successful completion of the same torture flavor.
+Only the verified report's diagnostic markers are filtered; the body
+is retained for the existing checks, including the configuration,
+build, and console checks that ``kvm-recheck.sh`` runs.  The original
+logs and the underlying ``kvm.sh`` runtime-error status are preserved.
+Saved results can be rechecked with ``kasan-aux.sh --check
+results-directory``, using the saved ``batches`` file and QEMU commands.
+As with the intentional warnings tested by ``srcu_lockdep.sh``, ordinary
+``kvm-recheck.sh`` and ``kvm-find-errors.sh`` still report the raw
+diagnostic; use the dedicated check to distinguish the expected report
+from failures.
+
 Kernel boot arguments can also be supplied, for example, to control
 rcutorture's module parameters.  For example, to test a change to RCU's
 CPU stall-warning code, use "--bootargs 'rcutorture.stall_cpu=30'".
diff --git a/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh b/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
new file mode 100755
index 0000000000000..7a6f425975207
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
@@ -0,0 +1,158 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Verify the intentional rcutorture KASAN report and remove its diagnostics.
+# Flavors without callback operations must instead show the expected skip.
+# Leave all other console output for the usual torture error checks.
+#
+# Authors: Kunwu Chan <kunwu.chan@gmail.com>
+#
+# Usage: kasan-aux-check.sh console.log flavor
+
+if test "$#" -ne 2 || ! test -r "$1"
+then
+	echo "Usage: $0 console.log flavor" >&2
+	exit 1
+fi
+
+awk -v flavor="$2" '
+BEGIN {
+	timestamp = "[[:space:]]*[0-9]+\\.[0-9]+";
+	caller = "[[:space:]]*[CT][[:space:]]*[0-9]+";
+	log_prefix = "^[[:space:]]*\\[(" timestamp "|" caller ")\\][[:space:]]*";
+	frame_prefix = "^(\\[<[[:xdigit:]]+>\\][[:space:]]*)?\\??[[:space:]]*";
+	frame_suffix = "([.][[:alnum:]_.]+)?\\+0x[[:xdigit:]]+/0x[[:xdigit:]]+([[:space:]]|$)";
+	test_name = "rcutorture: WARN: KASAN aux-stack call_" flavor "()";
+	success = flavor "-torture:--- End of test: SUCCESS: ";
+	skip_name = "rcutorture: " flavor " has no callback/barrier ops, skipping KASAN test";
+	skip_mode = flavor ~ /^(tasks-rude|busted|trivial)$/;
+}
+
+function fail(message)
+{
+	print "kasan-aux-check.sh: " message " at line " NR > "/dev/stderr";
+	failed = 1;
+	exit 1;
+}
+
+# Strip printk timestamps/caller IDs for matching, retaining the original line.
+function message(line)
+{
+	sub(/\r$/, "", line);
+	sub(/^<[0-9]+>/, "", line);
+	while (sub(log_prefix, "", line))
+		;
+	sub(/^[[:space:]]+/, "", line);
+	sub(/[[:space:]]+$/, "", line);
+	return line;
+}
+
+function frame(line, symbol)
+{
+	return line ~ (frame_prefix symbol frame_suffix);
+}
+
+{
+	line = message($0);
+	if (skip_mode) {
+		if (line == skip_name) {
+			if (++skips != 1 || succeeded)
+				fail("unexpected or late skip message");
+		} else if (line ~ /skipping KASAN test|KASAN aux-stack test skipped|not testing KASAN aux stack/)
+			fail("unexpected skip message");
+		if (line ~ /End of test: SUCCESS:/) {
+			if (index(line, success) != 1 || ++succeeded != 1 || skips != 1)
+				fail("unexpected SUCCESS marker");
+		} else if (line ~ /End of test:/)
+			fail("unexpected test result");
+		if (line ~ /^rcutorture: WARN: KASAN aux-stack/ || line ~ /BUG: KASAN:/)
+			fail("unexpected aux-stack test output");
+		print;
+		next;
+	}
+	if (line ~ /skipping KASAN test|KASAN aux-stack test skipped|not testing KASAN aux stack/)
+		fail("KASAN test was skipped");
+	if (line ~ /^rcutorture: WARN: KASAN aux-stack call_[-[:alnum:]_]+\(\) test starting\.$/) {
+		if (line != test_name " test starting." ||
+		    ++started != 1 || reports || completed || succeeded)
+			fail("unexpected test start");
+		next;
+	}
+	if (line ~ /^rcutorture: WARN: KASAN aux-stack call_[-[:alnum:]_]+\(\) test complete\.$/) {
+		if (line != test_name " test complete." ||
+		    ++completed != 1 || started != 1 || reports != 1 || in_report)
+			fail("unexpected test completion");
+		next;
+	}
+	if (line ~ /End of test: SUCCESS:/) {
+		if (index(line, success) != 1 ||
+		    ++succeeded != 1 || completed != 1 || in_report)
+			fail("unexpected SUCCESS marker");
+	}
+	else if (line ~ /End of test:/)
+		fail("unexpected test result");
+	if (line ~ /BUG: KASAN:/) {
+		if (line !~ ("^BUG: KASAN: slab-use-after-free in rcu_test_kasan" frame_suffix))
+			fail("unexpected KASAN report");
+		if (in_report || !separator || started != 1 || completed || ++reports != 1)
+			fail("unexpected or unbounded KASAN report");
+		report_separator = message(separator);
+		printf "%s", before_report;
+		before_report = "";
+		separator = "";
+		in_report = 1;
+		next;
+	}
+	if (in_report) {
+		if (line == report_separator) {
+			if (reads != 1 || traces != 1 || aux_stacks != 1 || !test_frame)
+				fail("incomplete KASAN report or missing caller in auxiliary stack");
+			in_report = 0;
+			next;
+		}
+		if (line ~ /^(Read|Write) of size /) {
+			if (line !~ /^Read of size 1 at addr / || ++reads != 1)
+				fail("unexpected KASAN access");
+		}
+		if (line == "Last potentially related work creation:") {
+			if (++aux_stacks != 1)
+				fail("duplicate auxiliary stack");
+			in_aux = 1;
+		}
+		else if (in_aux) {
+			if (!frame(line, "[[:alnum:]_]+"))
+				in_aux = 0;
+			else if (frame(line, "rcu_test_kasan"))
+				test_frame = 1;
+		}
+		# Suppress only the main trace title in the expected report.
+		if (line ~ /^Call [Tt]race:$/ && ++traces == 1)
+			next;
+		print;
+		next;
+	}
+	if (started && !reports && line ~ /^=+$/) {
+		if (separator) {
+			print separator;
+			printf "%s", before_report;
+		}
+		separator = $0;
+		before_report = "";
+		next;
+	}
+	if (separator) {
+		before_report = before_report $0 "\n";
+		next;
+	}
+	print;
+}
+
+END {
+	if (failed)
+		exit 1;
+	if (skip_mode) {
+		if (skips != 1 || succeeded != 1)
+			fail("missing skip message or SUCCESS marker");
+	} else if (in_report || started != 1 || completed != 1 || succeeded != 1 || reports != 1)
+		fail("missing test markers or truncated KASAN report");
+}' < "$1" || exit 1
diff --git a/tools/testing/selftests/rcutorture/bin/kasan-aux.sh b/tools/testing/selftests/rcutorture/bin/kasan-aux.sh
new file mode 100755
index 0000000000000..ae7896658e94d
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kasan-aux.sh
@@ -0,0 +1,228 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Run and check the intentional KASAN callback enqueue-stack tests.
+#
+# Authors: Kunwu Chan <kunwu.chan@gmail.com>
+
+scriptname=$0
+RCUTORTURE="$(pwd)/tools/testing/selftests/rcutorture"; export RCUTORTURE
+PATH=${RCUTORTURE}/bin:$PATH; export PATH
+. functions.sh
+
+usage () {
+	echo "Usage: $scriptname [ --datestamp string ] [ --duration time ]"
+	echo "       [ --configs \"existing scenario list\" ]"
+	echo "       $scriptname --check results-directory"
+	exit 1
+}
+
+ds="$(date +%Y.%m.%d-%H.%M.%S)-kasan-aux"
+duration=30s
+configs="TREE03 TASKS01 TRACE01 SRCU-P"
+if test "$(uname -m)" != aarch64
+then
+	configs="$configs TINY01 SRCU-T"
+fi
+checkdir=
+while test $# -gt 0
+do
+	case "$1" in
+	--check)
+		checkarg --check "(results directory)" "$#" "$2" '.' '^--'
+		checkdir=$2
+		shift
+		;;
+	--configs)
+		checkarg --configs "(scenario list)" "$#" "$2" '^[^/.a-z]\+$' '^--'
+		configs=$2
+		shift
+		;;
+	--datestamp)
+		checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'
+		ds=$2
+		shift
+		;;
+	--duration)
+		checkarg --duration "(time)" "$#" "$2" '^[0-9][0-9]*[smhd]\?$' '^--'
+		duration=$2
+		shift
+		;;
+	"")
+		;;
+	*)
+		usage
+		;;
+	esac
+	shift
+done
+
+T="$(mktemp -d "${TMPDIR-/tmp}/kasan-aux.sh.XXXXXX")" || exit 1
+trap 'rm -rf "$T"' EXIT
+nsupported=0
+
+# Keep raw logs intact and let the ordinary recheck handle the verified output.
+check_results () {
+	local rundir config dir copy flavor f configs
+	local work="$T/results"
+
+	rundir=$(cd "$1" && pwd) || return 1
+	if ! test -s "$rundir/batches" || ! test -r "$rundir/log"
+	then
+		echo "$rundir: missing batches or log"
+		return 1
+	fi
+	configs=$(awk '!/^#/ { print $2 }' "$rundir/batches")
+	if test -z "$configs"
+	then
+		echo "$rundir: empty scenario list"
+		return 1
+	fi
+	mkdir "$work" || return 1
+	ln -s "$rundir/log" "$work/log" || return 1
+	echo rcu > "$work/torture_suite"
+	if test -f "$rundir/re-run"
+	then
+		ln -s "$rundir/re-run" "$work/re-run" || return 1
+	fi
+	for config in $configs
+	do
+		dir="$rundir/$config"
+		copy="$work/$config"
+		mkdir "$copy" || return 1
+		# Link inputs only, so recheck cannot overwrite saved diagnostics.
+		for f in .config ConfigFragment ConfigFragment.input Make.defconfig.out Make.out qemu-cmd qemu-retval
+		do
+			if ! test -r "$dir/$f"
+			then
+				echo "$config: missing $f"
+				return 1
+			fi
+			ln -s "$dir/$f" "$copy/$f" || return 1
+		done
+		for f in Make.oldconfig.err Warnings vmlinux vmlinux.xz
+		do
+			ln -s "$dir/$f" "$copy/$f" || return 1
+		done
+		if ! grep -q '^CONFIG_KASAN_GENERIC=y$' "$dir/.config" ||
+		   test "$(cat "$dir/qemu-retval")" != 0
+		then
+			echo "$config: Generic KASAN required and QEMU must exit normally"
+			return 1
+		fi
+		# kvm.sh saves a single QEMU command with a double-quoted -append string.
+		# Read it once, retaining the last flavor parameter, as the kernel does.
+		if ! flavor=$(awk '
+			BEGIN { flavor = "rcu"; }
+			/^[[:space:]]*(#|$)/ { next; }
+			{
+				if (++commands != 1 ||
+				    !match($0, /(^|[[:space:]])-append[[:space:]]+"/))
+					exit 1;
+				args = substr($0, RSTART + RLENGTH);
+				if (!sub(/"[^"]*$/, "", args))
+					exit 1;
+				# Only the plain kvm.sh-generated format is supported.
+				if (args ~ /\\/)
+					exit 1;
+				# Keep quoted kernel parameter values together.
+				while (args ~ /[^[:space:]]/) {
+					sub(/^[[:space:]]+/, "", args);
+					if (!match(args, /^([^"[:space:]]|"[^"]*")+/))
+						exit 1;
+					word = substr(args, 1, RLENGTH);
+					args = substr(args, RLENGTH + 1);
+					if (args !~ /^([[:space:]]|$)/)
+						exit 1;
+					whole_quote = sub(/^"/, "", word);
+					equals = index(word, "=");
+					param = equals ? substr(word, 1, equals - 1) : word;
+					value = equals ? substr(word, equals + 1) : "";
+					value_quote = sub(/^"/, "", value);
+					if (whole_quote || value_quote) {
+						if (equals)
+							sub(/"$/, "", value);
+						else
+							sub(/"$/, "", param);
+					}
+					if (param == "--" && !equals)
+						break;
+					gsub(/-/, "_", param);
+					if (param == "rcutorture.torture_type")
+						flavor = value;
+					if (param == "kasan_multi_shot")
+						multi_shot = 1;
+				}
+				valid = 1;
+			}
+		END {
+			if (!valid || commands != 1 || !multi_shot ||
+			    flavor !~ /^(rcu|srcu|srcud|tasks|tasks-tracing|tasks-rude|busted|trivial)$/)
+				exit 1;
+			print flavor;
+		}' "$dir/qemu-cmd")
+		then
+			echo "$config: invalid saved boot arguments or missing kasan_multi_shot"
+			return 1
+		fi
+		case "$flavor" in
+		rcu|srcu|srcud|tasks|tasks-tracing)
+			nsupported=$((nsupported+1))
+			;;
+		esac
+		if ! TMPDIR="$T" kasan-aux-check.sh "$dir/console.log" "$flavor" > "$copy/console.log"
+		then
+			return 1
+		fi
+		# kvm-recheck.sh does not propagate parse-build.sh exit status.
+		TMPDIR="$T" parse-build.sh "$dir/Make.out" "$config" || return 1
+	done
+	if ! TMPDIR="$T" kvm-recheck.sh "$work" 2> "$T/recheck.err" || test -s "$T/recheck.err"
+	then
+		cat "$T/recheck.err"
+		return 1
+	fi
+	echo "Summary: KASAN aux-stack checks passed"
+}
+
+if test -n "$checkdir"
+then
+	check_results "$checkdir"
+	exit $?
+fi
+
+rundir="$RCUTORTURE/res/$ds"
+if test -e "$rundir"
+then
+	echo "Results directory already exists: $rundir"
+	exit 1
+fi
+kvm.sh --allcpus --kasan --kconfig "CONFIG_KASAN_GENERIC=y" \
+	--configs "$configs" --duration "$duration" --trust-make \
+	--bootargs "rcutorture.kasan_debug=1 rcutorture.object_debug=0 kasan_multi_shot" \
+	--datestamp "$ds"
+ret=$?
+err=0
+if ! check_results "$rundir" > "$T/check.out" 2>&1
+then
+	err=1
+fi
+# Scenarios with callback operations produce the intentional reports, so
+# kvm.sh must report them as runtime errors.  Skip-only selections exit 0.
+if test "$nsupported" -gt 0
+then
+	expected=3
+else
+	expected=0
+fi
+if test "$ret" -ne "$expected"
+then
+	echo "Expected kvm.sh exit status $expected, got $ret"
+	err=1
+fi
+cat "$T/check.out"
+if test -d "$rundir"
+then
+	cat "$T/check.out" >> "$rundir/log"
+fi
+exit "$err"
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 6/7] rcutorture: Run KASAN aux-stack checks from torture.sh
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
                   ` (4 preceding siblings ...)
  2026-11-28 14:27 ` [PATCH v3 5/7] rcutorture: Add kasan-aux.sh aux-stack checker Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  2026-11-28 14:27 ` [PATCH v3 7/7] rcutorture: Accept TRIVIAL-PREEMPT skips in kasan-aux.sh Kunwu Chan
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

Invoke kasan-aux.sh when torture.sh has both RCU-torture and KASAN
testing enabled, reusing the existing --do-kasan switch, the
torture_one bookkeeping, and the --configs-rcutorture scenario
selection, so the added kernel builds scale with that selection.
--no-kasan disables both ordinary KASAN and aux-stack testing.

Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Suggested-by: Joel Fernandes <joelagnelf@nvidia.com>
Cc: Kunwu Chan <kunwu.chan@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 Documentation/RCU/torture.rst                     | 14 ++++++++++++++
 tools/testing/selftests/rcutorture/bin/torture.sh |  9 +++++++++
 2 files changed, 23 insertions(+)

diff --git a/Documentation/RCU/torture.rst b/Documentation/RCU/torture.rst
index 15a430f5111f4..8c8dcf6449bf0 100644
--- a/Documentation/RCU/torture.rst
+++ b/Documentation/RCU/torture.rst
@@ -244,6 +244,20 @@ As with the intentional warnings tested by ``srcu_lockdep.sh``, ordinary
 diagnostic; use the dedicated check to distinguish the expected report
 from failures.
 
+``torture.sh`` includes these dedicated runs when both RCU torture and
+KASAN testing are enabled, as they are by default, using the scenarios
+selected by ``--configs-rcutorture`` and 30-second run durations.
+``--no-kasan`` disables both ordinary KASAN and auxiliary-stack testing.
+For example::
+
+	tools/testing/selftests/rcutorture/bin/torture.sh \
+		--do-none --do-rcutorture --do-kasan \
+		--configs-rcutorture TREE03 --duration 2
+
+This runs ordinary KASAN torture with TREE03, followed by the dedicated
+auxiliary-stack verification of TREE03.  To run only the auxiliary
+checks, invoke ``kasan-aux.sh`` directly.
+
 Kernel boot arguments can also be supplied, for example, to control
 rcutorture's module parameters.  For example, to test a change to RCU's
 CPU stall-warning code, use "--bootargs 'rcutorture.stall_cpu=30'".
diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh b/tools/testing/selftests/rcutorture/bin/torture.sh
index 0498fce14ccd6..98edd2f3e747a 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -514,6 +514,15 @@ then
 	torture_set "rcutorture" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus \
 		--duration "$duration_rcutorture" --configs "$configs_rcutorture" \
 		${qemu_args:+--qemu-args "$qemu_args"} --trust-make
+
+	# Check intentional reports separately from the ordinary KASAN bug hunts.
+	# kasan-aux.sh supplies its own boot arguments and rejects --bootargs.
+	if test "$do_kasan" = "yes"
+	then
+		torture_bootargs=""
+		curflavor=rcu-aux-kasan
+		torture_one tools/testing/selftests/rcutorture/bin/kasan-aux.sh --configs "$configs_rcutorture"
+	fi
 fi
 
 # Test atomic SRCU across Tree SRCU (SRCU-N and SRCU-P) and Tiny SRCU
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 7/7] rcutorture: Accept TRIVIAL-PREEMPT skips in kasan-aux.sh
  2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
                   ` (5 preceding siblings ...)
  2026-11-28 14:27 ` [PATCH v3 6/7] rcutorture: Run KASAN aux-stack checks from torture.sh Kunwu Chan
@ 2026-11-28 14:27 ` Kunwu Chan
  6 siblings, 0 replies; 8+ messages in thread
From: Kunwu Chan @ 2026-11-28 14:27 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, joelagnelf,
	boqun, urezki
  Cc: rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang,
	linux-kernel, rcu, Kunwu Chan, Kunwu Chan

The TRIVIAL-PREEMPT scenario selects trivial-preempt, which has no
callback or barrier operations. The kernel correctly skips the
KASAN aux-stack self-test, but kasan-aux.sh rejects the saved flavor
and kasan-aux-check.sh does not recognize the expected skip.

Accept trivial-preempt in both scripts and require its skip message
and a successful torture run, as for the other skip-only flavors.

Cc: Kunwu Chan <kunwu.chan@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh | 2 +-
 tools/testing/selftests/rcutorture/bin/kasan-aux.sh       | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh b/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
index 7a6f425975207..5518ca507557f 100755
--- a/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
+++ b/tools/testing/selftests/rcutorture/bin/kasan-aux-check.sh
@@ -25,7 +25,7 @@ BEGIN {
 	test_name = "rcutorture: WARN: KASAN aux-stack call_" flavor "()";
 	success = flavor "-torture:--- End of test: SUCCESS: ";
 	skip_name = "rcutorture: " flavor " has no callback/barrier ops, skipping KASAN test";
-	skip_mode = flavor ~ /^(tasks-rude|busted|trivial)$/;
+	skip_mode = flavor ~ /^(tasks-rude|busted|trivial(-preempt)?)$/;
 }
 
 function fail(message)
diff --git a/tools/testing/selftests/rcutorture/bin/kasan-aux.sh b/tools/testing/selftests/rcutorture/bin/kasan-aux.sh
index ae7896658e94d..6b6d9971f03d7 100755
--- a/tools/testing/selftests/rcutorture/bin/kasan-aux.sh
+++ b/tools/testing/selftests/rcutorture/bin/kasan-aux.sh
@@ -157,7 +157,8 @@ check_results () {
 			}
 		END {
 			if (!valid || commands != 1 || !multi_shot ||
-			    flavor !~ /^(rcu|srcu|srcud|tasks|tasks-tracing|tasks-rude|busted|trivial)$/)
+			    (flavor !~ /^(rcu|srcu|srcud|tasks|tasks-tracing)$/ &&
+			     flavor !~ /^(tasks-rude|busted|trivial(-preempt)?)$/))
 				exit 1;
 			print flavor;
 		}' "$dir/qemu-cmd")
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-28 14:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 14:27 [PATCH v3 0/7] rcu: Record callback enqueue stacks and add torture tests Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 1/7] rcu-tasks: Record callback enqueue stack Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 2/7] rcutorture: Require debug_objects flag for debug-objects test Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 3/7] rcutorture: Test duplicate call_rcu_tasks() callback enqueue Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 4/7] rcutorture: Add KASAN aux-stack self-test Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 5/7] rcutorture: Add kasan-aux.sh aux-stack checker Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 6/7] rcutorture: Run KASAN aux-stack checks from torture.sh Kunwu Chan
2026-11-28 14:27 ` [PATCH v3 7/7] rcutorture: Accept TRIVIAL-PREEMPT skips in kasan-aux.sh Kunwu Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®