[PATCH 14/21] namespace: keep the private nullfs instance in knullfs

From: Christian Brauner

Date: Fri Oct 02 2026 - 10:00:16 EST


The private nullfs instance that kernel threads are confined to is only
ever reachable through init_task's root and pwd. The following patches
point mounts at it as well, so keep it in a global.

No functional changes.

Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
fs/mount.h | 1 +
fs/namespace.c | 11 ++++++-----
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/mount.h b/fs/mount.h
index 2223fb141499..4e68e5cbc254 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -6,6 +6,7 @@
#include <linux/fs_pin.h>

extern struct file_system_type nullfs_fs_type;
+extern struct vfsmount *knullfs;
extern struct list_head notify_list;

struct mnt_namespace {
diff --git a/fs/namespace.c b/fs/namespace.c
index e116894c8667..d1e83cda57e6 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -80,6 +80,7 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;
static struct hlist_head *mount_hashtable __ro_after_init;
static struct hlist_head *mountpoint_hashtable __ro_after_init;
static struct kmem_cache *mnt_cache __ro_after_init;
+struct vfsmount *knullfs __ro_after_init; /* private nullfs instance */
static DECLARE_RWSEM(namespace_sem);
static HLIST_HEAD(unmounted); /* protected by namespace_sem */
static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
@@ -6335,7 +6336,7 @@ static void __init init_mount_tree(void)
*
* (1) nullfs with mount id 1
* (2) mutable rootfs with mount id 2
- * (3) private nullfs for kthreads (SB_KERNMOUNT)
+ * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs
*
* with (2) mounted on top of (1). The init_task's root and pwd
* are pointed at (3) so all kthreads start isolated in nullfs.
@@ -6370,11 +6371,11 @@ static void __init init_mount_tree(void)
init_mnt_ns.nr_mounts++;
}

- nullfs_mnt = kern_mount(&nullfs_fs_type);
- if (IS_ERR(nullfs_mnt))
+ knullfs = kern_mount(&nullfs_fs_type);
+ if (IS_ERR(knullfs))
panic("VFS: Failed to create private nullfs instance");
- root.mnt = nullfs_mnt;
- root.dentry = nullfs_mnt->mnt_root;
+ root.mnt = knullfs;
+ root.dentry = knullfs->mnt_root;

init_task.nsproxy->mnt_ns = &init_mnt_ns;
get_mnt_ns(&init_mnt_ns);

--
2.53.0