[PATCHSET sched_ext/for-7.5] sched/proxy: Handle retained donors on scheduling class transitions
From: Andrea Righi
Date: Thu Nov 26 2026 - 06:17:14 EST
Proxy execution keeps mutex-blocked donors on the runqueue. A BPF
scheduler with SCX_OPS_ENQ_BLOCKED admits donors that block while it
owns them, but sched_ext is not currently designed to pass it donors
retained elsewhere, regardless of SCX_OPS_ENQ_BLOCKED. To enforce this,
explicit hooks at the entry points into sched_ext block a retained donor
before sched_change_begin() records its queued state.
Tao Cui reported [1] that rt_mutex_setprio() has no such hook: an EXT
task that is PI-boosted into RT/DL and blocks on a second mutex while
boosted is retained by RT/DL, and when the boost goes away it is handed
back to sched_ext as a queued blocked donor that the BPF scheduler never
admitted.
The same can happen in __sched_setscheduler(). It calls
scx_prepare_setscheduler() to block a retained donor, but only when the
requested policy is SCHED_EXT. When the BPF scheduler takes over all
tasks (no SCX_OPS_SWITCH_PARTIAL), switching an RT/DL task to
SCHED_NORMAL, e.g., via sched_setscheduler(2) or sysrq-n, also moves it
into EXT without blocking the donor. In both cases, a BPF scheduler
without SCX_OPS_ENQ_BLOCKED receives a queued blocked donor it never
admitted: the donor is enqueued without SCX_ENQ_BLOCKED and, once
picked, proxy execution runs the mutex owner on its behalf, even though
the BPF scheduler opted out of it.
As suggested by Peter [2], instead of adding more hooks, let the
incoming class decide: switching_to() now returns whether the class
accepts a retained proxy donor, and sched_change_end() blocks the task
when it doesn't. This handles every class transition into sched_ext,
including PI deboost, and replaces the existing explicit hooks.
Moreover, moving a task between BPF schedulers (sub-sched enable,
rehome, punt) doesn't change its sched_class, so switching_to() doesn't
run there. Rather than keeping a separate hook for these paths, make
SCX_OPS_ENQ_BLOCKED a property of the whole hierarchy: a sub-scheduler
must match the root scheduler's setting or it fails to load, as also
suggested by Peter [3]. This makes the remaining scx-specific donor
blocking, and sched_proxy_block_task(), unnecessary.
Behavior change: a BPF scheduler with SCX_OPS_ENQ_BLOCKED now inherits
retained donors on class entry instead of having them blocked. A queued
donor is passed to ops.enqueue() with SCX_ENQ_BLOCKED as soon as the
scheduler isn't bypassing. The current donor, like any running task
entering sched_ext, keeps running without going through ops.enqueue(),
and gets SCX_ENQ_BLOCKED the next time it does.
Git tree: git://git.kernel.org/pub/scm/linux/kernel/git/arighi/linux.git scx-proxy-donors
Peter, should we route this through the sched_ext tree or would you
prefer that I rebase it onto tip/sched/core?
Thanks,
-Andrea
[1] https://lore.kernel.org/r/20261112144935.583937-3-cui.tao@xxxxxxxxx
[2] https://lore.kernel.org/r/20261112160136.GF1922751@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[3] https://lore.kernel.org/r/20261112164149.GE1813469@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Andrea Righi (4):
sched: Let switching_to() decide whether to keep a retained proxy donor
sched_ext: Make SCX_OPS_ENQ_BLOCKED a hierarchy-wide setting
sched: Remove sched_proxy_block_task()
selftests/sched_ext: Check that blocked donors are never enqueued unadmitted
kernel/sched/core.c | 118 ++++++++++++++-------
kernel/sched/ext/ext.c | 78 +++++---------
kernel/sched/ext/ext.h | 2 -
kernel/sched/ext/internal.h | 4 +-
kernel/sched/ext/sub.c | 12 +--
kernel/sched/idle.c | 2 +-
kernel/sched/sched.h | 16 +--
kernel/sched/stop_task.c | 2 +-
kernel/sched/syscalls.c | 2 -
tools/sched_ext/include/scx/enum_defs.autogen.h | 1 -
tools/sched_ext/include/scx/enums_abi.autogen.h | 1 -
tools/sched_ext/scx_qmap.c | 2 +-
.../testing/selftests/sched_ext/enq_blocked.bpf.c | 9 ++
tools/testing/selftests/sched_ext/enq_blocked.c | 18 +++-
14 files changed, 149 insertions(+), 118 deletions(-)