From: Peter Zijlstra <peterz@infradead.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
"André Almeida" <andrealmeid@igalia.com>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Ingo Molnar" <mingo@redhat.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Borislav Petkov" <bp@alien8.de>, "Yao Kai" <yaokai34@huawei.com>
Subject: Re: [PATCH v3 1/2] futex: Add missing rt_mutex_.*_schedule() around rt_mutex_wait_proxy_lock()
Date: Mon, 24 Aug 2026 15:23:34 +0200 [thread overview]
Message-ID: <20260824132334.GI687043@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260824125544.2353006-2-bigeasy@linutronix.de>
On Mon, Aug 24, 2026 at 02:55:42PM +0200, Sebastian Andrzej Siewior wrote:
> From: Yao Kai <yaokai34@huawei.com>
>
> A waiter requeued onto a PI futex can reach rt_mutex_wait_proxy_lock()
> without rtmutex schedule preparation, triggering the lockdep_assert() in
> rt_mutex_schedule().
> The lack of it, can be seen with requeue PI, multiple waiters and
> requeing multiple tasks, the subsequent requeued task can be requeued in
> the state Q_REQUEUE_PI_DONE:
>
> waiter requeue task
> ------ ------------
> futex_wait_requeue_pi()
> futex_wait_setup()
> futex_queue(&q)
> futex_requeue()
> futex_proxy_trylock_atomic()
> futex_requeue_pi_prepare()
> Q_REQUEUE_PI_NONE->Q_REQUEUE_PI_IN_PROGRESS
>
> rt_mutex_start_proxy_lock() (ret = 0)
> requeue_futex()
> futex_do_wait()
> futex_requeue_pi_complete()
> Q_REQUEUE_PI_IN_PROGRESS -> Q_REQUEUE_PI_DONE
> futex_requeue_pi_wakeup_sync()
> rt_mutex_wait_proxy_lock()
> rt_mutex_schedule() (on contention)
>
> In the Q_REQUEUE_PI_DONE case the waiter will acquire the pi_mutex.
> Should the lock be contended, the waiter will invoke rt_mutex_schedule()
> without invoking rt_mutex_.*_schedule() before/ after scheduling.
>
> Invoke rt_mutex_pre_schedule() and rt_mutex_post_schedule() directly around
> rt_mutex_wait_proxy_lock().
Still doesn't explain why this is makes sense. Perhaps something like
the below comment to demystify the code?
> [bigeasy: Redid parts of the changelog, dropped the comment misleading]
>
> Fixes: d14f9e930b90 ("locking/rtmutex: Use rt_mutex specific scheduler helpers")
> Suggested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Signed-off-by: Yao Kai <yaokai34@huawei.com>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> kernel/futex/requeue.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c
> index 79823ad136830..d8c9e7d218695 100644
> --- a/kernel/futex/requeue.c
> +++ b/kernel/futex/requeue.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0-or-later
>
> #include <linux/plist.h>
> +#include <linux/sched/rt.h>
> #include <linux/sched/signal.h>
>
> #include "futex.h"
> @@ -865,7 +866,10 @@ int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
> case Q_REQUEUE_PI_DONE:
> /* Requeue completed. Current is 'pi_blocked_on' the rtmutex */
> pi_mutex = &q.pi_state->pi_mutex;
> +
/*
* Since current is doing the requeue, it cannot also be
* a waiter on the same futex.
*/
> + rt_mutex_pre_schedule();
> ret = rt_mutex_wait_proxy_lock(pi_mutex, to, &rt_waiter);
> + rt_mutex_post_schedule();
>
> /*
> * See futex_unlock_pi()'s cleanup: comment.
> --
> 2.55.0
>
next prev parent reply other threads:[~2026-08-24 13:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 12:55 [PATCH v3 0/2] futex: Address two futex-requeue-pi issues Sebastian Andrzej Siewior
2026-08-24 12:55 ` [PATCH v3 1/2] futex: Add missing rt_mutex_.*_schedule() around rt_mutex_wait_proxy_lock() Sebastian Andrzej Siewior
2026-08-24 13:23 ` Peter Zijlstra [this message]
2026-08-24 14:09 ` Sebastian Andrzej Siewior
2026-08-24 12:55 ` [PATCH v3 2/2] futex: Prevent rcuwait use-after-free during requeue PI Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824132334.GI687043@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=bp@alien8.de \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=yaokai34@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox