Re: [PATCH] mm/zswap: validate dlen and normalize comp_ret on compression success

From: SJ Park

Date: Fri Oct 23 2026 - 20:10:30 EST


On Thu, 22 Oct 2026 23:27:33 +0000 Suseendran Bhaskaran <suseendranb@xxxxxxxxxx> wrote:

> In zswap_compress(), dlen is only meaningful when compression succeeds
> (!comp_ret), as compressors do not consistently set req->dlen on error
> (e.g. zstd, 842, and qat set dlen = 0; lz4, lz4hc, lzo, lzo-rle,
> deflate, and iaa leave dlen at PAGE_SIZE; hisi_zip sets dlen to the
> hardware-reported produced bytes).
>
> When !comp_ret and dlen == PAGE_SIZE with zswap writeback disabled,
> zswap_compress() sets comp_ret to -EINVAL instead of -ENOSPC,
> miscounting the page under reject_compress_fail instead of
> reject_compress_poor.
>
> When !comp_ret, set comp_ret = -ENOSPC if dlen == PAGE_SIZE, or
> comp_ret = -EINVAL if WARN_ON_ONCE(!dlen || dlen > PAGE_SIZE). This
> allows simplifying the failure check to 'if (comp_ret)' and dropping
> the ternary assignment in the writeback-disabled path.

Nice catch and fix!

>
> Fixes: dca4437a5861 ("mm/zswap: store <PAGE_SIZE compression failed page as-is")

Thank you for fixing this, Suseendran!

> Signed-off-by: Suseendran Bhaskaran <suseendranb@xxxxxxxxxx>

Reviewed-by: SJ Park <sj@xxxxxxxxxx>


Thanks,
SJ

[...]