sched_ext: Enforce SCX_CAP_BASE in core-sched task selection
Subsystems (3)
PATCH 1/1 sched_ext: Enforce SCX_CAP_BASE in core-sched task selection
Under CONFIG_EXT_SUB_SCHED, sched_ext enforces SCX_CAP_BASE on the dispatch path via scx_task_can_stay_on_cpu() and scx_rescuee(). However, ext_sched_class leaves .task_is_throttled unset. Under CONFIG_SCHED_CORE, sched_core_find() and try_steal_cookie() select tasks directly from rq->core_tree and rely on sched_task_is_throttled() to filter ineligible tasks before bypassing pick_task_scx(). As a result, a sub-scheduler task sharing a core-scheduling cookie with an SMT sibling can be picked or stolen onto a CPU where its sub-scheduler lacks SCX_CAP_BASE.
Patch 1 implements task_is_throttled_scx() under CONFIG_SCHED_CORE and wires it to ext_sched_class.task_is_throttled.
Patch 2 adds the sub_core_caps selftest exercising a cid-form root scheduler and child sub-scheduler on an SMT pair, verifying that a cookie-matching sub-scheduler task is not picked on a denied sibling and runs once SCX_CAP_BASE is granted. It requires CONFIG_SCHED_CORE=y (not enabled by default in tools/testing/selftests/sched_ext/config) and an SMT pair plus a third CPU. Without patch 1, the selftest fails with:
ERR: sub_core_caps.c:534
Sub task ran on denied CPU 1 via core-sched (run=6 deq_cse=6)
The patches were written with the help of an AI coding assistant. I have reviewed the patches and verified the tests run by the tool.
Kuba Piecuch (2):
sched_ext: Enforce SCX_CAP_BASE in core-sched task selection selftests/sched_ext: Add sub_core_caps test for core-sched
SCX_CAP_BASE
kernel/sched/ext/ext.c | 11 + tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/sub_core_caps.c | 616 ++++++++++++++++++ .../sched_ext/sub_core_caps_root.bpf.c | 78 +++ .../sched_ext/sub_core_caps_sub.bpf.c | 84 +++ 5 files changed, 790 insertions(+) create mode 100644 tools/testing/selftests/sched_ext/sub_core_caps.c create mode 100644 tools/testing/selftests/sched_ext/sub_core_caps_root.bpf.c create mode 100644 tools/testing/selftests/sched_ext/sub_core_caps_sub.bpf.c
base-commit: 0919f8bea37e7e354b342c2dff52dd8f5b958d6a
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 1/2 sched_ext: Enforce SCX_CAP_BASE in core-sched task selection
Under CONFIG_EXT_SUB_SCHED, a sub-scheduler is only allowed to run tasks on CPUs where it holds SCX_CAP_BASE (apart from migration-disabled tasks and a task admitted as rq->scx.rescue.curr). The sched_ext dispatch path enforces this via scx_task_can_stay_on_cpu() and scx_rescuee().
However, ext_sched_class leaves .task_is_throttled NULL. Under CONFIG_SCHED_CORE, pick_next_task() calls sched_core_find() on sibling runqueues and sched_core_balance() calls try_steal_cookie() across CPUs, both of which select directly from rq->core_tree and rely on sched_task_is_throttled() to filter ineligible tasks before bypassing pick_task_scx(). With .task_is_throttled unset, a sub-scheduler task sharing a core-scheduling cookie with a sibling can be picked by sched_core_find() or stolen by try_steal_cookie() onto a CPU where its sub-scheduler lacks SCX_CAP_BASE, running without ops.dispatch() and bypassing sub-scheduler CPU isolation.
Implement task_is_throttled_scx() under CONFIG_SCHED_CORE, returning true when !scx_task_can_stay_on_cpu(rq, p) && p != scx_rescuee(rq), and wire it to ext_sched_class.task_is_throttled. Both callers hold cpu_rq(cpu)'s lock, and scx_task_can_stay_on_cpu() already fast-paths !scx_has_subs() (and CONFIG_EXT_SUB_SCHED=n), allows local migration-disabled tasks, and resolves bypass via scx_exec_sched().
--- kernel/sched/ext/ext.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
kernel/sched/ext/ext.c +11 -0
@@ -4261,6 +4261,13 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b, return time_after(a->scx.runnable_at, b->scx.runnable_at); } + +static int task_is_throttled_scx (struct task_struct *p,int cpu) +{ +struct rq *rq =cpu_rq (cpu); + +return !scx_task_can_stay_on_cpu (rq, p) && p !=scx_rescuee (rq); +}#endif /* CONFIG_SCHED_CORE */ static int select_task_rq_scx (struct task_struct *p,int prev_cpu,int wake_flags)
@@ -5959,6 +5966,10 @@ DEFINE_SCHED_CLASS(ext) = { .update_curr = update_curr_scx, +#ifdef CONFIG_SCHED_CORE + .task_is_throttled = task_is_throttled_scx, +#endif +#ifdef CONFIG_UCLAMP_TASK .uclamp_enabled = 1,#endif
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 2/2 selftests/sched_ext: Add sub_core_caps test for core-sched SCX_CAP_BASE
In reply to Kuba PiecuchAdd a sub_core_caps selftest using a cid-form root scheduler and child sub-scheduler on an SMT sibling pair. A sub-scheduler task sharing a core-scheduling cookie with a root-scheduler task on sibling 0 is queued in a user DSQ on sibling 1 while an untagged root task competes on sibling 1:
- Phase 1 (no SCX_CAP_BASE on sibling 1): verify sched_core_find() does not dequeue or run the sub-scheduler task on sibling 1.
- Phase 2 (SCX_CAP_ENQ_IMMED | SCX_CAP_ENQ granted on sibling 1): verify the sub-scheduler task becomes eligible and runs on sibling 1.
The test requires CONFIG_SCHED_CORE=y (which is not enabled by default in tools/testing/selftests/sched_ext/config) and an SMT sibling pair plus a third CPU, skipping when core scheduling or that topology is unavailable.
--- tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/sub_core_caps.c | 616 ++++++++++++++++++ .../sched_ext/sub_core_caps_root.bpf.c | 78 +++ .../sched_ext/sub_core_caps_sub.bpf.c | 84 +++ 4 files changed, 779 insertions(+) create mode 100644 tools/testing/selftests/sched_ext/sub_core_caps.c create mode 100644 tools/testing/selftests/sched_ext/sub_core_caps_root.bpf.c create mode 100644 tools/testing/selftests/sched_ext/sub_core_caps_sub.bpf.c
tools/testing/selftests/sched_ext/Makefile +1 -0
@@ -197,6 +197,7 @@ auto-test-targets := \ select_cpu_dispatch_dbl_dsp \ select_cpu_vtime \ rt_stall \ + sub_core_caps \ test_example \ total_bw \ unlocked_kfunc \
tools/testing/selftests/sched_ext/sub_core_caps.c new file +616 -0
616 lines not on this page · raw message
tools/testing/selftests/sched_ext/sub_core_caps_root.bpf.c new file +78 -0
78 lines not on this page · raw message
tools/testing/selftests/sched_ext/sub_core_caps_sub.bpf.c new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.56.1.839.g22a8290db9-goog