summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup
diff options
context:
space:
mode:
authorYafang Shao <laoar.shao@gmail.com>2023-10-29 06:14:31 +0000
committerTejun Heo <tj@kernel.org>2023-11-09 13:25:47 -1000
commit0008454e8fd30ed0017a9a35b8dd708f168931b8 (patch)
treee1b0837749fe5823497f5206df8ebac983d1fe0d /kernel/cgroup
parent9067d90006df089b9a1da0d74f0cad232a5d726a (diff)
downloadlinux-0008454e8fd30ed0017a9a35b8dd708f168931b8.tar.gz
linux-0008454e8fd30ed0017a9a35b8dd708f168931b8.tar.bz2
linux-0008454e8fd30ed0017a9a35b8dd708f168931b8.zip
cgroup: Add annotation for holding namespace_sem in current_cgns_cgroup_from_root()
When I initially examined the function current_cgns_cgroup_from_root(), I was perplexed by its lack of holding cgroup_mutex. However, after Michal explained the reason[0] to me, I realized that it already holds the namespace_sem. I believe this intricacy could also confuse others, so it would be advisable to include an annotation for clarification. After we replace the cgroup_mutex with RCU read lock, if current doesn't hold the namespace_sem, the root cgroup will be NULL. So let's add a WARN_ON_ONCE() for it. [0]. https://lore.kernel.org/bpf/afdnpo3jz2ic2ampud7swd6so5carkilts2mkygcaw67vbw6yh@5b5mncf7qyet Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Cc: Michal Koutny <mkoutny@suse.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/cgroup')
-rw-r--r--kernel/cgroup/cgroup.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 9bb255e41cf2..4e610863cc37 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1420,6 +1420,11 @@ current_cgns_cgroup_from_root(struct cgroup_root *root)
rcu_read_unlock();
+ /*
+ * The namespace_sem is held by current, so the root cgroup can't
+ * be umounted. Therefore, we can ensure that the res is non-NULL.
+ */
+ WARN_ON_ONCE(!res);
return res;
}