]> 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)
committerTejun Heo <tj@kernel.org>
Wed, 17 Aug 2022 17:36:05 +0000 (07:36 -1000)
commitc816169ad60e4e64b73d03b23012f670e3af6945
tree35e9a5ce25341e6348141027edc1b4bfa141802c
parent65f313bda19ae2249b7495eea0c717094d424bfc
cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock

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: b73af54f52ab ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
Cc: stable@vger.kernel.org # v5.17+
kernel/cgroup/cgroup.c
kernel/cgroup/cpuset.c