Skip to content

Commit 5b14557

Browse files
committed
rcu: Avoid tick_dep_set_cpu() misordering
In the current code, rcu_nmi_enter_common() might decide to turn on the tick using tick_dep_set_cpu(), but be delayed just before doing so. Then the grace-period kthread might notice that the CPU in question had in fact gone through a quiescent state, thus turning off the tick using tick_dep_clear_cpu(). The later invocation of tick_dep_set_cpu() would then incorrectly leave the tick on. This commit therefore enlists the aid of the leaf rcu_node structure's ->lock to ensure that decisions to enable or disable the tick are carried out before they can be reversed. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 77339e6 commit 5b14557

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

kernel/rcu/tree.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ void rcu_user_exit(void)
800800
*/
801801
static __always_inline void rcu_nmi_enter_common(bool irq)
802802
{
803-
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
804803
long incby = 2;
804+
struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
805805

806806
/* Complain about underflow. */
807807
WARN_ON_ONCE(rdp->dynticks_nmi_nesting < 0);
@@ -828,8 +828,13 @@ static __always_inline void rcu_nmi_enter_common(bool irq)
828828
} else if (tick_nohz_full_cpu(rdp->cpu) &&
829829
rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE &&
830830
READ_ONCE(rdp->rcu_urgent_qs) && !rdp->rcu_forced_tick) {
831-
rdp->rcu_forced_tick = true;
832-
tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
831+
raw_spin_lock_rcu_node(rdp->mynode);
832+
// Recheck under lock.
833+
if (rdp->rcu_urgent_qs && !rdp->rcu_forced_tick) {
834+
rdp->rcu_forced_tick = true;
835+
tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
836+
}
837+
raw_spin_unlock_rcu_node(rdp->mynode);
833838
}
834839
trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),
835840
rdp->dynticks_nmi_nesting,
@@ -898,6 +903,7 @@ void rcu_irq_enter_irqson(void)
898903
*/
899904
static void rcu_disable_urgency_upon_qs(struct rcu_data *rdp)
900905
{
906+
raw_lockdep_assert_held_rcu_node(rdp->mynode);
901907
WRITE_ONCE(rdp->rcu_urgent_qs, false);
902908
WRITE_ONCE(rdp->rcu_need_heavy_qs, false);
903909
if (tick_nohz_full_cpu(rdp->cpu) && rdp->rcu_forced_tick) {

0 commit comments

Comments
 (0)