[PATCH 16/17] rcutorture: Document how to check SRCU NMI coverage

From: Kunwu Chan

Date: Tue Dec 01 2026 - 11:21:57 EST


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@xxxxxxxxx>
---
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