[PATCH v2] sched_ext: Fix stale errno in scx_sub_enable_workfn()

Cui Jian posted 1 patch 2 days, 12 hours ago
kernel/sched/ext/sub.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH v2] sched_ext: Fix stale errno in scx_sub_enable_workfn()
Posted by Cui Jian 2 days, 12 hours ago
The nesting depth check and the cgroup online check in
scx_sub_enable_workfn() reach err_disable without setting ret, so
the fallback error added by commit db4e9defd2e8 ("sched_ext: Record
an error on errno-only sub-enable failure") reports
"scx_sub_enable() failed (0)".

This is currently harmless because both paths record their own
scx_error() first and the first error wins, but it leaves the
fallback broken for these paths. Set -EINVAL and -ENODEV there
so the fallback always reports a real errno.

v2: The validate_ops() path from v1 is already fixed in for-7.3
    (sub.c already has ret = scx_validate_ops()), so only the two
    remaining paths are addressed.

Signed-off-by: Cui Jian <cjian720@163.com>
---
 kernel/sched/ext/sub.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index d7842a609d96..6da6c91e4287 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -1331,6 +1331,7 @@ void scx_sub_enable_workfn(struct kthread_work *work)
 	if (sch->level >= SCX_SUB_MAX_DEPTH) {
 		scx_error(sch, "max nesting depth %d violated",
 			  SCX_SUB_MAX_DEPTH);
+		ret = -EINVAL;
 		goto err_disable;
 	}
 
@@ -1378,6 +1379,7 @@ void scx_sub_enable_workfn(struct kthread_work *work)
 	set_cgroup_sched(sch_cgroup(sch), sch);
 	if (!(cgrp->self.flags & CSS_ONLINE)) {
 		scx_error(sch, "cgroup is not online");
+		ret = -ENODEV;
 		goto err_unlock_and_disable;
 	}
 
-- 
2.34.1
Re: [PATCH v2] sched_ext: Fix stale errno in scx_sub_enable_workfn()
Posted by Tejun Heo 2 days, 4 hours ago
Hello,

On Wed, Jul 22, 2026 at 06:03:52PM +0800, Cui Jian wrote:
> The nesting depth check and the cgroup online check in
> scx_sub_enable_workfn() reach err_disable without setting ret, so
> the fallback error added by commit db4e9defd2e8 ("sched_ext: Record
> an error on errno-only sub-enable failure") reports
> "scx_sub_enable() failed (0)".

Applied to sched_ext/for-7.3.

Thanks.

-- 
tejun
Re: [PATCH v2] sched_ext: Fix stale errno in scx_sub_enable_workfn()
Posted by Andrea Righi 2 days, 9 hours ago
Hi Cui,

On Wed, Jul 22, 2026 at 06:03:52PM +0800, Cui Jian wrote:
> The nesting depth check and the cgroup online check in
> scx_sub_enable_workfn() reach err_disable without setting ret, so
> the fallback error added by commit db4e9defd2e8 ("sched_ext: Record
> an error on errno-only sub-enable failure") reports
> "scx_sub_enable() failed (0)".
> 
> This is currently harmless because both paths record their own
> scx_error() first and the first error wins, but it leaves the
> fallback broken for these paths. Set -EINVAL and -ENODEV there
> so the fallback always reports a real errno.
> 
> v2: The validate_ops() path from v1 is already fixed in for-7.3
>     (sub.c already has ret = scx_validate_ops()), so only the two
>     remaining paths are addressed.
> 
> Signed-off-by: Cui Jian <cjian720@163.com>

Looks good to me now.

Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> ---
>  kernel/sched/ext/sub.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
> index d7842a609d96..6da6c91e4287 100644
> --- a/kernel/sched/ext/sub.c
> +++ b/kernel/sched/ext/sub.c
> @@ -1331,6 +1331,7 @@ void scx_sub_enable_workfn(struct kthread_work *work)
>  	if (sch->level >= SCX_SUB_MAX_DEPTH) {
>  		scx_error(sch, "max nesting depth %d violated",
>  			  SCX_SUB_MAX_DEPTH);
> +		ret = -EINVAL;
>  		goto err_disable;
>  	}
>  
> @@ -1378,6 +1379,7 @@ void scx_sub_enable_workfn(struct kthread_work *work)
>  	set_cgroup_sched(sch_cgroup(sch), sch);
>  	if (!(cgrp->self.flags & CSS_ONLINE)) {
>  		scx_error(sch, "cgroup is not online");
> +		ret = -ENODEV;
>  		goto err_unlock_and_disable;
>  	}
>  
> -- 
> 2.34.1
>