]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rcu: Support Clang's context analysis
authorMarco Elver <elver@google.com>
Fri, 19 Dec 2025 15:40:03 +0000 (16:40 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 5 Jan 2026 15:43:30 +0000 (16:43 +0100)
commitfe00f6e84621ad441aa99005f2f0fefd0e5e1a2c
tree718ec6a56a46e0114137658d66095c7815fe41ef
parenteb7d96a13bf45f86909006a59e7855d8810f020a
rcu: Support Clang's context analysis

Improve the existing annotations to properly support Clang's context
analysis.

The old annotations distinguished between RCU, RCU_BH, and RCU_SCHED;
however, to more easily be able to express that "hold the RCU read lock"
without caring if the normal, _bh(), or _sched() variant was used we'd
have to remove the distinction of the latter variants: change the _bh()
and _sched() variants to also acquire "RCU".

When (and if) we introduce context locks to denote more generally that
"IRQ", "BH", "PREEMPT" contexts are disabled, it would make sense to
acquire these instead of RCU_BH and RCU_SCHED respectively.

The above change also simplified introducing __guarded_by support, where
only the "RCU" context lock needs to be held: introduce __rcu_guarded,
where Clang's context analysis warns if a pointer is dereferenced
without any of the RCU locks held, or updated without the appropriate
helpers.

The primitives rcu_assign_pointer() and friends are wrapped with
context_unsafe(), which enforces using them to update RCU-protected
pointers marked with __rcu_guarded.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://patch.msgid.link/20251219154418.3592607-15-elver@google.com
Documentation/dev-tools/context-analysis.rst
include/linux/rcupdate.h
lib/test_context-analysis.c