]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
init: flush async file closing
authorChristian Brauner <brauner@kernel.org>
Tue, 6 Feb 2024 15:18:43 +0000 (16:18 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 8 Feb 2024 17:41:03 +0000 (18:41 +0100)
When unpacking the initramfs or when mounting block devices we need to
ensure that any delayed fput() finished to prevent spurious errors.
The init process can be a proper kernel thread or a user mode helper.
In the latter case PF_KTHREAD isn't set. So we need to do both
flush_delayed_work() and task_work_run().

Since we'll port block device opening and closing to regular file open
and closing we need to ensure the same as for the initramfs. So just
make that a little helper.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Srikanth Aithal <sraithal@amd.com>
Link: https://lore.kernel.org/r/CA+G9fYttTwsbFuVq10igbSvP5xC6bf_XijM=mpUqrJV=uvUirQ@mail.gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
init/do_mounts.c
init/do_mounts.h
init/initramfs.c

index 279ad28bf4fb148e37cbd9600842a567c813039c..3c5fd993bc7e3e955f322e506bdad8aea8e0edbb 100644 (file)
@@ -208,6 +208,9 @@ retry:
                                goto out;
                        case -EACCES:
                        case -EINVAL:
+#ifdef CONFIG_BLOCK
+                               init_flush_fput();
+#endif
                                continue;
                }
                /*
index 15e372b00ce704bc1b1e5db6514db3a4dcd654a4..6069ea3eb80d70106d6a8d8b3515d50176353206 100644 (file)
@@ -9,6 +9,8 @@
 #include <linux/major.h>
 #include <linux/root_dev.h>
 #include <linux/init_syscalls.h>
+#include <linux/task_work.h>
+#include <linux/file.h>
 
 void  mount_root_generic(char *name, char *pretty_name, int flags);
 void  mount_root(char *root_device_name);
@@ -41,3 +43,10 @@ static inline bool initrd_load(char *root_device_name)
        }
 
 #endif
+
+/* Ensure that async file closing finished to prevent spurious errors. */
+static inline void init_flush_fput(void)
+{
+       flush_delayed_fput();
+       task_work_run();
+}
index 76deb48c38cb16dd779de7ee91b35785b6890579..6554f28fa2dac4c115d67f104b65e7d3fc060086 100644 (file)
 #include <linux/mm.h>
 #include <linux/namei.h>
 #include <linux/init_syscalls.h>
-#include <linux/task_work.h>
 #include <linux/umh.h>
 
+#include "do_mounts.h"
+
 static __initdata bool csum_present;
 static __initdata u32 io_csum;
 
@@ -736,8 +737,7 @@ done:
        initrd_start = 0;
        initrd_end = 0;
 
-       flush_delayed_fput();
-       task_work_run();
+       init_flush_fput();
 }
 
 static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain);