rcu: Need to update rnp->gpnum if preemptable RCU is to be reliable
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Tue, 8 Sep 2009 22:54:36 +0000 (15:54 -0700)
committerIngo Molnar <mingo@elte.hu>
Thu, 17 Sep 2009 22:04:54 +0000 (00:04 +0200)
Without this patch, tasks preempted in RCU read-side critical
sections can fail to block the grace period, given that
rnp->gpnum is used to determine which rnp->blocked_tasks[]
element the preempted task is enqueued on.

Before the patch, rnp->gpnum is always zero, so preempted tasks
are always enqueued on rnp->blocked_tasks[0], which is correct
only when the current CPU has not checked into the current
grace period and the grace-period number is even, or,
similarly, if the current CPU -has- checked into the current
grace period and the grace-period number is odd.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: laijs@cn.fujitsu.com
Cc: dipankar@in.ibm.com
Cc: akpm@linux-foundation.org
Cc: mathieu.desnoyers@polymtl.ca
Cc: josht@linux.vnet.ibm.com
Cc: dvhltc@us.ibm.com
Cc: niv@us.ibm.com
Cc: peterz@infradead.org
LKML-Reference: <12524504771622-git-send-email->
Signed-off-by: Ingo Molnar <mingo@elte.hu>
kernel/rcutree.c

index 6b11b07..c634a92 100644 (file)
@@ -632,6 +632,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
        /* Special-case the common single-level case. */
        if (NUM_RCU_NODES == 1) {
                rnp->qsmask = rnp->qsmaskinit;
        /* Special-case the common single-level case. */
        if (NUM_RCU_NODES == 1) {
                rnp->qsmask = rnp->qsmaskinit;
+               rnp->gpnum = rsp->gpnum;
                rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */
                spin_unlock_irqrestore(&rnp->lock, flags);
                return;
                rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */
                spin_unlock_irqrestore(&rnp->lock, flags);
                return;
@@ -657,8 +658,10 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
         */
 
        rnp_end = rsp->level[NUM_RCU_LVLS - 1];
         */
 
        rnp_end = rsp->level[NUM_RCU_LVLS - 1];
-       for (rnp_cur = &rsp->node[0]; rnp_cur < rnp_end; rnp_cur++)
+       for (rnp_cur = &rsp->node[0]; rnp_cur < rnp_end; rnp_cur++) {
                rnp_cur->qsmask = rnp_cur->qsmaskinit;
                rnp_cur->qsmask = rnp_cur->qsmaskinit;
+               rnp->gpnum = rsp->gpnum;
+       }
 
        /*
         * Now set up the leaf nodes.  Here we must be careful.  First,
 
        /*
         * Now set up the leaf nodes.  Here we must be careful.  First,
@@ -679,6 +682,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
        for (; rnp_cur < rnp_end; rnp_cur++) {
                spin_lock(&rnp_cur->lock);      /* irqs already disabled. */
                rnp_cur->qsmask = rnp_cur->qsmaskinit;
        for (; rnp_cur < rnp_end; rnp_cur++) {
                spin_lock(&rnp_cur->lock);      /* irqs already disabled. */
                rnp_cur->qsmask = rnp_cur->qsmaskinit;
+               rnp->gpnum = rsp->gpnum;
                spin_unlock(&rnp_cur->lock);    /* irqs already disabled. */
        }
 
                spin_unlock(&rnp_cur->lock);    /* irqs already disabled. */
        }