[PATCH 1/2] sched_ext: Don't allow unlocked kfuncs from ops.dump() and ops.init_cids()

From: Kuba Piecuch

Date: Mon Nov 23 2026 - 08:56:54 EST


scx_kf_allow_flags[] grants SCX_KF_ALLOW_UNLOCKED to ops.dump(). This
allows ops.dump() to call scx_bpf_dsq_move*(), scx_bpf_dsq_reenq_task(),
and scx_bpf_select_cpu_*(). When no rq is locked, these kfuncs acquire
rq, DSQ, and pi locks and may invoke nested SCX ops such as
ops.dequeue().

scx_dump_state() runs ops.dump() with IRQs disabled under scx_dump_lock.
Callers include the hardirq disable irq_work and SysRq-D. With
SCX_KF_ALLOW_UNLOCKED, a debug dump can migrate tasks and run nested
scheduler callbacks instead of only inspecting state. ops.dump_cpu() and
ops.dump_task() already deny these kfuncs. Remove SCX_KF_ALLOW_UNLOCKED
from ops.dump().

ops.init_cids() runs before the cid tables are published and before the
arena pool and pshards are set up. Its only job is to finalize the cid
layout. SCX_KF_ALLOW_UNLOCKED also gave it scx_bpf_create_dsq(),
scx_bpf_dsq_move*(), and scx_bpf_dsq_reenq_task(). Restrict
ops.init_cids() to SCX_KF_ALLOW_INIT_CIDS.

No in-tree scheduler calls these kfuncs from either op.

Fixes: 4c30f5ce4f7a ("sched_ext: Implement scx_bpf_dispatch[_vtime]_from_dsq()")
Fixes: 874fdc0e86e4 ("sched_ext: Add ops.init_cids() to finalize the cid layout before init")
Signed-off-by: Kuba Piecuch <jpiecuch@xxxxxxxxxx>
---
kernel/sched/ext/ext.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index e8c30a21e03e..6274ea04fc6f 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -12293,7 +12293,6 @@ static const u32 scx_kf_allow_flags[] = {
[SCX_OP_IDX(dispatch)] = SCX_KF_ALLOW_ENQUEUE | SCX_KF_ALLOW_DISPATCH,
[SCX_OP_IDX(cpu_release)] = SCX_KF_ALLOW_CPU_RELEASE,
[SCX_OP_IDX(init_task)] = SCX_KF_ALLOW_UNLOCKED,
- [SCX_OP_IDX(dump)] = SCX_KF_ALLOW_UNLOCKED,
#ifdef CONFIG_EXT_GROUP_SCHED
[SCX_OP_IDX(cgroup_init)] = SCX_KF_ALLOW_UNLOCKED,
[SCX_OP_IDX(cgroup_exit)] = SCX_KF_ALLOW_UNLOCKED,
@@ -12309,7 +12308,12 @@ static const u32 scx_kf_allow_flags[] = {
[SCX_OP_IDX(sub_child_ecaps_updated)] = SCX_KF_ALLOW_ENQUEUE | SCX_KF_ALLOW_DISPATCH,
[SCX_OP_IDX(cpu_online)] = SCX_KF_ALLOW_UNLOCKED,
[SCX_OP_IDX(cpu_offline)] = SCX_KF_ALLOW_UNLOCKED,
- [SCX_OP_IDX(init_cids)] = SCX_KF_ALLOW_UNLOCKED | SCX_KF_ALLOW_INIT_CIDS,
+ /*
+ * ops.init_cids() runs before the cid tables are published and before
+ * the arena pool and pshards are allocated. Limit it to finalizing the
+ * cid layout; everything else belongs in ops.init().
+ */
+ [SCX_OP_IDX(init_cids)] = SCX_KF_ALLOW_INIT_CIDS,
[SCX_OP_IDX(init)] = SCX_KF_ALLOW_UNLOCKED,
[SCX_OP_IDX(exit)] = SCX_KF_ALLOW_UNLOCKED,
};
--
2.56.1.750.gf70dc682cf-goog