Commit d683398f authored by Tejun Heo's avatar Tejun Heo Committed by openeuler-sync-bot
Browse files

cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock

stable inclusion
from stable-v5.10.143
commit dee1e2b18cf5426eed985512ccc6636ec69dbdd6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60G94
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=dee1e2b18cf5426eed985512ccc6636ec69dbdd6



-------------------------------

[ Upstream commit 4f7e7236 ]

Bringing up a CPU may involve creating and destroying tasks which requires
read-locking threadgroup_rwsem, so threadgroup_rwsem nests inside
cpus_read_lock(). However, cpuset's ->attach(), which may be called with
thredagroup_rwsem write-locked, also wants to disable CPU hotplug and
acquires cpus_read_lock(), leading to a deadlock.

Fix it by guaranteeing that ->attach() is always called with CPU hotplug
disabled and removing cpus_read_lock() call from cpuset_attach().

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reviewed-and-tested-by: default avatarImran Khan <imran.f.khan@oracle.com>
Reported-and-tested-by: default avatarXuewen Yan <xuewen.yan@unisoc.com>
Fixes: 05c7b7a9 ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
Cc: stable@vger.kernel.org # v5.17+
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>

conflict:
	kernel/cgroup/cgroup.c

Signed-off-by: default avatarCai Xinchen <caixinchen1@huawei.com>
Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: default avatarWang Weiyang <wangweiyang2@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
(cherry picked from commit eb002abd)
parent d24a3b0b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment