rcu: Add READ_ONCE() to rcu_do_batch() access to rcu_resched_ns
authorPaul E. McKenney <paulmck@kernel.org>
Wed, 24 Jun 2020 00:49:40 +0000 (17:49 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 25 Aug 2020 01:36:07 +0000 (18:36 -0700)
Given that sysfs can change the value of rcu_resched_ns at any time,
this commit adds a READ_ONCE() to the sole access to that variable.
While in the area, this commit also adds bounds checking, clamping the
value to at least a millisecond, but no longer than a second.

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

index 1dca14cf66f9f432f4b7b904a1e6164f77a0abce..da05afc534931c83a300be83fc4e8d826583342c 100644 (file)
@@ -2394,8 +2394,12 @@ static void rcu_do_batch(struct rcu_data *rdp)
        div = READ_ONCE(rcu_divisor);
        div = div < 0 ? 7 : div > sizeof(long) * 8 - 2 ? sizeof(long) * 8 - 2 : div;
        bl = max(rdp->blimit, pending >> div);
-       if (unlikely(bl > 100))
-               tlimit = local_clock() + rcu_resched_ns;
+       if (unlikely(bl > 100)) {
+               long rrn = READ_ONCE(rcu_resched_ns);
+
+               rrn = rrn < NSEC_PER_MSEC ? NSEC_PER_MSEC : rrn > NSEC_PER_SEC ? NSEC_PER_SEC : rrn;
+               tlimit = local_clock() + rrn;
+       }
        trace_rcu_batch_start(rcu_state.name,
                              rcu_segcblist_n_cbs(&rdp->cblist), bl);
        rcu_segcblist_extract_done_cbs(&rdp->cblist, &rcl);