sched_ext: Fix build errors and unused label warning in non-cgroup configs
Subsystems (2)
PATCH 1/1 sched_ext: Fix build errors and unused label warning in non-cgroup configs
When building without CONFIG_EXT_GROUP_SCHED and CONFIG_EXT_SUB_SCHED, clang reports errors for undeclared cgroup_put() and cgroup_get() calls. It also flags an unused err_stop_helper label.
This conditionally compiles the cgroup reference counting functions and the error handling label to match the configurations that require them, preventing implicit declaration errors and unused label warnings.
Tested with both configs enabled/disabled.
--- kernel/sched/ext.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/sched/ext.c +6 -0
@@ -6494,8 +6494,10 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops,#endif /* CONFIG_EXT_SUB_SCHED */ return sch; +#ifdef CONFIG_EXT_SUB_SCHED err_stop_helper:kthread_destroy_worker (sch->helper); +#endif err_free_pcpu:for_each_possible_cpu (cpu) {if (cpu == bypass_fail_cpu)
@@ -6514,7 +6516,9 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, err_free_sch:kfree (sch); err_put_cgrp: +#if defined(CONFIG_EXT_GROUP_SCHED ) || defined(CONFIG_EXT_SUB_SCHED )cgroup_put (cgrp); +#endif return ERR_PTR (ret); }
@@ -6603,7 +6607,9 @@ static void scx_root_enable_workfn(struct kthread_work *work)if (ret) goto err_unlock; +#if defined(CONFIG_EXT_GROUP_SCHED ) || defined(CONFIG_EXT_SUB_SCHED )cgroup_get (cgrp); +#endif sch =scx_alloc_and_add_sched (ops, cgrp,NULL );if (IS_ERR (sch)) { ret =PTR_ERR (sch);
Signature · 1 line
2.48.1
Andrea Righi
reviewerHi Cheng-Yang,
Quoted 22 lines · Cheng-Yang Chou
When building without
CONFIG_EXT_GROUP_SCHEDandCONFIG_EXT_SUB_SCHED, clang reports errors for undeclaredcgroup_put()andcgroup_get()calls. It also flags an unusederr_stop_helperlabel.This conditionally compiles the cgroup reference counting functions and the error handling label to match the configurations that require them, preventing implicit declaration errors and unused label warnings.
Tested with both configs enabled/disabled.
Reported-by kernel test robot <[email protected]>Signed-off-by Cheng-Yang Chou <[email protected]>--- kernel/sched/ext.c | 6 ++++++ 1 file changed, 6 insertions(+)kernel/sched/ext.c +0
-0
kernel/sched/ext.c static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, · line 6500
Quoted 7 lines
kernel/sched/ext.c +2
-0@@ -6494,8 +6494,10 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops,#endif /* CONFIG_EXT_SUB_SCHED */ return sch; +#ifdef CONFIG_EXT_SUB_SCHED err_stop_helper:kthread_destroy_worker (sch->helper); +#endif
CONFIG_EXT_SUB_SCHED is always defined whenever ext.c compiles, so this one is unnecessary.
kernel/sched/ext.c static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, · line 6521
Quoted 10 lines
kernel/sched/ext.c +2
-0err_free_pcpu:for_each_possible_cpu (cpu) {if (cpu == bypass_fail_cpu)@@ -6514,7 +6516,9 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, err_free_sch:kfree (sch); err_put_cgrp: +#if defined(CONFIG_EXT_GROUP_SCHED ) || defined(CONFIG_EXT_SUB_SCHED )cgroup_put (cgrp); +#endif
This ifdef around cgroup_get()/cgroup_put() also always evaluates to true because EXT_SUB_SCHED is always true regardless of EXT_GROUP_SCHED.
kernel/sched/ext.c static void scx_root_enable_workfn(struct kthread_work *work) · line 6612
Quoted 10 lines
kernel/sched/ext.c +2
-0return ERR_PTR (ret); }@@ -6603,7 +6607,9 @@ static void scx_root_enable_workfn(struct kthread_work *work)if (ret) goto err_unlock; +#if defined(CONFIG_EXT_GROUP_SCHED ) || defined(CONFIG_EXT_SUB_SCHED )cgroup_get (cgrp); +#endif
Ditto.
kernel/sched/ext.c static void scx_root_enable_workfn(struct kthread_work *work) · line 6615
Quoted 4 lines
kernel/sched/ext.c +0
-0sch =scx_alloc_and_add_sched (ops, cgrp,NULL );if (IS_ERR (sch)) { ret =PTR_ERR (sch);
This looks like a false positive, the kernel test robot likely tested with a manually crafted config, so I think we shouldn't apply this patch.
Thanks,
-Andrea
Quoted 8 lines · Andrea Righi
kernel/sched/ext.c static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, · line 6500
Quoted 5 lines
kernel/sched/ext.c +2
-0+#ifdef CONFIG_EXT_SUB_SCHED err_stop_helper:kthread_destroy_worker (sch->helper); +#endif
CONFIG_EXT_SUB_SCHEDis always defined wheneverext.ccompiles, so this one is unnecessary.
Oh, I see the dependency below. Thanks for pointing that out.
// Kconfig
config EXT_SUB_SCHED
def_bool y
depends on SCHED_CLASS_EXT
Quoted 14 lines
kernel/sched/ext.c static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, · line 6521
Quoted 11 lines
err_free_pcpu:kernel/sched/ext.c +2
-0for_each_possible_cpu (cpu) {if (cpu == bypass_fail_cpu)@@ -6514,7 +6516,9 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, err_free_sch:kfree (sch); err_put_cgrp: +#if defined(CONFIG_EXT_GROUP_SCHED ) || defined(CONFIG_EXT_SUB_SCHED )cgroup_put (cgrp); +#endif This ifdef around cgroup_get()/cgroup_put() also always evaluates to true because
EXT_SUB_SCHEDis always true regardless ofEXT_GROUP_SCHED.
Understood, sorry for the noise.
Quoted 20 lines
kernel/sched/ext.c static void scx_root_enable_workfn(struct kthread_work *work) · line 6612
Quoted 10 lines
kernel/sched/ext.c +2
-0return ERR_PTR (ret); }@@ -6603,7 +6607,9 @@ static void scx_root_enable_workfn(struct kthread_work *work)if (ret) goto err_unlock; +#if defined(CONFIG_EXT_GROUP_SCHED ) || defined(CONFIG_EXT_SUB_SCHED )cgroup_get (cgrp); +#endif Ditto.
kernel/sched/ext.c static void scx_root_enable_workfn(struct kthread_work *work) · line 6615
Quoted 4 lines
kernel/sched/ext.c +0
-0sch =scx_alloc_and_add_sched (ops, cgrp,NULL );if (IS_ERR (sch)) { ret =PTR_ERR (sch);This looks like a false positive, the kernel test robot likely tested with a manually crafted config, so I think we shouldn't apply this patch.
Signature · 2 lines
Thanks, Cheng-Yang
Tejun Heo
reviewerHello,
Quoted 3 lines · Andrea Righi
This looks like a false positive, the kernel test robot likely tested with a manually crafted config, so I think we shouldn't apply this patch.
It's not a false positive. CONFIG_SCHED_CLASS_EXT doesn't depend on CONFIG_CGROUPS in Kconfig, so SCHED_CLASS_EXT=y with CGROUPS=n is a valid config. I reproduced the build failure using the bot's config.
The issue is that CONFIG_EXT_SUB_SCHED is def_bool y depending only on SCHED_CLASS_EXT, so it's always on. But EXT_SUB_SCHED fundamentally needs cgroups (cgroup_path, cgroup_get, cgroup_put, cgroup_id, etc.), so the missing dependency is there.
Cheng-Yang, can you send a v2 with the following approach?
1. Add CGROUPS dependency to EXT_SUB_SCHED in init/Kconfig:
config EXT_SUB_SCHED
def_bool y
- depends on SCHED_CLASS_EXT
+ depends on SCHED_CLASS_EXT && CGROUPS
2. Guard err_stop_helper with #ifdef CONFIG_EXT_SUB_SCHED (only jumped to from within CONFIG_EXT_SUB_SCHED code):
+#ifdef CONFIG_EXT_SUB_SCHED
err_stop_helper:
kthread_destroy_worker(sch->helper);
+#endif
err_free_pcpu:3. Guard cgroup_get/cgroup_put in common paths with the existing CONFIG_EXT_GROUP_SCHED || CONFIG_EXT_SUB_SCHED pattern (matching the root_cgroup() / sch_cgroup() stubs):
err_put_cgrp:
+#if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED)
cgroup_put(cgrp);
+#endif
and:
+#if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED)
cgroup_get(cgrp);
+#endif
sch = scx_alloc_and_add_sched(ops, cgrp, NULL);I verified this builds clean with both CGROUPS=y and CGROUPS=n.
Thanks.
--
tejun
Andrea Righi
reviewerHi,
Quoted 7 lines · Tejun Heo
Hello,
Quoted 3 lines · Andrea Righi
This looks like a false positive, the kernel test robot likely tested with a manually crafted config, so I think we shouldn't apply this patch.
Quoted 8 lines
It's not a false positive.
CONFIG_SCHED_CLASS_EXTdoesn't depend onCONFIG_CGROUPSinKconfig, so SCHED_CLASS_EXT=y with CGROUPS=n is a valid config. I reproduced the build failure using the bot's config.The issue is that
CONFIG_EXT_SUB_SCHEDisdef_booly depending only onSCHED_CLASS_EXT, so it's always on. ButEXT_SUB_SCHEDfundamentally needs cgroups (cgroup_path,cgroup_get,cgroup_put,cgroup_id, etc.), so the missing dependency is there.
Ah you guys are right! I was assuming that you can't have CONFIG_SCHED_CLASS_EXT=y and CONFIG_CGROUPS=n, but that's just wrong.
So ignore my comment and sorry for the noise.
Quoted 35 lines
Cheng-Yang, can you send a v2 with the following approach?
1. Add CGROUPS dependency to
EXT_SUB_SCHEDin init/Kconfig:config
EXT_SUB_SCHED
def_booly
- depends onSCHED_CLASS_EXT
+ depends onSCHED_CLASS_EXT&& CGROUPS2. Guard
err_stop_helperwith #ifdefCONFIG_EXT_SUB_SCHED(only jumped to from withinCONFIG_EXT_SUB_SCHEDcode):+#ifdef CONFIG_EXT_SUB_SCHED err_stop_helper: kthread_destroy_worker(sch->helper); +#endif err_free_pcpu:3. Guard cgroup_get/cgroup_put in common paths with the existing
CONFIG_EXT_GROUP_SCHED||CONFIG_EXT_SUB_SCHEDpattern (matching theroot_cgroup()/sch_cgroup()stubs):
err_put_cgrp:+#if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED) cgroup_put(cgrp); +#endif and: +#if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED) cgroup_get(cgrp); +#endif sch = scx_alloc_and_add_sched(ops, cgrp, NULL);
Quoted 1 line
I verified this builds clean with both CGROUPS=y and CGROUPS=n.
And this looks good also on my side.
Thanks,
-Andrea
Hi Tejun,
Quoted 50 lines · Tejun Heo
Hello,
Quoted 3 lines · Andrea Righi
This looks like a false positive, the kernel test robot likely tested with a manually crafted config, so I think we shouldn't apply this patch.
It's not a false positive.
CONFIG_SCHED_CLASS_EXTdoesn't depend onCONFIG_CGROUPSinKconfig, so SCHED_CLASS_EXT=y with CGROUPS=n is a valid config. I reproduced the build failure using the bot's config.The issue is that
CONFIG_EXT_SUB_SCHEDisdef_booly depending only onSCHED_CLASS_EXT, so it's always on. ButEXT_SUB_SCHEDfundamentally needs cgroups (cgroup_path,cgroup_get,cgroup_put,cgroup_id, etc.), so the missing dependency is there.Cheng-Yang, can you send a v2 with the following approach?
1. Add CGROUPS dependency to
EXT_SUB_SCHEDin init/Kconfig:config
EXT_SUB_SCHED
def_booly
- depends onSCHED_CLASS_EXT
+ depends onSCHED_CLASS_EXT&& CGROUPS2. Guard
err_stop_helperwith #ifdefCONFIG_EXT_SUB_SCHED(only jumped to from withinCONFIG_EXT_SUB_SCHEDcode):+#ifdef CONFIG_EXT_SUB_SCHED err_stop_helper: kthread_destroy_worker(sch->helper); +#endif err_free_pcpu:3. Guard cgroup_get/cgroup_put in common paths with the existing
CONFIG_EXT_GROUP_SCHED||CONFIG_EXT_SUB_SCHEDpattern (matching theroot_cgroup()/sch_cgroup()stubs):
err_put_cgrp:+#if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED) cgroup_put(cgrp); +#endif and: +#if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED) cgroup_get(cgrp); +#endif sch = scx_alloc_and_add_sched(ops, cgrp, NULL);
Quoted 6 lines
I verified this builds clean with both CGROUPS=y and CGROUPS=n.
Thanks.
--
tejun
I have sent a v2 patch.
Thanks for explaining the dependency issue!
Link to v2:
https://lore.kernel.org/r/[email protected]/
Signature · 2 lines
Thanks, Cheng-Yang