[PATCH] sched_ext: Arm the exit on the sub-scheduler enable error path
From: David Carlier
Date: Fri Jul 03 2026 - 15:10:14 EST
When enabling a sub-scheduler fails, scx_sub_enable_workfn() jumps to
err_disable and calls scx_flush_disable_work() to unwind. That flush only
does something once the exit has been armed, which happens via
scx_error()/scx_exit(). Several error paths reach err_disable without arming
it - most commonly ops.init_task() rejecting a task with a valid errno, and
the -ENOMEM cases from the arena and cmask scratch allocations.
On those paths teardown never runs: the half-enabled scheduler stays linked
in its parent, ops.exit() is never called, it is left stuck in bypass with
the cgroup subtree still pointing at it, and cmd->ret == 0 reports the attach
as successful. It only gets cleaned up later when the struct_ops map is
detached.
The root enable path already arms the exit before flushing; do the same here.
scx_claim_exit() makes it harmless for paths that already errored.
Signed-off-by: David Carlier <devnexen@xxxxxxxxx>
---
kernel/sched/ext/sub.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index 050420427273..12e2e0787b13 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -570,6 +570,17 @@ void scx_sub_enable_workfn(struct kthread_work *work)
percpu_up_write(&scx_fork_rwsem);
err_disable:
mutex_unlock(&scx_enable_mutex);
+ /*
+ * Several error edges reach here without having called scx_error()
+ * (e.g. ops.init_task() returning a valid errno, or -ENOMEM from the
+ * arena/cmask scratch allocation), leaving exit_kind == SCX_EXIT_NONE.
+ * Arm the exit so the disable work is queued; otherwise
+ * scx_flush_disable_work() is a no-op and the half-enabled
+ * sub-scheduler is left linked and reported as a successful attach.
+ * Mirrors scx_root_enable_workfn(); scx_claim_exit() makes this
+ * idempotent for paths that already errored.
+ */
+ scx_error(sch, "scx_sub_enable() failed (%d)", ret);
scx_flush_disable_work(sch);
cmd->ret = 0;
}
--
2.53.0