[PATCH v2 1/8] sched_ext: Reset task fields after ops.exit_task()

From: Changwoo Min

Date: Wed Dec 02 2026 - 23:56:39 EST


__scx_disable_and_exit_task() resets the task fields before
ops.exit_task(). ops.exit_task() runs while @p is still on the scheduler,
so scx_bpf_task_set_dsq_vtime() accepts its writes, and they outlive the
reset. When @p moves between a parent scheduler and a sub-scheduler, the
next scheduler's ops.enable() then finds the vtime the previous one left.

Reset after ops.exit_task() instead. ops.disable() and ops.exit_task()
still see the final values, and a cancelled init now gets the reset too.

Fixes: 5771e79e461e ("sched_ext: Reset dsq_vtime and slice when a task leaves SCX")
Reported-by: Andrea Righi <arighi@xxxxxxxxxx>
Link: https://lore.kernel.org/r/aw57uMvkiKrLBBBI@gpd4
Signed-off-by: Changwoo Min <changwoo@xxxxxxxxxx>
---
kernel/sched/ext/ext.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index a3cf580b0333..eaa68a1e9198 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -4814,12 +4814,9 @@ 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);
- /* after ops.disable() has seen the final values */
- scx_reset_task_fields(task_rq(p), p);
break;
default:
WARN_ON_ONCE(true);
@@ -4828,6 +4825,12 @@ void __scx_disable_and_exit_task(struct scx_sched *sch, struct task_struct *p)

if (SCX_HAS_OP(sch, exit_task))
SCX_CALL_OP_TASK(sch, exit_task, task_rq(p), p, &args);
+
+ /*
+ * After ops.disable() and ops.exit_task() have seen the final values.
+ * ops.exit_task() can still write them while @p is on @sch.
+ */
+ scx_reset_task_fields(task_rq(p), p);
}

/*
--
2.56.1