* [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1
@ 2026-11-26 16:26 Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 1/2] sched_ext: Reset task fields on exit of an SCX_TASK_READY task Cheng-Yang Chou
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-11-26 16:26 UTC (permalink / raw)
To: stable, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Cheng-Yang Chou, Greg Kroah-Hartman, Sasha Levin, Jiri Slaby,
Rahad Bhuiya, Kang Chen, Ching-Chun Huang, Chia-Ping Tsai,
sched-ext
These are 7.3 backports of two sched_ext fixes dropped from 7.3.7-rc2
because their rc1 versions failed to build [1][2].
- Patch1: factor scx_reset_task_fields() out of scx_disable_task()
instead of taking a298fd5f4ee8.
- Patch2: drop the __SCX_DSQ_ITER_HAS_REENQ context line, so
b3768d058c98, which adds a new kfunc, isn't needed.
Build tested on 7.3.7-rc2 with CONFIG_SCHED_CLASS_EXT=y.
[1] https://lore.kernel.org/r/0782adf7-20af-45a3-a09b-2a34c76afbac@kernel.org
[2] https://lore.kernel.org/r/6e2e92cb-6663-457b-8225-0809917f4332@kernel.org
Kang Chen (1):
sched_ext: make DSQ iterator stay drained after NULL
Rahad Bhuiya (1):
sched_ext: Reset task fields on exit of an SCX_TASK_READY task
kernel/sched/ext/ext.c | 57 +++++++++++++++++++++++++++++-------------
1 file changed, 39 insertions(+), 18 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 7.3.y 1/2] sched_ext: Reset task fields on exit of an SCX_TASK_READY task
2026-11-26 16:26 [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Cheng-Yang Chou
@ 2026-11-26 16:26 ` Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 2/2] sched_ext: make DSQ iterator stay drained after NULL Cheng-Yang Chou
2026-11-27 17:00 ` [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Sasha Levin
2 siblings, 0 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-11-26 16:26 UTC (permalink / raw)
To: stable, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Rahad Bhuiya, Greg Kroah-Hartman, Sasha Levin, Jiri Slaby,
Kang Chen, Ching-Chun Huang, Chia-Ping Tsai, sched-ext,
Cheng-Yang Chou
From: Rahad Bhuiya <rahadbhuiya2021@gmail.com>
commit 564405c424f49d70b13debe7fe5b550234ad6b84 upstream.
Tasks in SCX_TASK_READY are attached to a scheduler but outside the ext
class, such as RT/DL tasks, or non-SCHED_EXT tasks under a partial switch.
The scheduler's BPF code can still update their dsq_vtime and slice (for
instance, via ops.cgroup_move() as done by scx_flatcg).
Because __scx_disable_and_exit_task() currently breaks out of the state
switch for SCX_TASK_READY without calling scx_reset_task_fields(), these
fields are not cleared when the task leaves the scheduler. If the task is
subsequently moved to another cgroup/sub-scheduler and later switches to
SCHED_NORMAL, the new scheduler's ops.enable() sees stale dsq_vtime from
the previous scheduler's clock.
Call scx_reset_task_fields() in the SCX_TASK_READY case of
__scx_disable_and_exit_task() to ensure SCX-managed fields are properly
reset when leaving the scheduler.
Fixes: 5771e79e461e ("sched_ext: Reset dsq_vtime and slice when a task leaves SCX")
Signed-off-by: Rahad Bhuiya <rahadbhuiya2021@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
[ chengyang: 7.3 lacks scx_reset_task_fields(), so factor it out of
scx_disable_task() ]
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
kernel/sched/ext/ext.c | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index cc8d09924fa1..1049a0914d60 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -4159,6 +4159,27 @@ void scx_enable_task(struct scx_sched *sch, struct task_struct *p)
scx_set_task_state(p, SCX_TASK_ENABLED);
}
+/*
+ * Reset the SCX-managed fields when @p leaves the BPF scheduler's control.
+ */
+static void scx_reset_task_fields(struct rq *rq, struct task_struct *p)
+{
+ lockdep_assert_rq_held(rq);
+
+ p->scx.dsq_vtime = 0;
+ scx_task_slice_ended(rq, p);
+ scx_set_task_slice(p, 0);
+ p->scx.reenq_cnt = 0;
+
+ /*
+ * If @p is runnable but not running, its wait started at runnable_at,
+ * which ops_dequeue() didn't reset. Leaving the scheduler ends the
+ * wait. Reset runnable_at the next time @p is enqueued on SCX, so that
+ * the watchdog doesn't count the time @p spends elsewhere.
+ */
+ p->scx.flags |= SCX_TASK_RESET_RUNNABLE_AT;
+}
+
static void scx_disable_task(struct scx_sched *sch, struct task_struct *p)
{
struct rq *rq = task_rq(p);
@@ -4172,22 +4193,8 @@ static void scx_disable_task(struct scx_sched *sch, struct task_struct *p)
SCX_CALL_OP_TASK(sch, disable, rq, p);
scx_set_task_state(p, SCX_TASK_READY);
- /*
- * Reset the SCX-managed fields when @p leaves the BPF scheduler's
- * control, after ops.disable() has observed their final values.
- */
- p->scx.dsq_vtime = 0;
- scx_task_slice_ended(rq, p);
- scx_set_task_slice(p, 0);
- p->scx.reenq_cnt = 0;
-
- /*
- * If @p is runnable but not running, its wait started at runnable_at,
- * which ops_dequeue() didn't reset. Leaving @sch ends the wait. Reset
- * runnable_at the next time @p is enqueued on SCX, so that the watchdog
- * doesn't count the time @p spends elsewhere.
- */
- p->scx.flags |= SCX_TASK_RESET_RUNNABLE_AT;
+ /* after ops.disable() has observed the final values */
+ scx_reset_task_fields(rq, p);
/*
* Verify the task is not in BPF scheduler's custody. If flag
@@ -4213,6 +4220,7 @@ void __scx_disable_and_exit_task(struct scx_sched *sch, struct task_struct *p)
args.cancelled = true;
break;
case SCX_TASK_READY:
+ scx_reset_task_fields(task_rq(p), p);
break;
case SCX_TASK_ENABLED:
scx_disable_task(sch, p);
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 7.3.y 2/2] sched_ext: make DSQ iterator stay drained after NULL
2026-11-26 16:26 [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 1/2] sched_ext: Reset task fields on exit of an SCX_TASK_READY task Cheng-Yang Chou
@ 2026-11-26 16:26 ` Cheng-Yang Chou
2026-11-26 17:03 ` Rahad Bhuiya
2026-11-27 17:00 ` [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Sasha Levin
2 siblings, 1 reply; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-11-26 16:26 UTC (permalink / raw)
To: stable, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Kang Chen, Greg Kroah-Hartman, Sasha Levin, Jiri Slaby,
Rahad Bhuiya, Ching-Chun Huang, Chia-Ping Tsai, sched-ext,
Cheng-Yang Chou
From: Kang Chen <k.chen@smail.nju.edu.cn>
commit fcbff7b56a881bbe041b6c5ba12831a3c1ac1bb4 upstream.
nldsq_cursor_next_task() unlinks the iteration cursor when it reaches the
end of the DSQ. A later call sees list_empty(&cursor->node), starts
from the DSQ head again, and returns the first task of the same
iteration.
The verifier relies on the iterator contract that once next() returns
NULL it keeps returning NULL: process_iter_next_call() marks the
iterator DRAINED and treats the result of later next() calls as the
constant zero. A restarted DSQ iteration therefore hands the BPF
program a task pointer while the verifier believes R0 == 0.
Remember the drained state in the cursor flags and return NULL on every
later next() call. The cursor has spare flag bits and the BPF-visible
iterator layout is unchanged.
Fixes: 650ba21b131e ("sched_ext: Implement DSQ iterator")
Signed-off-by: Kang Chen <k.chen@smail.nju.edu.cn>
Signed-off-by: Tejun Heo <tj@kernel.org>
[ chengyang: drop __SCX_DSQ_ITER_HAS_REENQ, which 7.3 lacks ]
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
kernel/sched/ext/ext.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 1049a0914d60..6db6ca912bb3 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -492,11 +492,13 @@ enum scx_dsq_iter_flags {
/* iterate in the reverse dispatch order */
SCX_DSQ_ITER_REV = 1U << 16,
+ __SCX_DSQ_ITER_DRAINED = 1U << 28,
__SCX_DSQ_ITER_HAS_SLICE = 1U << 30,
__SCX_DSQ_ITER_HAS_VTIME = 1U << 31,
__SCX_DSQ_ITER_USER_FLAGS = SCX_DSQ_ITER_REV,
__SCX_DSQ_ITER_ALL_FLAGS = __SCX_DSQ_ITER_USER_FLAGS |
+ __SCX_DSQ_ITER_DRAINED |
__SCX_DSQ_ITER_HAS_SLICE |
__SCX_DSQ_ITER_HAS_VTIME,
};
@@ -10255,13 +10257,24 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
__bpf_kfunc struct task_struct *bpf_iter_scx_dsq_next(struct bpf_iter_scx_dsq *it)
{
struct bpf_iter_scx_dsq_kern *kit = (void *)it;
+ struct task_struct *p;
- if (!kit->dsq)
+ if (!kit->dsq || (kit->cursor.flags & __SCX_DSQ_ITER_DRAINED))
return NULL;
guard(raw_spinlock_irqsave)(&kit->dsq->lock);
- return nldsq_cursor_next_task(&kit->cursor, kit->dsq);
+ p = nldsq_cursor_next_task(&kit->cursor, kit->dsq);
+ /*
+ * nldsq_cursor_next_task() unlinks the cursor and starts from the DSQ
+ * head when it is called again. The verifier relies on an iterator
+ * which returned NULL to keep returning NULL (see
+ * process_iter_next_call()), so remember the drained state.
+ */
+ if (!p)
+ kit->cursor.flags |= __SCX_DSQ_ITER_DRAINED;
+
+ return p;
}
/**
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 7.3.y 2/2] sched_ext: make DSQ iterator stay drained after NULL
2026-11-26 16:26 ` [PATCH 7.3.y 2/2] sched_ext: make DSQ iterator stay drained after NULL Cheng-Yang Chou
@ 2026-11-26 17:03 ` Rahad Bhuiya
0 siblings, 0 replies; 5+ messages in thread
From: Rahad Bhuiya @ 2026-11-26 17:03 UTC (permalink / raw)
To: Cheng-Yang Chou
Cc: stable, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min,
Kang Chen, Greg Kroah-Hartman, Sasha Levin, Jiri Slaby,
Ching-Chun Huang, Chia-Ping Tsai, sched-ext
Thanks for fixing the 7.3 backport and cleanly factoring out
scx_reset_task_fields().
Acked-by: Rahad Bhuiya <rahadbhuiya2021@gmail.com>
On Thu, Nov 26, 2026 at 10:27 PM Cheng-Yang Chou <yphbchou0911@gmail.com> wrote:
>
> From: Kang Chen <k.chen@smail.nju.edu.cn>
>
> commit fcbff7b56a881bbe041b6c5ba12831a3c1ac1bb4 upstream.
>
> nldsq_cursor_next_task() unlinks the iteration cursor when it reaches the
> end of the DSQ. A later call sees list_empty(&cursor->node), starts
> from the DSQ head again, and returns the first task of the same
> iteration.
>
> The verifier relies on the iterator contract that once next() returns
> NULL it keeps returning NULL: process_iter_next_call() marks the
> iterator DRAINED and treats the result of later next() calls as the
> constant zero. A restarted DSQ iteration therefore hands the BPF
> program a task pointer while the verifier believes R0 == 0.
>
> Remember the drained state in the cursor flags and return NULL on every
> later next() call. The cursor has spare flag bits and the BPF-visible
> iterator layout is unchanged.
>
> Fixes: 650ba21b131e ("sched_ext: Implement DSQ iterator")
> Signed-off-by: Kang Chen <k.chen@smail.nju.edu.cn>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> [ chengyang: drop __SCX_DSQ_ITER_HAS_REENQ, which 7.3 lacks ]
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> kernel/sched/ext/ext.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 1049a0914d60..6db6ca912bb3 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -492,11 +492,13 @@ enum scx_dsq_iter_flags {
> /* iterate in the reverse dispatch order */
> SCX_DSQ_ITER_REV = 1U << 16,
>
> + __SCX_DSQ_ITER_DRAINED = 1U << 28,
> __SCX_DSQ_ITER_HAS_SLICE = 1U << 30,
> __SCX_DSQ_ITER_HAS_VTIME = 1U << 31,
>
> __SCX_DSQ_ITER_USER_FLAGS = SCX_DSQ_ITER_REV,
> __SCX_DSQ_ITER_ALL_FLAGS = __SCX_DSQ_ITER_USER_FLAGS |
> + __SCX_DSQ_ITER_DRAINED |
> __SCX_DSQ_ITER_HAS_SLICE |
> __SCX_DSQ_ITER_HAS_VTIME,
> };
> @@ -10255,13 +10257,24 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
> __bpf_kfunc struct task_struct *bpf_iter_scx_dsq_next(struct bpf_iter_scx_dsq *it)
> {
> struct bpf_iter_scx_dsq_kern *kit = (void *)it;
> + struct task_struct *p;
>
> - if (!kit->dsq)
> + if (!kit->dsq || (kit->cursor.flags & __SCX_DSQ_ITER_DRAINED))
> return NULL;
>
> guard(raw_spinlock_irqsave)(&kit->dsq->lock);
>
> - return nldsq_cursor_next_task(&kit->cursor, kit->dsq);
> + p = nldsq_cursor_next_task(&kit->cursor, kit->dsq);
> + /*
> + * nldsq_cursor_next_task() unlinks the cursor and starts from the DSQ
> + * head when it is called again. The verifier relies on an iterator
> + * which returned NULL to keep returning NULL (see
> + * process_iter_next_call()), so remember the drained state.
> + */
> + if (!p)
> + kit->cursor.flags |= __SCX_DSQ_ITER_DRAINED;
> +
> + return p;
> }
>
> /**
> --
> 2.56.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1
2026-11-26 16:26 [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 1/2] sched_ext: Reset task fields on exit of an SCX_TASK_READY task Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 2/2] sched_ext: make DSQ iterator stay drained after NULL Cheng-Yang Chou
@ 2026-11-27 17:00 ` Sasha Levin
2 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2026-11-27 17:00 UTC (permalink / raw)
To: stable, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Sasha Levin, Cheng-Yang Chou, Greg Kroah-Hartman, Jiri Slaby,
Rahad Bhuiya, Kang Chen, Ching-Chun Huang, Chia-Ping Tsai,
sched-ext
> These are 7.3 backports of two sched_ext fixes dropped from 7.3.7-rc2
> because their rc1 versions failed to build [1][2].
Queued the series for 7.3, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 17:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 16:26 [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 1/2] sched_ext: Reset task fields on exit of an SCX_TASK_READY task Cheng-Yang Chou
2026-11-26 16:26 ` [PATCH 7.3.y 2/2] sched_ext: make DSQ iterator stay drained after NULL Cheng-Yang Chou
2026-11-26 17:03 ` Rahad Bhuiya
2026-11-27 17:00 ` [PATCH 7.3.y 0/2] sched_ext: Backport two fixes dropped from 7.3.7-rc1 Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox