Re: [PATCH v4 1/2] futex: Provide rt_mutex_.*_schedule() equivalents for futex scheduling
From: Sebastian Andrzej Siewior
Date: Tue Sep 01 2026 - 10:58:58 EST
On 2026-09-01 15:54:51 [+0200], To linux-kernel@xxxxxxxxxxxxxxx wrote:
> By mistake futex_wait_requeue_pi() -> rt_mutex_wait_proxy_lock() did not
> get the rt_mutex_{pre|post}_schedule() annotation. This was not noticed
> because in this callchain the lock is (usually) not contended and so
> rt_mutex_slowlock_block() does not schedule, triggering the assert.
The following makes it trigger more reliably.
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 4728631ae7194..15037c35c684f 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1633,13 +1633,14 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock,
struct rt_mutex *rtm = container_of(lock, struct rt_mutex, rtmutex);
struct task_struct *owner;
int ret = 0;
+ int first_loop = 1;
__assume_ctx_lock(&rtm->rtmutex.wait_lock);
lockevent_inc(rtmutex_slow_block);
for (;;) {
/* Try to acquire the lock: */
- if (try_to_take_rt_mutex(lock, current, waiter)) {
+ if (!first_loop && try_to_take_rt_mutex(lock, current, waiter)) {
lockevent_inc(rtmutex_slow_acq3);
break;
}
@@ -1665,7 +1666,11 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock,
owner = NULL;
raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q);
- if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) {
+ if (first_loop || !owner || !rtmutex_spin_on_owner(lock, waiter, owner)) {
+ if (first_loop) {
+ first_loop = 0;
+ __set_current_state(TASK_RUNNING);
+ }
lockevent_inc(rtmutex_slow_sleep);
rt_mutex_schedule();
}
Sebastian