Skip to content

Commit f8ce622

Browse files
paulmckrcuFrederic Weisbecker
authored andcommitted
srcu: Check for srcu_read_lock_lite() across all CPUs
If srcu_read_lock_lite() is used on a given srcu_struct structure, then the grace-period processing must do synchronize_rcu() instead of smp_mb() between the scans of the ->srcu_unlock_count[] and ->srcu_lock_count[] counters. Currently, it does that by testing the SRCU_READ_FLAVOR_LITE bit of the ->srcu_reader_flavor mask, which works well. But only if the CPU running that srcu_struct structure's grace period has previously executed srcu_read_lock_lite(), which might not be the case, especially just after that srcu_struct structure has been created and initialized. This commit therefore updates the srcu_readers_unlock_idx() function to OR together the ->srcu_reader_flavor masks from all CPUs, and then make the srcu_readers_active_idx_check() function that test the SRCU_READ_FLAVOR_LITE bit in the resulting mask. Note that the srcu_readers_unlock_idx() function is already scanning all the CPUs to sum up the ->srcu_unlock_count[] fields and that this is on the grace-period slow path, hence no concerns about the small amount of extra work. Reported-by: Neeraj Upadhyay <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: c0f08d6 ("srcu: Add srcu_read_lock_lite() and srcu_read_unlock_lite()") Signed-off-by: Paul E. McKenney <[email protected]> Cc: Frederic Weisbecker <[email protected]> Reviewed-by: Neeraj Upadhyay <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent 174dd22 commit f8ce622

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kernel/rcu/srcutree.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static bool srcu_readers_lock_idx(struct srcu_struct *ssp, int idx, bool gp, uns
458458
* Returns approximate total of the readers' ->srcu_unlock_count[] values
459459
* for the rank of per-CPU counters specified by idx.
460460
*/
461-
static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx)
461+
static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx, unsigned long *rdm)
462462
{
463463
int cpu;
464464
unsigned long mask = 0;
@@ -468,11 +468,11 @@ static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx)
468468
struct srcu_data *sdp = per_cpu_ptr(ssp->sda, cpu);
469469

470470
sum += atomic_long_read(&sdp->srcu_unlock_count[idx]);
471-
if (IS_ENABLED(CONFIG_PROVE_RCU))
472-
mask = mask | READ_ONCE(sdp->srcu_reader_flavor);
471+
mask = mask | READ_ONCE(sdp->srcu_reader_flavor);
473472
}
474473
WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)),
475474
"Mixed reader flavors for srcu_struct at %ps.\n", ssp);
475+
*rdm = mask;
476476
return sum;
477477
}
478478

@@ -482,10 +482,12 @@ static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx)
482482
*/
483483
static bool srcu_readers_active_idx_check(struct srcu_struct *ssp, int idx)
484484
{
485-
bool did_gp = !!(raw_cpu_read(ssp->sda->srcu_reader_flavor) & SRCU_READ_FLAVOR_LITE);
485+
bool did_gp;
486+
unsigned long rdm;
486487
unsigned long unlocks;
487488

488-
unlocks = srcu_readers_unlock_idx(ssp, idx);
489+
unlocks = srcu_readers_unlock_idx(ssp, idx, &rdm);
490+
did_gp = !!(rdm & SRCU_READ_FLAVOR_LITE);
489491

490492
/*
491493
* Make sure that a lock is always counted if the corresponding

0 commit comments

Comments
 (0)