]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched_ext: Reset dsq_vtime and slice when a task leaves SCX
authorAndrea Righi <arighi@nvidia.com>
Mon, 8 Jun 2026 16:55:57 +0000 (18:55 +0200)
committerTejun Heo <tj@kernel.org>
Wed, 24 Jun 2026 21:39:50 +0000 (11:39 -1000)
When a task leaves the BPF scheduler's control, p->scx.dsq_vtime and
p->scx.slice keep whatever values they last held. The slice value is
core-managed and is refilled on the next enqueue, but dsq_vtime is owned
by the BPF scheduler and is never cleared by the core, so a task that
leaves SCX and later returns carries a stale dsq_vtime across the
round-trip.

The stale values are also visible to other SCX schedulers that inspect
the scx fields of non-SCX tasks.

Fix this by resetting both dsq_vtime and slice in scx_disable_task(),
after ops.disable(), so the BPF scheduler can still observe the task's
final values and non-SCX tasks do not retain stale SCX state.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext/ext.c

index d62b93f48a85450aefd4e90abf605d55f3857ae8..5efc97437c0a0e3776fb8c08dd4450dbdd443d0b 100644 (file)
@@ -3647,6 +3647,13 @@ 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;
+       p->scx.slice = 0;
+
        /*
         * Verify the task is not in BPF scheduler's custody. If flag
         * transitions are consistent, the flag should always be clear