Skip to content

Commit 0008454

Browse files
laoarhtejun
authored andcommitted
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 <[email protected]> Cc: Michal Koutny <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 9067d90 commit 0008454

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/cgroup/cgroup.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,11 @@ current_cgns_cgroup_from_root(struct cgroup_root *root)
14201420

14211421
rcu_read_unlock();
14221422

1423+
/*
1424+
* The namespace_sem is held by current, so the root cgroup can't
1425+
* be umounted. Therefore, we can ensure that the res is non-NULL.
1426+
*/
1427+
WARN_ON_ONCE(!res);
14231428
return res;
14241429
}
14251430

0 commit comments

Comments
 (0)