Re: [PATCH v9 2/7] ww_mutex: add ww_class field unconditionally

From: Boqun Feng

Date: Wed Sep 23 2026 - 01:34:37 EST


On Fri, Jan 02, 2026 at 08:52:57PM +0300, Onur Özkan wrote:
> Removes DEBUG_WW_MUTEXES guard around the ww_class field
> in struct ww_mutex and struct ww_acquire_ctx to always
> initialize it.
>
> Keeping the class pointer available unconditionally allows
> Rust abstractions to keep from_raw() simple on Mutex and
> AcquireCtx, simplify AcquireCtx reinitialization logic and
> validate Mutex and AcquireCtx class pairing in much simpler way.
>

@Peter and @Waiman, any dispute on this patch? I would like to make some
progress on this since it'll be needed for GPUVM and KMS if I understand
correctly.

Regards,
Boqun

> Link: https://lore.kernel.org/all/ECC0425A-8B18-4626-8EA8-2F843C45E0A1@xxxxxxxxxxxxx/
> Signed-off-by: Onur Özkan <work@xxxxxxxxxxxxx>
> ---
> include/linux/ww_mutex.h | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h
> index 45ff6f7a872b..c9835035b6d6 100644
> --- a/include/linux/ww_mutex.h
> +++ b/include/linux/ww_mutex.h
> @@ -47,9 +47,7 @@ struct ww_class {
> struct ww_mutex {
> struct WW_MUTEX_BASE base;
> struct ww_acquire_ctx *ctx;
> -#ifdef DEBUG_WW_MUTEXES
> struct ww_class *ww_class;
> -#endif
> };
>
> struct ww_acquire_ctx {
> @@ -58,9 +56,9 @@ struct ww_acquire_ctx {
> unsigned int acquired;
> unsigned short wounded;
> unsigned short is_wait_die;
> + struct ww_class *ww_class;
> #ifdef DEBUG_WW_MUTEXES
> unsigned int done_acquire;
> - struct ww_class *ww_class;
> void *contending_lock;
> #endif
> #ifdef CONFIG_DEBUG_LOCK_ALLOC
> @@ -110,9 +108,7 @@ static inline void ww_mutex_init(struct ww_mutex *lock,
> {
> ww_mutex_base_init(&lock->base, ww_class->mutex_name, &ww_class->mutex_key);
> lock->ctx = NULL;
> -#ifdef DEBUG_WW_MUTEXES
> lock->ww_class = ww_class;
> -#endif
> }
>
> /**
> @@ -147,8 +143,8 @@ static inline void ww_acquire_init(struct ww_acquire_ctx *ctx,
> ctx->acquired = 0;
> ctx->wounded = false;
> ctx->is_wait_die = ww_class->is_wait_die;
> -#ifdef DEBUG_WW_MUTEXES
> ctx->ww_class = ww_class;
> +#ifdef DEBUG_WW_MUTEXES
> ctx->done_acquire = 0;
> ctx->contending_lock = NULL;
> #endif
> --
> 2.51.2
>