Skip to content

Commit 4546ffc

Browse files
committed
srcu: Check for consistent global per-srcu_struct NMI safety
This commit adds runtime checks to verify that a given srcu_struct uses consistent NMI-safe (or not) read-side primitives globally, but based on the per-CPU data. These global checks are made by the grace-period code that must scan the srcu_data structures anyway, and are done only in kernels built with CONFIG_PROVE_RCU=y. Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Paul E. McKenney <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: John Ogness <[email protected]> Cc: Petr Mladek <[email protected]>
1 parent 2df5ade commit 4546ffc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/rcu/srcutree.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,18 @@ static unsigned long srcu_readers_lock_idx(struct srcu_struct *ssp, int idx)
429429
static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx)
430430
{
431431
int cpu;
432+
unsigned long mask = 0;
432433
unsigned long sum = 0;
433434

434435
for_each_possible_cpu(cpu) {
435436
struct srcu_data *cpuc = per_cpu_ptr(ssp->sda, cpu);
436437

437438
sum += atomic_long_read(&cpuc->srcu_unlock_count[idx]);
439+
if (IS_ENABLED(CONFIG_PROVE_RCU))
440+
mask = mask | READ_ONCE(cpuc->srcu_nmi_safety);
438441
}
442+
WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask >> 1)),
443+
"Mixed NMI-safe readers for srcu_struct at %ps.\n", ssp);
439444
return sum;
440445
}
441446

0 commit comments

Comments
 (0)