[PATCH kexec-tools v2] arm-zImage: prepare for more malloc requirements of zstd

Andreas Kemnade andreas at kemnade.info
Sat Sep 12 03:35:14 PDT 2026


As there are plans for zstd in zImage for ARM, which requires more malloc
size fo, decompression, look at the header for the required size.

References:
https://lore.kernel.org/lkml/ZFDMRst2O+RJUYuu@shell.armlinux.org.uk/#t
https://lore.kernel.org/lkml/20260828-zstd2-v2-0-4d9ce7150877@kemnade.info/

Suggested-by: Russell King (Oracle) <linux at armlinux.org.uk>
Signed-off-by: Andreas Kemnade <andreas at kemnade.info>
---
To: kexec at lists.infradead.org
To: Andrew Morton <akpm at linux-foundation.org>
To: Baoquan He <baoquan.he at linux.dev>
To: Mike Rapoport <rppt at kernel.org>
To: Pasha Tatashin <pasha.tatashin at soleen.com>
To: Pratyush Yadav <pratyush at kernel.org>
To: Simon Horman <horms at kernel.org>
Cc: Russell King <linux at armlinux.org.uk>
Cc: j.neuschaefer at gmx.net
---
Changes in v2:
- extract malloc size from zImage header
- Link to v1: https://patch.msgid.link/20260829094607.689485-1-andreas@kemnade.info
---
 kexec/arch/arm/kexec-zImage-arm.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index 8b474dd..1e682db 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -131,6 +131,8 @@ struct zimage_tag {
 		struct zimage_krnl_size {
 			uint32_t size_ptr;
 			uint32_t bss_size;
+			uint32_t text_offset;
+			uint32_t malloc_size;
 		} krnl_size;
 	} u;
 };
@@ -663,18 +665,21 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 
 	/*
 	 * The zImage length does not include its stack (4k) or its
-	 * malloc space (64k).  Include this.
+	 * malloc space (128k).  Include this.
 	 */
-	len += 0x11000;
+	len += 0x1000;
 
-	dbgprintf("zImage requires 0x%08llx bytes\n", (unsigned long long)len);
 
 	if (tag) {
 		uint32_t *p = (void *)buf + le32_to_cpu(tag->u.krnl_size.size_ptr);
 		uint32_t edata_size = le32_to_cpu(get_unaligned(p));
 		uint32_t bss_size = le32_to_cpu(tag->u.krnl_size.bss_size);
+		uint32_t malloc_size = tag->hdr.size >= 6 ? tag->u.krnl_size.malloc_size : 65536;
 		uint32_t kernel_size = edata_size + bss_size;
 
+		len += malloc_size;
+		dbgprintf("malloc size: 0x%lx\n", (unsigned long)malloc_size);
+
 		dbgprintf("Decompressed kernel sizes:\n");
 		dbgprintf(" text+data 0x%08lx bss 0x%08lx total 0x%08lx\n",
 			  (unsigned long)edata_size,
@@ -699,8 +704,13 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 				(unsigned long)kernel_size);
 			kexec_arm_image_size = kernel_size;
 		}
+	} else {
+		/* add default malloc size */
+		len += 0x10000;
 	}
 
+	dbgprintf("zImage requires 0x%08llx bytes\n", (unsigned long long)len);
+
 	/*
 	 * If the user didn't specify the size of the image, and we don't
 	 * have the extension tables, assume the maximum kernel compression

---
base-commit: 43c5cba85ad23cc69c423527d9587c59b89fa437
change-id: 20260912-malloc-fix-31a13574cb84

Best regards,
--  
Andreas Kemnade <andreas at kemnade.info>




More information about the kexec mailing list