[PATCH 02/10] sched_ext: Block proxy donors across scheduler transitions
Andrea Righi <[email protected]> Mon, 13 Jul 2026 18:17:02 +0200
| Newsgroups | dev.linux.lists.sched-ext,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Proxy execution retains mutex-blocked donors on the runqueue so their scheduling context can execute a lock owner. sched_ext cannot safely retain such donors unless the BPF scheduler explicitly participates in their admission and ordering. Make sched_ext reject retained donors by default. Force blocked EXT tasks through the regular block path in schedule(), and fully deactivate a retained donor before sched_setscheduler() moves it into the EXT class. These hooks establish the safe default that a later opt-in can relax. This is a preparatory change to support proxy execution with sched_ext. Signed-off-by: Andrea Righi <[email protected]> --- kernel/sched/core.c | 3 ++- kernel/sched/ext/ext.c | 21 +++++++++++++++++++++ kernel/sched/ext/ext.h | 6 ++++++ kernel/sched/syscalls.c | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 17f37ad639680..cdeb189f63cdd 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7173,7 +7173,8 @@ static void __sched notrace __schedule(int sched_mode) * task_is_blocked() will always be false). */ try_to_block_task(rq, prev, &prev_state, - !task_is_blocked(prev)); + !task_is_blocked(prev) || + !scx_allow_proxy_exec(prev)); switch_count = &prev->nvcsw; } diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index 9aeb378fa894b..8c527fa14a15f 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -23,6 +23,27 @@ DEFINE_RAW_SPINLOCK(scx_sched_lock); +bool scx_allow_proxy_exec(const struct task_struct *p) +{ + return p->sched_class != &ext_sched_class; +} + +/* + * Called after sched_setscheduler() validation and immediately before + * sched_change_begin(), with @p's pi and rq locks held. + */ +void scx_prepare_setscheduler(struct task_struct *p, + const struct sched_class *next_class) +{ + lockdep_assert_held(&p->pi_lock); + lockdep_assert_rq_held(task_rq(p)); + + if (p->sched_class == next_class || next_class != &ext_sched_class) + return; + + sched_proxy_block_task(task_rq(p), p); +} + /* * NOTE: sched_ext is in the process of growing multiple scheduler support and * scx_root usage is in a transitional state. Naked dereferences are safe if the diff --git a/kernel/sched/ext/ext.h b/kernel/sched/ext/ext.h index 0b7fc46aee08c..d708abf2c3bb8 100644 --- a/kernel/sched/ext/ext.h +++ b/kernel/sched/ext/ext.h @@ -18,8 +18,11 @@ bool scx_can_stop_tick(struct rq *rq); void scx_rq_activate(struct rq *rq); void scx_rq_deactivate(struct rq *rq); int scx_check_setscheduler(struct task_struct *p, int policy); +void scx_prepare_setscheduler(struct task_struct *p, + const struct sched_class *next_class); bool task_should_scx(int policy); bool scx_allow_ttwu_queue(const struct task_struct *p); +bool scx_allow_proxy_exec(const struct task_struct *p); void init_sched_ext_class(void); static inline u32 scx_cpuperf_target(s32 cpu) @@ -52,8 +55,11 @@ static inline bool scx_can_stop_tick(struct rq *rq) { return true; } static inline void scx_rq_activate(struct rq *rq) {} static inline void scx_rq_deactivate(struct rq *rq) {} static inline int scx_check_setscheduler(struct task_struct *p, int policy) { return 0; } +static inline void scx_prepare_setscheduler(struct task_struct *p, + const struct sched_class *next_class) {} static inline bool task_on_scx(const struct task_struct *p) { return false; } static inline bool scx_allow_ttwu_queue(const struct task_struct *p) { return true; } +static inline bool scx_allow_proxy_exec(const struct task_struct *p) { return true; } static inline void init_sched_ext_class(void) {} #endif /* CONFIG_SCHED_CLASS_EXT */ diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c index b215b0ead9a60..2bbba3dc8c890 100644 --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -678,6 +678,9 @@ int __sched_setscheduler(struct task_struct *p, if (prev_class != next_class) queue_flags |= DEQUEUE_CLASS; + if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) + scx_prepare_setscheduler(p, next_class); + scoped_guard (sched_change, p, queue_flags) { if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) { -- 2.55.0