Skip to content

Commit 05a0192

Browse files
htejunjfvogel
authored andcommitted
sched_ext, sched/core: Don't call scx_group_set_weight() prematurely from sched_create_group()
commit 33796b91871ad4010c8188372dd1faf97cf0f1c0 upstream. During task_group creation, sched_create_group() calls scx_group_set_weight() with CGROUP_WEIGHT_DFL to initialize the sched_ext portion. This is premature and ends up calling ops.cgroup_set_weight() with an incorrect @CGRP before ops.cgroup_init() is called. sched_create_group() should just initialize SCX related fields in the new task_group. Fix it by factoring out scx_tg_init() from sched_init() and making sched_create_group() call that function instead of scx_group_set_weight(). v2: Retain CONFIG_EXT_GROUP_SCHED ifdef in sched_init() as removing it leads to build failures on !CONFIG_GROUP_SCHED configs. Signed-off-by: Tejun Heo <[email protected]> Fixes: 8195136 ("sched_ext: Add cgroup support") Cc: [email protected] # v6.12+ Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 57ec0818698c7d587ebc204971387bdf9d3c9fa1) Signed-off-by: Jack Vogel <[email protected]>
1 parent 2544c9a commit 05a0192

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

kernel/sched/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8455,7 +8455,7 @@ void __init sched_init(void)
84558455
init_cfs_bandwidth(&root_task_group.cfs_bandwidth, NULL);
84568456
#endif /* CONFIG_FAIR_GROUP_SCHED */
84578457
#ifdef CONFIG_EXT_GROUP_SCHED
8458-
root_task_group.scx_weight = CGROUP_WEIGHT_DFL;
8458+
scx_tg_init(&root_task_group);
84598459
#endif /* CONFIG_EXT_GROUP_SCHED */
84608460
#ifdef CONFIG_RT_GROUP_SCHED
84618461
root_task_group.rt_se = (struct sched_rt_entity **)ptr;
@@ -8895,7 +8895,7 @@ struct task_group *sched_create_group(struct task_group *parent)
88958895
if (!alloc_rt_sched_group(tg, parent))
88968896
goto err;
88978897

8898-
scx_group_set_weight(tg, CGROUP_WEIGHT_DFL);
8898+
scx_tg_init(tg);
88998899
alloc_uclamp_sched_group(tg, parent);
89008900

89018901
return tg;

kernel/sched/ext.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,6 +3923,11 @@ static void scx_cgroup_warn_missing_idle(struct task_group *tg)
39233923
cgroup_warned_missing_idle = true;
39243924
}
39253925

3926+
void scx_tg_init(struct task_group *tg)
3927+
{
3928+
tg->scx_weight = CGROUP_WEIGHT_DFL;
3929+
}
3930+
39263931
int scx_tg_online(struct task_group *tg)
39273932
{
39283933
int ret = 0;

kernel/sched/ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static inline void scx_update_idle(struct rq *rq, bool idle, bool do_notify) {}
7070

7171
#ifdef CONFIG_CGROUP_SCHED
7272
#ifdef CONFIG_EXT_GROUP_SCHED
73+
void scx_tg_init(struct task_group *tg);
7374
int scx_tg_online(struct task_group *tg);
7475
void scx_tg_offline(struct task_group *tg);
7576
int scx_cgroup_can_attach(struct cgroup_taskset *tset);
@@ -79,6 +80,7 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset);
7980
void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight);
8081
void scx_group_set_idle(struct task_group *tg, bool idle);
8182
#else /* CONFIG_EXT_GROUP_SCHED */
83+
static inline void scx_tg_init(struct task_group *tg) {}
8284
static inline int scx_tg_online(struct task_group *tg) { return 0; }
8385
static inline void scx_tg_offline(struct task_group *tg) {}
8486
static inline int scx_cgroup_can_attach(struct cgroup_taskset *tset) { return 0; }

0 commit comments

Comments
 (0)