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-context-analysys: Add __cond_releases()

Useful for things like unlock fastpaths, which on success release the
lock.

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

+32
+32
include/linux/compiler-context-analysis.h
··· 320 320 */ 321 321 #define __releases(...) __releases_ctx_lock(__VA_ARGS__) 322 322 323 + /* 324 + * Clang's analysis does not care precisely about the value, only that it is 325 + * either zero or non-zero. So the __cond_acquires() interface might be 326 + * misleading if we say that @ret is the value returned if acquired. Instead, 327 + * provide symbolic variants which we translate. 328 + */ 329 + #define __cond_acquires_impl_not_true(x, ...) __try_acquires##__VA_ARGS__##_ctx_lock(0, x) 330 + #define __cond_acquires_impl_not_false(x, ...) __try_acquires##__VA_ARGS__##_ctx_lock(1, x) 331 + #define __cond_acquires_impl_not_nonzero(x, ...) __try_acquires##__VA_ARGS__##_ctx_lock(0, x) 332 + #define __cond_acquires_impl_not_0(x, ...) __try_acquires##__VA_ARGS__##_ctx_lock(1, x) 333 + #define __cond_acquires_impl_not_nonnull(x, ...) __try_acquires##__VA_ARGS__##_ctx_lock(0, x) 334 + #define __cond_acquires_impl_not_NULL(x, ...) __try_acquires##__VA_ARGS__##_ctx_lock(1, x) 335 + 336 + /** 337 + * __cond_releases() - function attribute, function conditionally 338 + * releases a context lock exclusively 339 + * @ret: abstract value returned by function if context lock releases 340 + * @x: context lock instance pointer 341 + * 342 + * Function attribute declaring that the function conditionally releases the 343 + * given context lock instance @x exclusively. The associated context(s) must 344 + * be active on entry. The function return value @ret denotes when the context 345 + * lock is released. 346 + * 347 + * @ret may be one of: true, false, nonzero, 0, nonnull, NULL. 348 + * 349 + * NOTE: clang does not have a native attribute for this; instead implement 350 + * it as an unconditional release and a conditional acquire for the 351 + * inverted condition -- which is semantically equivalent. 352 + */ 353 + #define __cond_releases(ret, x) __releases(x) __cond_acquires_impl_not_##ret(x) 354 + 323 355 /** 324 356 * __acquire() - function to acquire context lock exclusively 325 357 * @x: context lock instance pointer