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/[email protected]/#t
https://lore.kernel.org/lkml/[email protected]/

Suggested-by: Russell King (Oracle) <[email protected]>
Signed-off-by: Andreas Kemnade <[email protected]>
---
To: [email protected]
To: Andrew Morton <[email protected]>
To: Baoquan He <[email protected]>
To: Mike Rapoport <[email protected]>
To: Pasha Tatashin <[email protected]>
To: Pratyush Yadav <[email protected]>
To: Simon Horman <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
---
Changes in v2:
- extract malloc size from zImage header
- Link to v1: 
https://patch.msgid.link/[email protected]
---
 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 <[email protected]>


Reply via email to