rcu: Make rcu_cpu_starting() use its "cpu" argument
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Tue, 20 Dec 2016 15:17:58 +0000 (07:17 -0800)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Mon, 23 Jan 2017 19:37:13 +0000 (11:37 -0800)
The rcu_cpu_starting() function uses this_cpu_ptr() to locate the
incoming CPU's rcu_data structure.  This works for the boot CPU and for
all CPUs onlined after rcu_init() executes (during very early boot).
Currently, this is the full set of CPUs, so all is well.  But if
anyone ever parallelizes boot before rcu_init() time, it will fail.
This commit therefore substitutes the rcu_cpu_starting() function's
this_cpu_pointer() for per_cpu_ptr(), future-proofing the code and
(arguably) improving readability.

This commit inadvertently fixes a latent bug: If there ever had been
more than just the boot CPU online at rcu_init() time, the old code
would not initialize the non-boot CPUs, but rather would repeatedly
initialize the boot CPU.

Reported-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
kernel/rcu/tree.c

index be2301238a2387d16e62dd8ceb1485599439bd53..a4b4762442bb099de57b419a988c466348b40272 100644 (file)
@@ -3873,7 +3873,7 @@ void rcu_cpu_starting(unsigned int cpu)
        struct rcu_state *rsp;
 
        for_each_rcu_flavor(rsp) {
-               rdp = this_cpu_ptr(rsp->rda);
+               rdp = per_cpu_ptr(rsp->rda, cpu);
                rnp = rdp->mynode;
                mask = rdp->grpmask;
                raw_spin_lock_irqsave_rcu_node(rnp, flags);