From 4fec59cdc2f3cdcdbb71d665b53daf384b36d60d Mon Sep 17 00:00:00 2001 From: Kuba Piecuch Date: Mon, 23 Nov 2026 13:55:24 +0000 Subject: sched_ext: Don't allow unlocked kfuncs from ops.dump() and ops.init_cids() 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") Cc: stable@vger.kernel.org # v7.3+ Signed-off-by: Kuba Piecuch Signed-off-by: Tejun Heo --- kernel/sched/ext/ext.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'kernel') diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index 7eda101a0e47..dfda426c768f 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -12291,7 +12291,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, @@ -12307,7 +12306,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, }; -- cgit v1.2.3