Re: [PATCH v2 2/5] locking/rtmutex: Initialize the ww_mutex context of a waiter

From: Sebastian Andrzej Siewior

Date: Mon Nov 16 2026 - 08:59:08 EST


On 2026-11-08 09:13:44 [-0500], Mathieu Desnoyers wrote:
> With PREEMPT_RT and CONFIG_DEBUG_RT_MUTEXES, FUTEX_LOCK_PI reports no
> deadlock. Two threads that each block on a PI futex the other holds
> sleep forever. Without PREEMPT_RT, the second one gets EDEADLK. A chain
> deeper than max_lock_depth is also admitted.
>
> With PREEMPT_RT, ww_mutexes are built on rtmutexes. They can create a
> cycle in the lock graph legitimately, and the wound/die logic resolves
> it. So the PREEMPT_RT chain walk turns deadlock detection off when it
> finds a waiter with a ww_mutex context, waiter->ww_ctx. It also drops
> the -EDEADLK of a walk that started from such a waiter.

I *think* this is unrelated because the futex caller shouldn't end up
here. The __rt_mutex_slowlock() -> rt_mutex_handle_deadlock() should be
different for the futex and ww_mutex case.

> But rt_mutex_init_waiter() does not set waiter->ww_ctx. Only
> __rt_mutex_slowlock_locked() sets it. So the waiters of PI futexes and
> rtlocks keep the 0x11 poison of CONFIG_DEBUG_RT_MUTEXES. Without that
> option, they keep what was on the stack, unless the compiler zeroes it.
> The chain walk then takes them for ww_mutex waiters.

Is this really the case?
You have a lock chain where the ww_mutex and a regular rtmutex interact?
This doesn't sound too crazy. __waiter_less() expects it to be NULL for
those.

>
> The ww_mutex build of the chain walk can also requeue such waiters. On
> two of them with equal priority, __waiter_less() would dereference the
> poison.

I *think* the enqueue part is only affected if a regular rtmutex already
exists. Because the rtmutex enqueue would ignore ww_mutex/ treat it as
equals.
This will affect rt_mutex_adjust_prio_chain(), the futex interface which
is the only user of the chainwalk.

> Fix this by clearing waiter->ww_ctx in rt_mutex_init_waiter().
>
> With this patch, the ABBA and the deep chain both get EDEADLK. The
> futex_lock_pi_inherit selftest added later in this series found this.
> Its deadlock and max_lock_depth cases cover it.


> Fixes: 6467822b8cc9 ("locking/rtmutex: Prevent spurious EDEADLK return caused by ww_mutexes")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

This is the right thing to do. Either my analysis is wrong or the
changelog confusing. I would argue that the full-chainwalk depends now
on a random stack value _and_ __waiter_less() might access the random
value if ww_mutex is enqueued and a regular mutex exists in the lock
chain.

Sebastian