Skip to content

Commit 28ecd58

Browse files
paulmckIngo Molnar
authored andcommitted
rcu: Add WARN_ON_ONCE() consistency checks covering state transitions
o Verify that qsmask bits stay clear through GP initialization. o Verify that cpu_quiet_msk_finish() is never invoked unless there actually is an RCU grace period in progress. o Verify that all internal-node rcu_node structures have empty blocked_tasks[] lists. o Verify that child rcu_node structure's bits remain clear after acquiring parent's lock. 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: <12532926191947-git-send-email-> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 16e3081 commit 28ecd58

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

kernel/rcutree.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
628628

629629
/* Special-case the common single-level case. */
630630
if (NUM_RCU_NODES == 1) {
631-
rnp->qsmask = rnp->qsmaskinit;
632631
rcu_preempt_check_blocked_tasks(rnp);
632+
rnp->qsmask = rnp->qsmaskinit;
633633
rnp->gpnum = rsp->gpnum;
634634
rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */
635635
spin_unlock_irqrestore(&rnp->lock, flags);
@@ -662,8 +662,8 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
662662
rnp_end = &rsp->node[NUM_RCU_NODES];
663663
for (rnp_cur = &rsp->node[0]; rnp_cur < rnp_end; rnp_cur++) {
664664
spin_lock(&rnp_cur->lock); /* irqs already disabled. */
665-
rnp_cur->qsmask = rnp_cur->qsmaskinit;
666665
rcu_preempt_check_blocked_tasks(rnp);
666+
rnp_cur->qsmask = rnp_cur->qsmaskinit;
667667
rnp->gpnum = rsp->gpnum;
668668
spin_unlock(&rnp_cur->lock); /* irqs already disabled. */
669669
}
@@ -708,6 +708,7 @@ rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp)
708708
static void cpu_quiet_msk_finish(struct rcu_state *rsp, unsigned long flags)
709709
__releases(rnp->lock)
710710
{
711+
WARN_ON_ONCE(rsp->completed == rsp->gpnum);
711712
rsp->completed = rsp->gpnum;
712713
rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]);
713714
rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */
@@ -725,6 +726,8 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp,
725726
unsigned long flags)
726727
__releases(rnp->lock)
727728
{
729+
struct rcu_node *rnp_c;
730+
728731
/* Walk up the rcu_node hierarchy. */
729732
for (;;) {
730733
if (!(rnp->qsmask & mask)) {
@@ -748,8 +751,10 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp,
748751
break;
749752
}
750753
spin_unlock_irqrestore(&rnp->lock, flags);
754+
rnp_c = rnp;
751755
rnp = rnp->parent;
752756
spin_lock_irqsave(&rnp->lock, flags);
757+
WARN_ON_ONCE(rnp_c->qsmask);
753758
}
754759

755760
/*
@@ -858,7 +863,7 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp)
858863
spin_lock_irqsave(&rsp->onofflock, flags);
859864

860865
/* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */
861-
rnp = rdp->mynode;
866+
rnp = rdp->mynode; /* this is the outgoing CPU's rnp. */
862867
mask = rdp->grpmask; /* rnp->grplo is constant. */
863868
do {
864869
spin_lock(&rnp->lock); /* irqs already disabled. */
@@ -867,7 +872,7 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp)
867872
spin_unlock(&rnp->lock); /* irqs remain disabled. */
868873
break;
869874
}
870-
rcu_preempt_offline_tasks(rsp, rnp);
875+
rcu_preempt_offline_tasks(rsp, rnp, rdp);
871876
mask = rnp->grpmask;
872877
spin_unlock(&rnp->lock); /* irqs remain disabled. */
873878
rnp = rnp->parent;

kernel/rcutree_plugin.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ static void rcu_read_unlock_special(struct task_struct *t)
206206
*/
207207
if (!empty && rnp->qsmask == 0 &&
208208
list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1])) {
209-
t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
209+
struct rcu_node *rnp_p;
210+
210211
if (rnp->parent == NULL) {
211212
/* Only one rcu_node in the tree. */
212213
cpu_quiet_msk_finish(&rcu_preempt_state, flags);
@@ -215,9 +216,10 @@ static void rcu_read_unlock_special(struct task_struct *t)
215216
/* Report up the rest of the hierarchy. */
216217
mask = rnp->grpmask;
217218
spin_unlock_irqrestore(&rnp->lock, flags);
218-
rnp = rnp->parent;
219-
spin_lock_irqsave(&rnp->lock, flags);
220-
cpu_quiet_msk(mask, &rcu_preempt_state, rnp, flags);
219+
rnp_p = rnp->parent;
220+
spin_lock_irqsave(&rnp_p->lock, flags);
221+
WARN_ON_ONCE(rnp->qsmask);
222+
cpu_quiet_msk(mask, &rcu_preempt_state, rnp_p, flags);
221223
return;
222224
}
223225
spin_unlock(&rnp->lock);
@@ -278,6 +280,7 @@ static void rcu_print_task_stall(struct rcu_node *rnp)
278280
static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
279281
{
280282
WARN_ON_ONCE(!list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]));
283+
WARN_ON_ONCE(rnp->qsmask);
281284
}
282285

283286
/*
@@ -302,7 +305,8 @@ static int rcu_preempted_readers(struct rcu_node *rnp)
302305
* The caller must hold rnp->lock with irqs disabled.
303306
*/
304307
static void rcu_preempt_offline_tasks(struct rcu_state *rsp,
305-
struct rcu_node *rnp)
308+
struct rcu_node *rnp,
309+
struct rcu_data *rdp)
306310
{
307311
int i;
308312
struct list_head *lp;
@@ -314,6 +318,9 @@ static void rcu_preempt_offline_tasks(struct rcu_state *rsp,
314318
WARN_ONCE(1, "Last CPU thought to be offlined?");
315319
return; /* Shouldn't happen: at least one CPU online. */
316320
}
321+
WARN_ON_ONCE(rnp != rdp->mynode &&
322+
(!list_empty(&rnp->blocked_tasks[0]) ||
323+
!list_empty(&rnp->blocked_tasks[1])));
317324

318325
/*
319326
* Move tasks up to root rcu_node. Rely on the fact that the
@@ -489,7 +496,8 @@ static int rcu_preempted_readers(struct rcu_node *rnp)
489496
* tasks that were blocked within RCU read-side critical sections.
490497
*/
491498
static void rcu_preempt_offline_tasks(struct rcu_state *rsp,
492-
struct rcu_node *rnp)
499+
struct rcu_node *rnp,
500+
struct rcu_data *rdp)
493501
{
494502
}
495503

0 commit comments

Comments
 (0)