Skip to content

Commit 0f38c06

Browse files
paulmckrcuurezki
authored andcommitted
rcutorture: Check preemption for failing reader
This commit checks to see if the RCU reader has been preempted within its read-side critical section for RCU flavors supporting this notion (currently only preemptible RCU). If such a preemption occurred, then this is printed at the end of the "Failure/close-call rcutorture reader segments" list at the end of the rcutorture run. [ paulmck: Apply kernel test robot feedback. ] Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Frederic Weisbecker <frederic@kernel.org> Tested-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
1 parent 4569cf6 commit 0f38c06

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/linux/rcupdate_wait.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ static inline void cond_resched_rcu(void)
6565
#endif
6666
}
6767

68+
// Has the current task blocked within its current RCU read-side
69+
// critical section?
70+
static inline bool has_rcu_reader_blocked(void)
71+
{
72+
#ifdef CONFIG_PREEMPT_RCU
73+
return !list_empty(&current->rcu_node_entry);
74+
#else
75+
return false;
76+
#endif
77+
}
78+
6879
#endif /* _LINUX_SCHED_RCUPDATE_WAIT_H */

kernel/rcu/rcutorture.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ struct rt_read_seg {
267267
static int err_segs_recorded;
268268
static struct rt_read_seg err_segs[RCUTORTURE_RDR_MAX_SEGS];
269269
static int rt_read_nsegs;
270+
static int rt_read_preempted;
270271

271272
static const char *rcu_torture_writer_state_getname(void)
272273
{
@@ -394,6 +395,7 @@ struct rcu_torture_ops {
394395
void (*get_gp_data)(int *flags, unsigned long *gp_seq);
395396
void (*gp_slow_register)(atomic_t *rgssp);
396397
void (*gp_slow_unregister)(atomic_t *rgssp);
398+
bool (*reader_blocked)(void);
397399
long cbflood_max;
398400
int irq_capable;
399401
int can_boost;
@@ -587,6 +589,9 @@ static struct rcu_torture_ops rcu_ops = {
587589
.get_gp_data = rcutorture_get_gp_data,
588590
.gp_slow_register = rcu_gp_slow_register,
589591
.gp_slow_unregister = rcu_gp_slow_unregister,
592+
.reader_blocked = IS_ENABLED(CONFIG_RCU_TORTURE_TEST_LOG_CPU)
593+
? has_rcu_reader_blocked
594+
: NULL,
590595
.irq_capable = 1,
591596
.can_boost = IS_ENABLED(CONFIG_RCU_BOOST),
592597
.extendables = RCUTORTURE_MAX_EXTEND,
@@ -2035,6 +2040,7 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid)
20352040
int newstate;
20362041
struct rcu_torture *p;
20372042
int pipe_count;
2043+
bool preempted = false;
20382044
int readstate = 0;
20392045
struct rt_read_seg rtseg[RCUTORTURE_RDR_MAX_SEGS] = { { 0 } };
20402046
struct rt_read_seg *rtrsp = &rtseg[0];
@@ -2100,6 +2106,8 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid)
21002106
rcu_torture_writer_state,
21012107
cpumask_pr_args(cpu_online_mask));
21022108
}
2109+
if (cur_ops->reader_blocked)
2110+
preempted = cur_ops->reader_blocked();
21032111
rcutorture_one_extend(&readstate, 0, trsp, rtrsp);
21042112
WARN_ON_ONCE(readstate);
21052113
// This next splat is expected behavior if leakpointer, especially
@@ -2112,6 +2120,7 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid)
21122120
for (rtrsp1 = &rtseg[0]; rtrsp1 < rtrsp; rtrsp1++)
21132121
err_segs[i++] = *rtrsp1;
21142122
rt_read_nsegs = i;
2123+
rt_read_preempted = preempted;
21152124
}
21162125

21172126
return true;
@@ -3569,6 +3578,8 @@ rcu_torture_cleanup(void)
35693578
pr_cont("\n");
35703579

35713580
}
3581+
if (rt_read_preempted)
3582+
pr_alert("\tReader was preempted.\n");
35723583
}
35733584
if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
35743585
rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");

0 commit comments

Comments
 (0)