Commit 386dc41c authored by Christian Brauner's avatar Christian Brauner

init: flush async file closing

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: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Tested-by: default avatarSrikanth Aithal <sraithal@amd.com>
Link: https://lore.kernel.org/r/CA+G9fYttTwsbFuVq10igbSvP5xC6bf_XijM=mpUqrJV=uvUirQ@mail.gmail.comSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 6613476e
...@@ -208,6 +208,9 @@ void __init mount_root_generic(char *name, char *pretty_name, int flags) ...@@ -208,6 +208,9 @@ void __init mount_root_generic(char *name, char *pretty_name, int flags)
goto out; goto out;
case -EACCES: case -EACCES:
case -EINVAL: case -EINVAL:
#ifdef CONFIG_BLOCK
init_flush_fput();
#endif
continue; continue;
} }
/* /*
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <linux/major.h> #include <linux/major.h>
#include <linux/root_dev.h> #include <linux/root_dev.h>
#include <linux/init_syscalls.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_generic(char *name, char *pretty_name, int flags);
void mount_root(char *root_device_name); void mount_root(char *root_device_name);
...@@ -41,3 +43,10 @@ static inline bool initrd_load(char *root_device_name) ...@@ -41,3 +43,10 @@ static inline bool initrd_load(char *root_device_name)
} }
#endif #endif
/* Ensure that async file closing finished to prevent spurious errors. */
static inline void init_flush_fput(void)
{
flush_delayed_fput();
task_work_run();
}
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/namei.h> #include <linux/namei.h>
#include <linux/init_syscalls.h> #include <linux/init_syscalls.h>
#include <linux/task_work.h>
#include <linux/umh.h> #include <linux/umh.h>
#include "do_mounts.h"
static __initdata bool csum_present; static __initdata bool csum_present;
static __initdata u32 io_csum; static __initdata u32 io_csum;
...@@ -736,8 +737,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) ...@@ -736,8 +737,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
initrd_start = 0; initrd_start = 0;
initrd_end = 0; initrd_end = 0;
flush_delayed_fput(); init_flush_fput();
task_work_run();
} }
static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain); static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment