[PATCH v34 03/14] sched/proxy: Reschedule when a blocked task is woken under a proxy

From: John Stultz

Date: Tue Dec 01 2026 - 22:53:11 EST


From: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

With proxy execution, a task blocked on a mutex stays on its runqueue.
The scheduler can pick it as the donor and run the mutex owner in its
place. When the donor is woken, the CPU must stop running the owner on
the donor's context.

Commit 7918cf369361 ("sched/proxy: Only return migrate when needed")
wakes a blocked task in place when it is still on its original CPU.
ttwu_runnable() then relies on wakeup_preempt() to preempt the running
task. But every class compares the woken task with rq->donor. When the
woken task is the donor, it compares the task with itself, and no
reschedule is requested. Only sched_ext handles this, with WF_TTWU_RQ.

So the old owner keeps the donor's context after the mutex hand-off or
after a signal. With a SCHED_FIFO donor nothing bounds this: the owner
runs at the donor's priority until it blocks. With a SCHED_DEADLINE
donor the owner consumes the donor's runtime.

In a test on one CPU, a SCHED_OTHER owner kept spinning in user space
after it released the mutex. A SCHED_FIFO waiter then ran 800ms late. A
SCHED_DEADLINE waiter ran one period late.

The same would happen when a task in the middle of a chain is woken.
proxy_needs_return() resets the donor only when the woken task is the
donor.

Fix this in ttwu_runnable(). When a blocked task is woken on a runqueue
that runs a proxy, reschedule. The next pick walks the chain again. A
blocked task outside the donor's chain causes a harmless reschedule
too.

Fixes: 7918cf369361 ("sched/proxy: Only return migrate when needed")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
[jstultz: Slightly simplified Mathieu's patch]
Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
---
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
Cc: Suleiman Souhlal <suleiman@xxxxxxxxxx>
Cc: Andrea Righi <arighi@xxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Metin Kaya <Metin.Kaya@xxxxxxx>
Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Zimuzo Ezeozue <zezeozue@xxxxxxxxxx>
Cc: Waiman Long <longman@xxxxxxxxxx>
Cc: Boqun Feng <boqun.feng@xxxxxxxxx>
Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxx>
Cc: Joel Fernandes <joelagnelf@xxxxxxxxxx>
Cc: Qais Yousef <qyousef@xxxxxxxxxxx>
Cc: Xuewen Yan <xuewen.yan94@xxxxxxxxx>
Cc: kuyo chang <kuyo.chang@xxxxxxxxxxxx>
Cc: hupu <hupu.gm@xxxxxxxxx>
Cc: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
Cc: zhidao su (Xiaomi) <soolaugust@xxxxxxxxx>
Cc: Hui Su <sh_def@xxxxxxx>
Cc: Shubhang Kaushik (Ampere) <sh@xxxxxxxxxx>
Cc: kernel-team@xxxxxxxxxxx
---
kernel/sched/core.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 181d0e70c88d4..9ba25925c928a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3981,6 +3981,14 @@ static int ttwu_runnable(struct task_struct *p, int wake_flags)
if (p->is_blocked) {
if (p->se.sched_delayed)
enqueue_task(rq, p, ENQUEUE_NOCLOCK | ENQUEUE_DELAYED);
+ /*
+ * If we're waking a blocked task and we are
+ * currently proxying, force a resched in case
+ * the woken task p is in the current donor chain
+ */
+ if (rq->donor != rq->curr)
+ resched_curr(rq);
+
if (proxy_needs_return(rq, p))
return 0;
}
--
2.56.1.911.g883d8bcb20-goog