On Mon, Nov 23, 2026 at 10:07:01PM +0100, Mikulas Patocka wrote:
> +static int __init dm_compress_init(void)
> +{
> + int r;
> + unsigned i;
> +
> + for (i = 0; i < dm_compress_n_algorithms; i++) {
> + unsigned request_size;
> + dm_compress_algorithms[i].cc =
> crypto_alloc_acomp(dm_compress_algorithms[i].name, 0, 0);
> + if (IS_ERR(dm_compress_algorithms[i].cc)) {
> + r = PTR_ERR(dm_compress_algorithms[i].cc);
> + dm_compress_algorithms[i].cc = NULL;
> + DMERR("Could not initialize algorithm %s",
> dm_compress_algorithms[i].name);
> + goto bad;
> + }
> + request_size = ALIGN(sizeof(struct acomp_req) +
> crypto_acomp_reqsize(dm_compress_algorithms[i].cc), CRYPTO_MINALIGN);
> + dm_compress_max_request_size =
> max(dm_compress_max_request_size, request_size);
> + }
I would strongly suggest avoiding crypto_acomp for now. Instead, it
would be better to simplify the set of supported algorithms to ZSTD and
LZ4 (the ones that are well known to do the best on the space/time
tradeoff curve) and call those library APIs directly.
That avoids all the scatterlist nonsense and other crypto_acomp issues,
especially when it seems the caller in this module has linear buffers
already and waits synchronously for each one to complete. (acomp does
now support virtual addresses too, but it's still an extra layer that
provides no benefit for a synchronous software-only user like this.)
As-is, it looks like it also doesn't work correctly with the scomp-based
algorithms (lz4, lz4hc, lzo, 842) when chunk_size > PAGE_SIZE. In that
case scomp either returns -ENOSYS (making dm-compress silently store
everything uncompressed) or overflows its internal scratch buffer.
There's plenty of precedent for just using the compression libraries
directly: zram, dm-vdo, btrfs, f2fs, etc. If hardware offload is ever
wanted, it can be added later as an optional path, like erofs does.
- Eric