rcu: Mark rcu_state.ncpus to detect concurrent writes
authorPaul E. McKenney <paulmck@kernel.org>
Mon, 10 Feb 2020 13:29:58 +0000 (05:29 -0800)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 27 Apr 2020 18:01:15 +0000 (11:01 -0700)
The rcu_state structure's ncpus field is only to be modified by the
CPU-hotplug CPU-online code path, which is single-threaded.  This
commit therefore enlists KCSAN's help in enforcing this restriction.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree.c

index 156ac8d0418befabc18852e89126acf4e06bf9d3..c88240a685ec81ca6f0078641a7961563069ce60 100644 (file)
@@ -3612,6 +3612,7 @@ void rcu_cpu_starting(unsigned int cpu)
        nbits = bitmap_weight(&oldmask, BITS_PER_LONG);
        /* Allow lockless access for expedited grace periods. */
        smp_store_release(&rcu_state.ncpus, rcu_state.ncpus + nbits); /* ^^^ */
+       ASSERT_EXCLUSIVE_WRITER(rcu_state.ncpus);
        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);