* [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched
@ 2026-04-23 2:58 zhidao su
2026-04-23 4:27 ` Cheng-Yang Chou
2026-04-23 16:40 ` Tejun Heo
0 siblings, 2 replies; 3+ messages in thread
From: zhidao su @ 2026-04-23 2:58 UTC (permalink / raw)
To: Tejun Heo, Andrea Righi
Cc: David Vernet, Changwoo Min, sched-ext, linux-kernel, zhidao su
local_dsq_post_enq() calls call_task_dequeue() with scx_root instead of
the scheduler instance actually managing the task. When
CONFIG_EXT_SUB_SCHED is enabled, tasks may be managed by a sub-scheduler
whose ops.dequeue() callback differs from root's. Using scx_root causes
the wrong scheduler's ops.dequeue() to be consulted: sub-sched tasks
dispatched to a local DSQ via scx_bpf_dsq_move_to_local() will have
SCX_TASK_IN_CUSTODY cleared but the sub-scheduler's ops.dequeue() is
never invoked, violating the custody exit semantics.
Fix by adding a 'struct scx_sched *sch' parameter to local_dsq_post_enq()
and move_local_task_to_local_dsq(), and propagating the correct scheduler
from their callers dispatch_enqueue(), move_task_between_dsqs(), and
consume_dispatch_q().
This is consistent with dispatch_enqueue()'s non-local path which already
passes 'sch' directly to call_task_dequeue() for global/bypass DSQs.
Fixes: ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics")
Signed-off-by: zhidao su <suzhidao@xiaomi.com>
---
kernel/sched/ext.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 9628c64e5592..6ab743777a54 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1467,13 +1467,13 @@ static void call_task_dequeue(struct scx_sched *sch, struct rq *rq,
p->scx.flags &= ~SCX_TASK_IN_CUSTODY;
}
-static void local_dsq_post_enq(struct scx_dispatch_q *dsq, struct task_struct *p,
- u64 enq_flags)
+static void local_dsq_post_enq(struct scx_sched *sch, struct scx_dispatch_q *dsq,
+ struct task_struct *p, u64 enq_flags)
{
struct rq *rq = container_of(dsq, struct rq, scx.local_dsq);
bool preempt = false;
- call_task_dequeue(scx_root, rq, p, 0);
+ call_task_dequeue(sch, rq, p, 0);
/*
* If @rq is in balance, the CPU is already vacant and looking for the
@@ -1606,7 +1606,7 @@ static void dispatch_enqueue(struct scx_sched *sch, struct rq *rq,
* concurrently in a non-atomic way.
*/
if (is_local) {
- local_dsq_post_enq(dsq, p, enq_flags);
+ local_dsq_post_enq(sch, dsq, p, enq_flags);
} else {
/*
* Task on global/bypass DSQ: leave custody, task on
@@ -2192,7 +2192,8 @@ static void wakeup_preempt_scx(struct rq *rq, struct task_struct *p, int wake_fl
schedule_reenq_local(rq, 0);
}
-static void move_local_task_to_local_dsq(struct task_struct *p, u64 enq_flags,
+static void move_local_task_to_local_dsq(struct scx_sched *sch,
+ struct task_struct *p, u64 enq_flags,
struct scx_dispatch_q *src_dsq,
struct rq *dst_rq)
{
@@ -2212,7 +2213,7 @@ static void move_local_task_to_local_dsq(struct task_struct *p, u64 enq_flags,
dsq_inc_nr(dst_dsq, p, enq_flags);
p->scx.dsq = dst_dsq;
- local_dsq_post_enq(dst_dsq, p, enq_flags);
+ local_dsq_post_enq(sch, dst_dsq, p, enq_flags);
}
/**
@@ -2433,7 +2434,7 @@ static struct rq *move_task_between_dsqs(struct scx_sched *sch,
/* @p is going from a non-local DSQ to a local DSQ */
if (src_rq == dst_rq) {
task_unlink_from_dsq(p, src_dsq);
- move_local_task_to_local_dsq(p, enq_flags,
+ move_local_task_to_local_dsq(sch, p, enq_flags,
src_dsq, dst_rq);
raw_spin_unlock(&src_dsq->lock);
} else {
@@ -2486,7 +2487,7 @@ static bool consume_dispatch_q(struct scx_sched *sch, struct rq *rq,
if (rq == task_rq) {
task_unlink_from_dsq(p, dsq);
- move_local_task_to_local_dsq(p, enq_flags, dsq, rq);
+ move_local_task_to_local_dsq(sch, p, enq_flags, dsq, rq);
raw_spin_unlock(&dsq->lock);
return true;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched
2026-04-23 2:58 [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched zhidao su
@ 2026-04-23 4:27 ` Cheng-Yang Chou
2026-04-23 16:40 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Cheng-Yang Chou @ 2026-04-23 4:27 UTC (permalink / raw)
To: zhidao su
Cc: Tejun Heo, Andrea Righi, David Vernet, Changwoo Min, sched-ext,
linux-kernel, zhidao su, Ching-Chun Huang, Chia-Ping Tsai
Hi zhidao,
On Thu, Apr 23, 2026 at 10:58:32AM +0800, zhidao su wrote:
> local_dsq_post_enq() calls call_task_dequeue() with scx_root instead of
> the scheduler instance actually managing the task. When
> CONFIG_EXT_SUB_SCHED is enabled, tasks may be managed by a sub-scheduler
> whose ops.dequeue() callback differs from root's. Using scx_root causes
> the wrong scheduler's ops.dequeue() to be consulted: sub-sched tasks
> dispatched to a local DSQ via scx_bpf_dsq_move_to_local() will have
> SCX_TASK_IN_CUSTODY cleared but the sub-scheduler's ops.dequeue() is
> never invoked, violating the custody exit semantics.
>
> Fix by adding a 'struct scx_sched *sch' parameter to local_dsq_post_enq()
> and move_local_task_to_local_dsq(), and propagating the correct scheduler
> from their callers dispatch_enqueue(), move_task_between_dsqs(), and
> consume_dispatch_q().
>
> This is consistent with dispatch_enqueue()'s non-local path which already
> passes 'sch' directly to call_task_dequeue() for global/bypass DSQs.
>
> Fixes: ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics")
> Signed-off-by: zhidao su <suzhidao@xiaomi.com>
This fix looks correct for the parameter mismatch.
Reviewed-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Regarding the Fixes tag: I'm not entirely sure if it's strictly required
since the sub-scheduler groundwork is still a new feature. However, since
it fixes a specific logic error, keeping the tag seems appropriate.
Thanks.
--
Cheers,
Cheng-Yang
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched
2026-04-23 2:58 [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched zhidao su
2026-04-23 4:27 ` Cheng-Yang Chou
@ 2026-04-23 16:40 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-04-23 16:40 UTC (permalink / raw)
To: zhidao su, Andrea Righi
Cc: David Vernet, Changwoo Min, sched-ext, linux-kernel,
Emil Tsalapatis
Hello,
On Thu, Apr 23, 2026 at 10:58:32AM +0800, zhidao su wrote:
> local_dsq_post_enq() calls call_task_dequeue() with scx_root instead of
> the scheduler instance actually managing the task. When
> CONFIG_EXT_SUB_SCHED is enabled, tasks may be managed by a sub-scheduler
> whose ops.dequeue() callback differs from root's.
...
> Fixes: ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics")
> Signed-off-by: zhidao su <suzhidao@xiaomi.com>
Applied to sched_ext/for-7.1-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-23 16:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 2:58 [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched zhidao su
2026-04-23 4:27 ` Cheng-Yang Chou
2026-04-23 16:40 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox