[PATCH] sched/proxy, sched_ext: Skip proxy-exec on SCX owner with holding_cpu

From: Peng Huang

Date: Sat Nov 21 2026 - 22:53:07 EST


During remote DSQ consumption or dispatch_to_local_dsq(), another CPU
claims @p->scx.holding_cpu and drops the DSQ lock while switching to
@p's source rq lock. Because commit 13ae184e4b82 ("sched_ext: Handle
proxy-exec races in remote DSQ transfers") made proxy execution
compatible with sched_ext, find_proxy_task() on the source CPU can pick
such an owner while holding source rq->lock, forcing the transferring CPU
to abort the placement and bounce the task to reject_dsq once it acquires
source rq->lock.

Like task_on_rq_migrating(), an SCX task with holding_cpu >= 0 is in an
in-flight cross-rq lock handoff. Expose scx_task_held() in ext.h, have
find_proxy_task() yield to rq->idle via resched_idle when an SCX owner
is held so the transfer can complete, and pair the lockless READ_ONCE()
with WRITE_ONCE()/READ_ONCE() on holding_cpu updates.

Signed-off-by: Peng Huang <penghuang@xxxxxxxxxx>
---
kernel/sched/core.c | 9 +++++++++
kernel/sched/ext/ext.c | 14 +++++++-------
kernel/sched/ext/ext.h | 6 ++++++
3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5ed660f099a5..8aa309d86a6c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7108,6 +7108,15 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
if (!task_on_rq_queued(owner) || task_cpu(owner) != this_cpu)
return NULL;

+ /*
+ * Do not proxy-execute a sched_ext owner while another CPU has
+ * claimed holding_cpu to transfer it off a DSQ before locking
+ * this rq; yield the rq lock so the transfer can finish
+ * without bouncing the owner into reject_dsq.
+ */
+ if (unlikely(scx_task_held(owner)))
+ goto resched_idle;
+
if (owner == p) {
/*
* It's possible we interleave with mutex_unlock like:
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index e29c9c18e1ab..5202f750a3b5 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -2043,8 +2043,8 @@ void scx_dispatch_dequeue(struct rq *rq, struct task_struct *p)
* but @p->scx.holding_cpu may be set. Clearing holding_cpu
* tells dispatch_to_local_dsq() that it lost to a dequeue.
*/
- if (p->scx.holding_cpu >= 0)
- p->scx.holding_cpu = -1;
+ if (READ_ONCE(p->scx.holding_cpu) >= 0)
+ WRITE_ONCE(p->scx.holding_cpu, -1);

return;
}
@@ -2067,7 +2067,7 @@ void scx_dispatch_dequeue(struct rq *rq, struct task_struct *p)
* unlink_dsq_and_switch_rq_lock() that it lost the race.
*/
WARN_ON_ONCE(!list_empty(&p->scx.dsq_list.node));
- p->scx.holding_cpu = -1;
+ WRITE_ONCE(p->scx.holding_cpu, -1);
}
p->scx.dsq = NULL;

@@ -2978,7 +2978,7 @@ static bool unlink_dsq_and_switch_rq_lock(struct task_struct *p,

WARN_ON_ONCE(p->scx.holding_cpu >= 0);
scx_task_unlink_from_dsq(p, dsq);
- p->scx.holding_cpu = cpu;
+ WRITE_ONCE(p->scx.holding_cpu, cpu);

raw_spin_unlock(&dsq->lock);
switch_rq_lock(locked_rq, src_rq);
@@ -2993,7 +2993,7 @@ static bool unlink_dsq_and_switch_rq_lock(struct task_struct *p,
* holding_cpu with it so that no caller has to.
*/
p->scx.dsq = NULL;
- p->scx.holding_cpu = -1;
+ WRITE_ONCE(p->scx.holding_cpu, -1);
scx_wait_dispatching(p);
return true;
}
@@ -3213,7 +3213,7 @@ static void dispatch_to_local_dsq(struct scx_sched *sch, struct rq *rq,
* under transfer with holding_cpu, release DISPATCHING and then follow
* the same protocol. See unlink_dsq_and_switch_rq_lock().
*/
- p->scx.holding_cpu = raw_smp_processor_id();
+ WRITE_ONCE(p->scx.holding_cpu, raw_smp_processor_id());

/* store_release ensures that dequeue sees the above */
atomic_long_set_release(&p->scx.ops_state, SCX_OPSS_NONE);
@@ -3230,7 +3230,7 @@ static void dispatch_to_local_dsq(struct scx_sched *sch, struct rq *rq,
bool fallback = false;

/* the handshake is over, see unlink_dsq_and_switch_rq_lock() */
- p->scx.holding_cpu = -1;
+ WRITE_ONCE(p->scx.holding_cpu, -1);

/*
* If @p is staying on the same rq, there's no need to go
diff --git a/kernel/sched/ext/ext.h b/kernel/sched/ext/ext.h
index d32bc01071b0..f936300b5aea 100644
--- a/kernel/sched/ext/ext.h
+++ b/kernel/sched/ext/ext.h
@@ -54,6 +54,11 @@ static inline bool task_on_scx(const struct task_struct *p)
return scx_enabled() && p->sched_class == &ext_sched_class;
}

+static inline bool scx_task_held(const struct task_struct *p)
+{
+ return task_on_scx(p) && READ_ONCE(p->scx.holding_cpu) >= 0;
+}
+
#ifdef CONFIG_SCHED_CORE
bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
bool in_fi);
@@ -75,6 +80,7 @@ static inline void scx_prepare_setscheduler(struct task_struct *p, int policy) {
static inline bool task_on_scx(const struct task_struct *p) { return false; }
static inline bool scx_allow_ttwu_queue(const struct task_struct *p) { return true; }
static inline bool scx_allow_proxy_exec(const struct task_struct *p) { return true; }
+static inline bool scx_task_held(const struct task_struct *p) { return false; }
static inline void scx_proxy_donor_start(struct rq *rq) {}
static inline void scx_proxy_reenqueue_retry(struct rq *rq,
struct task_struct *next) {}
--
2.56.1.750.gf70dc682cf-goog