cgroup: Reorganize css_set_lock and kernfs path processing
authorMichal Koutný <mkoutny@suse.com>
Mon, 10 Oct 2022 08:29:18 +0000 (10:29 +0200)
committerTejun Heo <tj@kernel.org>
Mon, 10 Oct 2022 20:23:18 +0000 (10:23 -1000)
commit46307fd6e27a3f678a1678b02e667678c22aa8cc
tree95c66c1e5f3932f79a5c10c58be734992004fa57
parent4de65c5830233e7a4adf2e679510089ec4e210c7
cgroup: Reorganize css_set_lock and kernfs path processing

The commit 74e4b956eb1c incorrectly wrapped kernfs_walk_and_get
(might_sleep) under css_set_lock (spinlock). css_set_lock is needed by
__cset_cgroup_from_root to ensure stable cset->cgrp_links but not for
kernfs_walk_and_get.

We only need to make sure that the returned root_cgrp won't be freed
under us. This is given in the case of global root because it is static
(cgrp_dfl_root.cgrp). When the root_cgrp is lower in the hierarchy, it
is pinned by cgroup_ns->root_cset (and `current` task cannot switch
namespace asynchronously so ns_proxy pins cgroup_ns).

Note this reasoning won't hold for root cgroups in v1 hierarchies,
therefore create a special-cased helper function just for the default
hierarchy.

Fixes: 74e4b956eb1c ("cgroup: Honor caller's cgroup NS when resolving path")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c