Skip to content

Commit d16e32f

Browse files
paulmckrcuurezki
authored andcommitted
rcu: Make rcu_report_exp_cpu_mult() caller acquire lock
There is a hard-to-trigger bug in the expedited grace-period computation whose fix requires that the __sync_rcu_exp_select_node_cpus() function to check that the grace-period sequence number has not changed before invoking rcu_report_exp_cpu_mult(). However, this check must be done while holding the leaf rcu_node structure's ->lock. This commit therefore prepares for that fix by moving this lock's acquisition from rcu_report_exp_cpu_mult() to its callers (all two of them). Signed-off-by: Paul E. McKenney <[email protected]> Cc: Frederic Weisbecker <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]>
1 parent 049dfe9 commit d16e32f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

kernel/rcu/tree_exp.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,16 @@ static void __maybe_unused rcu_report_exp_rnp(struct rcu_node *rnp, bool wake)
227227

228228
/*
229229
* Report expedited quiescent state for multiple CPUs, all covered by the
230-
* specified leaf rcu_node structure.
230+
* specified leaf rcu_node structure, which is acquired by the caller.
231231
*/
232-
static void rcu_report_exp_cpu_mult(struct rcu_node *rnp,
232+
static void rcu_report_exp_cpu_mult(struct rcu_node *rnp, unsigned long flags,
233233
unsigned long mask, bool wake)
234+
__releases(rnp->lock)
234235
{
235236
int cpu;
236-
unsigned long flags;
237237
struct rcu_data *rdp;
238238

239-
raw_spin_lock_irqsave_rcu_node(rnp, flags);
239+
raw_lockdep_assert_held_rcu_node(rnp);
240240
if (!(rnp->expmask & mask)) {
241241
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
242242
return;
@@ -257,8 +257,12 @@ static void rcu_report_exp_cpu_mult(struct rcu_node *rnp,
257257
*/
258258
static void rcu_report_exp_rdp(struct rcu_data *rdp)
259259
{
260+
unsigned long flags;
261+
struct rcu_node *rnp = rdp->mynode;
262+
260263
WRITE_ONCE(rdp->cpu_no_qs.b.exp, false);
261-
rcu_report_exp_cpu_mult(rdp->mynode, rdp->grpmask, true);
264+
raw_spin_lock_irqsave_rcu_node(rnp, flags);
265+
rcu_report_exp_cpu_mult(rnp, flags, rdp->grpmask, true);
262266
}
263267

264268
/* Common code for work-done checking. */
@@ -432,8 +436,10 @@ static void __sync_rcu_exp_select_node_cpus(struct rcu_exp_work *rewp)
432436
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
433437
}
434438
/* Report quiescent states for those that went offline. */
435-
if (mask_ofl_test)
436-
rcu_report_exp_cpu_mult(rnp, mask_ofl_test, false);
439+
if (mask_ofl_test) {
440+
raw_spin_lock_irqsave_rcu_node(rnp, flags);
441+
rcu_report_exp_cpu_mult(rnp, flags, mask_ofl_test, false);
442+
}
437443
}
438444

439445
static void rcu_exp_sel_wait_wake(unsigned long s);

0 commit comments

Comments
 (0)