Commit 3635ad87 authored by Marco Elver's avatar Marco Elver Committed by Peter Zijlstra
Browse files

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: default avatarMarco Elver <elver@google.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251219154418.3592607-27-elver@google.com
parent c237f1ce
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;								\
})
+2 −0
Original line number Diff line number Diff line
@@ -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);