Skip to content

Commit 386dc41

Browse files
committed
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: Marek Szyprowski <[email protected]> Tested-by: Srikanth Aithal <[email protected]> Link: https://lore.kernel.org/r/CA+G9fYttTwsbFuVq10igbSvP5xC6bf_XijM=mpUqrJV=uvUirQ@mail.gmail.com Signed-off-by: Christian Brauner <[email protected]>
1 parent 6613476 commit 386dc41

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

init/do_mounts.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ void __init mount_root_generic(char *name, char *pretty_name, int flags)
208208
goto out;
209209
case -EACCES:
210210
case -EINVAL:
211+
#ifdef CONFIG_BLOCK
212+
init_flush_fput();
213+
#endif
211214
continue;
212215
}
213216
/*

init/do_mounts.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <linux/major.h>
1010
#include <linux/root_dev.h>
1111
#include <linux/init_syscalls.h>
12+
#include <linux/task_work.h>
13+
#include <linux/file.h>
1214

1315
void mount_root_generic(char *name, char *pretty_name, int flags);
1416
void mount_root(char *root_device_name);
@@ -41,3 +43,10 @@ static inline bool initrd_load(char *root_device_name)
4143
}
4244

4345
#endif
46+
47+
/* Ensure that async file closing finished to prevent spurious errors. */
48+
static inline void init_flush_fput(void)
49+
{
50+
flush_delayed_fput();
51+
task_work_run();
52+
}

init/initramfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#include <linux/mm.h>
1717
#include <linux/namei.h>
1818
#include <linux/init_syscalls.h>
19-
#include <linux/task_work.h>
2019
#include <linux/umh.h>
2120

21+
#include "do_mounts.h"
22+
2223
static __initdata bool csum_present;
2324
static __initdata u32 io_csum;
2425

@@ -736,8 +737,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
736737
initrd_start = 0;
737738
initrd_end = 0;
738739

739-
flush_delayed_fput();
740-
task_work_run();
740+
init_flush_fput();
741741
}
742742

743743
static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain);

0 commit comments

Comments
 (0)