The patch titled Subject: initramfs: panic with memory information has been added to the -mm tree. Its filename is initramfs-panic-with-memory-information.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/initramfs-panic-with-memory-information.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/initramfs-panic-with-memory-information.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Florian Fainelli <f.fainelli@xxxxxxxxx> Subject: initramfs: panic with memory information On systems with large amounts of reserved memory we may fail to successfully complete unpack_to_rootfs() and be left with: Kernel panic - not syncing: write error this is not too helpful to understand what happened, so let's wrap the panic() calls with a surrounding show_mem() such that we have a chance of understanding the memory conditions leading to these allocation failures. Link: https://lkml.kernel.org/r/20210114231517.1854379-1-f.fainelli@xxxxxxxxx Signed-off-by: Florian Fainelli <f.fainelli@xxxxxxxxx> Cc: Barret Rhoden <brho@xxxxxxxxxx> Cc: Arnd Bergmann <arnd@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- init/initramfs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/init/initramfs.c~initramfs-panic-with-memory-information +++ a/init/initramfs.c @@ -11,6 +11,7 @@ #include <linux/utime.h> #include <linux/file.h> #include <linux/memblock.h> +#include <linux/mm.h> #include <linux/namei.h> #include <linux/init_syscalls.h> @@ -45,6 +46,11 @@ static void __init error(char *x) message = x; } +#define panic_show_mem(...) { \ + show_mem(0, NULL); \ + panic(__VA_ARGS__); \ +} + /* link hash */ #define N_ALIGN(len) ((((len) + 1) & ~3) + 2) @@ -80,7 +86,7 @@ static char __init *find_link(int major, } q = kmalloc(sizeof(struct hash), GFP_KERNEL); if (!q) - panic("can't allocate link hash entry"); + panic_show_mem("can't allocate link hash entry"); q->major = major; q->minor = minor; q->ino = ino; @@ -125,7 +131,7 @@ static void __init dir_add(const char *n { struct dir_entry *de = kmalloc(sizeof(struct dir_entry), GFP_KERNEL); if (!de) - panic("can't allocate dir_entry buffer"); + panic_show_mem("can't allocate dir_entry buffer"); INIT_LIST_HEAD(&de->list); de->name = kstrdup(name, GFP_KERNEL); de->mtime = mtime; @@ -460,7 +466,7 @@ static char * __init unpack_to_rootfs(ch name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL); if (!header_buf || !symlink_buf || !name_buf) - panic("can't allocate buffers"); + panic_show_mem("can't allocate buffers"); state = Start; this_header = 0; @@ -607,7 +613,7 @@ static int __init populate_rootfs(void) /* Load the built in initramfs */ char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size); if (err) - panic("%s", err); /* Failed to decompress INTERNAL initramfs */ + panic_show_mem("%s", err); /* Failed to decompress INTERNAL initramfs */ if (!initrd_start || IS_ENABLED(CONFIG_INITRAMFS_FORCE)) goto done; _ Patches currently in -mm which might be from f.fainelli@xxxxxxxxx are initramfs-panic-with-memory-information.patch