Skip to content

Commit d685514

Browse files
committed
rcutorture: Allow pointer leaks to test diagnostic code
This commit adds an rcutorture.leakpointer module parameter that intentionally leaks an RCU-protected pointer out of the RCU read-side critical section and checks to see if the corresponding grace period has elapsed, emitting a WARN_ON_ONCE() if so. This module parameter can be used to test facilities like CONFIG_RCU_STRICT_GRACE_PERIOD that end grace periods quickly. While in the area, also document rcutorture.irqreader, which was previously left out. Reported-by Jann Horn <jannh@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 299c7d9 commit d685514

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4269,6 +4269,18 @@
42694269
are zero, rcutorture acts as if is interpreted
42704270
they are all non-zero.
42714271

4272+
rcutorture.irqreader= [KNL]
4273+
Run RCU readers from irq handlers, or, more
4274+
accurately, from a timer handler. Not all RCU
4275+
flavors take kindly to this sort of thing.
4276+
4277+
rcutorture.leakpointer= [KNL]
4278+
Leak an RCU-protected pointer out of the reader.
4279+
This can of course result in splats, and is
4280+
intended to test the ability of things like
4281+
CONFIG_RCU_STRICT_GRACE_PERIOD=y to detect
4282+
such leaks.
4283+
42724284
rcutorture.n_barrier_cbs= [KNL]
42734285
Set callbacks/threads for rcu_barrier() testing.
42744286

kernel/rcu/rcutorture.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ torture_param(bool, gp_normal, false,
8787
"Use normal (non-expedited) GP wait primitives");
8888
torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
8989
torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
90+
torture_param(int, leakpointer, 0, "Leak pointer dereferences from readers");
9091
torture_param(int, n_barrier_cbs, 0,
9192
"# of callbacks/kthreads for barrier testing");
9293
torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
@@ -1401,6 +1402,9 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp)
14011402
preempt_enable();
14021403
rcutorture_one_extend(&readstate, 0, trsp, rtrsp);
14031404
WARN_ON_ONCE(readstate & RCUTORTURE_RDR_MASK);
1405+
// This next splat is expected behavior if leakpointer, especially
1406+
// for CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels.
1407+
WARN_ON_ONCE(leakpointer && READ_ONCE(p->rtort_pipe_count) > 1);
14041408

14051409
/* If error or close call, record the sequence of reader protections. */
14061410
if ((pipe_count > 1 || completed > 1) && !xchg(&err_segs_recorded, 1)) {

0 commit comments

Comments
 (0)