cgroup: reduce dependency on cgroup_mutex
authorShakeel Butt <shakeelb@google.com>
Mon, 25 Oct 2021 06:19:14 +0000 (23:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Oct 2022 08:39:35 +0000 (10:39 +0200)
commitae04dd5ef1801784eb0717de2141e094d7544195
tree81827e5705725d3ae0e02fe90adaaf9bcd28fe7a
parent7a64e6dc6cb7c9b1a21b4e29d663c7788bb596f6
cgroup: reduce dependency on cgroup_mutex

[ Upstream commit be288169712f3dea0bc6b50c00b3ab53d85f1435 ]

Currently cgroup_get_from_path() and cgroup_get_from_id() grab
cgroup_mutex before traversing the default hierarchy to find the
kernfs_node corresponding to the path/id and then extract the linked
cgroup. Since cgroup_mutex is still held, it is guaranteed that the
cgroup will be alive and the reference can be taken on it.

However similar guarantee can be provided without depending on the
cgroup_mutex and potentially reducing avenues of cgroup_mutex contentions.
The kernfs_node's priv pointer is RCU protected pointer and with just
rcu read lock we can grab the reference on the cgroup without
cgroup_mutex. So, remove cgroup_mutex from them.

Signed-off-by: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Stable-dep-of: df02452f3df0 ("cgroup: cgroup_get_from_id() must check the looked-up kn is a directory")
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/cgroup/cgroup.c