]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sched_ext: Handle SCX_TASK_NONE in disable/switched_from paths
authorTejun Heo <tj@kernel.org>
Sun, 10 May 2026 20:08:16 +0000 (10:08 -1000)
committerTejun Heo <tj@kernel.org>
Sun, 10 May 2026 20:08:16 +0000 (10:08 -1000)
scx_fail_parent() leaves cgroup tasks at (state=NONE, sched=parent,
sched_class=ext) until the parent itself is torn down by the scx_error() it
raised. When the later root_disable iterates them, two paths trip on NONE.

scx_disable_and_exit_task() re-enters the wrapper at NONE: the inner switch
returns early but the trailing scx_set_task_sched(p, NULL) clobbers the
parent sched left by scx_fail_parent(), and scx_set_task_state(p, NONE)
wastes a write on an already-NONE task. switched_from_scx() then calls
scx_disable_task(), which WARNs on non-ENABLED state and writes state=READY,
producing a NONE -> READY transition the validation matrix rejects.

Treat NONE as "nothing to do" in both paths. Add a NONE early-return at the
top of scx_disable_and_exit_task() and a parallel NONE check in
switched_from_scx() next to task_dead_and_done().

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

index 6fbe3160eccd665f1a4cbedb3a72eec5c6c227c0..4efe0099f79af870149c378fec897d28332a6f94 100644 (file)
@@ -3703,6 +3703,15 @@ static void scx_sub_init_cancel_task(struct scx_sched *sch, struct task_struct *
 static void scx_disable_and_exit_task(struct scx_sched *sch,
                                      struct task_struct *p)
 {
+       /*
+        * %NONE means @p is already detached at the SCX level (e.g. handed
+        * back to the parent by scx_fail_parent() with no init to undo).
+        * Skip to avoid clobbering scx_task_sched() and writing %NONE again
+        * on a state that's already %NONE.
+        */
+       if (scx_get_task_state(p) == SCX_TASK_NONE)
+               return;
+
        __scx_disable_and_exit_task(sch, p);
 
        /*
@@ -3921,6 +3930,16 @@ static void switched_from_scx(struct rq *rq, struct task_struct *p)
        if (task_dead_and_done(p))
                return;
 
+       /*
+        * %NONE means SCX is no longer tracking @p at the task level (e.g.
+        * scx_fail_parent() handed @p back to the parent at NONE pending the
+        * parent's own teardown). There is nothing to disable; calling
+        * scx_disable_task() would WARN on the non-%ENABLED state and trigger a
+        * NONE -> READY validation failure.
+        */
+       if (scx_get_task_state(p) == SCX_TASK_NONE)
+               return;
+
        scx_disable_task(scx_task_sched(p), p);
 }