[PATCH 07/11] sched_ext: Handle blocked donor migration with proxy execution

From: Andrea Righi

Date: Thu Jul 16 2026 - 09:24:53 EST


From: John Stultz <jstultz@xxxxxxxxxx>

With proxy execution enabled, mutex-blocked donors stay runnable so
their scheduling context can execute the lock owner.

sched_ext may normally relocate a queued blocked donor. set_task_cpu()
updates both task_cpu() and wake_cpu, making the destination rq the
donor's new callback home. This remains valid if the donor was previously
proxy-migrated: the BPF scheduler is intentionally selecting a new return
destination, which the next proxy migration will preserve. The usual
migration-disabled, affinity, and rq-online checks apply.

An active donor cannot be moved normally because the source rq still
references it through rq->donor for scheduling-class operations and
runtime accounting. Moving it would associate the task with a different
rq while leaving those source-rq references in place. The core proxy
migration path avoids this by switching the rq donor to idle before moving
the scheduling context.

Check active-donor state in task_can_move_from_locked_rq(), where the
source rq is held and the result is authoritative. Keep it out of the
preliminary lockless DSQ filter so a donor transition during the rq-lock
handoff is resolved by the locked recheck rather than consuming a dispatch
kick and skipping the task.

Allow normal sched_ext migration of blocked donors unless the donor is
active on its rq. In that case, defer migration until it is switched out
or leave it to the proxy machinery.

Keep blocked donors on the local DSQ when they are put so they remain
visible to the proxy pick path.

Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
Co-developed-by: Andrea Righi <arighi@xxxxxxxxxx>
Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
---
kernel/sched/ext/ext.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index c924af485224f..02e3ea7add16f 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -2444,6 +2444,10 @@ static bool task_can_move_from_locked_rq(struct scx_sched *sch,
if (task_on_cpu(src_rq, p))
return false;

+ /* Don't move a donor while its source rq still references it. */
+ if (p->is_blocked && rcu_access_pointer(src_rq->donor) == p)
+ return false;
+
return task_can_run_on_remote_rq(sch, p, dst_rq, enforce);
}

@@ -3093,6 +3097,22 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
if (p->scx.flags & SCX_TASK_QUEUED) {
set_task_runnable(rq, p);

+ /*
+ * Mutex-blocked donors stay queued on the runqueue under proxy
+ * execution, but the donor never runs as itself, proxy-exec
+ * walks the blocked_on chain on the next __schedule() and runs
+ * the lock owner in its place.
+ *
+ * Put the donor on the local DSQ directly so pick_next_task()
+ * can still see it. find_proxy_task() will either run the chain
+ * owner or deactivate the donor so the wakeup path can return it
+ * and let BPF make a new dispatch decision once it is unblocked.
+ */
+ if (p->is_blocked) {
+ scx_dispatch_enqueue(sch, rq, &rq->scx.local_dsq, p, 0);
+ goto switch_class;
+ }
+
/*
* If @p has slice left and is being put, @p is getting
* preempted by a higher priority scheduler class or core-sched
--
2.55.0