Skip to content

Commit a657f26

Browse files
committed
rcu: Execute RCU reader shortly after rcu_core for strict GPs
A kernel built with CONFIG_RCU_STRICT_GRACE_PERIOD=y needs a quiescent state to appear very shortly after a CPU has noticed a new grace period. Placing an RCU reader immediately after this point is ineffective because this normally happens in softirq context, which acts as a big RCU reader. This commit therefore introduces a new per-CPU work_struct, which is used at the end of rcu_core() processing to schedule an RCU read-side critical section from within a clean environment. Reported-by Jann Horn <jannh@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 3d29aaf commit a657f26

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

kernel/rcu/tree.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,14 @@ void rcu_force_quiescent_state(void)
26462646
}
26472647
EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
26482648

2649+
// Workqueue handler for an RCU reader for kernels enforcing struct RCU
2650+
// grace periods.
2651+
static void strict_work_handler(struct work_struct *work)
2652+
{
2653+
rcu_read_lock();
2654+
rcu_read_unlock();
2655+
}
2656+
26492657
/* Perform RCU core processing work for the current CPU. */
26502658
static __latent_entropy void rcu_core(void)
26512659
{
@@ -2690,6 +2698,10 @@ static __latent_entropy void rcu_core(void)
26902698
/* Do any needed deferred wakeups of rcuo kthreads. */
26912699
do_nocb_deferred_wakeup(rdp);
26922700
trace_rcu_utilization(TPS("End RCU core"));
2701+
2702+
// If strict GPs, schedule an RCU reader in a clean environment.
2703+
if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD))
2704+
queue_work_on(rdp->cpu, rcu_gp_wq, &rdp->strict_work);
26932705
}
26942706

26952707
static void rcu_core_si(struct softirq_action *h)
@@ -3887,6 +3899,7 @@ rcu_boot_init_percpu_data(int cpu)
38873899

38883900
/* Set up local state, ensuring consistent view of global state. */
38893901
rdp->grpmask = leaf_node_cpu_bit(rdp->mynode, cpu);
3902+
INIT_WORK(&rdp->strict_work, strict_work_handler);
38903903
WARN_ON_ONCE(rdp->dynticks_nesting != 1);
38913904
WARN_ON_ONCE(rcu_dynticks_in_eqs(rcu_dynticks_snap(rdp)));
38923905
rdp->rcu_ofl_gp_seq = rcu_state.gp_seq;

kernel/rcu/tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct rcu_data {
164164
/* period it is aware of. */
165165
struct irq_work defer_qs_iw; /* Obtain later scheduler attention. */
166166
bool defer_qs_iw_pending; /* Scheduler attention pending? */
167+
struct work_struct strict_work; /* Schedule readers for strict GPs. */
167168

168169
/* 2) batch handling */
169170
struct rcu_segcblist cblist; /* Segmented callback list, with */

0 commit comments

Comments
 (0)