mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 00/17] srcu: Try idle expedited GPs in the caller
@ 2026-12-01 16:17 Kunwu Chan
  2026-12-01 16:17 ` [PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper Kunwu Chan
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:17 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

David Woodhouse asked for the reader-free fastpath to also be used
from synchronize_srcu_expedited(). On eligible idle Tree SRCU domains
with full-barrier readers, this series tries to finish an expedited
grace period in the caller: when both ordered reader scans pass, the
caller avoids queueing its completion callback,
sleeping and being woken by the worker.

The attempt uses the normal grace-period completion path and
preserves the guarantee that a cookie obtained before
synchronize_srcu_expedited() polls complete after it
returns.

Preemption is disabled before either mutex is taken and held
across both. If either scan misses after the grace period starts,
irq_work is queued before the mutexes are released so the worker can
continue that grace period while the caller falls back to the normal
synchronous wait.

In nested x86 KVM tests with the vCPU stopped and no bus
registration, memslot move p50 fell from 8.95 to 5.15 and from 12.58
to 4.77 us in two paired groups. Immediately after MMIO eventfd
registration, the first wait always entered with a grace period
already in flight and used the worker, so p50 stayed near 19.6 ms;
the second wait completed in the caller in under a microsecond.

With one sleep between calls, single-writer expedited API p50 fell
from 17.2 to 3.0 us on four-vCPU x86 RT BIG and from 24.1 to 5.8 us on
32-vCPU arm64 RT BIG. With two arm64 writers, p50 stayed near 39 us,
and the x86 RT SMALL two-writer p99 rose in two of three pairs and
fell in the third.

In an unbroken FIFO loop, the first sequence-maintenance fallback
keeps later calls on the worker: the fallback callback wakes the
writer before the worker drops the callback count, so the callback
queue never looks empty. A sleep between calls drains the count and
restores caller completion.

Patches 1-4 prepare, implement and tune the caller path.
Patches 5-11 add parser selftests, report completed writer waits
and add optional expedited wait bursts.
Patches 12-17 print one final NMI coverage record after the
producers stop and callbacks drain, check it and document the workload.

A successful run without the requested NMI activity reports SKIP,
and a missing or invalid final record reports FAIL.

Tested on x86-64 and arm64 KVM. The base and every patch built with
W=1 in ordinary and PREEMPT_RT configurations (36 x86 builds, plus
the arm64 base and tip).

All 43 x86 KVM runs met their expected results:
SMALL and BIG exercised NMI readers and callbacks, both
PMU-off runs reported SKIP, and 60-second hotplug runs matched
NMI callback counts.

Directed trace runs covered caller completion and both forced scan
misses, with the worker finishing the original
grace period before the caller queued its fallback in both cases.
Two arm64 RT runs converted SMALL to BIG at runtime. Eight LKMM litmus
cases gave the expected results, and the writer-progress and NMI
shell suites passed 33 and 31 cases under mawk, gawk and BusyBox awk.
The documented x86 kvm.sh recipe needs the separate QEMU CPU-selection
fix; the guest tests set the CPU option directly.


Kunwu Chan (17):
  srcu: Move callback mutex acquisition to the GP end wrapper
  srcu: Let GP completion take a size-state snapshot
  srcu: Try idle expedited GPs in the caller
  srcu: Check only the boot CPU callback queue in SMALL domains
  rcutorture: Add selftests for console writer progress
  rcutorture: Compare console version counters exactly
  rcutorture: Recognize completed writer waits in console logs
  rcutorture: Emit the version with the statistics prefix
  rcutorture: Report completed synchronous writer waits
  rcutorture: Use writer wait counts in kernel stall diagnostics
  rcutorture: Add consecutive expedited waits per writer iteration
  rcutorture: Check NMI coverage
  rcutorture: Test NMI coverage result classification
  rcutorture: Test NMI summary field validation
  rcutorture: Test NMI console-log boundaries
  rcutorture: Document how to check SRCU NMI coverage
  rcutorture: Document directed SRCU NMI tests

 Documentation/RCU/torture.rst                 | 101 ++++++++++
 .../admin-guide/kernel-parameters.txt         |   5 +
 kernel/rcu/rcutorture.c                       |  67 +++++--
 kernel/rcu/srcutree.c                         | 150 ++++++++++++++-
 .../rcutorture/bin/kvm-recheck-nmi-test.sh    | 172 ++++++++++++++++++
 .../rcutorture/bin/kvm-recheck-nmi.sh         |  72 ++++++++
 .../bin/parse-console-progress-test.sh        | 123 +++++++++++++
 .../selftests/rcutorture/bin/parse-console.sh |  46 ++++-
 8 files changed, 710 insertions(+), 26 deletions(-)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
 create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh
 create mode 100755 tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh


base-commit: 68dcfb0e34ee3a9628f6b5ce7e06931b5248bb9e
-- 
2.43.0


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

* [PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
@ 2026-12-01 16:17 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 02/17] srcu: Let GP completion take a size-state snapshot Kunwu Chan
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:17 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Move the srcu_cb_mutex acquisition into srcu_gp_end() so callers
that already hold both mutexes can reuse the completion body.
Keep the size-state load and mutex releases in the completion body.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/srcutree.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 75ff54c9025e..1ab5a1cdc163 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -983,7 +983,7 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *ssp, struct srcu_node *snp
  * are initiating callback invocation.  This allows the ->srcu_have_cbs[]
  * array to have a finite number of elements.
  */
-static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
+static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 {
 	unsigned long cbdelay = 1;
 	bool cbs;
@@ -999,9 +999,10 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 	int ss_state;
 	struct srcu_usage *sup = ssp->srcu_sup;
 
-	/* Prevent more than one additional grace period. */
-	if (!is_atomic)
-		mutex_lock(&sup->srcu_cb_mutex);
+	if (!is_atomic) {
+		lockdep_assert_held(&sup->srcu_gp_mutex);
+		lockdep_assert_held(&sup->srcu_cb_mutex);
+	}
 
 	/* End the current grace period. */
 	raw_spin_lock_irqsave_rcu_node(sup, flags);
@@ -1089,6 +1090,14 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 	}
 }
 
+static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
+{
+	/* Prevent more than one additional grace period. */
+	if (!is_atomic)
+		mutex_lock(&ssp->srcu_sup->srcu_cb_mutex);
+	__srcu_gp_end(ssp, is_atomic);
+}
+
 /*
  * Funnel-locking scheme to scalably mediate many concurrent expedited
  * grace-period requests.  This function is invoked for the first known
-- 
2.43.0


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

* [PATCH 02/17] srcu: Let GP completion take a size-state snapshot
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
  2026-12-01 16:17 ` [PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 03/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Allow callers holding both mutexes to pass a SMALL or BIG size state.
The existing wrapper requests a size-state load during completion.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/srcutree.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 1ab5a1cdc163..16b1a6b677e1 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -974,6 +974,9 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *ssp, struct srcu_node *snp
 			srcu_schedule_cbs_sdp(per_cpu_ptr(ssp->sda, cpu), delay);
 }
 
+/* GP-end sentinel, outside the size-state range. */
+#define SRCU_GP_END_CURRENT_SIZE (-1)
+
 /*
  * Note the end of an SRCU grace period.  Initiates callback invocation
  * and starts a new grace period if needed.
@@ -982,8 +985,11 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *ssp, struct srcu_node *snp
  * instead prevents more than one grace period from starting while we
  * are initiating callback invocation.  This allows the ->srcu_have_cbs[]
  * array to have a finite number of elements.
+ *
+ * SRCU_GP_END_CURRENT_SIZE reads the current size here. The fastpath
+ * samples SMALL or BIG under both mutexes to avoid allocation.
  */
-static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
+static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic, int ss_state)
 {
 	unsigned long cbdelay = 1;
 	bool cbs;
@@ -996,7 +1002,6 @@ static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 	struct srcu_data *sdp;
 	unsigned long sgsne;
 	struct srcu_node *snp;
-	int ss_state;
 	struct srcu_usage *sup = ssp->srcu_sup;
 
 	if (!is_atomic) {
@@ -1022,7 +1027,8 @@ static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 	/* A new grace period can start at this point.  But only one. */
 
 	/* Initiate callback invocation as needed. */
-	ss_state = smp_load_acquire(&sup->srcu_size_state);
+	if (ss_state < 0)
+		ss_state = smp_load_acquire(&sup->srcu_size_state); /* Size-state publication. */
 	if (!is_atomic && ss_state < SRCU_SIZE_WAIT_BARRIER) {
 		srcu_schedule_cbs_sdp(per_cpu_ptr(ssp->sda, get_boot_cpu_id()),
 					cbdelay);
@@ -1095,7 +1101,7 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 	/* Prevent more than one additional grace period. */
 	if (!is_atomic)
 		mutex_lock(&ssp->srcu_sup->srcu_cb_mutex);
-	__srcu_gp_end(ssp, is_atomic);
+	__srcu_gp_end(ssp, is_atomic, SRCU_GP_END_CURRENT_SIZE);
 }
 
 /*
-- 
2.43.0


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

* [PATCH 03/17] srcu: Try idle expedited GPs in the caller
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
  2026-12-01 16:17 ` [PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper Kunwu Chan
  2026-12-01 16:18 ` [PATCH 02/17] srcu: Let GP completion take a size-state snapshot Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 04/17] srcu: Check only the boot CPU callback queue in SMALL domains Kunwu Chan
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Avoid the completion callback round trip for expedited GPs that can
finish in the caller. If the cookie is already complete after taking
the locks, return. When starting a GP, scan each retired rank once
and use normal GP completion. The fastpath preserves the guarantee
that a cookie obtained before synchronize_srcu_expedited() polls
complete after it returns.

Disable preemption before taking either mutex. On a scan miss, queue
irq_work before unlocking because the fallback callback may need a
later GP.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/srcutree.c | 113 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 112 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 16b1a6b677e1..d7773825e814 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -588,6 +588,25 @@ static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx, u
 	return sum;
 }
 
+/*
+ * Check the inactive rank once under srcu_gp_mutex. Retirement limits
+ * late increments for the wrap bound in srcu_readers_active_idx_check().
+ * Reject SLOWGP even without PROVE_RCU.
+ */
+static bool srcu_readers_inactive_check(struct srcu_struct *ssp)
+{
+	int idx = !(ssp->srcu_ctrp - &ssp->sda->srcu_ctrs[0]);
+	unsigned long rdm;
+	unsigned long unlocks;
+
+	lockdep_assert_held(&ssp->srcu_sup->srcu_gp_mutex);
+	unlocks = srcu_readers_unlock_idx(ssp, idx, &rdm);
+	if (rdm & SRCU_READ_FLAVOR_SLOWGP)
+		return false;
+	smp_mb(); /* A, pairs with the readers' B and C. */
+	return srcu_readers_lock_idx(ssp, idx, false, unlocks);
+}
+
 /*
  * Return true if the number of pre-existing readers is determined to
  * be zero.
@@ -1693,8 +1712,96 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
 EXPORT_SYMBOL_GPL(call_srcu);
 
 /*
- * Helper function for synchronize_srcu() and synchronize_srcu_expedited().
+ * Try one reader-free GP without waiting for mutexes or readers.
+ * Take both mutexes before GP start to exclude an older callback tail.
+ * Disable preemption across both mutexes to keep the GP moving.
  */
+static bool srcu_expedited_fastpath(struct srcu_struct *ssp)
+{
+	unsigned long cookie, flags;
+	int cpu;
+	int ss_state;
+	struct srcu_usage *sup = ssp->srcu_sup;
+
+	if (!srcu_init_done || rcu_scheduler_active != RCU_SCHEDULER_RUNNING ||
+	    (READ_ONCE(ssp->srcu_reader_flavor) & SRCU_READ_FLAVOR_SLOWGP))
+		return false;
+
+	/* Pending callbacks are a hint to use the worker. */
+	for_each_possible_cpu(cpu)
+		if (rcu_segcblist_n_cbs(&per_cpu_ptr(ssp->sda, cpu)->srcu_cblist))
+			return false;
+
+	/* Reader hint. Ordered scans follow GP start. */
+	if (srcu_readers_active(ssp))
+		return false;
+	cookie = get_state_synchronize_srcu(ssp);
+
+	preempt_disable();
+	if (!mutex_trylock(&sup->srcu_gp_mutex))
+		goto out_preempt;
+	if (!mutex_trylock(&sup->srcu_cb_mutex))
+		goto out_gp;
+	raw_spin_lock_irqsave_rcu_node(sup, flags);
+	if (poll_state_synchronize_srcu(ssp, cookie)) {
+		raw_spin_unlock_irqrestore_rcu_node(sup, flags);
+		mutex_unlock(&sup->srcu_cb_mutex);
+		mutex_unlock(&sup->srcu_gp_mutex);
+		preempt_enable();
+		return true;
+	}
+
+	ss_state = smp_load_acquire(&sup->srcu_size_state); /* See init_srcu_struct_nodes(). */
+	/* Keep per-CPU sequence maintenance in the normal driver. */
+	if (rcu_seq_state(READ_ONCE(sup->srcu_gp_seq)) != SRCU_STATE_IDLE ||
+	    ULONG_CMP_LT(sup->srcu_gp_seq, sup->srcu_gp_seq_needed) ||
+	    !((sup->srcu_gp_seq + RCU_SEQ_GP) & counter_wrap_check) ||
+	    (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG)) {
+		raw_spin_unlock_irqrestore_rcu_node(sup, flags);
+		goto out_cb;
+	}
+
+	smp_store_release(&sup->srcu_gp_seq_needed, cookie); /* See srcu_funnel_gp_start(). */
+	WRITE_ONCE(sup->srcu_gp_seq_needed_exp, cookie);
+	srcu_gp_start(ssp);
+	raw_spin_unlock_irqrestore_rcu_node(sup, flags);
+
+	/* Match the scan and flip order in srcu_advance_state(). */
+	if (!srcu_readers_inactive_check(ssp))
+		goto out_reschedule;
+
+	srcu_flip(ssp);
+	raw_spin_lock_irqsave_rcu_node(sup, flags);
+	rcu_seq_set_state(&sup->srcu_gp_seq, SRCU_STATE_SCAN2);
+	sup->srcu_n_exp_nodelay = 0;
+	raw_spin_unlock_irqrestore_rcu_node(sup, flags);
+
+	if (!srcu_readers_inactive_check(ssp))
+		goto out_reschedule;
+
+	/*
+	 * Contention can set ALLOC during a SMALL GP. Both states queue
+	 * callbacks on the boot CPU. Leave allocation to the worker.
+	 */
+	__srcu_gp_end(ssp, false, ss_state);
+	preempt_enable();
+	return poll_state_synchronize_srcu(ssp, cookie);
+
+out_reschedule:
+	/*
+	 * Hand off this GP before unlocking. The caller's callback
+	 * may need another GP.
+	 */
+	irq_work_queue(&sup->irq_work);
+out_cb:
+	mutex_unlock(&sup->srcu_cb_mutex);
+out_gp:
+	mutex_unlock(&sup->srcu_gp_mutex);
+out_preempt:
+	preempt_enable();
+	return false;
+}
+
 static void __synchronize_srcu(struct srcu_struct *ssp, bool do_norm)
 {
 	struct rcu_synchronize rcu;
@@ -1716,6 +1823,10 @@ static void __synchronize_srcu(struct srcu_struct *ssp, bool do_norm)
 	}
 	might_sleep();
 	check_init_srcu_struct(ssp, false);
+
+	if (!do_norm && srcu_expedited_fastpath(ssp))
+		return;
+
 	init_completion(&rcu.completion);
 	init_rcu_head_on_stack(&rcu.head);
 	__call_srcu(ssp, &rcu.head, wakeme_after_rcu, do_norm);
-- 
2.43.0


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

* [PATCH 04/17] srcu: Check only the boot CPU callback queue in SMALL domains
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (2 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 03/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 05/17] rcutorture: Add selftests for console writer progress Kunwu Chan
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

SMALL domains route callbacks through the boot CPU. Check only that
queue before attempting a caller-driven expedited GP.

In three earlier paired idle SMALL runs on 192-vCPU arm64 KVM, p50
fell from 15.25-15.26 to 14.26-14.30 us versus the all-CPU check.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/srcutree.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index d7773825e814..1588973432cb 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1721,6 +1721,7 @@ static bool srcu_expedited_fastpath(struct srcu_struct *ssp)
 	unsigned long cookie, flags;
 	int cpu;
 	int ss_state;
+	struct srcu_data *sdp;
 	struct srcu_usage *sup = ssp->srcu_sup;
 
 	if (!srcu_init_done || rcu_scheduler_active != RCU_SCHEDULER_RUNNING ||
@@ -1728,9 +1729,18 @@ static bool srcu_expedited_fastpath(struct srcu_struct *ssp)
 		return false;
 
 	/* Pending callbacks are a hint to use the worker. */
-	for_each_possible_cpu(cpu)
-		if (rcu_segcblist_n_cbs(&per_cpu_ptr(ssp->sda, cpu)->srcu_cblist))
+	if (READ_ONCE(sup->srcu_size_state) == SRCU_SIZE_SMALL) {
+		/* SMALL uses the boot CPU in srcu_gp_start_if_needed(). */
+		sdp = per_cpu_ptr(ssp->sda, get_boot_cpu_id());
+		if (rcu_segcblist_n_cbs(&sdp->srcu_cblist))
 			return false;
+	} else {
+		for_each_possible_cpu(cpu) {
+			sdp = per_cpu_ptr(ssp->sda, cpu);
+			if (rcu_segcblist_n_cbs(&sdp->srcu_cblist))
+				return false;
+		}
+	}
 
 	/* Reader hint. Ordered scans follow GP start. */
 	if (srcu_readers_active(ssp))
-- 
2.43.0


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

* [PATCH 05/17] rcutorture: Add selftests for console writer progress
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (3 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 04/17] srcu: Check only the boot CPU callback queue in SMALL domains Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 06/17] rcutorture: Compare console version counters exactly Kunwu Chan
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Cover legacy writer-progress detection in parse-console.sh before
changing how it compares or interprets counters.

Require each parser invocation to exit successfully, then check the
diagnostic generated for that case.  Clear any previous diagnostic so a
reused result directory cannot supply a stale expected failure.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 .../bin/parse-console-progress-test.sh        | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh

diff --git a/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh b/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
new file mode 100755
index 000000000000..bc51b598291c
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Check writer progress through parse-console.sh and its diagnostic files.
+# Usage: parse-console-progress-test.sh [parse-console.sh [result-directory]]
+#
+# Author: Kunwu Chan <kunwu.chan@gmail.com>
+
+set -u
+
+bindir="$(cd -- "$(dirname -- "$0")" && pwd)"
+parser="${1:-$bindir/parse-console.sh}"
+if test "$#" -gt 1
+then
+	t="$2"
+	mkdir -p "$t"
+else
+	t="$(mktemp -d "${TMPDIR-/tmp}/parse-console-progress-test.XXXXXX")" || exit 1
+	trap 'rm -rf "$t"' EXIT
+fi
+mkdir -p "$t/tmp"
+t="$(cd -- "$t" && pwd)"
+nchecks=0
+nfailed=0
+
+stats () {
+	printf '[   %s] srcud-torture: rtc: ffff888012345678 ver: %s tfle: 0 %s\n' \
+		"${3:-5.000000}" "$1" "$2"
+}
+
+check () {
+	local name="$1" expected="$2" pattern="${3:-.}" actual status
+	local dir="$t/$name"
+
+	mkdir -p "$dir"
+	cat > "$dir/console.log"
+	printf 'srcud-torture: End of test: SUCCESS\n' >> "$dir/console.log"
+	rm -f -- "$dir/console.log.diags" || exit 1
+	# The parser reports these console failures through its diagnostics.
+	TORTURE_SUITE=rcu LC_ALL=C TMPDIR="$t/tmp" PATH="$bindir:$PATH" \
+		bash "$parser" "$dir/console.log" "$name" > "$dir/output" 2>&1
+	status=$?
+	printf '%s\n' "$status" > "$dir/exit-status"
+	actual=pass
+	if test -s "$dir/console.log.diags"
+	then
+		actual=fail
+	fi
+	nchecks=$((nchecks + 1))
+	if test "$status" -eq 0 && test "$actual" = "$expected" &&
+	   { test "$expected" = pass || grep -Eq "$pattern" "$dir/console.log.diags"; }
+	then
+		echo "ok $nchecks - $name"
+	else
+		echo "not ok $nchecks - $name (parser exit $status, $actual, expected $expected)"
+		cat "$dir/output"
+		if test -f "$dir/console.log.diags"
+		then
+			cat "$dir/console.log.diags"
+		fi
+		nfailed=$((nfailed + 1))
+	fi
+}
+
+check legacy-progress pass < <(stats 106 ''; stats 107 '')
+check legacy-stall fail 'GP HANG' < <(stats 106 ''; stats 106 '')
+check legacy-regression fail 'BAD SEQ' < <(stats 107 ''; stats 106 '')
+check legacy-nonnumeric fail 'BAD SEQ' < <(stats 106 ''; stats broken '')
+check legacy-initial-zero fail 'BAD SEQ|GP HANG' < <(stats 0 ''; stats 1 '')
+
+echo "1..$nchecks"
+test "$nfailed" -eq 0
-- 
2.43.0


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

* [PATCH 06/17] rcutorture: Compare console version counters exactly
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (4 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 05/17] rcutorture: Add selftests for console writer progress Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 07/17] rcutorture: Recognize completed writer waits in console logs Kunwu Chan
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Compare unsigned decimal counters as strings so awk can distinguish
adjacent 64-bit version numbers. Test progress and regression at the
double-precision boundary, digit-count growth and a decreasing
counter.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 .../bin/parse-console-progress-test.sh        | 11 ++++++++++
 .../selftests/rcutorture/bin/parse-console.sh | 21 ++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh b/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
index bc51b598291c..b9603ce04fce 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
@@ -68,5 +68,16 @@ check legacy-regression fail 'BAD SEQ' < <(stats 107 ''; stats 106 '')
 check legacy-nonnumeric fail 'BAD SEQ' < <(stats 106 ''; stats broken '')
 check legacy-initial-zero fail 'BAD SEQ|GP HANG' < <(stats 0 ''; stats 1 '')
 
+check double-adjacent-progress pass < <(stats 9007199254740992 ''; stats 9007199254740993 '')
+check double-adjacent-regression fail 'BAD SEQ' < <(
+	stats 9007199254740993 ''
+	stats 9007199254740992 ''
+)
+check digit-growth-progress pass < <(stats 9 ''; stats 10 '')
+check large-version-regression fail 'BAD SEQ' < <(
+	stats 18446744073709551615 'wgps: 1'
+	stats 18446744073709551614 'wgps: 2'
+)
+
 echo "1..$nchecks"
 test "$nfailed" -eq 0
diff --git a/tools/testing/selftests/rcutorture/bin/parse-console.sh b/tools/testing/selftests/rcutorture/bin/parse-console.sh
index be1e943ca4d5..d63fa43864ad 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-console.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-console.sh
@@ -69,24 +69,39 @@ then
 	sed -e 's/^(initramfs)[^]]*] //' -e 's/^\[[^]]*] //' |
 	sed -e 's/^.*ver: //' |
 	awk '
+	# Compare decimal counters exactly.
+	function countcmp(a, b) {
+		sub(/^0+/, "", a);
+		sub(/^0+/, "", b);
+		if (length(a) != length(b))
+			return length(a) > length(b) ? 1 : -1;
+		if ("x" a == "x" b)
+			return 0;
+		return "x" a > "x" b ? 1 : -1;
+	}
+
 	BEGIN	{
 		ver = 0;
 		badseq = 0;
 		}
 
 		{
-		if (!badseq && ($1 + 0 != $1 || $1 <= ver)) {
+		sub(/\r$/, "");
+		vcmp = countcmp($1, ver);
+		if (!badseq && ($1 !~ /^[0-9]+$/ || vcmp <= 0)) {
 			badseqno1 = ver;
 			badseqno2 = $1;
 			badseqnr = NR;
+			badseq_invalid = $1 !~ /^[0-9]+$/;
 			badseq = 1;
 		}
-		ver = $1
+		ver = $1;
 		}
 
 	END	{
 		if (badseq) {
-			if (badseqno1 == badseqno2 && badseqno2 == ver)
+			if (!badseq_invalid && countcmp(badseqno1, badseqno2) == 0 &&
+			    countcmp(badseqno2, ver) == 0)
 				print "GP HANG at " ver " torture stat " badseqnr;
 			else
 				print "BAD SEQ " badseqno1 ":" badseqno2 " last:" ver " version " badseqnr;
-- 
2.43.0


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

* [PATCH 07/17] rcutorture: Recognize completed writer waits in console logs
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (5 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 06/17] rcutorture: Compare console version counters exactly Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 08/17] rcutorture: Emit the version with the statistics prefix Kunwu Chan
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

A slow expedited wait can span multiple statistics intervals
without advancing ver. Treat changes in wgps as writer progress
when ver stays constant.

Keep support for ver-only logs and test malformed wgps fields and
counter wrap.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 .../bin/parse-console-progress-test.sh        | 40 +++++++++++++++++++
 .../selftests/rcutorture/bin/parse-console.sh | 29 ++++++++++++--
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh b/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
index b9603ce04fce..a01d9e6ad94b 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-console-progress-test.sh
@@ -68,6 +68,29 @@ check legacy-regression fail 'BAD SEQ' < <(stats 107 ''; stats 106 '')
 check legacy-nonnumeric fail 'BAD SEQ' < <(stats 106 ''; stats broken '')
 check legacy-initial-zero fail 'BAD SEQ|GP HANG' < <(stats 0 ''; stats 1 '')
 
+# Constant version with wait progress.
+check burst-progress pass < <(stats 106 'wgps: 840' 73.381162; stats 106 'wgps: 845' 78.506285)
+check first-burst-progress pass < <(stats 0 'wgps: 1'; stats 0 'wgps: 2')
+check serial-crlf pass < <(
+	stats 106 'wgps: 840' | sed 's/$/\r/'
+	stats 106 'wgps: 845' | sed 's/$/\r/'
+)
+check burst-stall fail 'GP HANG' < <(stats 106 'wgps: 840'; stats 106 'wgps: 840')
+check burst-stall-then-recovery fail 'BAD SEQ' < <(
+	stats 106 'wgps: 840'
+	stats 106 'wgps: 840'
+	stats 106 'wgps: 845'
+)
+check burst-initial-stall fail 'BAD SEQ|GP HANG' < <(stats 0 'wgps: 0'; stats 1 'wgps: 1')
+check burst-regression fail 'BAD SEQ' < <(stats 107 'wgps: 840'; stats 106 'wgps: 845')
+check burst-nonnumeric-version fail 'BAD SEQ' < <(stats 106 'wgps: 840'; stats broken 'wgps: 845')
+check other-flavor-progress pass < <(stats 106 'wgps: 0'; stats 107 'wgps: 0')
+check unsigned-wrap pass < <(stats 106 'wgps: 18446744073709551615'; stats 106 'wgps: 0')
+check unsigned-adjacent pass < <(
+	stats 106 'wgps: 18446744073709551614'
+	stats 106 'wgps: 18446744073709551615'
+)
+check counter-decrease pass < <(stats 106 'wgps: 845'; stats 106 'wgps: 5')
 check double-adjacent-progress pass < <(stats 9007199254740992 ''; stats 9007199254740993 '')
 check double-adjacent-regression fail 'BAD SEQ' < <(
 	stats 9007199254740993 ''
@@ -78,6 +101,23 @@ check large-version-regression fail 'BAD SEQ' < <(
 	stats 18446744073709551615 'wgps: 1'
 	stats 18446744073709551614 'wgps: 2'
 )
+check padded-stall fail 'GP HANG' < <(stats 106 'wgps: 007'; stats 106 'wgps: 7')
+
+check missing-first-field fail 'BAD WGPS' < <(stats 106 ''; stats 107 'wgps: 845')
+check missing-later-field fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 '')
+check missing-first-value fail 'BAD WGPS' < <(stats 106 'wgps:'; stats 107 'wgps: 845')
+check missing-later-value fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 'wgps:')
+check malformed-first-value fail 'BAD WGPS' < <(stats 106 'wgps: broken'; stats 107 'wgps: 845')
+check malformed-later-value fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 'wgps: broken')
+check negative-value fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 'wgps: -1')
+check decimal-value fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 'wgps: 845.5')
+check compact-field fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 'wgps:845')
+check duplicate-field fail 'BAD WGPS' < <(stats 106 'wgps: 840'; stats 107 'wgps: 845 wgps: 846')
+check writer-stall-diagnostic fail 'Writer stall state' < <(
+	stats 106 'wgps: 840'
+	stats 106 'wgps: 845'
+	printf '??? Writer stall state RTWS_EXP_SYNC(4)\n'
+)
 
 echo "1..$nchecks"
 test "$nfailed" -eq 0
diff --git a/tools/testing/selftests/rcutorture/bin/parse-console.sh b/tools/testing/selftests/rcutorture/bin/parse-console.sh
index d63fa43864ad..9b08a56a4977 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-console.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-console.sh
@@ -82,26 +82,49 @@ then
 
 	BEGIN	{
 		ver = 0;
+		wgps = 0;
 		badseq = 0;
 		}
 
 		{
 		sub(/\r$/, "");
+		nwgps = 0;
+		wgps_bad = 0;
+		for (i = 2; i <= NF; i++) {
+			if ($i ~ /^wgps:/) {
+				nwgps++;
+				newwgps = $(i + 1);
+				if ($i != "wgps:" || newwgps !~ /^[0-9]+$/)
+					wgps_bad = 1;
+			}
+		}
+		if (NR == 1)
+			has_wgps = nwgps != 0;
+		if (!badwgps && (wgps_bad || nwgps > 1 || has_wgps != (nwgps != 0)))
+			badwgps = NR;
+		# A change in wgps also counts, even on wrap.
 		vcmp = countcmp($1, ver);
-		if (!badseq && ($1 !~ /^[0-9]+$/ || vcmp <= 0)) {
+		if (!badseq && ($1 !~ /^[0-9]+$/ || vcmp < 0 ||
+		    (vcmp == 0 && (!has_wgps || countcmp(newwgps, wgps) == 0)))) {
 			badseqno1 = ver;
 			badseqno2 = $1;
 			badseqnr = NR;
+			badseq_wgps = newwgps;
+			badseq_has_wgps = has_wgps;
 			badseq_invalid = $1 !~ /^[0-9]+$/;
 			badseq = 1;
 		}
 		ver = $1;
+		wgps = newwgps;
 		}
 
 	END	{
-		if (badseq) {
+		if (badwgps) {
+			print "BAD WGPS torture stat " badwgps;
+		} else if (badseq) {
 			if (!badseq_invalid && countcmp(badseqno1, badseqno2) == 0 &&
-			    countcmp(badseqno2, ver) == 0)
+			    countcmp(badseqno2, ver) == 0 &&
+			    (!badseq_has_wgps || countcmp(badseq_wgps, wgps) == 0))
 				print "GP HANG at " ver " torture stat " badseqnr;
 			else
 				print "BAD SEQ " badseqno1 ":" badseqno2 " last:" ver " version " badseqnr;
-- 
2.43.0


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

* [PATCH 08/17] rcutorture: Emit the version with the statistics prefix
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (6 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 07/17] rcutorture: Recognize completed writer waits in console logs Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 09/17] rcutorture: Report completed synchronous writer waits Kunwu Chan
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

The console progress parser matches the suite prefix and ver on the
same line. Emit both with one printk so that a split continuation
cannot separate them.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/rcutorture.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 67fc770abc10..397220ed7064 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -3342,16 +3342,15 @@ rcu_torture_stats_print(void)
 			break;
 	} // Same for "j", for the readers in NMI.
 
-	pr_alert("%s%s ", torture_type, TORTURE_FLAG);
 	rtcp = rcu_access_pointer(rcu_torture_current);
-	pr_cont("rtc: %p %s: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
-		rtcp,
-		rtcp && !rcu_stall_is_suppressed_at_boot() ? "ver" : "VER",
-		rcu_torture_current_version,
-		list_empty(&rcu_torture_freelist),
-		atomic_read(&n_rcu_torture_alloc),
-		atomic_read(&n_rcu_torture_alloc_fail),
-		atomic_read(&n_rcu_torture_free));
+	pr_alert("%s%s rtc: %p %s: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
+		 torture_type, TORTURE_FLAG, rtcp,
+		 rtcp && !rcu_stall_is_suppressed_at_boot() ? "ver" : "VER",
+		 rcu_torture_current_version,
+		 list_empty(&rcu_torture_freelist),
+		 atomic_read(&n_rcu_torture_alloc),
+		 atomic_read(&n_rcu_torture_alloc_fail),
+		 atomic_read(&n_rcu_torture_free));
 	pr_cont("rtmbe: %d rtmbkf: %d/%d rtbe: %ld rtbke: %ld ",
 		atomic_read(&n_rcu_torture_mberror),
 		atomic_read(&n_rcu_torture_mbchk_fail), atomic_read(&n_rcu_torture_mbchk_tries),
-- 
2.43.0


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

* [PATCH 09/17] rcutorture: Report completed synchronous writer waits
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (7 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 08/17] rcutorture: Emit the version with the statistics prefix Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 10/17] rcutorture: Use writer wait counts in kernel stall diagnostics Kunwu Chan
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Count completed do_rtws_sync() operations and report them as wgps
alongside the version.

Read both counters after reading the current object pointer, just
before printing. Otherwise statistics can pair counters sampled
before the per-CPU scan with an object published during the scan.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/rcutorture.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 397220ed7064..8b53a68865fa 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -204,6 +204,8 @@ struct rcu_torture {
 static LIST_HEAD(rcu_torture_freelist);
 static struct rcu_torture __rcu *rcu_torture_current;
 static unsigned long rcu_torture_current_version;
+/* Completed writer wait operations. */
+static unsigned long rcu_torture_writer_gp_completed;
 static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
 static DEFINE_SPINLOCK(rcu_torture_lock);
 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count);
@@ -1808,6 +1810,7 @@ static void do_rtws_sync(struct torture_random_state *trsp, void (*sync)(void))
 		  __func__, sync, cpumask_pr_args(cpu_online_mask));
 	if (dopoll || dopoll_full)
 		cpus_read_unlock();
+	WRITE_ONCE(rcu_torture_writer_gp_completed, rcu_torture_writer_gp_completed + 1);
 }
 
 /*
@@ -3313,6 +3316,8 @@ rcu_torture_stats_print(void)
 	unsigned long nmigrates = 0;
 	unsigned long nups = 0;
 	struct rcu_torture *rtcp;
+	unsigned long version;
+	unsigned long writer_gp;
 	static unsigned long rtcv_snap = ULONG_MAX;
 	static bool splatted;
 	struct task_struct *wtp;
@@ -3343,10 +3348,12 @@ rcu_torture_stats_print(void)
 	} // Same for "j", for the readers in NMI.
 
 	rtcp = rcu_access_pointer(rcu_torture_current);
-	pr_alert("%s%s rtc: %p %s: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
+	version = READ_ONCE(rcu_torture_current_version);
+	writer_gp = READ_ONCE(rcu_torture_writer_gp_completed);
+	pr_alert("%s%s rtc: %p %s: %lu wgps: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
 		 torture_type, TORTURE_FLAG, rtcp,
 		 rtcp && !rcu_stall_is_suppressed_at_boot() ? "ver" : "VER",
-		 rcu_torture_current_version,
+		 version, writer_gp,
 		 list_empty(&rcu_torture_freelist),
 		 atomic_read(&n_rcu_torture_alloc),
 		 atomic_read(&n_rcu_torture_alloc_fail),
@@ -5200,6 +5207,7 @@ rcu_torture_init(void)
 
 	rcu_torture_current = NULL;
 	rcu_torture_current_version = 0;
+	rcu_torture_writer_gp_completed = 0;
 	atomic_set(&n_rcu_torture_alloc, 0);
 	atomic_set(&n_rcu_torture_alloc_fail, 0);
 	atomic_set(&n_rcu_torture_free, 0);
-- 
2.43.0


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

* [PATCH 10/17] rcutorture: Use writer wait counts in kernel stall diagnostics
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (8 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 09/17] rcutorture: Report completed synchronous writer waits Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 11/17] rcutorture: Add consecutive expedited waits per writer iteration Kunwu Chan
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Only diagnose a writer stall when both ver and wgps are unchanged.
Use the samples reported in the console statistics.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/rcutorture.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 8b53a68865fa..3b01c2e5bb5a 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -3319,6 +3319,7 @@ rcu_torture_stats_print(void)
 	unsigned long version;
 	unsigned long writer_gp;
 	static unsigned long rtcv_snap = ULONG_MAX;
+	static unsigned long writer_gp_snap = ULONG_MAX;
 	static bool splatted;
 	struct task_struct *wtp;
 
@@ -3433,7 +3434,7 @@ rcu_torture_stats_print(void)
 
 	if (cur_ops->stats)
 		cur_ops->stats();
-	if (rtcv_snap == rcu_torture_current_version &&
+	if (rtcv_snap == version && writer_gp_snap == writer_gp &&
 	    rcu_access_pointer(rcu_torture_current) &&
 	    !rcu_stall_is_suppressed() &&
 	    rcu_inkernel_boot_has_ended()) {
@@ -3456,7 +3457,8 @@ rcu_torture_stats_print(void)
 			cur_ops->gp_kthread_dbg();
 		rcu_ftrace_dump(DUMP_ALL);
 	}
-	rtcv_snap = rcu_torture_current_version;
+	rtcv_snap = version;
+	writer_gp_snap = writer_gp;
 }
 
 /*
-- 
2.43.0


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

* [PATCH 11/17] rcutorture: Add consecutive expedited waits per writer iteration
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (9 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 10/17] rcutorture: Use writer wait counts in kernel stall diagnostics Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 12/17] rcutorture: Check NMI coverage Kunwu Chan
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

The writer normally delays and publishes a new object between
expedited waits. Allow multiple waits per iteration, defaulting to
one. Advance the retired-object pipeline after every wait.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  5 +++++
 kernel/rcu/rcutorture.c                         | 14 ++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a49523c52c75..b30a473a35a6 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6148,6 +6148,11 @@ Kernel parameters
 	rcutorture.gp_exp= [KNL]
 			Use expedited update-side primitives, if available.
 
+	rcutorture.gp_exp_burst= [KNL]
+			Number of consecutive synchronous expedited waits
+			per writer iteration.  Defaults to one; values below
+			one also perform one update.
+
 	rcutorture.gp_normal= [KNL]
 			Use normal (non-expedited) asynchronous
 			update-side primitives, if available.
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 3b01c2e5bb5a..8905abe8725e 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -102,6 +102,7 @@ torture_param(int, gp_cond_wi, 16 * USEC_PER_SEC / HZ,
 torture_param(int, gp_cond_wi_exp, 128,
 		   "Wait interval for expedited conditional grace periods, us (default 128 us)");
 torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
+torture_param(int, gp_exp_burst, 1, "Number of consecutive expedited waits (minimum 1)");
 torture_param(bool, gp_normal, false, "Use normal (non-expedited) GP wait primitives");
 torture_param(bool, gp_poll, false, "Use polling GP wait primitives");
 torture_param(bool, gp_poll_exp, false, "Use polling expedited GP wait primitives");
@@ -1963,8 +1964,14 @@ rcu_torture_writer(void *arg)
 				break;
 			case RTWS_EXP_SYNC:
 				rcu_torture_writer_state = RTWS_EXP_SYNC;
+				/* Retire the old object even at shutdown. */
 				do_rtws_sync(&rand, cur_ops->exp_sync);
 				rcu_torture_pipe_update(old_rp);
+				for (i = 1; i < gp_exp_burst && !torture_must_stop(); i++) {
+					cond_resched();
+					do_rtws_sync(&rand, cur_ops->exp_sync);
+					rcu_torture_pipe_update(NULL);
+				}
 				break;
 			case RTWS_COND_GET:
 				rcu_torture_writer_state = RTWS_COND_GET;
@@ -3531,8 +3538,7 @@ static void rcu_torture_mem_dump_obj(void)
 static void
 rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
 {
-	pr_alert("%s" TORTURE_FLAG
-		 "--- %s: nreaders=%d nwriters=%d nfakewriters=%d "
+	pr_alert("%s%s--- %s: nreaders=%d nwriters=%d nfakewriters=%d gp_exp_burst=%d "
 		 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
 		 "shuffle_interval=%d stutter=%d irqreader=%d "
 		 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
@@ -3547,8 +3553,8 @@ rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
 		 "nocbs_nthreads=%d nocbs_toggle=%d "
 		 "test_nmis=%d nmi_calls=%d "
 		 "preempt_duration=%d preempt_interval=%d n_up_down=%d\n",
-		 torture_type, tag, nrealreaders, nwriters, nrealfakewriters,
-		 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
+		 torture_type, TORTURE_FLAG, tag, nrealreaders, nwriters, nrealfakewriters,
+		 gp_exp_burst, stat_interval, verbose, test_no_idle_hz, shuffle_interval,
 		 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
 		 test_boost, cur_ops->can_boost,
 		 test_boost_interval, test_boost_duration, test_boost_holdoff, shutdown_secs,
-- 
2.43.0


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

* [PATCH 12/17] rcutorture: Check NMI coverage
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (10 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 11/17] rcutorture: Add consecutive expedited waits per writer iteration Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 13/17] rcutorture: Test NMI coverage result classification Kunwu Chan
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Periodic statistics use printk continuations and can split across
console lines. Emit a single NMI coverage summary after the perf
events and statistics thread stop and the callback barrier completes.

Require one valid summary followed by SUCCESS from the same flavor.
Return 0 if the requested coverage is present or 4 if it is absent.
Return 1 if the record is invalid or missing, or the run failed.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/rcu/rcutorture.c                       | 22 ++++++
 .../rcutorture/bin/kvm-recheck-nmi.sh         | 72 +++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 8905abe8725e..60c2f4cdccc6 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -3468,6 +3468,27 @@ rcu_torture_stats_print(void)
 	writer_gp_snap = writer_gp;
 }
 
+/* Print one complete record after the NMI sources stop and callbacks drain. */
+static void rcu_torture_nmi_coverage_print(void)
+{
+	unsigned long count, samples = 0;
+	unsigned int too_old = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(rcu_torture_nmi_pipe); i++) {
+		count = atomic_long_read(&rcu_torture_nmi_pipe[i]);
+		samples += count;
+		if (i > 1 && count)
+			too_old = 1;
+	}
+	pr_alert("%s%s NMI coverage: reads=%lu samples=%lu too-old=%u calls=%lu callbacks=%lu\n",
+		 torture_type, TORTURE_FLAG,
+		 (unsigned long)atomic_long_read(&n_rcu_torture_nmi_read),
+		 samples, too_old,
+		 (unsigned long)atomic_long_read(&n_rcu_torture_nmi_call),
+		 (unsigned long)atomic_long_read(&n_rcu_torture_nmi_cb));
+}
+
 /*
  * Periodically prints torture statistics, if periodic statistics printing
  * was specified via the stat_interval module parameter.
@@ -4730,6 +4751,7 @@ rcu_torture_cleanup(void)
 	rcu_torture_mem_dump_obj();
 
 	rcu_torture_stats_print();  /* -After- the stats thread is stopped! */
+	rcu_torture_nmi_coverage_print();
 
 	if (err_segs_recorded) {
 		pr_alert("Failure/close-call rcutorture reader segments:\n");
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh
new file mode 100755
index 000000000000..8a0e2fbc0660
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Usage: kvm-recheck-nmi.sh resdir [readers|calls|both]
+# Exit codes are 0 for coverage, 1 for failure, and 4 for untested.
+#
+# Author: Kunwu Chan <kunwu.chan@gmail.com>
+
+resdir="${1-}"
+mode="${2-both}"
+case "$mode" in
+readers|calls|both) ;;
+*) echo "Usage: $0 resdir [readers|calls|both]" >&2; exit 1 ;;
+esac
+if test -z "$resdir" || test ! -f "$resdir/console.log" ||
+   test ! -r "$resdir/console.log"
+then
+	echo "FAIL: unreadable console.log in $resdir" >&2
+	exit 1
+fi
+
+LC_ALL=C awk -v mode="$mode" '
+function fail(message) { print "FAIL: " message; exit 1 }
+function skip(message) { print "SKIP: " message; exit 4 }
+{
+	sub(/\r$/, "")
+	sub(/^\[[[:space:]]*[0-9]+\.[0-9]+\][[:space:]]*/, "")
+	sub(/^\[[[:space:]]*[CT][0-9]+\][[:space:]]*/, "")
+}
+/printk messages dropped/ { dropped = 1 }
+/^[^[:space:]]+-torture:[[:space:]]+NMI coverage:([[:space:]]|$)/ {
+	if (++summaries != 1 || results || NF != 8 ||
+	    $4 !~ /^reads=(0|[1-9][0-9]*)$/ ||
+	    $5 !~ /^samples=(0|[1-9][0-9]*)$/ ||
+	    $6 !~ /^too-old=[01]$/ ||
+	    $7 !~ /^calls=(0|[1-9][0-9]*)$/ ||
+	    $8 !~ /^callbacks=(0|[1-9][0-9]*)$/) {
+		malformed = 1
+		next
+	}
+	flavor = $1
+	reads = substr($4, 7)
+	samples = substr($5, 9)
+	too_old = ($6 == "too-old=1")
+	calls = substr($7, 7)
+	callbacks = substr($8, 11)
+}
+/^[^[:space:]]+-torture:(---)?[[:space:]]+End of test:/ {
+	result_flavor = $1
+	sub(/---$/, "", result_flavor)
+	if (++results != 1 || result_flavor != flavor || $5 !~ /^SUCCESS:?$/)
+		bad_result = 1
+}
+END {
+	if (dropped) fail("console reports dropped printk messages")
+	if (!summaries) fail("missing final NMI coverage summary")
+	if (malformed) fail("invalid, duplicate or misplaced NMI coverage summary")
+	if (bad_result || !results) fail("missing matching successful test completion")
+	if (too_old) fail("NMI reader observed a too-old object")
+	# Compare decimal strings exactly, including counts beyond awk precision.
+	if (length(samples) > length(reads) ||
+	    (length(samples) == length(reads) && "n" samples > "n" reads))
+		fail("NMI object samples exceed reader count")
+	if (mode != "readers" && "n" calls != "n" callbacks)
+		fail("NMI callback count differs after cleanup")
+	if (mode != "calls" && samples == "0")
+		skip("no protected object sampled from NMI")
+	if (mode != "readers" && calls == "0")
+		skip("no callback submitted from NMI")
+	printf "PASS: NMI reads=%s object-samples=%s calls=%s callbacks=%s\n", \
+		reads, samples, calls, callbacks
+}' < "$resdir/console.log"
-- 
2.43.0


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

* [PATCH 13/17] rcutorture: Test NMI coverage result classification
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (11 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 12/17] rcutorture: Check NMI coverage Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 14/17] rcutorture: Test NMI summary field validation Kunwu Chan
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Verify the NMI checker in readers, calls and both modes.  Cover
unexercised paths, readers that did not sample an object, too-old object
samples and callback counts that disagree after cleanup.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 .../rcutorture/bin/kvm-recheck-nmi-test.sh    | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
new file mode 100755
index 000000000000..5a3acea8c60b
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+# Exercise the NMI coverage checker, including untested and broken cases.
+#
+# Author: Kunwu Chan <kunwu.chan@gmail.com>
+
+bindir="$(dirname "$0")"
+t="$(mktemp -d "${TMPDIR-/tmp}/kvm-recheck-nmi-test.XXXXXX")" || exit 1
+trap 'rm -rf "$t"' EXIT
+nfailed=0
+ntested=0
+
+check () {
+	local name="$1" expected="$2" mode="$3" actual
+	ntested=$((ntested + 1))
+	cat > "$t/console.log"
+	bash "$bindir/kvm-recheck-nmi.sh" "$t" "$mode" > "$t/output" 2>&1
+	actual=$?
+	if test "$actual" -ne "$expected"
+	then
+		echo "FAIL: $name returned $actual, expected $expected"
+		cat "$t/output"
+		nfailed=$((nfailed + 1))
+	fi
+}
+
+check covered 0 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check no-nmi 4 both <<'EOF'
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=0 callbacks=0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check callbacks-only-not-readers 4 both <<'EOF'
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check readers-only-not-callbacks 4 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check no-object-sample 4 readers <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=0 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check readers-only 0 readers <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check callbacks-only 0 calls <<'EOF'
+rcu-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=2 callbacks=2
+rcu-torture:--- End of test: SUCCESS
+EOF
+check too-old 1 readers <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=1 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check too-old-in-calls-mode 1 calls <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=1 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check missing-callback 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=1
+srcud-torture:--- End of test: SUCCESS
+EOF
+check missing-callback-without-readers 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=2 callbacks=1
+srcud-torture:--- End of test: SUCCESS
+EOF
+check excess-callback 1 calls <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=1
+srcud-torture:--- End of test: SUCCESS
+EOF
+
+if test "$nfailed" -ne 0
+then
+	exit 1
+fi
+echo "PASS: $ntested NMI coverage checker cases"
-- 
2.43.0


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

* [PATCH 14/17] rcutorture: Test NMI summary field validation
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (12 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 13/17] rcutorture: Test NMI coverage result classification Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 15/17] rcutorture: Test NMI console-log boundaries Kunwu Chan
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Check summary field syntax, sample totals and callback counts,
including decimal values beyond awk's exact numeric range.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 .../rcutorture/bin/kvm-recheck-nmi-test.sh    | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
index 5a3acea8c60b..2a37d9a25747 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
@@ -73,6 +73,47 @@ srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=1
 srcud-torture:--- End of test: SUCCESS
 EOF
 
+check missing-callback-count 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check duplicate-field 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2 calls=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check malformed-counter 1 calls <<'EOF'
+srcud-torture: NMI coverage: reads=broken samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check negative-counter 1 readers <<'EOF'
+srcud-torture: NMI coverage: reads=100 samples=-1 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check invalid-too-old-flag 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=2 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check excess-object-samples 1 readers <<'EOF'
+srcud-torture: NMI coverage: reads=1 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+
+# Adjacent integers across awk's double-precision boundary.
+exact_count=9007199254740992
+next_count=9007199254740993
+check large-callback-count-match 0 calls <<EOF
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=$next_count callbacks=$next_count
+srcud-torture:--- End of test: SUCCESS
+EOF
+check large-callback-count-mismatch 1 calls <<EOF
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=$exact_count callbacks=$next_count
+srcud-torture:--- End of test: SUCCESS
+EOF
+check large-sample-count-exceeds-reads 1 readers <<EOF
+srcud-torture: NMI coverage: reads=$exact_count samples=$next_count too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+
 if test "$nfailed" -ne 0
 then
 	exit 1
-- 
2.43.0


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

* [PATCH 15/17] rcutorture: Test NMI console-log boundaries
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (13 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 14/17] rcutorture: Test NMI summary field validation Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 16/17] rcutorture: Document how to check SRCU NMI coverage Kunwu Chan
  2026-12-01 16:18 ` [PATCH 17/17] rcutorture: Document directed SRCU NMI tests Kunwu Chan
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Verify that the checker requires one complete NMI coverage summary
before the matching successful test result.  Reject logs that report
dropped printk records or duplicate test results.  Accept a split
periodic histogram when the final summary and result are intact.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 .../rcutorture/bin/kvm-recheck-nmi-test.sh    | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
index 2a37d9a25747..c674ed2c4eaf 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
@@ -114,6 +114,57 @@ srcud-torture: NMI coverage: reads=$exact_count samples=$next_count too-old=0 ca
 srcud-torture:--- End of test: SUCCESS
 EOF
 
+check duplicate-test-result 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+srcud-torture:--- End of test: SUCCESS
+EOF
+check incomplete-run 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+EOF
+check failed-run 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: FAILURE
+EOF
+check missing-final-summary 1 both <<'EOF'
+srcud-torture: rtc: 1234 ver: 1 nmi-calls: 2 nmi-cbs: 2 nmi-reads: 3
+srcud-torture: NMI Reader Pipe: 2 1 0 0 0 0 0 0 0 0 0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check duplicate-final-summary 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check valid-summary-after-malformed-summary 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=broken samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check summary-after-success 1 both <<'EOF'
+srcud-torture:--- End of test: SUCCESS
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+EOF
+check different-flavor-success 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+rcu-torture:--- End of test: SUCCESS
+EOF
+check printk-records-dropped 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+** 3 printk messages dropped **
+srcud-torture:--- End of test: SUCCESS
+EOF
+check split-periodic-pipe 0 both < <(printf '%s %s\r\n' \
+	'[    5.000000][    T1]' \
+	'srcud-torture: rtc: 1234 ver: 1 nmi-calls: 2 nmi-cbs: 1 nmi-reads: 3' \
+	'[    5.000001][    T1]' 'srcud-torture: NMI Reader Pipe: 2 1 0 0 0' \
+	'[    5.000002][    C1]' 'other kernel message' \
+	'[    5.000003][    T1]' '0 0 0 0 0 0' \
+	'[    6.000000][    T1]' 'rcu_torture_cleanup: Invoking srcu_barrier().' \
+	'[    6.000001][    T1]' \
+	'srcud-torture: NMI coverage: reads=6 samples=6 too-old=0 calls=2 callbacks=2' \
+	'[    6.000002][    T1]' 'srcud-torture:--- End of test: SUCCESS: nreaders=4')
+
 if test "$nfailed" -ne 0
 then
 	exit 1
-- 
2.43.0


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

* [PATCH 16/17] rcutorture: Document how to check SRCU NMI coverage
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (14 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 15/17] rcutorture: Test NMI console-log boundaries Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  2026-12-01 16:18 ` [PATCH 17/17] rcutorture: Document directed SRCU NMI tests Kunwu Chan
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Describe how to enable the guest PMU, run the coverage checker and
confirm that a PMU-off run reports SKIP. The x86 KVM example uses
the separate QEMU CPU-selection fix. The same methodology applies
on arm64 KVM; adjust the QEMU CPU option accordingly.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 Documentation/RCU/torture.rst | 52 +++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/Documentation/RCU/torture.rst b/Documentation/RCU/torture.rst
index 1ad5cc793811..d6fcc900ccab 100644
--- a/Documentation/RCU/torture.rst
+++ b/Documentation/RCU/torture.rst
@@ -304,6 +304,58 @@ the following summary at the end of the run on a 12-CPU system::
     TREE09 ------- 752238 GPs (139.303/s) [rcu: g13075057 f0x0 ] n_max_cbs: 99011
 
 
+Checking NMI coverage
+=====================
+
+NMI-safe SRCU readers can run from the per-CPU perf-counter NMI.  This
+needs a guest PMU because the test uses perf counters to generate NMIs.  The x86 KVM example below requires the
+separate rcutorture fix that honors an explicit QEMU CPU selection.
+Check the saved ``qemu-cmd`` to verify the effective CPU option.
+For example, an ordinary expedited SRCU run can use::
+
+    kvm.sh --configs SRCU-P --cpus 4 --duration 5m \
+        --kconfig 'CONFIG_FORCE_NEED_SRCU_NMI_SAFE=y' \
+        --qemu-args '-cpu host,pmu=on' \
+        --bootargs "rcutorture.reader_flavor=0x2 rcutorture.gp_exp=1 \
+                    rcutorture.nmi_readers=1 rcutorture.nmi_calls=1 \
+                    rcupdate.rcu_normal=0 rcupdate.rcu_normal_after_boot=0 \
+                    srcutree.convert_to_big=0" \
+        --datestamp srcu-exp-nmi-small
+
+Use ``srcutree.convert_to_big=1`` and a fresh ``--datestamp`` for BIG.  ``reader_flavor=0x2`` selects
+full-barrier NMI-safe readers in place of SRCU-P's default FAST_UPDOWN.
+The expedited updater runs in task context.
+
+In addition to the normal result checks, require actual NMI coverage::
+
+    kvm-recheck-nmi.sh \
+        tools/testing/selftests/rcutorture/res/srcu-exp-nmi-small/SRCU-P both
+
+After stopping the NMI producers and the statistics thread and draining
+callbacks, the kernel prints a final ``NMI coverage:`` record.  The checker
+requires exactly one complete record before the same flavor reports
+``End of test: SUCCESS``.  It returns 1 for failure or a missing, invalid
+or duplicate record, including when the kernel predates this record.
+
+``readers`` requires samples of protected objects, ``calls`` requires
+nonzero callback submissions and the same number of completions, and
+``both`` requires both.  All modes reject samples of objects that have
+passed through two or more grace periods.  The checker returns 0 when the
+requested coverage was observed, or 4 when the run succeeded with valid
+statistics but the requested activity was absent.  Use the normal console
+checks for general kernel diagnostics.  See NMI Reader Batch in the
+console log for close-call analysis.
+
+Observe fastpath hits separately.  To check autonomous callback
+progress, observe completion before the cleanup barrier.
+
+For the PMU-off control, rerun kvm.sh with ``-cpu host,pmu=off`` and a
+fresh ``--datestamp``.  If torture reports SUCCESS, expect a zero-count
+summary and SKIP from the coverage checker.
+Check a fresh run's QEMU arguments because
+``kvm-again.sh`` reuses the saved ``qemu-cmd``.
+
+
 Repeated Runs
 =============
 
-- 
2.43.0


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

* [PATCH 17/17] rcutorture: Document directed SRCU NMI tests
  2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
                   ` (15 preceding siblings ...)
  2026-12-01 16:18 ` [PATCH 16/17] rcutorture: Document how to check SRCU NMI coverage Kunwu Chan
@ 2026-12-01 16:18 ` Kunwu Chan
  16 siblings, 0 replies; 18+ messages in thread
From: Kunwu Chan @ 2026-12-01 16:18 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: dwmw2, jiangshanlai, josh, work, rostedt, mathieu.desnoyers,
	dave, jfern, frederic, neeraj.upadhyay, boqun, urezki,
	qiang.zhang, puranjay, shuah, linux-kernel, linux-kselftest,
	Kunwu Chan

Describe the idle and loaded workloads and reader-flavor matrix.
Explain how to read ver and wgps in a burst. Note that irqsave
readers require task context and are not exercised from NMI.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 Documentation/RCU/torture.rst | 49 +++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/Documentation/RCU/torture.rst b/Documentation/RCU/torture.rst
index d6fcc900ccab..791774698440 100644
--- a/Documentation/RCU/torture.rst
+++ b/Documentation/RCU/torture.rst
@@ -349,6 +349,55 @@ console log for close-call analysis.
 Observe fastpath hits separately.  To check autonomous callback
 progress, observe completion before the cleanup barrier.
 
+For a synchronous expedited update, ``rcutorture.gp_exp_burst=N`` is
+the per-iteration limit of waits when the writer selects the
+synchronous expedited operation.  ``ver`` counts completed update
+iterations and ``wgps`` counts completed synchronous waits.  Choose a
+statistics interval that accommodates stutter and slow readers.
+
+An idle-biased NMI reader run can add the following boot arguments to the
+ordinary expedited example::
+
+    rcutorture.gp_exp_burst=64 rcutorture.nreaders=0
+    rcutorture.nfakewriters=0 rcutorture.n_up_down=0
+    rcutorture.read_exit_burst=0 rcutorture.fwd_progress=0
+    rcutorture.irqreader=0 rcutorture.stutter=0 rcutorture.n_barrier_cbs=0
+
+Keep a loaded run with task readers and callbacks enabled.  Test reader
+flavors separately.  The atomic cases exercise a separate updater.
+
+.. list-table:: Directed SRCU NMI coverage
+   :header-rows: 1
+
+   * - Case
+     - Configuration and workload
+     - NMI checker mode
+   * - Ordinary expedited
+     - Flavor 0x2; SMALL and BIG; NEED_SRCU_NMI_SAFE disabled and enabled
+     - both
+   * - FAST fallback
+     - Flavor 0x4; PROVE_RCU disabled; synchronous expedited updates
+     - both
+   * - FAST_UPDOWN fallback
+     - Flavor 0x8; PROVE_RCU disabled; NMI readers unsupported
+     - calls
+   * - Atomic regression
+     - Flavor 0x10; atomic_irqsave=0 and 1; both counter implementations
+     - readers
+   * - Tiny atomic regression
+     - SRCU-T; flavor 0x10; atomic_irqsave=1; PREEMPTION enabled
+     - readers
+
+Keep task readers enabled to exercise the irqsave variant.  NMI
+readers always use the plain atomic API.  A ``readers`` PASS with
+no task readers validates only the NMI atomic reader, not the
+irqsave variant.
+
+On x86, toggle ``CONFIG_FORCE_NEED_SRCU_NMI_SAFE`` to exercise
+``this_cpu_inc()`` and atomic increments.  Verify ``CONFIG_NEED_SRCU_NMI_SAFE``
+in the built configuration.  FAST readers have a different ordering
+contract and fall back to the worker.
+
 For the PMU-off control, rerun kvm.sh with ``-cpu host,pmu=off`` and a
 fresh ``--datestamp``.  If torture reports SUCCESS, expect a zero-count
 summary and SKIP from the coverage checker.
-- 
2.43.0


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

end of thread, other threads:[~2026-12-01 16:20 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 16:17 [PATCH 00/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
2026-12-01 16:17 ` [PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper Kunwu Chan
2026-12-01 16:18 ` [PATCH 02/17] srcu: Let GP completion take a size-state snapshot Kunwu Chan
2026-12-01 16:18 ` [PATCH 03/17] srcu: Try idle expedited GPs in the caller Kunwu Chan
2026-12-01 16:18 ` [PATCH 04/17] srcu: Check only the boot CPU callback queue in SMALL domains Kunwu Chan
2026-12-01 16:18 ` [PATCH 05/17] rcutorture: Add selftests for console writer progress Kunwu Chan
2026-12-01 16:18 ` [PATCH 06/17] rcutorture: Compare console version counters exactly Kunwu Chan
2026-12-01 16:18 ` [PATCH 07/17] rcutorture: Recognize completed writer waits in console logs Kunwu Chan
2026-12-01 16:18 ` [PATCH 08/17] rcutorture: Emit the version with the statistics prefix Kunwu Chan
2026-12-01 16:18 ` [PATCH 09/17] rcutorture: Report completed synchronous writer waits Kunwu Chan
2026-12-01 16:18 ` [PATCH 10/17] rcutorture: Use writer wait counts in kernel stall diagnostics Kunwu Chan
2026-12-01 16:18 ` [PATCH 11/17] rcutorture: Add consecutive expedited waits per writer iteration Kunwu Chan
2026-12-01 16:18 ` [PATCH 12/17] rcutorture: Check NMI coverage Kunwu Chan
2026-12-01 16:18 ` [PATCH 13/17] rcutorture: Test NMI coverage result classification Kunwu Chan
2026-12-01 16:18 ` [PATCH 14/17] rcutorture: Test NMI summary field validation Kunwu Chan
2026-12-01 16:18 ` [PATCH 15/17] rcutorture: Test NMI console-log boundaries Kunwu Chan
2026-12-01 16:18 ` [PATCH 16/17] rcutorture: Document how to check SRCU NMI coverage Kunwu Chan
2026-12-01 16:18 ` [PATCH 17/17] rcutorture: Document directed SRCU NMI tests 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®