For kernels built with CONFIG_NO_HZ_FULL=y, the following scenario can result in the scheduling-clock interrupt remaining enabled on a holdout CPU after its quiescent state has been reported: CPU1 CPU2 rcu_report_exp_cpu_mult synchronize_rcu_expedited_wait acquires rnp->lock mask = rnp->expmask; for_each_leaf_node_cpu_mask(rnp, cpu, mask) rnp->expmask = rnp->expmask & ~mask; rdp = per_cpu_ptr(&rcu_data, cpu1); for_each_leaf_node_cpu_mask(rnp, cpu, mask) rdp = per_cpu_ptr(&rcu_data, cpu1); if (!rdp->rcu_forced_tick_exp) continue; rdp->rcu_forced_tick_exp = true; tick_dep_set_cpu(cpu1, TICK_DEP_BIT_RCU_EXP); The problem is that CPU2's sampling of rnp->expmask is obsolete by the time it invokes tick_dep_set_cpu(), and CPU1 is not guaranteed to see CPU2's store to ->rcu_forced_tick_exp in time to clear it. And even if CPU1 does see that store, it might invoke tick_dep_clear_cpu() before CPU2 got around to executing its tick_dep_set_cpu(), which would still leave the victim CPU with its scheduler-clock tick running. Either way, an nohz_full real-time application running on the victim CPU would have its latency needlessly degraded. Note that expedited RCU grace periods look at context-tracking information, and so if the CPU is executing in nohz_full usermode throughout, that CPU cannot be victimized in this manner. This commit therefore causes synchronize_rcu_expedited_wait to hold the rcu_node structure's ->lock when checking for holdout CPUs, setting TICK_DEP_BIT_RCU_EXP, and invoking tick_dep_set_cpu(), thus preventing this race.
Unified · Split
| @@ -594,6 +594,7 @@ static void synchronize_rcu_expedited_wait(void) · 593 unmodified lines | |||
| 594 | struct rcu_data *rdp; | 594 | struct rcu_data *rdp; |
| 595 | struct rcu_node *rnp; | 595 | struct rcu_node *rnp; |
| 596 | struct rcu_node *rnp_root = rcu_get_root(); | 596 | struct rcu_node *rnp_root = rcu_get_root(); |
| 597 | unsigned long flags; | ||
| 597 | 598 | ||
| 598 | trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait")); | 599 | trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait")); |
| 599 | jiffies_stall = rcu_exp_jiffies_till_stall_check(); | 600 | jiffies_stall = rcu_exp_jiffies_till_stall_check(); |
| @@ -602,17 +603,17 @@ static void synchronize_rcu_expedited_wait(void) · 2 unmodified lines | |||
| 602 | if (synchronize_rcu_expedited_wait_once(1)) | 603 | if (synchronize_rcu_expedited_wait_once(1)) |
| 603 | return; | 604 | return; |
| 604 | rcu_for_each_leaf_node(rnp) { | 605 | rcu_for_each_leaf_node(rnp) { |
| 606 | raw_spin_lock_irqsave_rcu_node(rnp, flags); | ||
| 605 | mask = READ_ONCE(rnp->expmask); | 607 | mask = READ_ONCE(rnp->expmask); |
| 606 | for_each_leaf_node_cpu_mask(rnp, cpu, mask) { | 608 | for_each_leaf_node_cpu_mask(rnp, cpu, mask) { |
| 607 | rdp = per_cpu_ptr(&rcu_data, cpu); | 609 | rdp = per_cpu_ptr(&rcu_data, cpu); |
| 608 | if (rdp->rcu_forced_tick_exp) | 610 | if (rdp->rcu_forced_tick_exp) |
| 609 | continue; | 611 | continue; |
| 610 | rdp->rcu_forced_tick_exp = true; | 612 | rdp->rcu_forced_tick_exp = true; |
| 611 | preempt_disable(); | ||
| 612 | if (cpu_online(cpu)) | 613 | if (cpu_online(cpu)) |
| 613 | tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP); | 614 | tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP); |
| 614 | preempt_enable(); | ||
| 615 | } | 615 | } |
| 616 | raw_spin_unlock_irqrestore_rcu_node(rnp, flags); | ||
| 616 | } | 617 | } |
| 617 | j = READ_ONCE(jiffies_till_first_fqs); | 618 | j = READ_ONCE(jiffies_till_first_fqs); |
| 618 | if (synchronize_rcu_expedited_wait_once(j + HZ)) | 619 | if (synchronize_rcu_expedited_wait_once(j + HZ)) |