[PATCH 4/6] sched_ext: Reject cid_online/cid_offline on sub-schedulers

From: Tao Cui

Date: Thu Nov 12 2026 - 08:20:03 EST


From: Tao Cui <cuitao@xxxxxxxxxx>

A sub-sched's enable path sets the has_op bits for every callback it
declares, and validate_ops doesn't stop it from declaring
ops.cid_online()/cid_offline(), but handle_hotplug() delivers hotplug
callbacks to the root scheduler only, so those callbacks would never
run while the per-cid online masks are maintained for the sub-sched
regardless.

Reject the declaration at load time like the cpu-form sub_attach/
sub_detach rejection next to it, and note the root-only delivery in the
ops kerneldoc. The ecaps notifier, in contrast, is delivered per
sub-sched; if per-sub hotplug delivery is wanted later, this rejection
is the piece to relax.

Fixes: 337ec00b1d9c ("sched_ext: Implement cgroup sub-sched enabling and disabling")
Signed-off-by: Tao Cui <cuitao@xxxxxxxxxx>
---
kernel/sched/ext/ext.c | 9 +++++++++
kernel/sched/ext/internal.h | 3 +++
2 files changed, 12 insertions(+)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 063b2964099a..792cf0c1d582 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -8630,6 +8630,15 @@ int scx_validate_ops(struct scx_sched *sch, const struct sched_ext_ops *ops)
}
}

+ /*
+ * Hotplug callbacks are delivered to the root scheduler only, so a
+ * sub-sched's ops.cid_online()/cid_offline() would never run.
+ */
+ if (scx_parent(sch) && (ops->cpu_online || ops->cpu_offline)) {
+ scx_error(sch, "cpu_online/cpu_offline are root-scheduler callbacks");
+ return -EINVAL;
+ }
+
return 0;
}

diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h
index d79a48afbff0..64d87d03e112 100644
--- a/kernel/sched/ext/internal.h
+++ b/kernel/sched/ext/internal.h
@@ -1000,6 +1000,9 @@ struct sched_ext_ops {
* @cpu just came online. @cpu will not call ops.enqueue() or
* ops.dispatch(), nor run tasks associated with other CPUs beforehand.
* ops.sub_child_ecaps_updated() runs for @cpu only after this op.
+ *
+ * Root schedulers only: hotplug callbacks are delivered to the root
+ * scheduler and are never invoked on sub-scheds.
*/
void (*cpu_online)(s32 cpu);

--
2.53.0

base-commit: 5b740a72b55c4267ba4d8010f17dde26b26f52d3