Skip to content

Commit 32750c7

Browse files
committed
fs: start all kthreads in nullfs
Point init_task's fs_struct (root and pwd) at a private nullfs instance instead of the mutable rootfs. All kthreads now start isolated in nullfs and must use scoped_with_init_fs() for any path resolution. PID 1 is moved from nullfs into the initramfs by init_userspace_fs(). Usermodehelper threads use userspace_init_fs via the umh flag in copy_fs(). All subsystems that need init's filesystem state for path resolution already use scoped_with_init_fs() from earlier commits in this series. This isolates kthreads from userspace filesystem state and makes it hard to perform filesystem operations from kthread context. Link: https://patch.msgid.link/[email protected] Signed-off-by: Christian Brauner (Amutable) <[email protected]>
1 parent e435696 commit 32750c7

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎fs/namespace.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6184,12 +6184,14 @@ static void __init init_mount_tree(void)
61846184
struct path root;
61856185

61866186
/*
6187-
* We create two mounts:
6187+
* We create three mounts:
61886188
*
61896189
* (1) nullfs with mount id 1
61906190
* (2) mutable rootfs with mount id 2
6191+
* (3) private nullfs for kthreads (SB_KERNMOUNT)
61916192
*
6192-
* with (2) mounted on top of (1).
6193+
* with (2) mounted on top of (1). The init_task's root and pwd
6194+
* are pointed at (3) so all kthreads start isolated in nullfs.
61936195
*/
61946196
nullfs_mnt = vfs_kern_mount(&nullfs_fs_type, 0, "nullfs", NULL);
61956197
if (IS_ERR(nullfs_mnt))
@@ -6229,12 +6231,14 @@ static void __init init_mount_tree(void)
62296231
init_mnt_ns.nr_mounts++;
62306232
}
62316233

6234+
nullfs_mnt = kern_mount(&nullfs_fs_type);
6235+
if (IS_ERR(nullfs_mnt))
6236+
panic("VFS: Failed to create private nullfs instance");
6237+
root.mnt = nullfs_mnt;
6238+
root.dentry = nullfs_mnt->mnt_root;
6239+
62326240
init_task.nsproxy->mnt_ns = &init_mnt_ns;
62336241
get_mnt_ns(&init_mnt_ns);
6234-
6235-
/* The root and pwd always point to the mutable rootfs. */
6236-
root.mnt = mnt;
6237-
root.dentry = mnt->mnt_root;
62386242
set_fs_pwd(current->fs, &root);
62396243
set_fs_root(current->fs, &root);
62406244

0 commit comments

Comments
 (0)