rcu/tree: Add a warning if CPU being onlined did not report QS already
authorJoel Fernandes (Google) <joel@joelfernandes.org>
Tue, 29 Sep 2020 19:29:27 +0000 (15:29 -0400)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 20 Nov 2020 03:37:16 +0000 (19:37 -0800)
Currently, rcu_cpu_starting() checks to see if the RCU core expects a
quiescent state from the incoming CPU.  However, the current interaction
between RCU quiescent-state reporting and CPU-hotplug operations should
mean that the incoming CPU never needs to report a quiescent state.
First, the outgoing CPU reports a quiescent state if needed.  Second,
the race where the CPU is leaving just as RCU is initializing a new
grace period is handled by an explicit check for this condition.  Third,
the CPU's leaf rcu_node structure's ->lock serializes these checks.

This means that if rcu_cpu_starting() ever feels the need to report
a quiescent state, then there is a bug somewhere in the CPU hotplug
code or the RCU grace-period handling code.  This commit therefore
adds a WARN_ON_ONCE() to bring that bug to everyone's attention.

Cc: Neeraj Upadhyay <neeraju@codeaurora.org>
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree.c

index 39e14cf6a9c001b73ace0aeb07077d6ab92ec1be..e4d6d0b1b8535c75097fe338143f24f15b73d7e8 100644 (file)
@@ -4075,7 +4075,9 @@ void rcu_cpu_starting(unsigned int cpu)
        rcu_gpnum_ovf(rnp, rdp); /* Offline-induced counter wrap? */
        rdp->rcu_onl_gp_seq = READ_ONCE(rcu_state.gp_seq);
        rdp->rcu_onl_gp_flags = READ_ONCE(rcu_state.gp_flags);
-       if (rnp->qsmask & mask) { /* RCU waiting on incoming CPU? */
+
+       /* An incoming CPU should never be blocking a grace period. */
+       if (WARN_ON_ONCE(rnp->qsmask & mask)) { /* RCU waiting on incoming CPU? */
                rcu_disable_urgency_upon_qs(rdp);
                /* Report QS -after- changing ->qsmaskinitnext! */
                rcu_report_qs_rnp(mask, rnp, rnp->gp_seq, flags);