]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
69e7924217edbd84eb32acb6bcb1f0b92e3e76a6
[thirdparty/kernel/stable-queue.git] /
1 From 33796b91871ad4010c8188372dd1faf97cf0f1c0 Mon Sep 17 00:00:00 2001
2 From: Tejun Heo <tj@kernel.org>
3 Date: Mon, 16 Jun 2025 10:13:25 -1000
4 Subject: sched_ext, sched/core: Don't call scx_group_set_weight() prematurely from sched_create_group()
5
6 From: Tejun Heo <tj@kernel.org>
7
8 commit 33796b91871ad4010c8188372dd1faf97cf0f1c0 upstream.
9
10 During task_group creation, sched_create_group() calls
11 scx_group_set_weight() with CGROUP_WEIGHT_DFL to initialize the sched_ext
12 portion. This is premature and ends up calling ops.cgroup_set_weight() with
13 an incorrect @cgrp before ops.cgroup_init() is called.
14
15 sched_create_group() should just initialize SCX related fields in the new
16 task_group. Fix it by factoring out scx_tg_init() from sched_init() and
17 making sched_create_group() call that function instead of
18 scx_group_set_weight().
19
20 v2: Retain CONFIG_EXT_GROUP_SCHED ifdef in sched_init() as removing it leads
21 to build failures on !CONFIG_GROUP_SCHED configs.
22
23 Signed-off-by: Tejun Heo <tj@kernel.org>
24 Fixes: 819513666966 ("sched_ext: Add cgroup support")
25 Cc: stable@vger.kernel.org # v6.12+
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27 ---
28 kernel/sched/core.c | 4 ++--
29 kernel/sched/ext.c | 5 +++++
30 kernel/sched/ext.h | 2 ++
31 3 files changed, 9 insertions(+), 2 deletions(-)
32
33 --- a/kernel/sched/core.c
34 +++ b/kernel/sched/core.c
35 @@ -8571,7 +8571,7 @@ void __init sched_init(void)
36 init_cfs_bandwidth(&root_task_group.cfs_bandwidth, NULL);
37 #endif /* CONFIG_FAIR_GROUP_SCHED */
38 #ifdef CONFIG_EXT_GROUP_SCHED
39 - root_task_group.scx_weight = CGROUP_WEIGHT_DFL;
40 + scx_tg_init(&root_task_group);
41 #endif /* CONFIG_EXT_GROUP_SCHED */
42 #ifdef CONFIG_RT_GROUP_SCHED
43 root_task_group.rt_se = (struct sched_rt_entity **)ptr;
44 @@ -9011,7 +9011,7 @@ struct task_group *sched_create_group(st
45 if (!alloc_rt_sched_group(tg, parent))
46 goto err;
47
48 - scx_group_set_weight(tg, CGROUP_WEIGHT_DFL);
49 + scx_tg_init(tg);
50 alloc_uclamp_sched_group(tg, parent);
51
52 return tg;
53 --- a/kernel/sched/ext.c
54 +++ b/kernel/sched/ext.c
55 @@ -3936,6 +3936,11 @@ bool scx_can_stop_tick(struct rq *rq)
56 DEFINE_STATIC_PERCPU_RWSEM(scx_cgroup_rwsem);
57 static bool scx_cgroup_enabled;
58
59 +void scx_tg_init(struct task_group *tg)
60 +{
61 + tg->scx_weight = CGROUP_WEIGHT_DFL;
62 +}
63 +
64 int scx_tg_online(struct task_group *tg)
65 {
66 int ret = 0;
67 --- a/kernel/sched/ext.h
68 +++ b/kernel/sched/ext.h
69 @@ -80,6 +80,7 @@ static inline void scx_update_idle(struc
70
71 #ifdef CONFIG_CGROUP_SCHED
72 #ifdef CONFIG_EXT_GROUP_SCHED
73 +void scx_tg_init(struct task_group *tg);
74 int scx_tg_online(struct task_group *tg);
75 void scx_tg_offline(struct task_group *tg);
76 int scx_cgroup_can_attach(struct cgroup_taskset *tset);
77 @@ -89,6 +90,7 @@ void scx_cgroup_cancel_attach(struct cgr
78 void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight);
79 void scx_group_set_idle(struct task_group *tg, bool idle);
80 #else /* CONFIG_EXT_GROUP_SCHED */
81 +static inline void scx_tg_init(struct task_group *tg) {}
82 static inline int scx_tg_online(struct task_group *tg) { return 0; }
83 static inline void scx_tg_offline(struct task_group *tg) {}
84 static inline int scx_cgroup_can_attach(struct cgroup_taskset *tset) { return 0; }