mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
sched_ext: Align cgroup #ifdef guards with SUB_SCHED vs GROUP_SCHED
Two EXT_GROUP_SCHED/SUB_SCHED guards are misclassified:
- scx_root_enable_workfn()'s cgroup_get(cgrp) and the err_put_cgrp unwind
in scx_alloc_and_add_sched() are under `#if GROUP || SUB`, but the
matching cgroup_put() in scx_sched_free_rcu_work() is inside `#ifdef SUB`
only (via sch->cgrp, stored only under SUB). GROUP-only would leak a
reference on every root-sched enable.
- sch_cgroup() / set_cgroup_sched() live under `#if GROUP || SUB` but touch
SUB-only fields (sch->cgrp, cgroup->scx_sched). GROUP-only wouldn't
compile.
GROUP needs CGROUP_SCHED; SUB needs only CGROUPS. CGROUPS=y/CGROUP_SCHED=n
gives the reachable GROUP=n, SUB=y combination; GROUP=y, SUB=n isn't
reachable today (SUB is def_bool y under CGROUPS). Neither miscategorization
triggers a real bug in any reachable config, but keep the guards honest:
- Narrow cgroup_get and err_put_cgrp to `#ifdef SUB` (matches the free-side
put).
- Move sch_cgroup() and set_cgroup_sched() to a separate `#ifdef SUB` block
with no-op stubs for the !SUB case; keep root_cgroup() and scx_cgroup_{
lock,unlock}() under `#if GROUP || SUB` since those only need cgroup core.
Fixes: ebeca1f930 ("sched_ext: Introduce cgroup sub-sched support")
Reported-by: Chris Mason <clm@meta.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
This commit is contained in:
parent
d292aa00de
commit
c0e8ddc76d
|
|
@ -4413,21 +4413,6 @@ static struct cgroup *root_cgroup(void)
|
|||
return &cgrp_dfl_root.cgrp;
|
||||
}
|
||||
|
||||
static struct cgroup *sch_cgroup(struct scx_sched *sch)
|
||||
{
|
||||
return sch->cgrp;
|
||||
}
|
||||
|
||||
/* for each descendant of @cgrp including self, set ->scx_sched to @sch */
|
||||
static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch)
|
||||
{
|
||||
struct cgroup *pos;
|
||||
struct cgroup_subsys_state *css;
|
||||
|
||||
cgroup_for_each_live_descendant_pre(pos, css, cgrp)
|
||||
rcu_assign_pointer(pos->scx_sched, sch);
|
||||
}
|
||||
|
||||
static void scx_cgroup_lock(void)
|
||||
{
|
||||
#ifdef CONFIG_EXT_GROUP_SCHED
|
||||
|
|
@ -4445,12 +4430,30 @@ static void scx_cgroup_unlock(void)
|
|||
}
|
||||
#else /* CONFIG_EXT_GROUP_SCHED || CONFIG_EXT_SUB_SCHED */
|
||||
static struct cgroup *root_cgroup(void) { return NULL; }
|
||||
static struct cgroup *sch_cgroup(struct scx_sched *sch) { return NULL; }
|
||||
static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch) {}
|
||||
static void scx_cgroup_lock(void) {}
|
||||
static void scx_cgroup_unlock(void) {}
|
||||
#endif /* CONFIG_EXT_GROUP_SCHED || CONFIG_EXT_SUB_SCHED */
|
||||
|
||||
#ifdef CONFIG_EXT_SUB_SCHED
|
||||
static struct cgroup *sch_cgroup(struct scx_sched *sch)
|
||||
{
|
||||
return sch->cgrp;
|
||||
}
|
||||
|
||||
/* for each descendant of @cgrp including self, set ->scx_sched to @sch */
|
||||
static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch)
|
||||
{
|
||||
struct cgroup *pos;
|
||||
struct cgroup_subsys_state *css;
|
||||
|
||||
cgroup_for_each_live_descendant_pre(pos, css, cgrp)
|
||||
rcu_assign_pointer(pos->scx_sched, sch);
|
||||
}
|
||||
#else /* CONFIG_EXT_SUB_SCHED */
|
||||
static struct cgroup *sch_cgroup(struct scx_sched *sch) { return NULL; }
|
||||
static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch) {}
|
||||
#endif /* CONFIG_EXT_SUB_SCHED */
|
||||
|
||||
/*
|
||||
* Omitted operations:
|
||||
*
|
||||
|
|
@ -6604,7 +6607,7 @@ 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)
|
||||
#ifdef CONFIG_EXT_SUB_SCHED
|
||||
cgroup_put(cgrp);
|
||||
#endif
|
||||
return ERR_PTR(ret);
|
||||
|
|
@ -6695,7 +6698,7 @@ 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)
|
||||
#ifdef CONFIG_EXT_SUB_SCHED
|
||||
cgroup_get(cgrp);
|
||||
#endif
|
||||
sch = scx_alloc_and_add_sched(ops, cgrp, NULL);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user