[PATCH v34 10/14] sched/proxy: Break cyclic proxy chains by deactivating blocked tasks
From: John Stultz
Date: Tue Dec 01 2026 - 22:53:11 EST
From: "zhidao su (Xiaomi)" <soolaugust@xxxxxxxxx>
find_proxy_task() follows the blocked_on/owner chain for a
blocked donor. If the chain forms a cycle, __schedule() can keep
walking the same chain while holding rq->lock.
Kernel locks are not allowed to have cycles (except ww_mutexes,
which we handle properly), so this logic isn't likely to trip
unless a bad driver has incorrect locking (which lockdep should
detect). However, eventually we want to have proxy-enabled
futexes, where we can't control userland's locking, and will
need to avoid wasting cpu time iterating around a cycle.
Rescheduling idle is not enough here: the same blocked_on
relation remains, so the next scheduling pass can select the
same donor and re-enter the same cycle.
So if we hit an excessive chain depth, clear the blocked_on
relation and deactivate the blocked task. This removes the task
from the proxy-exec runnable-chain selection path and lets the
scheduler make progress.
Use 1024 as the depth limit to match rtmutex's default
max_lock_depth.
Fixes: 7de9d4f94638 ("sched: Start blocked_on chain processing in find_proxy_task()")
Signed-off-by: zhidao su (Xiaomi) <soolaugust@xxxxxxxxx>
[jstultz: Simplified slightly, dropping WARN_ON and owner == donor
check, slightly reworked commit message, added curr_in_chain
check]
Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
---
v34:
* Added curr_in_chain check to make sure we don't deactivate
current.
* Included fixes tag suggested by Kayra Cizmeci
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 | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 6691afa9da906..6f5e1a896ee41 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7092,6 +7092,8 @@ static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf,
proxy_reacquire_rq_lock(rq, rf);
}
+#define MAX_PROXY_CHAIN_DEPTH 1024
+
/*
* Find runnable lock owner to proxy for mutex blocked donor
*
@@ -7127,6 +7129,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
int this_cpu = cpu_of(rq);
struct task_struct *p;
int owner_cpu;
+ int chain_depth = 0;
/* Follow blocked_on chain. */
for (p = donor; p->is_blocked; p = owner) {
@@ -7236,6 +7239,15 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
*/
goto resched_idle;
}
+
+ /* Limit the depth we'll proxy to avoid cyclic deadlocks */
+ if (++chain_depth > MAX_PROXY_CHAIN_DEPTH) {
+ if (curr_in_chain)
+ return proxy_resched_idle(rq);
+ __clear_task_blocked_on(p, NULL);
+ goto deactivate;
+ }
+
/*
* OK, now we're absolutely sure @owner is on this
* rq, therefore holding @rq->lock is sufficient to
--
2.56.1.911.g883d8bcb20-goog