Skip to content

Commit 7118daa

Browse files
committed
ns: add asserts for initial namespace active reference counts
They always remain fixed at one. Notice when that assumptions is broken. Link: https://patch.msgid.link/20251110-work-namespace-nstree-fixes-v1-14-e8a9264e0fb9@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 2b60d56 commit 7118daa

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

include/linux/ns_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
6969
{
7070
if (is_ns_init_id(ns)) {
7171
VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1);
72+
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) != 1);
7273
return false;
7374
}
7475
if (refcount_dec_and_test(&ns->__ns_ref)) {
@@ -82,6 +83,7 @@ static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns)
8283
{
8384
if (is_ns_init_id(ns)) {
8485
VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1);
86+
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) != 1);
8587
return true;
8688
}
8789
if (refcount_inc_not_zero(&ns->__ns_ref))
@@ -94,6 +96,7 @@ static __always_inline void __ns_ref_inc(struct ns_common *ns)
9496
{
9597
if (is_ns_init_id(ns)) {
9698
VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1);
99+
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) != 1);
97100
return;
98101
}
99102
refcount_inc(&ns->__ns_ref);
@@ -104,6 +107,7 @@ static __always_inline __must_check bool __ns_ref_dec_and_lock(struct ns_common
104107
{
105108
if (is_ns_init_id(ns)) {
106109
VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1);
110+
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) != 1);
107111
return false;
108112
}
109113
return refcount_dec_and_lock(&ns->__ns_ref, ns_lock);

0 commit comments

Comments
 (0)