]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
compiler: Let data_race() imply disabled context analysis
authorMarco Elver <elver@google.com>
Fri, 19 Dec 2025 15:40:15 +0000 (16:40 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 5 Jan 2026 15:43:34 +0000 (16:43 +0100)
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
include/linux/compiler.h
lib/test_context-analysis.c

index 04487c9bd7510cf2ef803f5f29af32c87dd1e751..110b28dfd1d1031dd481e406f3dab0f5c954e8cd 100644 (file)
@@ -190,7 +190,9 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 #define data_race(expr)                                                        \
 ({                                                                     \
        __kcsan_disable_current();                                      \
+       disable_context_analysis();                                     \
        auto __v = (expr);                                              \
+       enable_context_analysis();                                      \
        __kcsan_enable_current();                                       \
        __v;                                                            \
 })
index 2dc4044564977d2eba39b932a01b3cc6b97c07dc..1c5a381461fc07f0f2532309003ef1e835669785 100644 (file)
@@ -92,6 +92,8 @@ static void __used test_raw_spinlock_trylock_extra(struct test_raw_spinlock_data
 {
        unsigned long flags;
 
+       data_race(d->counter++); /* no warning */
+
        if (raw_spin_trylock_irq(&d->lock)) {
                d->counter++;
                raw_spin_unlock_irq(&d->lock);