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.

lockdep: Annotate lockdep assertions for context analysis

Clang's context analysis can be made aware of functions that assert that
locks are held.

Presence of these annotations causes the analysis to assume the context
lock is held after calls to the annotated function, and avoid false
positives with complex control-flow; for example, where not all
control-flow paths in a function require a held lock, and therefore
marking the function with __must_hold(..) is inappropriate.

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

authored by

Marco Elver and committed by
Peter Zijlstra
7c451541 3931d4b9

+6 -6
+6 -6
include/linux/lockdep.h
··· 282 282 do { WARN_ON_ONCE(debug_locks && !(cond)); } while (0) 283 283 284 284 #define lockdep_assert_held(l) \ 285 - lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD) 285 + do { lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD); __assume_ctx_lock(l); } while (0) 286 286 287 287 #define lockdep_assert_not_held(l) \ 288 288 lockdep_assert(lockdep_is_held(l) != LOCK_STATE_HELD) 289 289 290 290 #define lockdep_assert_held_write(l) \ 291 - lockdep_assert(lockdep_is_held_type(l, 0)) 291 + do { lockdep_assert(lockdep_is_held_type(l, 0)); __assume_ctx_lock(l); } while (0) 292 292 293 293 #define lockdep_assert_held_read(l) \ 294 - lockdep_assert(lockdep_is_held_type(l, 1)) 294 + do { lockdep_assert(lockdep_is_held_type(l, 1)); __assume_shared_ctx_lock(l); } while (0) 295 295 296 296 #define lockdep_assert_held_once(l) \ 297 297 lockdep_assert_once(lockdep_is_held(l) != LOCK_STATE_NOT_HELD) ··· 389 389 #define lockdep_assert(c) do { } while (0) 390 390 #define lockdep_assert_once(c) do { } while (0) 391 391 392 - #define lockdep_assert_held(l) do { (void)(l); } while (0) 392 + #define lockdep_assert_held(l) __assume_ctx_lock(l) 393 393 #define lockdep_assert_not_held(l) do { (void)(l); } while (0) 394 - #define lockdep_assert_held_write(l) do { (void)(l); } while (0) 395 - #define lockdep_assert_held_read(l) do { (void)(l); } while (0) 394 + #define lockdep_assert_held_write(l) __assume_ctx_lock(l) 395 + #define lockdep_assert_held_read(l) __assume_shared_ctx_lock(l) 396 396 #define lockdep_assert_held_once(l) do { (void)(l); } while (0) 397 397 #define lockdep_assert_none_held_once() do { } while (0) 398 398