Skip to content

Commit 30d224b

Browse files
committed
sched_ext, sched/core: Don't call scx_group_set_weight() prematurely from sched_create_group()
JIRA: https://issues.redhat.com/browse/RHEL-111810 commit 33796b9 Author: Tejun Heo <tj@kernel.org> Date: Mon Jun 16 10:13:25 2025 -1000 sched_ext, sched/core: Don't call scx_group_set_weight() prematurely from sched_create_group() 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 <tj@kernel.org> Fixes: 8195136 ("sched_ext: Add cgroup support") Cc: stable@vger.kernel.org # v6.12+ Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent 7f80c0d commit 30d224b

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
@@ -8582,7 +8582,7 @@ void __init sched_init(void)
85828582
init_cfs_bandwidth(&root_task_group.cfs_bandwidth, NULL);
85838583
#endif /* CONFIG_FAIR_GROUP_SCHED */
85848584
#ifdef CONFIG_EXT_GROUP_SCHED
8585-
root_task_group.scx_weight = CGROUP_WEIGHT_DFL;
8585+
scx_tg_init(&root_task_group);
85868586
#endif /* CONFIG_EXT_GROUP_SCHED */
85878587
#ifdef CONFIG_RT_GROUP_SCHED
85888588
root_task_group.rt_se = (struct sched_rt_entity **)ptr;
@@ -9022,7 +9022,7 @@ struct task_group *sched_create_group(struct task_group *parent)
90229022
if (!alloc_rt_sched_group(tg, parent))
90239023
goto err;
90249024

9025-
scx_group_set_weight(tg, CGROUP_WEIGHT_DFL);
9025+
scx_tg_init(tg);
90269026
alloc_uclamp_sched_group(tg, parent);
90279027

90289028
return tg;

kernel/sched/ext.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,6 +4056,11 @@ bool scx_can_stop_tick(struct rq *rq)
40564056
DEFINE_STATIC_PERCPU_RWSEM(scx_cgroup_rwsem);
40574057
static bool scx_cgroup_enabled;
40584058

4059+
void scx_tg_init(struct task_group *tg)
4060+
{
4061+
tg->scx_weight = CGROUP_WEIGHT_DFL;
4062+
}
4063+
40594064
int scx_tg_online(struct task_group *tg)
40604065
{
40614066
struct scx_sched *sch = scx_root;

kernel/sched/ext.h

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

9696
#ifdef CONFIG_CGROUP_SCHED
9797
#ifdef CONFIG_EXT_GROUP_SCHED
98+
void scx_tg_init(struct task_group *tg);
9899
int scx_tg_online(struct task_group *tg);
99100
void scx_tg_offline(struct task_group *tg);
100101
int scx_cgroup_can_attach(struct cgroup_taskset *tset);
@@ -104,6 +105,7 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset);
104105
void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight);
105106
void scx_group_set_idle(struct task_group *tg, bool idle);
106107
#else /* CONFIG_EXT_GROUP_SCHED */
108+
static inline void scx_tg_init(struct task_group *tg) {}
107109
static inline int scx_tg_online(struct task_group *tg) { return 0; }
108110
static inline void scx_tg_offline(struct task_group *tg) {}
109111
static inline int scx_cgroup_can_attach(struct cgroup_taskset *tset) { return 0; }

0 commit comments

Comments
 (0)