Skip to content

Commit c2f9467

Browse files
paulmckrcuFrederic Weisbecker
authored andcommitted
srcu: Bit manipulation changes for additional reader flavor
Currently, there are only two flavors of readers, normal and NMI-safe. Very straightforward state updates suffice to check for erroneous mixing of reader flavors on a given srcu_struct structure. This commit upgrades the checking in preparation for the addition of light-weight (as in memory-barrier-free) readers. 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]> Reviewed-by: Neeraj Upadhyay <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent 365f344 commit c2f9467

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/rcu/srcutree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx)
462462
if (IS_ENABLED(CONFIG_PROVE_RCU))
463463
mask = mask | READ_ONCE(cpuc->srcu_reader_flavor);
464464
}
465-
WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask >> 1)),
465+
WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)),
466466
"Mixed NMI-safe readers for srcu_struct at %ps.\n", ssp);
467467
return sum;
468468
}
@@ -712,8 +712,9 @@ void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor)
712712
sdp = raw_cpu_ptr(ssp->sda);
713713
old_reader_flavor_mask = READ_ONCE(sdp->srcu_reader_flavor);
714714
if (!old_reader_flavor_mask) {
715-
WRITE_ONCE(sdp->srcu_reader_flavor, reader_flavor_mask);
716-
return;
715+
old_reader_flavor_mask = cmpxchg(&sdp->srcu_reader_flavor, 0, reader_flavor_mask);
716+
if (!old_reader_flavor_mask)
717+
return;
717718
}
718719
WARN_ONCE(old_reader_flavor_mask != reader_flavor_mask, "CPU %d old state %d new state %d\n", sdp->cpu, old_reader_flavor_mask, reader_flavor_mask);
719720
}

0 commit comments

Comments
 (0)