Re: [PATCH 15/13] sched_ext: Release cpus_read_lock on scx_link_sched() failure in root enable

Andrea Righi
2026-04-24T22:00:58Z

Hi Tejun,

On Fri, Apr 24, 2026 at 11:08:02AM -1000, Tejun Heo wrote:
> scx_root_enable_workfn() takes cpus_read_lock() before
> scx_link_sched(sch), but the `if (ret) goto err_disable` on failure
> skips the matching cpus_read_unlock() - all other err_disable gotos
> along this path drop the lock first.
>
> scx_link_sched() only returns non-zero on the sub-sched path
> (parent != NULL), so the leak path is unreachable via the root
> caller today. Still, the unwind is out of line with the surrounding
> paths.
>
> Drop cpus_read_lock() before goto err_disable.
>
> Fixes: 0128c850513a ("sched_ext: Exit early on hotplug events during attach")

I think we're fixing:

25037af712eb ("sched_ext: Add rhashtable lookup for sub-schedulers")

Thanks,
-Andrea

> Reported-by: Chris Mason <clm@meta.com>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---
> kernel/sched/ext.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 52b63266e647..d374a5a16bf9 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -6715,8 +6715,10 @@ static void scx_root_enable_workfn(struct kthread_work *work)
> rcu_assign_pointer(scx_root, sch);
>
> ret = scx_link_sched(sch);
> - if (ret)
> + if (ret) {
> + cpus_read_unlock();
> goto err_disable;
> + }
>
> scx_idle_enable(ops);
>
> --
> 2.53.0
>