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

Tom Fitzhenry tom at tom-fitzhenry.me.uk
Mon Sep 14 05:12:27 PDT 2026


Hi Andreas,

I'm glad to see improvements to kexec-tools on arm.

For context, I recently posted "arm: use the zImage tag's real 
TEXT_OFFSET for kernel placement"[0] to add support for text_offset.

I hadn't seen your v1 at the time, and will happily rebase my patch 
after your patch is merged. (Or, feel free to add support for 
text_offset, instead.)

I'll leave some comments, since I have a tiny bit of state on this code.

On 9/12/26 20:35, Andreas Kemnade wrote:
> @@ -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.

This line no longer adds the malloc space (and nor is it necessarily 
128k), so maybe remove the mention of malloc space in this comment.

>   	 */
> -	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;

There is support for big endian arm[1], so use le32_to_cpu to convert, 
similar to the other fields.

Also, consider replacing "65536" with "0x10000" to be consistent with 
the else-clause in your patch below.

>   		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;

It's a bit awkward that this fallback case is far from the happy-case 
where the header defines a malloc size.

Consider adding a "if (tag && le32_to_cpu(tag->hdr.size) >= 6)" block 
before the "if (tag)" block to handle this.

This allows us to remove the two fallback cases (!tag, and 
tag&&tag->hdr.size >=6), in favour of just one fallback case.

Something like:

```
if (tag && le32_to_cpu(tag->hdr.size) >= 6)
	len += le32_to_cpu(tag->u.krnl_size.malloc_size);
else
	len += 0x10000;

if (tag) {
[...]
```

Regards,
Tom Fitzhenry

0. https://lists.infradead.org/pipermail/kexec/2026-August/038363.html
1. 
https://github.com/torvalds/linux/blob/704340f1cd0dcef829eb62f5b48ae95a2ce17bdf/arch/arm/mm/Kconfig#L780




More information about the kexec mailing list