Skip to content

Conversation

@alex-moch
Copy link
Contributor

@alex-moch alex-moch commented Dec 28, 2025

This pull request updates the bundled Zstandard (zstd) library to version 1.5.7 and adds the necessary OpenZFS integration and build system changes required to make zstd 1.5.7 compile and function correctly.


Motivation and context

This pull request is motivated by build failures observed when building with GCC using -Og, as reported in:

The version of Zstandard currently shipped with OpenZFS ignores -DZSTD_NO_INLINE due to how inlining is enforced around xxhash.c in the upstream sources.

Fixing this issue for the currently bundled Zstandard version would require carrying local patches to upstream code.

Zstandard 1.5.7, among other changes, removes the standalone xxhash.c source and adjusts inlining behavior such that builds with -Og -g -DZSTD_NO_INLINE succeed. As a first step, this pull request updates the bundled Zstandard version in OpenZFS to 1.5.7 and performs the required integration changes. This is considered the cleanest approach for the master branch.

Updating the Zstandard version in released OpenZFS stable branches is likely not an option. The approach taken here is therefore to fix master first and then evaluate whether a targeted workaround is feasible for OpenZFS 2.4 and possibly earlier releases.

Description

The latest upstream Zstandard 1.5.7 release has been imported into module/zstd. Where required, corresponding changes to the OpenZFS build system and integration code have been applied.

This pull request intentionally deviates from the “one commit per pull request” model:

  • The first commit is a direct import of the Zstandard 1.5.7 sources without functional modifications.
  • The second commit contains the necessary OpenZFS integration and build system adjustments.

This separation is intended to simplify review and improve traceability of upstream versus OpenZFS-specific changes.

A third commit will add SPDX license identifiers to newly imported files to match existing OpenZFS conventions.

The upstream Zstandard sources are imported without reformatting or style adjustments, which intentionally deviates from OpenZFS coding style guidelines to keep the vendor update easy to track and review.

How has this been tested?

  • OpenZFS CI Chain
  • OpenZFS Alpine Linux 3.23 Runner
  • Build testing on Gentoo ~arm64 with musl libc
    • From the source tree and through Portage
  • Build testing on Gentoo ~amd64 with --enable-linux-builtin

Todos before marking this ready for review

  • Add SPDX license identifiers to newly imported files.
  • Remove temporary allocator bypass and implement proper fix.
  • Test against the new Alpine Linux CI runner.
  • Perform additional compatibility checks with older ZFS releases.
  • Check kernel builds with --enable-linux-builtin.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist

@github-actions github-actions bot added the Status: Work in Progress Not yet ready for general review label Dec 28, 2025
This commit only replaces the bundled source and does not include any
ZFS integration changes. Because the build depends on integration
adjustments, it will fail until the accompanying integration commit is
applied.

Upstream release: https://github.com/facebook/zstd/releases/tag/v1.5.7

Signed-off-by: Alexander Moch <[email protected]>
@alex-moch
Copy link
Contributor Author

Memory is now unpoisoned when handing buffers out to Zstd and poisoned again when buffers are returned to the pool. Testing on the new Alpine runner looks good. I also restored SPDX license identifiers and fixed minor style issues in zstd-in.c.

Compatibility with older ZFS releases and --enable-linux-builtin still need to be verified.

@alex-moch alex-moch changed the title ZSTD: Update bundled library to version 1.5.7 Zstd: Update bundled library to version 1.5.7 Dec 31, 2025
@alex-moch alex-moch force-pushed the zstd-1.5.7 branch 2 times, most recently from 69e0508 to d35d2c3 Compare December 31, 2025 15:32
This commit builds on the previous zstd library update and adds the
necessary ZFS integration and build system changes required to make
zstd 1.5.7 compile and function correctly.

Changes:
- Add zstd_preSplit.c (new in 1.5.7) to all build systems.
- Enable x86_64 assembly in userspace (huf_decompress_amd64.S).
- Disable assembly in kernel for RETHUNK/IBT compatibility.
- Disable intrinsics in kernel for EL10 x86_64-v3 baseline.
- Disable tracing in kernel builds for AArch64 compatibility.
- Fix ZSTD_isError symbol renaming with __asm__ directive.
- Rename abs64 to ZSTD_abs64 (FreeBSD kernel conflict).
- Fix bitstream.h attributes (MEM_STATIC -> FORCE_INLINE_TEMPLATE).
- Remove xxhash.c from BSD build (now header-only).
- Update symbol names in zstd_compat_wrapper.h.

Kernel assembly disabled for security mitigation compatibility. User
space retains full performance.

Signed-off-by: Alexander Moch <[email protected]>
The Zstd context mempool can reuse buffers that were previously poisoned
under AddressSanitizer, leading to false-positive use-after-poison reports
during zloop and other stress tests.

Explicitly unpoison memory when handing buffers out to Zstd and poison the
user-visible region again when buffers are returned to the pool. This makes
the allocator ASan-correct while preserving existing pooling behavior.

Also fix non-standard void * pointer arithmetic in zstd_free() and remove an
early return in zstd_dctx_alloc() so kmem_type/kmem_size are always set on
pool hits.

This only affects ASan bookkeeping in user space, does not change runtime
behavior in non-ASan configurations, and does not affect on-disk formats.

Signed-off-by: Alexander Moch <[email protected]>
When updating Zstandard to version 1.5.7 the SPDX license identifiers
were lost. This commit restores them.

Signed-off-by: Alexander Moch <[email protected]>
Dropping in `zstd-in.c` while updating Zstandard to version 1.5.7 caused
checkstyle to complain about tabs vs. spaces. This commit fixes that.

Signed-off-by: Alexander Moch <[email protected]>
@alex-moch
Copy link
Contributor Author

I successfully build-tested --enable-linux-builtin on a custom kernel built with LLVM/Clang using Full LTO. I also created a new pool with -O compression=zstd, wrote a random file, verified its hash, and successfully read it back on 2.4.0 without issues.

In the latest push, tracing is disabled for kernel builds, as it caused issues on AArch64.

This is now ready for review.

@alex-moch alex-moch marked this pull request as ready for review December 31, 2025 17:56
@github-actions github-actions bot added Status: Code Review Needed Ready for review and testing and removed Status: Work in Progress Not yet ready for general review labels Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Code Review Needed Ready for review and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant