Skip to content

Commit d31e313

Browse files
paulmckrcufbq
authored andcommitted
srcu: Force synchronization for srcu_get_delay()
Currently, srcu_get_delay() can be called concurrently, for example, by a CPU that is the first to request a new grace period and the CPU processing the current grace period. Although concurrent access is harmless, it unnecessarily expands the state space. Additionally, all calls to srcu_get_delay() are from slow paths. This commit therefore protects all calls to srcu_get_delay() with ssp->srcu_sup->lock, which is already held on the invocation from the srcu_funnel_gp_start() function. While in the area, this commit also adds a lockdep_assert_held() to srcu_get_delay() itself. Reported-by: [email protected] Signed-off-by: Paul E. McKenney <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: <[email protected]> Signed-off-by: Boqun Feng <[email protected]>
1 parent 821ca6f commit d31e313

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kernel/rcu/srcutree.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ static unsigned long srcu_get_delay(struct srcu_struct *ssp)
648648
unsigned long jbase = SRCU_INTERVAL;
649649
struct srcu_usage *sup = ssp->srcu_sup;
650650

651+
lockdep_assert_held(&ACCESS_PRIVATE(ssp->srcu_sup, lock));
651652
if (srcu_gp_is_expedited(ssp))
652653
jbase = 0;
653654
if (rcu_seq_state(READ_ONCE(sup->srcu_gp_seq))) {
@@ -675,9 +676,13 @@ static unsigned long srcu_get_delay(struct srcu_struct *ssp)
675676
void cleanup_srcu_struct(struct srcu_struct *ssp)
676677
{
677678
int cpu;
679+
unsigned long delay;
678680
struct srcu_usage *sup = ssp->srcu_sup;
679681

680-
if (WARN_ON(!srcu_get_delay(ssp)))
682+
spin_lock_irq_rcu_node(ssp->srcu_sup);
683+
delay = srcu_get_delay(ssp);
684+
spin_unlock_irq_rcu_node(ssp->srcu_sup);
685+
if (WARN_ON(!delay))
681686
return; /* Just leak it! */
682687
if (WARN_ON(srcu_readers_active(ssp)))
683688
return; /* Just leak it! */
@@ -1101,7 +1106,9 @@ static bool try_check_zero(struct srcu_struct *ssp, int idx, int trycount)
11011106
{
11021107
unsigned long curdelay;
11031108

1109+
spin_lock_irq_rcu_node(ssp->srcu_sup);
11041110
curdelay = !srcu_get_delay(ssp);
1111+
spin_unlock_irq_rcu_node(ssp->srcu_sup);
11051112

11061113
for (;;) {
11071114
if (srcu_readers_active_idx_check(ssp, idx))
@@ -1850,7 +1857,9 @@ static void process_srcu(struct work_struct *work)
18501857
ssp = sup->srcu_ssp;
18511858

18521859
srcu_advance_state(ssp);
1860+
spin_lock_irq_rcu_node(ssp->srcu_sup);
18531861
curdelay = srcu_get_delay(ssp);
1862+
spin_unlock_irq_rcu_node(ssp->srcu_sup);
18541863
if (curdelay) {
18551864
WRITE_ONCE(sup->reschedule_count, 0);
18561865
} else {

0 commit comments

Comments
 (0)