Skip to content

Commit 37481ad

Browse files
Qais Yousefgregkh
authored andcommitted
sched/uclamp: Fix locking around cpu_util_update_eff()
[ Upstream commit 93b7385 ] cpu_cgroup_css_online() calls cpu_util_update_eff() without holding the uclamp_mutex or rcu_read_lock() like other call sites, which is a mistake. The uclamp_mutex is required to protect against concurrent reads and writes that could update the cgroup hierarchy. The rcu_read_lock() is required to traverse the cgroup data structures in cpu_util_update_eff(). Surround the caller with the required locks and add some asserts to better document the dependency in cpu_util_update_eff(). Fixes: 7226017 ("sched/uclamp: Fix a bug in propagating uclamp value in new cgroups") Reported-by: Quentin Perret <qperret@google.com> Signed-off-by: Qais Yousef <qais.yousef@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20210510145032.1934078-3-qais.yousef@arm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6c2b3d5 commit 37481ad

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7620,7 +7620,11 @@ static int cpu_cgroup_css_online(struct cgroup_subsys_state *css)
76207620

76217621
#ifdef CONFIG_UCLAMP_TASK_GROUP
76227622
/* Propagate the effective uclamp value for the new group */
7623+
mutex_lock(&uclamp_mutex);
7624+
rcu_read_lock();
76237625
cpu_util_update_eff(css);
7626+
rcu_read_unlock();
7627+
mutex_unlock(&uclamp_mutex);
76247628
#endif
76257629

76267630
return 0;
@@ -7710,6 +7714,9 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css)
77107714
enum uclamp_id clamp_id;
77117715
unsigned int clamps;
77127716

7717+
lockdep_assert_held(&uclamp_mutex);
7718+
SCHED_WARN_ON(!rcu_read_lock_held());
7719+
77137720
css_for_each_descendant_pre(css, top_css) {
77147721
uc_parent = css_tg(css)->parent
77157722
? css_tg(css)->parent->uclamp : NULL;

0 commit comments

Comments
 (0)