Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: ebeca1f930ea ("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>

+22 -19
+22 -19
kernel/sched/ext.c
··· 4413 4413 return &cgrp_dfl_root.cgrp; 4414 4414 } 4415 4415 4416 - static struct cgroup *sch_cgroup(struct scx_sched *sch) 4417 - { 4418 - return sch->cgrp; 4419 - } 4420 - 4421 - /* for each descendant of @cgrp including self, set ->scx_sched to @sch */ 4422 - static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch) 4423 - { 4424 - struct cgroup *pos; 4425 - struct cgroup_subsys_state *css; 4426 - 4427 - cgroup_for_each_live_descendant_pre(pos, css, cgrp) 4428 - rcu_assign_pointer(pos->scx_sched, sch); 4429 - } 4430 - 4431 4416 static void scx_cgroup_lock(void) 4432 4417 { 4433 4418 #ifdef CONFIG_EXT_GROUP_SCHED ··· 4430 4445 } 4431 4446 #else /* CONFIG_EXT_GROUP_SCHED || CONFIG_EXT_SUB_SCHED */ 4432 4447 static struct cgroup *root_cgroup(void) { return NULL; } 4433 - static struct cgroup *sch_cgroup(struct scx_sched *sch) { return NULL; } 4434 - static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch) {} 4435 4448 static void scx_cgroup_lock(void) {} 4436 4449 static void scx_cgroup_unlock(void) {} 4437 4450 #endif /* CONFIG_EXT_GROUP_SCHED || CONFIG_EXT_SUB_SCHED */ 4451 + 4452 + #ifdef CONFIG_EXT_SUB_SCHED 4453 + static struct cgroup *sch_cgroup(struct scx_sched *sch) 4454 + { 4455 + return sch->cgrp; 4456 + } 4457 + 4458 + /* for each descendant of @cgrp including self, set ->scx_sched to @sch */ 4459 + static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch) 4460 + { 4461 + struct cgroup *pos; 4462 + struct cgroup_subsys_state *css; 4463 + 4464 + cgroup_for_each_live_descendant_pre(pos, css, cgrp) 4465 + rcu_assign_pointer(pos->scx_sched, sch); 4466 + } 4467 + #else /* CONFIG_EXT_SUB_SCHED */ 4468 + static struct cgroup *sch_cgroup(struct scx_sched *sch) { return NULL; } 4469 + static void set_cgroup_sched(struct cgroup *cgrp, struct scx_sched *sch) {} 4470 + #endif /* CONFIG_EXT_SUB_SCHED */ 4438 4471 4439 4472 /* 4440 4473 * Omitted operations: ··· 6607 6604 err_free_sch: 6608 6605 kfree(sch); 6609 6606 err_put_cgrp: 6610 - #if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED) 6607 + #ifdef CONFIG_EXT_SUB_SCHED 6611 6608 cgroup_put(cgrp); 6612 6609 #endif 6613 6610 return ERR_PTR(ret); ··· 6698 6695 if (ret) 6699 6696 goto err_unlock; 6700 6697 6701 - #if defined(CONFIG_EXT_GROUP_SCHED) || defined(CONFIG_EXT_SUB_SCHED) 6698 + #ifdef CONFIG_EXT_SUB_SCHED 6702 6699 cgroup_get(cgrp); 6703 6700 #endif 6704 6701 sch = scx_alloc_and_add_sched(ops, cgrp, NULL);