Skip to content

Commit b0e165c

Browse files
paulmckIngo Molnar
authored andcommitted
rcu: Add debug checks to TREE_PREEMPT_RCU for premature grace periods
Check to make sure that there are no blocked tasks for the previous grace period while initializing for the next grace period, verify that rcu_preempt_qs() is given the correct CPU number and is never called for an offline CPU. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: laijs@cn.fujitsu.com Cc: dipankar@in.ibm.com Cc: akpm@linux-foundation.org Cc: mathieu.desnoyers@polymtl.ca Cc: josh@joshtriplett.org Cc: dvhltc@us.ibm.com Cc: niv@us.ibm.com Cc: peterz@infradead.org Cc: rostedt@goodmis.org Cc: Valdis.Kletnieks@vt.edu LKML-Reference: <12528585111986-git-send-email-> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent bbe3eae commit b0e165c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

kernel/rcutree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
632632
/* Special-case the common single-level case. */
633633
if (NUM_RCU_NODES == 1) {
634634
rnp->qsmask = rnp->qsmaskinit;
635+
rcu_preempt_check_blocked_tasks(rnp);
635636
rnp->gpnum = rsp->gpnum;
636637
rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */
637638
spin_unlock_irqrestore(&rnp->lock, flags);
@@ -665,6 +666,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
665666
for (rnp_cur = &rsp->node[0]; rnp_cur < rnp_end; rnp_cur++) {
666667
spin_lock(&rnp_cur->lock); /* irqs already disabled. */
667668
rnp_cur->qsmask = rnp_cur->qsmaskinit;
669+
rcu_preempt_check_blocked_tasks(rnp);
668670
rnp->gpnum = rsp->gpnum;
669671
spin_unlock(&rnp_cur->lock); /* irqs already disabled. */
670672
}

kernel/rcutree_plugin.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static void rcu_preempt_qs(int cpu)
8686

8787
if (t->rcu_read_lock_nesting &&
8888
(t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
89+
WARN_ON_ONCE(cpu != smp_processor_id());
8990

9091
/* Possibly blocking in an RCU read-side critical section. */
9192
rdp = rcu_preempt_state.rda[cpu];
@@ -103,7 +104,11 @@ static void rcu_preempt_qs(int cpu)
103104
* state for the current grace period), then as long
104105
* as that task remains queued, the current grace period
105106
* cannot end.
107+
*
108+
* But first, note that the current CPU must still be
109+
* on line!
106110
*/
111+
WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0);
107112
phase = !(rnp->qsmask & rdp->grpmask) ^ (rnp->gpnum & 0x1);
108113
list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]);
109114
smp_mb(); /* Ensure later ctxt swtch seen after above. */
@@ -258,6 +263,18 @@ static void rcu_print_task_stall(struct rcu_node *rnp)
258263

259264
#endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
260265

266+
/*
267+
* Check that the list of blocked tasks for the newly completed grace
268+
* period is in fact empty. It is a serious bug to complete a grace
269+
* period that still has RCU readers blocked! This function must be
270+
* invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock
271+
* must be held by the caller.
272+
*/
273+
static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
274+
{
275+
WARN_ON_ONCE(!list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]));
276+
}
277+
261278
/*
262279
* Check for preempted RCU readers for the specified rcu_node structure.
263280
* If the caller needs a reliable answer, it must hold the rcu_node's
@@ -450,6 +467,14 @@ static void rcu_print_task_stall(struct rcu_node *rnp)
450467

451468
#endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
452469

470+
/*
471+
* Because there is no preemptable RCU, there can be no readers blocked,
472+
* so there is no need to check for blocked tasks.
473+
*/
474+
static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
475+
{
476+
}
477+
453478
/*
454479
* Because preemptable RCU does not exist, there are never any preempted
455480
* RCU readers.

0 commit comments

Comments
 (0)