Re: [PATCH v2 11/14] futex: Verify exit_mutex ownership in futex_exit_recursive()

From: Marco Elver

Date: Wed Nov 11 2026 - 06:05:44 EST


On Mon, 9 Nov 2026 at 20:14, Bart Van Assche <bvanassche@xxxxxxx> wrote:
>
> futex_exit_recursive() unlocks tsk->futex.exit_mutex if the futex state
> is FUTEX_STATE_EXITING. It uses __assume_ctx_lock() to inform Clang's
> context analysis that this mutex is held. However, __assume_ctx_lock()
> does not verify that assumption. Convert the __assume_ctx_lock() call
> into a lockdep_assume_ctx_held() call such that the lock ownership
> assumption is also verified at runtime by lockdep.
>
> Cc: Marco Elver <elver@xxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
> ---
> kernel/futex/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/futex/core.c b/kernel/futex/core.c
> index a240638f69e5..4e5aa0160dd2 100644
> --- a/kernel/futex/core.c
> +++ b/kernel/futex/core.c
> @@ -1503,7 +1503,7 @@ void futex_exit_recursive(struct task_struct *tsk)
> {
> /* If the state is FUTEX_STATE_EXITING then futex_exit_mutex is held */
> if (tsk->futex.state == FUTEX_STATE_EXITING) {
> - __assume_ctx_lock(&tsk->futex.exit_mutex);
> + lockdep_assume_ctx_held(&tsk->futex.exit_mutex);
> mutex_unlock(&tsk->futex.exit_mutex);

mutex_unlock() on the next line already (dynamically) checks
ownership. If it's broken, it'll splat with lockdep (or crash in other
spectacular ways without lockdep).

Drop this.