Re: [patch V5 41/72] locking/ww_mutex: Gather mutex_waiter initialization

From: Sebastian Andrzej Siewior
Date: Thu Aug 19 2021 - 13:51:16 EST


On 2021-08-15 23:28:39 [+0200], Thomas Gleixner wrote:
> --- a/kernel/locking/mutex-debug.c
> +++ b/kernel/locking/mutex-debug.c
> @@ -30,6 +30,7 @@ void debug_mutex_lock_common(struct mute
> memset(waiter, MUTEX_DEBUG_INIT, sizeof(*waiter));
> waiter->magic = waiter;
> INIT_LIST_HEAD(&waiter->list);
> + waiter->ww_ctx = MUTEX_POISON_WW_CTX;
> }
>
> void debug_mutex_wake_waiter(struct mutex *lock, struct mutex_waiter *waiter)
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -980,17 +980,15 @@ static __always_inline int __sched
> }
>
> debug_mutex_lock_common(lock, &waiter);
> + waiter.task = current;
> + if (ww_ctx)
> + waiter.ww_ctx = ww_ctx;
>
> lock_contended(&lock->dep_map, ip);
>
> if (!use_ww_ctx) {
> /* add waiting tasks to the end of the waitqueue (FIFO): */
> __mutex_add_waiter(lock, &waiter, &lock->wait_list);
> -
> -
> -#ifdef CONFIG_DEBUG_MUTEXES
> - waiter.ww_ctx = MUTEX_POISON_WW_CTX;
> -#endif

The crash, Guenter Roeck reported, is because now waiter.ww_ctx is
always initialized to poisen.
Previously in the ww-mutex case without a context it was set to NULL
in the next hunk.
Keeping the ww_ctx assigment in the next hunk seems to work.

> } else {
> /*
> * Add in stamp order, waking up waiters that must kill
> @@ -999,12 +997,8 @@ static __always_inline int __sched
> ret = __ww_mutex_add_waiter(&waiter, lock, ww_ctx);
> if (ret)
> goto err_early_kill;
> -
> - waiter.ww_ctx = ww_ctx;
> }
>
> - waiter.task = current;
> -
> set_current_state(state);
> for (;;) {
> /*

Sebastian