[PATCH v4 08/35] locking/rwlock, spinlock: Support Clang's context analysis

Peter Zijlstra peterz at infradead.org
Thu Dec 11 11:49:05 UTC 2025


On Thu, Nov 20, 2025 at 04:09:33PM +0100, Marco Elver wrote:

> To avoid warnings in constructors, the initialization functions mark a
> lock as acquired when initialized before guarded variables.

> diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
> index 5b87c6f4a243..a2f85a0356c4 100644
> --- a/include/linux/rwlock.h
> +++ b/include/linux/rwlock.h
> @@ -22,23 +22,24 @@ do {								\
>  	static struct lock_class_key __key;			\
>  								\
>  	__rwlock_init((lock), #lock, &__key);			\
> +	__assume_ctx_guard(lock);				\
>  } while (0)
>  #else
>  # define rwlock_init(lock)					\
> -	do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0)
> +	do { *(lock) = __RW_LOCK_UNLOCKED(lock); __assume_ctx_guard(lock); } while (0)
>  #endif

This is again somewhat magical and confused the living daylight out of
me. I know (from having looked back on previous discussions) that I was
confused about this before, and clearly it didn't stick.

So obviously I'll be confused again when I look at this code in a years
time or so :/

Can we get a comment near this __assume_ctx_guard() thing (because
putting it all over the lock initializers would probably be duplicating
things too much)?



More information about the Linux-security-module-archive mailing list