ARM ZSTD boot compression
v2 cover ARM ZSTD boot compression
Add ZSTD compression to still have a quite high compression but with not too much boot delay penality.
---
Changes in v2:
- rebased
- practically rewritten 3/3 (and therefore changed author)
- added more measurements
- Link to v1: https://lore.kernel.org/lkml/ZDoDYh01GYjdwp63@probook/
To: Russell King <[email protected]>
To: Nick Terrell <[email protected]>
To: David Sterba <[email protected]>
To: Nathan Chancellor <[email protected]>
To: Nick Desaulniers <[email protected]>
To: Bill Wendling <[email protected]>
To: Justin Stitt <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Linus Walleij <[email protected]>
Cc: Tony Lindgren <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
Andreas Kemnade (1):
ARM: compressed: Enable ZSTD compression
Jonathan Neuschäfer (2):
ARM: compressed: Pass the actual output length to the decompressor
ARM: compressed: Bump MALLOC_SIZE to 128 KiB
arch/arm/Kconfig | 1 + arch/arm/boot/compressed/Makefile | 3 ++- arch/arm/boot/compressed/decompress.c | 15 ++++++++++++--- arch/arm/boot/compressed/head.S | 4 ++-- arch/arm/boot/compressed/misc.c | 10 +++++++++- arch/arm/boot/compressed/misc.h | 3 ++- 6 files changed, 28 insertions(+), 8 deletions(-)
---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260828-zstd2-045ce924f624
Best regards,
Signature · 1 line
Andreas Kemnade <[email protected]>
PATCH v2 1/3 ARM: compressed: Pass the actual output length to the decompressor
From: Jonathan Neuschäfer <[email protected]>
ZSTD writes outside of the space that is necessary for the uncompressed data, when it is told it has unlimited output length. To fix this, pass the actual output length (the length of the uncompressed kernel) to the decompressor.
The uncompressed length is already stored as a little endian 32-bit constant before the input_data_end symbol.
--- arch/arm/boot/compressed/decompress.c | 4 ++-- arch/arm/boot/compressed/misc.c | 10 +++++++++- arch/arm/boot/compressed/misc.h | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-)
arch/arm/boot/compressed/decompress.c +2 -2
@@ -60,7 +60,7 @@ extern char * strchrnul(const char *, int);#include "../../../../lib/decompress_unlz4.c" #endif -int do_decompress (u8 *input,int len,u8 *output,void (*error)(char *x)) +int do_decompress (u8 *input,int len,u8 *output,int outlen,void (*error)(char *x)) { -return __decompress (input, len,NULL ,NULL , output,0 ,NULL , error); +return __decompress (input, len,NULL ,NULL , output, outlen,NULL , error); }
arch/arm/boot/compressed/misc.c +9 -1
@@ -22,6 +22,7 @@ unsigned int __machine_arch_type;#include <linux/compiler.h> /* for inline */ #include <linux/types.h> #include <linux/linkage.h> +#include <linux/unaligned.h> #include "misc.h" #ifdef CONFIG_ARCH_EP93XX #include "misc-ep93xx.h"
@@ -128,14 +129,21 @@ asmlinkage void __div0(void)error ("Attempting division by 0!" ); } +static u32 get_inflated_image_size (void ) +{ +return get_unaligned_le32 (input_data_end -4 ); +} +void decompress_kernel (unsigned long output_start,unsigned long free_mem_ptr_p,unsigned long free_mem_ptr_end_p,int arch_id) { +unsigned long output_data_len;int ret; output_data = (unsigned char *)output_start; + output_data_len =get_inflated_image_size (); free_mem_ptr = free_mem_ptr_p; free_mem_end_ptr = free_mem_ptr_end_p; __machine_arch_type = arch_id;
@@ -147,7 +155,7 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,putstr ("Uncompressing Linux..." ); ret =do_decompress (input_data, input_data_end - input_data, - output_data, error); + output_data, output_data_len, error);if (ret)error ("decompressor returned an error" );else
arch/arm/boot/compressed/misc.h +2 -1
@@ -13,7 +13,8 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,void __fortify_panic (const u8 reason,size_t avail,size_t size);int atags_to_fdt (void *atag_list,void *fdt,int total_space);uint32_t fdt_check_mem_start (uint32_t mem_start,const void *fdt); -int do_decompress (u8 *input,int len,u8 *output,void (*error)(char *x)); +int do_decompress (u8 *input,int len,u8 *output,int outlen, +void (*error)(char *x));extern char input_data[];extern char input_data_end[];
Signature · 1 line
2.47.3
PATCH v2 2/3 ARM: compressed: Bump MALLOC_SIZE to 128 KiB
In reply to Andreas KemnadeFrom: Jonathan Neuschäfer <[email protected]>
The ZSTD compressor needs about 100 KiB.
--- arch/arm/boot/compressed/Makefile | 2 +- arch/arm/boot/compressed/head.S | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/boot/compressed/Makefile +1 -1
@@ -62,7 +62,7 @@ ZTEXTADDR := 0 ZBSSADDR := ALIGN(8) endif -MALLOC_SIZE := 65536 +MALLOC_SIZE := 131072 AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET) -DMALLOC_SIZE=$(MALLOC_SIZE) CPPFLAGS_vmlinux.lds := -DTEXT_START="$(ZTEXTADDR)" -DBSS_START="$(ZBSSADDR)"
arch/arm/boot/compressed/head.S +2 -2
@@ -337,7 +337,7 @@ restart: adr r0, LC1 get_inflated_image_size r9, r10, lr #ifndef CONFIG_ZBOOT_ROM - /* malloc space is above the relocated stack (64k max) */ + /* malloc space is above the relocated stack (128k max) */ add r10, sp, #MALLOC_SIZE #else /*
@@ -629,7 +629,7 @@ not_relocated: mov r0, #0 */ mov r0, r4 mov r1, sp @ malloc space above stack - add r2, sp, #MALLOC_SIZE @ 64k max + add r2, sp, #MALLOC_SIZE @ 128k max mov r3, r7 bl decompress_kernel
Signature · 1 line
2.47.3
PATCH v2 3/3 ARM: compressed: Enable ZSTD compression
In reply to Andreas KemnadeWith the previous two commits, it is possible to enable ZSTD in the decompressor stub for 32-bit ARM.
KASAN logic for XZ is extended for ZSTD, since
the affected functions are also in use.
Measurement was done with clang-19.
Setup was: starting a fastboot image via u-boot, serial console attached.
Time was measured using ts -s %.s </dev/ttyUSBx | tee logfile from the last words from u-boot still the first kernel message. No early serial output was in use.
GTA04 (OMAP3) with something based on omap2plus_defconfig:
zImage size time
GZIP 7997 KiB 1.6s
LZMA 5794 KiB 4.6s
ZSTD 6774 KiB 2.7s
Tolino Shine 2 HD (i.MX6SL) with something based on imx_v6_v7_defconfig
GZIP 10499 KiB 0.9s
LZMA 7611 KiB 3.8s
ZSTD 8884 KiB 2.0s
--- arch/arm/Kconfig | 1 + arch/arm/boot/compressed/Makefile | 1 + arch/arm/boot/compressed/decompress.c | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-)
arch/arm/Kconfig +1 -0
@@ -122,6 +122,7 @@ config ARM select HAVE_KERNEL_LZMA select HAVE_KERNEL_LZO select HAVE_KERNEL_XZ + select HAVE_KERNEL_ZSTD select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M select HAVE_KRETPROBES if HAVE_KPROBES select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if (LD_VERSION >= 23600 || LD_IS_LLD) && LD_CAN_USE_KEEP_IN_OVERLAY
arch/arm/boot/compressed/Makefile +1 -0
@@ -74,6 +74,7 @@ compress-$(CONFIG_KERNEL_LZO) = lzo_with_size compress-$(CONFIG_KERNEL_LZMA) = lzma_with_size compress-$(CONFIG_KERNEL_XZ) = xzkern_with_size compress-$(CONFIG_KERNEL_LZ4) = lz4_with_size +compress-$(CONFIG_KERNEL_ZSTD) = zstd22_with_size libfdt_objs := fdt_rw.o fdt_ro.o fdt_wip.o fdt.o
arch/arm/boot/compressed/decompress.c +10 -1
@@ -47,15 +47,24 @@ extern char * strchrnul(const char *, int);#include "../../../../lib/decompress_unlzma.c" #endif -#ifdef CONFIG_KERNEL_XZ +#if defined(CONFIG_KERNEL_XZ ) || defined(CONFIG_KERNEL_ZSTD )/* Prevent KASAN override of string helpers in decompressor */ #undef memmove#define memmove memmove#undef memcpy#define memcpy memcpy +#undef memset +#define memset memset +#endif + +#ifdef CONFIG_KERNEL_XZ #include "../../../../lib/decompress_unxz.c" #endif +#ifdef CONFIG_KERNEL_ZSTD +#include "../../../../lib/decompress_unzstd.c" +#endif +#ifdef CONFIG_KERNEL_LZ4 #include "../../../../lib/decompress_unlz4.c" #endif
Signature · 1 line
2.47.3
Quoted 4 lines · On Fri, 28 Aug 2026 22:32:18 +0200 Andreas Kemnade <[email protected]> wrote:
Add ZSTD compression to still have a quite high compression but with not too much boot delay penality.
Signed-off-by Andreas Kemnade <[email protected]>
Anything left for me to do here?
Regards,
Andreas
Quoted 45 lines
---
Changes in v2:
- rebased
- practically rewritten 3/3 (and therefore changed author)
- added more measurements
- Link to v1: https://lore.kernel.org/lkml/ZDoDYh01GYjdwp63@probook/To: Russell King <[email protected]>
To: Nick Terrell <[email protected]>
To: David Sterba <[email protected]>
To: Nathan Chancellor <[email protected]>
To: Nick Desaulniers <[email protected]>
To: Bill Wendling <[email protected]>
To: Justin Stitt <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Linus Walleij <[email protected]>
Cc: Tony Lindgren <[email protected]>
Cc: [email protected]
Cc: [email protected]---
Andreas Kemnade (1):
ARM: compressed: Enable ZSTD compressionJonathan Neuschäfer (2):
ARM: compressed: Pass the actual output length to the decompressor
ARM: compressed: BumpMALLOC_SIZEto 128 KiBarch/arm/Kconfig | 1 + arch/arm/boot/compressed/Makefile | 3 ++- arch/arm/boot/compressed/decompress.c | 15 ++++++++++++--- arch/arm/boot/compressed/head.S | 4 ++-- arch/arm/boot/compressed/misc.c | 10 +++++++++- arch/arm/boot/compressed/misc.h | 3 ++- 6 files changed, 28 insertions(+), 8 deletions(-)---
base-commit:8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260828-zstd2-045ce924f624Best regards,
Signature · 1 line
Andreas Kemnade <[email protected]>
Linus Walleij
Reviewed-byHi Andreas,
Quoted 10 lines · Andreas Kemnade
On Fri, 28 Aug 2026 22:32:18 +0200
Quoted 4 lines · Andreas Kemnade
Add ZSTD compression to still have a quite high compression but with not too much boot delay penality.
Signed-off-by Andreas Kemnade <[email protected]>Anything left for me to do here?
I think the patches look good.
Please put them into Russell's patch tracker:
https://www.arm.linux.org.uk/developer/patches/
Yours,
Linus Walleij
Quoted 12 lines · On Sun, 13 Sep 2026 20:17:53 +0200 Linus Walleij <[email protected]> wrote:
Hi Andreas,
Quoted 9 lines · Andreas Kemnade
On Fri, 28 Aug 2026 22:32:18 +0200
Quoted 4 lines · Andreas Kemnade
Add ZSTD compression to still have a quite high compression but with not too much boot delay penality.
Signed-off-by Andreas Kemnade <[email protected]>
Quoted 8 lines
Quoted 1 line
Anything left for me to do here?
I think the patches look good.
Reviewed-by Linus Walleij <[email protected]>Please put them into Russell's patch tracker:
https://www.arm.linux.org.uk/developer/patches/
I have put them there.
I constantly get this from emails:
[email protected]
retry timeout exceeded
So how to proceed here. Am I just feeding some kind of black hole here?
Regards,
Andreas
Quoted 10 lines · Andreas Kemnade
Quoted 3 lines
Please put them into Russell's patch tracker:
https://www.arm.linux.org.uk/developer/patches/I have put them there.
I constantly get this from emails:[email protected]
retry timeout exceededSo how to proceed here. Am I just feeding some kind of black hole here?
Try using the web interface and see if it works.
Yours,
Linus Walleij