Re: [PATCH 1/2] sched_ext: Fix cgroup double-put on sub-sched abort path

From: Andrea Righi

Date: Mon Mar 16 2026 - 02:12:04 EST


On Sun, Mar 15, 2026 at 07:43:27PM -1000, Tejun Heo wrote:
> The abort path in scx_sub_enable_workfn() fell through to out_put_cgrp,
> double-putting the cgroup ref already owned by sch->cgrp. It also skipped
> kthread_flush_work() needed to flush the disable path.
>
> Relocate the abort block above err_unlock_and_disable so it falls through to
> err_disable.
>
> Fixes: ebeca1f930ea ("sched_ext: Introduce cgroup sub-sched support")

Maybe we should point to commit 337ec00b1d9c ("sched_ext: Implement cgroup
sub-sched enabling and disabling")

That's where we added the real sub-sched enable/disable implementation and
the abort block.

Apart from that looks good.

Reviewed-by: Andrea Righi <arighi@xxxxxxxxxx>

Thanks,
-Andrea

> Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
> ---
> kernel/sched/ext.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 9202c6d7a771..2f70effcc4a6 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -7050,6 +7050,13 @@ static void scx_sub_enable_workfn(struct kthread_work *work)
> ret = 0;
> goto out_unlock;
>
> +out_put_cgrp:
> + cgroup_put(cgrp);
> +out_unlock:
> + mutex_unlock(&scx_enable_mutex);
> + cmd->ret = ret;
> + return;
> +
> abort:
> put_task_struct(p);
> scx_task_iter_stop(&sti);
> @@ -7063,15 +7070,6 @@ static void scx_sub_enable_workfn(struct kthread_work *work)
> }
> }
> scx_task_iter_stop(&sti);
> - scx_cgroup_unlock();
> - percpu_up_write(&scx_fork_rwsem);
> -out_put_cgrp:
> - cgroup_put(cgrp);
> -out_unlock:
> - mutex_unlock(&scx_enable_mutex);
> - cmd->ret = ret;
> - return;
> -
> err_unlock_and_disable:
> /* we'll soon enter disable path, keep bypass on */
> scx_cgroup_unlock();
> --
> 2.53.0
>