summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorKuba Piecuch <jpiecuch@google.com>2026-11-23 13:55:24 +0000
committerTejun Heo <tj@kernel.org>2026-11-24 09:47:29 -1000
commit4fec59cdc2f3cdcdbb71d665b53daf384b36d60d (patch)
treed56915747ff33f9a1d7b92685d77ea8e89ca185c /kernel
parente667a652dd0a6f6d0d89e2d0f80881ddabea1ead (diff)
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 <jpiecuch@google.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/ext/ext.c8
1 files changed, 6 insertions, 2 deletions
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,
};