Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler: Let data_race() imply disabled context analysis

Many patterns that involve data-racy accesses often deliberately ignore
normal synchronization rules to avoid taking a lock.

If we have a lock-guarded variable on which we do a lock-less data-racy
access, rather than having to write context_unsafe(data_race(..)),
simply make the data_race(..) macro imply context-unsafety. The
data_race() macro already denotes the intent that something subtly
unsafe is about to happen, so it should be clear enough as-is.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251219154418.3592607-27-elver@google.com

authored by

Marco Elver and committed by
Peter Zijlstra
3635ad87 c237f1ce

+4
+2
include/linux/compiler.h
··· 190 190 #define data_race(expr) \ 191 191 ({ \ 192 192 __kcsan_disable_current(); \ 193 + disable_context_analysis(); \ 193 194 auto __v = (expr); \ 195 + enable_context_analysis(); \ 194 196 __kcsan_enable_current(); \ 195 197 __v; \ 196 198 })
+2
lib/test_context-analysis.c
··· 92 92 { 93 93 unsigned long flags; 94 94 95 + data_race(d->counter++); /* no warning */ 96 + 95 97 if (raw_spin_trylock_irq(&d->lock)) { 96 98 d->counter++; 97 99 raw_spin_unlock_irq(&d->lock);