mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-21 01:51:18 +00:00
sched/uclamp: Fix locking around cpu_util_update_eff()
[ Upstream commit93b7385870
] 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:7226017ad3
("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>
This commit is contained in:
parent
0b199ce65b
commit
8e5ffc1039
1 changed files with 7 additions and 0 deletions
|
@ -7199,7 +7199,11 @@ static int cpu_cgroup_css_online(struct cgroup_subsys_state *css)
|
||||||
|
|
||||||
#ifdef CONFIG_UCLAMP_TASK_GROUP
|
#ifdef CONFIG_UCLAMP_TASK_GROUP
|
||||||
/* Propagate the effective uclamp value for the new group */
|
/* Propagate the effective uclamp value for the new group */
|
||||||
|
mutex_lock(&uclamp_mutex);
|
||||||
|
rcu_read_lock();
|
||||||
cpu_util_update_eff(css);
|
cpu_util_update_eff(css);
|
||||||
|
rcu_read_unlock();
|
||||||
|
mutex_unlock(&uclamp_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7289,6 +7293,9 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css)
|
||||||
enum uclamp_id clamp_id;
|
enum uclamp_id clamp_id;
|
||||||
unsigned int clamps;
|
unsigned int clamps;
|
||||||
|
|
||||||
|
lockdep_assert_held(&uclamp_mutex);
|
||||||
|
SCHED_WARN_ON(!rcu_read_lock_held());
|
||||||
|
|
||||||
css_for_each_descendant_pre(css, top_css) {
|
css_for_each_descendant_pre(css, top_css) {
|
||||||
uc_parent = css_tg(css)->parent
|
uc_parent = css_tg(css)->parent
|
||||||
? css_tg(css)->parent->uclamp : NULL;
|
? css_tg(css)->parent->uclamp : NULL;
|
||||||
|
|
Loading…
Reference in a new issue