lib: zstd: update to latest Linux zstd 1.5.2
Subsystems (3)
PATCH 1/1 lib: zstd: update to latest Linux zstd 1.5.2
Update the zstd implementation to match Linux zstd 1.5.2 from commit 2aa14b1ab2.
This was motivated by running into decompression corruption issues when trying to uncompress files compressed with newer versions of zstd. zstd users also claim significantly improved decompression times with newer zstd versions which is a side benefit.
Original zstd code was copied from Linux commit 2aa14b1ab2 which is a custom-built implementation based on zstd 1.3.1. Linux switched to an implementation that is a copy of the upstream zstd code in Linux commit e0c1b49f5b, this results in a large code diff. However this should make future updates easier along with other benefits[1].
This commit is a straight mirror of the Linux zstd code, except to:
- update a few #include that do not translate cleanly
- linux/swab.h -> asm/byteorder.h
- linux/limits.h -> linux/kernel.h
- linux/module.h -> linux/compat.h
- remove assert() from debug.h so it doesn't conflict with u-boot's assert()
- strip out the compressor code as was done in the previous u-boot zstd
- update existing zstd users to the new Linux zstd API
- add a new KConfig option that sets zstd build options to minify code based on zstd's ZSTD_LIB_MINIFY[2].
These changes were tested by booting a zstd 1.5.2 compressed kernel inside a FIT. And the squashfs changes by loading a file from zstd compressed squashfs with sqfsload. buildman was used to compile test other boards and check for binary bloat, as follows:
Quoted 7 lines
$ buildman -f -b zstd2 --boards dh_imx6,m53menlo,mvebu_espressobin-88f3720,stm32mp15_dhcom_basic,stm32mp15_dhcor_basic,turris_mox,turris_omnia -sS Summary of 2 commits for 7 boards (7 threads, 2 jobs per thread) 01: Merge tag 'tpm-23122022' of https://source.denx.de/u-boot/custodians/u-boot-tpm arm: w+ m53menlo dh_imx6 02: lib: update zstd decompressor to 1.5.2 aarch64: (for 2/2 boards) all +65.5 rodata +923.5 text -858.0 arm: (for 5/5 boards) all +4091.6 rodata +898.0 text +3193.6
[1] https://github.com/torvalds/linux/commit/e0c1b49f5b674cca7b10549c53b3791d0bbc90a8
[2] https://github.com/facebook/zstd/blob/f302ad8811643c428c4e3498e28f53a0578020d3/lib/libzstd.mk#L31
--- fs/squashfs/sqfs_decompressor.c | 15 +- include/linux/zstd.h | 1244 ++------ include/linux/zstd_errors.h | 77 + include/linux/zstd_lib.h | 2551 +++++++++++++++++ lib/Kconfig | 15 + lib/zstd/Makefile | 35 +- lib/zstd/bitstream.h | 344 --- lib/zstd/common/bitstream.h | 446 +++ lib/zstd/common/compiler.h | 184 ++ lib/zstd/common/cpu.h | 194 ++ lib/zstd/common/debug.c | 24 + lib/zstd/common/debug.h | 92 + lib/zstd/common/entropy_common.c | 357 +++ lib/zstd/common/error_private.c | 56 + lib/zstd/common/error_private.h | 145 + lib/zstd/common/fse.h | 711 +++++ lib/zstd/common/fse_decompress.c | 390 +++ lib/zstd/common/huf.h | 358 +++ lib/zstd/common/mem.h | 261 ++ lib/zstd/common/portability_macros.h | 93 + lib/zstd/common/zstd_common.c | 83 + lib/zstd/common/zstd_deps.h | 125 + lib/zstd/common/zstd_internal.h | 443 +++ lib/zstd/decompress.c | 2516 ---------------- lib/zstd/decompress/huf_decompress.c | 1740 +++++++++++ lib/zstd/decompress/zstd_ddict.c | 241 ++ lib/zstd/decompress/zstd_ddict.h | 44 + lib/zstd/decompress/zstd_decompress.c | 2131 ++++++++++++++ lib/zstd/decompress/zstd_decompress_block.c | 2072 +++++++++++++ lib/zstd/decompress/zstd_decompress_block.h | 68 + .../decompress/zstd_decompress_internal.h | 228 ++ lib/zstd/decompress_sources.h | 34 + lib/zstd/entropy_common.c | 213 -- lib/zstd/error_private.h | 43 - lib/zstd/fse.h | 545 ---- lib/zstd/fse_decompress.c | 302 -- lib/zstd/huf.h | 182 -- lib/zstd/huf_decompress.c | 930 ------ lib/zstd/mem.h | 142 - lib/zstd/zstd.c | 43 +- lib/zstd/zstd_common.c | 66 - lib/zstd/zstd_common_module.c | 32 + lib/zstd/zstd_decompress_module.c | 105 + lib/zstd/zstd_internal.h | 253 -- lib/zstd/zstd_opt.h | 1004 ------- 45 files changed, 13628 insertions(+), 7549 deletions(-) create mode 100644 include/linux/zstd_errors.h create mode 100644 include/linux/zstd_lib.h delete mode 100644 lib/zstd/bitstream.h create mode 100644 lib/zstd/common/bitstream.h create mode 100644 lib/zstd/common/compiler.h create mode 100644 lib/zstd/common/cpu.h create mode 100644 lib/zstd/common/debug.c create mode 100644 lib/zstd/common/debug.h create mode 100644 lib/zstd/common/entropy_common.c create mode 100644 lib/zstd/common/error_private.c create mode 100644 lib/zstd/common/error_private.h create mode 100644 lib/zstd/common/fse.h create mode 100644 lib/zstd/common/fse_decompress.c create mode 100644 lib/zstd/common/huf.h create mode 100644 lib/zstd/common/mem.h create mode 100644 lib/zstd/common/portability_macros.h create mode 100644 lib/zstd/common/zstd_common.c create mode 100644 lib/zstd/common/zstd_deps.h create mode 100644 lib/zstd/common/zstd_internal.h delete mode 100644 lib/zstd/decompress.c create mode 100644 lib/zstd/decompress/huf_decompress.c create mode 100644 lib/zstd/decompress/zstd_ddict.c create mode 100644 lib/zstd/decompress/zstd_ddict.h create mode 100644 lib/zstd/decompress/zstd_decompress.c create mode 100644 lib/zstd/decompress/zstd_decompress_block.c create mode 100644 lib/zstd/decompress/zstd_decompress_block.h create mode 100644 lib/zstd/decompress/zstd_decompress_internal.h create mode 100644 lib/zstd/decompress_sources.h delete mode 100644 lib/zstd/entropy_common.c delete mode 100644 lib/zstd/error_private.h delete mode 100644 lib/zstd/fse.h delete mode 100644 lib/zstd/fse_decompress.c delete mode 100644 lib/zstd/huf.h delete mode 100644 lib/zstd/huf_decompress.c delete mode 100644 lib/zstd/mem.h delete mode 100644 lib/zstd/zstd_common.c create mode 100644 lib/zstd/zstd_common_module.c create mode 100644 lib/zstd/zstd_decompress_module.c delete mode 100644 lib/zstd/zstd_internal.h delete mode 100644 lib/zstd/zstd_opt.h
fs/squashfs/sqfs_decompressor.c +9 -6
@@ -40,7 +40,7 @@ int sqfs_decompressor_init(struct squashfs_ctxt *ctxt)#endif #if IS_ENABLED (CONFIG_ZSTD )case SQFS_COMP_ZSTD : - ctxt->zstd_workspace =malloc (ZSTD_DCtxWorkspaceBound ()); + ctxt->zstd_workspace =malloc (zstd_dctx_workspace_bound ());if (!ctxt->zstd_workspace)return -ENOMEM ;break ;
@@ -99,11 +99,14 @@ static int sqfs_zstd_decompress(struct squashfs_ctxt *ctxt, void *dest,size_t wsize;int ret; - wsize =ZSTD_DCtxWorkspaceBound (); - ctx =ZSTD_initDCtx (ctxt->zstd_workspace, wsize); - ret =ZSTD_decompressDCtx (ctx, dest, dest_len, source, src_len); + wsize =zstd_dctx_workspace_bound (); - return ZSTD_isError(ret); + ctx =zstd_init_dctx (ctxt->zstd_workspace, wsize); +if (!ctx) +return -EINVAL ; + ret =zstd_decompress_dctx (ctx, dest, dest_len, source, src_len); + + return zstd_is_error(ret); }#endif /* CONFIG_ZSTD */
@@ -140,7 +143,7 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,case SQFS_COMP_ZSTD : ret =sqfs_zstd_decompress (ctxt, dest, *dest_len, source, src_len);if (ret) { -printf ("ZSTD Error code: %d\n" ,ZSTD_getErrorCode (ret)); +printf ("ZSTD Error: %d\n" ,zstd_get_error_code (ret));return -EINVAL ; }
include/linux/zstd.h +272 -972
1,422 lines not on this page · raw message
include/linux/zstd_errors.h new file +77 -0
77 lines not on this page · raw message
include/linux/zstd_lib.h new file +2551 -0
1,467 lines not on this page · raw message
lib/zstd/bitstream.h deleted +0 -344
344 lines not on this page · raw message
lib/zstd/common/bitstream.h new file +446 -0
446 lines not on this page · raw message
lib/zstd/common/compiler.h new file +184 -0
184 lines not on this page · raw message
lib/zstd/common/cpu.h new file +194 -0
194 lines not on this page · raw message
lib/zstd/common/debug.h new file +92 -0
92 lines not on this page · raw message
lib/zstd/common/entropy_common.c new file +357 -0
357 lines not on this page · raw message
lib/zstd/common/error_private.c new file +56 -0
56 lines not on this page · raw message
lib/zstd/common/error_private.h new file +145 -0
145 lines not on this page · raw message
lib/zstd/common/fse.h new file +711 -0
711 lines not on this page · raw message
lib/zstd/common/fse_decompress.c new file +390 -0
390 lines not on this page · raw message
lib/zstd/common/huf.h new file +358 -0
358 lines not on this page · raw message
lib/zstd/common/mem.h new file +261 -0
261 lines not on this page · raw message
lib/zstd/common/portability_macros.h new file +93 -0
93 lines not on this page · raw message
lib/zstd/common/zstd_common.c new file +83 -0
83 lines not on this page · raw message
lib/zstd/common/zstd_deps.h new file +125 -0
125 lines not on this page · raw message
lib/zstd/common/zstd_internal.h new file +443 -0
443 lines not on this page · raw message
lib/zstd/decompress.c deleted +0 -2516
2,516 lines not on this page · raw message
lib/zstd/decompress/huf_decompress.c new file +1740 -0
1,740 lines not on this page · raw message
lib/zstd/decompress/zstd_ddict.c new file +241 -0
241 lines not on this page · raw message
lib/zstd/decompress/zstd_ddict.h new file +44 -0
44 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress.c new file +2131 -0
2,131 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress_block.c new file +2072 -0
2,072 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress_block.h new file +68 -0
68 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress_internal.h new file +228 -0
228 lines not on this page · raw message
lib/zstd/decompress_sources.h new file +34 -0
Lines of this file are not shown. View the raw message.
lib/zstd/entropy_common.c deleted +0 -213
213 lines not on this page · raw message
lib/zstd/error_private.h deleted +0 -43
43 lines not on this page · raw message
lib/zstd/fse.h deleted +0 -545
545 lines not on this page · raw message
lib/zstd/fse_decompress.c deleted +0 -302
302 lines not on this page · raw message
lib/zstd/huf.h deleted +0 -182
182 lines not on this page · raw message
lib/zstd/huf_decompress.c deleted +0 -930
930 lines not on this page · raw message
lib/zstd/mem.h deleted +0 -142
142 lines not on this page · raw message
lib/zstd/zstd.c +14 -29
43 lines not on this page · raw message
lib/zstd/zstd_common.c deleted +0 -66
66 lines not on this page · raw message
lib/zstd/zstd_common_module.c new file +32 -0
Lines of this file are not shown. View the raw message.
lib/zstd/zstd_decompress_module.c new file +105 -0
105 lines not on this page · raw message
lib/zstd/zstd_internal.h deleted +0 -253
253 lines not on this page · raw message
lib/zstd/zstd_opt.h deleted +0 -1004
1,004 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.39.0
Part of the diff is not shown here. View the raw message.