]> git.baikalelectronics.ru Git - kernel.git/commit
cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock
authorTejun Heo <tj@kernel.org>
Mon, 15 Aug 2022 23:27:38 +0000 (13:27 -1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 10:04:54 +0000 (12:04 +0200)
commit35a36a1c300aa0808aca73be71213d2bda7df8b2
tree30857253bbe2de939cf4f31b50905db0d4c39db2
parentc89c4402fd3273a8f5a529c4c9e7063585906b77
cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock

[ Upstream commit baf59de3daebd355ec1f4d7e92ef928050c7e089 ]

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: Tejun Heo <tj@kernel.org>
Reviewed-and-tested-by: Imran Khan <imran.f.khan@oracle.com>
Reported-and-tested-by: Xuewen Yan <xuewen.yan@unisoc.com>
Fixes: 260673b4348d ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
Cc: stable@vger.kernel.org # v5.17+
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/cgroup/cgroup.c
kernel/cgroup/cpuset.c