From: Cheng-Yang Chou <yphbchou0911@gmail.com>
To: stable@vger.kernel.org, Tejun Heo <tj@kernel.org>,
David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>
Cc: Rahad Bhuiya <rahadbhuiya2021@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>,
Jiri Slaby <jirislaby@kernel.org>,
Kang Chen <k.chen@smail.nju.edu.cn>,
Ching-Chun Huang <jserv@ccns.ncku.edu.tw>,
Chia-Ping Tsai <chia7712@gmail.com>,
sched-ext@lists.linux.dev,
Cheng-Yang Chou <yphbchou0911@gmail.com>
Subject: [PATCH 7.3.y 1/2] sched_ext: Reset task fields on exit of an SCX_TASK_READY task
Date: Fri, 27 Nov 2026 00:26:57 +0800 [thread overview]
Message-ID: <20261126162700.22257-2-yphbchou0911@gmail.com> (raw)
In-Reply-To: <20261126162700.22257-1-yphbchou0911@gmail.com>
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
next prev parent reply other threads:[~2026-11-26 16:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126162700.22257-2-yphbchou0911@gmail.com \
--to=yphbchou0911@gmail.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=chia7712@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=k.chen@smail.nju.edu.cn \
--cc=rahadbhuiya2021@gmail.com \
--cc=sashal@kernel.org \
--cc=sched-ext@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox