From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.118.77.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795117430; b=oNW/I4EEa7/ZqC2+l/eqb4DJvyPluBeyAmalQoFQk4CrVgAlmIcExiQb0+qir+UiJQY/ QlAEw0Jx4ZnChf6YEB8vyUIayOf6quq165ZIo6a66gv3PFJAG4NrHOzJ35QNVL4fISha8 34Lunp2iRR1eSASSr2rUF2GSGT6sICkV33d2oibMcIcamjOHyyqRYBEkfB64dmZiZiNpA QN36FTrV28iG9DkuHp6gyPWtpM+33AaafmSVjXqSK4DYAaAfc5NPwD1uw+cdNmQoj0ZOd SIXSw3QcVu9FUSF+WAi0HhxJShYL8G2nOokyCQxZOTGtZCL7Gal+qJUuqU0QWXQsVbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795117430; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: Content-Language:From:In-Reply-To:Content-Transfer-Encoding: X-CMS-MailID:X-Msg-Generator:Content-Type:X-RootMTR:X-EPHeader: X-CMS-RootMailID:References; bh=090F43O6xwbTXOOBTz6I2219/meRL0E1+FYz/xdX8XU=; b=d5CLmPLiOhA9g+Y6ppPl/OIu9DKEVjfYSYePSF7kcdtwGObdMXzaqchVveXrz5J4fKbs YSKejzPZNN9kEElMlMisjcON+sxF1eiUATsO6pd5fY8zThYxXhKvKglWx/sGwHL0EZrJb s4nQKhdYdJ8yFRswmTTYA4i5q3zOjTc0O5oX2jx9pMOUS0As1hQ2sL71zJHeW6R8aEH+v 8S/gGEAwxux2THtqmnMhhDgqD0NzEoVkubzzyYqSL6A6TA+EaxcfLN6FEaCpotgVuB99/ LwGgAIvPc6miWHZBJ3UhwTiaTiBGQSy1XFVPMKaScOOYRycJiBCGtXo3wbEwvl3DZkw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b="NRZI0/g0"; arc=none smtp.remote-ip=210.118.77.12 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B8BF606A335 for ; Thu, 19 Nov 2026 19:43:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B8BF606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=NRZI0/g0 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20261119194346euoutp02f4ed1927b4e48c71ffdd6887384c337b~picnFlbsp3173231732euoutp02c for ; Thu, 19 Nov 2026 19:43:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20261119194346euoutp02f4ed1927b4e48c71ffdd6887384c337b~picnFlbsp3173231732euoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1795117426; bh=090F43O6xwbTXOOBTz6I2219/meRL0E1+FYz/xdX8XU=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=NRZI0/g0ShOOBLLsJPWC86qh3P8zV1Hh4g+2gBGi5NcIr4nz5+tTS5Rf/2EsfIxuS 3LPdhpTuMT62WSRpGp7tP8ct7nFDtwFvblFIV1fUXyZhU8CfOtLn/2+tOQ8a8YMKqw dbWTXP1P+rpYp8VaTsCbEbeLXkttRKfeXqS0Ew4I= Received: from eusmtip1.samsung.com (unknown [203.254.199.221]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20261119194345eucas1p19bddf3b3f2155b0f4777a822db00aec1~picm3UpHR0237702377eucas1p1Y; Thu, 19 Nov 2026 19:43:45 +0000 (GMT) Received: from [192.168.1.44] (unknown [106.210.136.40]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20261119194345eusmtip1e59aab635f10627422e5da54c5d41eaa~picmWhHfe0313403134eusmtip13; Thu, 19 Nov 2026 19:43:45 +0000 (GMT) Message-ID: Date: Thu, 19 Nov 2026 20:43:45 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] lib/lz4: add KUnit tests for compression and decompression To: "S. Biplab Raut" Cc: Andrew Morton , Gao Xiang , linux-erofs@lists.ozlabs.org, Yann Collet , Nick Terrell , Brendan Higgins , David Gow , Rae Moar , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Language: en-US From: Michal Wilczynski In-Reply-To: <20261118182343.1628236-1-Biplab.Raut@amd.com> Content-Transfer-Encoding: 7bit X-CMS-MailID: 20261119194345eucas1p19bddf3b3f2155b0f4777a822db00aec1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20261118182347eucas1p2f85df57ccf85e78fd2c104d4046f5295 X-EPHeader: CA X-CMS-RootMailID: 20261118182347eucas1p2f85df57ccf85e78fd2c104d4046f5295 References: <20261106-lz4-vendor-upstream-v2-0-ee04c3f0d7dc@samsung.com> <20261118182343.1628236-1-Biplab.Raut@amd.com> On 11/18/26 19:23, S. Biplab Raut wrote: > lib/lz4 has no in-tree tests, and this series replaces both the > compressor and the decompressor. Add KUnit suites for the behaviour > callers rely on. > > lz4_decompress: > - round-trips through LZ4_decompress_safe() and > LZ4_decompress_safe_partial() with exact, oversized and partial > capacities; > - truncated and corrupted blocks never write past the destination, > through either entry point. The input sits at the end of its > allocation, so KASAN also reports over-reads; > - an offset-0 match decodes the same whatever the buffer held before; > - literal and match lengths longer than the output are rejected. On > 32-bit, lengths whose extension bytes sum to SIZE_MAX are rejected > rather than wrapped; > - in-place decoding within LZ4_DECOMPRESS_INPLACE_MARGIN() leaves the > output intact. A fixed block that corrupts with the old +32 margin > covers the vendored decoder's 32-byte wild copies, and a port of > upstream's worst-case test covers the 64-byte copies its decoder > makes since v1.11.0. > > lz4_compress: > - LZ4_compress_default() fits LZ4_COMPRESSBOUND(), and with a smaller > buffer fails rather than overflowing; > - LZ4_compress_fast() across documented acceleration boundaries; > - LZ4_compress_destSize() output decodes to exactly the consumed > prefix; > - the dictionary paths of zram's lz4 and lz4hc backends; > - LZ4_compress_HC() across supported levels, including the kernel's > clamp boundary, with full and limited output. > > Work memory is allocated at exactly LZ4_MEM_COMPRESS, LZ4HC_MEM_COMPRESS > and LZ4_MEM_DECOMPRESS bytes, so KASAN reports an implementation that > outgrows them. > > Without this series, the 32-bit length case fails on i386 ("long match > accepted: ret=31"): the old decoder wraps the match length to 18 bytes > and accepts the block. > > Signed-off-by: S. Biplab Raut > --- > > Michal, this goes on top of your v2: it uses LZ4_MEM_DECOMPRESS and the > opaque stream types, so please fold it into v3 if you find it useful. > > The tests are deterministic regression tests. Every randomized case > uses a fixed seed, so each run checks the same inputs and any failure > reproduces exactly. The in-place suite has two fixed cases: > > - a block that corrupts with the old (compressedSize >> 8) + 32 margin > under a 32-byte fast loop, the case patch 12 fixes; > > - a port of upstream's decompress_safe_inPlace_worstCase test [1]: > fixed noise with a 65-byte match at offset 65, for every source size > from 300 to 4096. > > On patch 12 and the +65 margin: since v1.11.0, upstream's decoder makes > 64-byte wild copies on x86-64, aarch64 and ppc64, and upstream has raised > its margin to (compressedSize >> 8) + 65 to match [1]. That fix is on > the dev branch for v1.11.2; the released v1.11.0 and v1.11.1 headers > still say +32. Your v1.10.0 import uses the 32-byte loop, so +36 is > right for this series. A later re-sync to v1.11.0 or newer needs the > kernel's margin raised to +65 in the same patch, whatever the upstream > header at that tag says. > > I checked that the worst-case test catches this, using a userspace > build of the same test. Against upstream dev's decoder, all 3797 sizes > fail at +36 and none fail at +65. Against your vendored v1.10.0 > decoder, none fail at +36. > > The HC cases are built only when LZ4HC_COMPRESS is reachable. > > With your v2 applied on v7.3-rc4, the suite passes on UML (17 passed, > one 32-bit-only skip), on i386 (18 passed), and on x86_64 with KASAN and > KASAN_VMALLOC (17 passed, the same skip). A UML build without > LZ4HC_COMPRESS passes 15 tests with the same skip. > > [1] https://protect2.fireeye.com/v1/url?k=f02093a2-91ab868d-f02118ed-74fe485cbfe7-df7f89af9c73957c&q=1&e=79e95ae8-ccd9-4aaa-b235-c5f62451957b&u=https%3A%2F%2Fgithub.com%2Flz4%2Flz4%2Fpull%2F2104 > > lib/Kconfig | 15 + > lib/lz4/.kunitconfig | 5 + > lib/lz4/Makefile | 1 + > lib/lz4/tests/Makefile | 2 + > lib/lz4/tests/lz4_kunit.c | 911 ++++++++++++++++++++++++++++++++++++++ > 5 files changed, 934 insertions(+) > create mode 100644 lib/lz4/.kunitconfig > create mode 100644 lib/lz4/tests/Makefile > create mode 100644 lib/lz4/tests/lz4_kunit.c > Hi Biplab, Thanks for the tests and for testing v2 v3 is coming in a couple of days. It vendors v1.11.1 instead of v1.10.0, so it already has the 64-byte copies, and the in-place margin is (compressedSize >> 8) + 68. I ran your suite on v3. Everything passes except lz4hc_compress_test_levels. That's because v3 no longer clamps HC levels to 9: levels 10-12 need a bigger state, sized with the new lz4hc_mem_compress(level). Allocating wrkmem per level with it fixes the test. If that's OK with you, I'll carry your patch in v3 with that small change keeping you as the author. Since patches 10, 11 and 13 changed a lot I'll drop your Tested-by - a re-test on v3 would be great. Best regards, -- Michal Wilczynski