[PATCH v2] sched/proxy_exec: Break cyclic proxy chains by deactivating blocked tasks
From: soolaugust
Date: Tue Jul 14 2026 - 11:22:46 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.
A PE cycle reproducer creates two tasks blocked on each other's mutexes.
Without a guard, the guest does not complete within a 90s vng timeout. With
this change, loading the reproducer reports:
sched/pe: deadlock cycle detected, pid 128
and a heartbeat kthread pinned to the same CPU continues to run:
pe_cycle_kmod: heartbeat 3 pid 129
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.
When the walk reaches the original donor again, clear the current
blocked_on relation and deactivate that blocked task. Do the same for
excessive chain depth after revalidating blocked_on under p->blocked_lock.
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.
Signed-off-by: zhidao su (Xiaomi) <soolaugust@xxxxxxxxx>
---
Changes from v1:
- Deactivate the blocked task instead of rescheduling idle.
- Add direct owner == donor cycle detection.
- Raise MAX_PROXY_CHAIN_DEPTH from 64 to 1024.
kernel/sched/core.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2e7cde033a319..cff1a3b58660b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6724,6 +6724,8 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
}
#ifdef CONFIG_SCHED_PROXY_EXEC
+#define MAX_PROXY_CHAIN_DEPTH 1024
+
static inline void proxy_set_task_cpu(struct task_struct *p, int cpu)
{
unsigned int wake_cpu;
@@ -6873,6 +6875,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) {
@@ -6905,6 +6908,13 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
return NULL;
}
+ if (++chain_depth > MAX_PROXY_CHAIN_DEPTH) {
+ WARN_ONCE(1, "sched/pe: proxy chain depth exceeded %d, pid %d\n",
+ MAX_PROXY_CHAIN_DEPTH, p->pid);
+ __clear_task_blocked_on(p, NULL);
+ goto deactivate;
+ }
+
if (task_current(rq, p))
curr_in_chain = true;
@@ -6923,6 +6933,13 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
goto deactivate;
}
+ if (owner == donor) {
+ WARN_ONCE(1, "sched/pe: deadlock cycle detected, pid %d\n",
+ p->pid);
+ __clear_task_blocked_on(p, NULL);
+ goto deactivate;
+ }
+
if (!READ_ONCE(owner->on_rq) || owner->se.sched_delayed) {
/* XXX Don't handle blocked owners/delayed dequeue yet */
if (curr_in_chain)
--
2.43.0