From nobody Thu Apr 9 18:53:54 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3D80369217; Fri, 6 Mar 2026 03:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772768296; cv=none; b=HO+jEiax9+pDqvwY5ejj7ishdEVimK2jpDZJ6o5ztflb+MqTy+lfeEWB98rBXky4ehoJ4Gkjii8h5LWTm/6iLosP6sZSXzLR72ZlT9IscmDy+iERPKnrZ29xQ5J9Lhpa3JukbIxZD3k5ZANb1AJr41KRudIsQMPAz8WGwZ/oyBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772768296; c=relaxed/simple; bh=agnbrV4bRkUCMC0bqRHHY8STp+AM8bV+FkZeMZ8KuYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r1VYn8qhnnp0nMBm7c9rGpVZDsRIA+mLI2ROe00tQcNBNjsQVm37pKiH8SQlFhgPlQ044AFSNaj4JTpohM54qQg9VSCE04wKcZeKLLrIih6h8FRg+KHYH5GKijhUJ4jd1d369g7jj5gR3VE27I+eWNYEbI1G9JuL1RmsVqM8sDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H5LMPYRz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H5LMPYRz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7819C19423; Fri, 6 Mar 2026 03:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772768295; bh=agnbrV4bRkUCMC0bqRHHY8STp+AM8bV+FkZeMZ8KuYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H5LMPYRzibSOT4oXX4rXkEw6vtgQJCETn9WARaQANTBV/+n+8LiOlWYrGOoApsUl5 Qt8nzpu1tbMZdsIb2yM9AQYROBftskWlG6W6g6kebJLe3kkre6vzLSmUwPstbjs/bS UfoQ500YHGH2V8T/iPtWtaUVCJe7eBfFrQ1R++TO/YRQ8bNTjCPdLKx3t6gBLkjE23 TdSFhgNtgJksIMqjMWeoj5eenx0ZEMO7OD6wKe/YkRPjk7Ug5b4m/D/EMcAAHLFeHe KWQqMRwWT1SYoLzKq3CJu9Hzd0cDyxo1TtFWEp+1oG0ohJOcnZOOI3Tg1ysQWCFOmA WHWnFqB/6Mchw== From: Eric Biggers To: linux-kernel@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel , kunit-dev@googlegroups.com, Eric Biggers , stable@vger.kernel.org Subject: [PATCH 1/3] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Date: Thu, 5 Mar 2026 19:35:55 -0800 Message-ID: <20260306033557.250499-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306033557.250499-1-ebiggers@kernel.org> References: <20260306033557.250499-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Like commit 4478e8eeb871 ("lib/crypto: tests: Depend on library options rather than selecting them") did with the crypto library tests, make crc_kunit depend on the code it tests rather than selecting it. This follows the standard convention for KUnit and fixes an issue where enabling KUNIT_ALL_TESTS enabled non-test code. crc_kunit does differ from the crypto library tests in that it consolidates the tests for multiple CRC variants, with 5 kconfig options, into one KUnit suite. Since depending on *all* of these kconfig options would greatly restrict the ability to enable crc_kunit, instead just depend on *any* of these options. Update crc_kunit accordingly to test only the reachable code. Alternatively we could split crc_kunit into 5 test suites. But keeping it as one is simpler for now. Fixes: e47d9b1a76ed ("lib/crc_kunit.c: add KUnit test suite for CRC library= functions") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers --- lib/crc/Kconfig | 7 +------ lib/crc/tests/crc_kunit.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/crc/Kconfig b/lib/crc/Kconfig index 70e7a6016de3..9ddfd1a29757 100644 --- a/lib/crc/Kconfig +++ b/lib/crc/Kconfig @@ -97,17 +97,12 @@ config CRC_OPTIMIZATIONS Keep this enabled unless you're really trying to minimize the size of the kernel. =20 config CRC_KUNIT_TEST tristate "KUnit tests for CRC functions" if !KUNIT_ALL_TESTS - depends on KUNIT + depends on KUNIT && (CRC7 || CRC16 || CRC_T10DIF || CRC32 || CRC64) default KUNIT_ALL_TESTS - select CRC7 - select CRC16 - select CRC_T10DIF - select CRC32 - select CRC64 help Unit tests for the CRC library functions. =20 This is intended to help people writing architecture-specific optimized versions. If unsure, say N. diff --git a/lib/crc/tests/crc_kunit.c b/lib/crc/tests/crc_kunit.c index 9a450e25ac81..9428cd913625 100644 --- a/lib/crc/tests/crc_kunit.c +++ b/lib/crc/tests/crc_kunit.c @@ -266,12 +266,11 @@ crc_benchmark(struct kunit *test, kunit_info(test, "len=3D%zu: %llu MB/s\n", len, div64_u64((u64)len * num_iters * 1000, t)); } } =20 -/* crc7_be */ - +#if IS_REACHABLE(CONFIG_CRC7) static u64 crc7_be_wrapper(u64 crc, const u8 *p, size_t len) { /* * crc7_be() left-aligns the 7-bit CRC in a u8, whereas the test wants a * right-aligned CRC (in a u64). Convert between the conventions. @@ -292,13 +291,13 @@ static void crc7_be_test(struct kunit *test) =20 static void crc7_be_benchmark(struct kunit *test) { crc_benchmark(test, crc7_be_wrapper); } +#endif /* CONFIG_CRC7 */ =20 -/* crc16 */ - +#if IS_REACHABLE(CONFIG_CRC16) static u64 crc16_wrapper(u64 crc, const u8 *p, size_t len) { return crc16(crc, p, len); } =20 @@ -316,13 +315,13 @@ static void crc16_test(struct kunit *test) =20 static void crc16_benchmark(struct kunit *test) { crc_benchmark(test, crc16_wrapper); } +#endif /* CONFIG_CRC16 */ =20 -/* crc_t10dif */ - +#if IS_REACHABLE(CONFIG_CRC_T10DIF) static u64 crc_t10dif_wrapper(u64 crc, const u8 *p, size_t len) { return crc_t10dif_update(crc, p, len); } =20 @@ -340,10 +339,13 @@ static void crc_t10dif_test(struct kunit *test) =20 static void crc_t10dif_benchmark(struct kunit *test) { crc_benchmark(test, crc_t10dif_wrapper); } +#endif /* CONFIG_CRC_T10DIF */ + +#if IS_REACHABLE(CONFIG_CRC32) =20 /* crc32_le */ =20 static u64 crc32_le_wrapper(u64 crc, const u8 *p, size_t len) { @@ -412,10 +414,13 @@ static void crc32c_test(struct kunit *test) =20 static void crc32c_benchmark(struct kunit *test) { crc_benchmark(test, crc32c_wrapper); } +#endif /* CONFIG_CRC32 */ + +#if IS_REACHABLE(CONFIG_CRC64) =20 /* crc64_be */ =20 static u64 crc64_be_wrapper(u64 crc, const u8 *p, size_t len) { @@ -461,28 +466,39 @@ static void crc64_nvme_test(struct kunit *test) =20 static void crc64_nvme_benchmark(struct kunit *test) { crc_benchmark(test, crc64_nvme_wrapper); } +#endif /* CONFIG_CRC64 */ =20 static struct kunit_case crc_test_cases[] =3D { +#if IS_REACHABLE(CONFIG_CRC7) KUNIT_CASE(crc7_be_test), KUNIT_CASE(crc7_be_benchmark), +#endif +#if IS_REACHABLE(CONFIG_CRC16) KUNIT_CASE(crc16_test), KUNIT_CASE(crc16_benchmark), +#endif +#if IS_REACHABLE(CONFIG_CRC_T10DIF) KUNIT_CASE(crc_t10dif_test), KUNIT_CASE(crc_t10dif_benchmark), +#endif +#if IS_REACHABLE(CONFIG_CRC32) KUNIT_CASE(crc32_le_test), KUNIT_CASE(crc32_le_benchmark), KUNIT_CASE(crc32_be_test), KUNIT_CASE(crc32_be_benchmark), KUNIT_CASE(crc32c_test), KUNIT_CASE(crc32c_benchmark), +#endif +#if IS_REACHABLE(CONFIG_CRC64) KUNIT_CASE(crc64_be_test), KUNIT_CASE(crc64_be_benchmark), KUNIT_CASE(crc64_nvme_test), KUNIT_CASE(crc64_nvme_benchmark), +#endif {}, }; =20 static struct kunit_suite crc_test_suite =3D { .name =3D "crc", --=20 2.53.0 From nobody Thu Apr 9 18:53:54 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EFE636C0D8; Fri, 6 Mar 2026 03:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772768296; cv=none; b=JsmvxIJyd/FS2e6QswAkYl+jj29IAAws/ZFUmx8t2xM3JCH/nhbjSXxRMpziC5PqFzTNXu1FJHvx1me+i/30Xw892+Dx2cJbEMNoINNPuj9hAdmM0PsCmuGq2EoR+w55TMumzDMnVF2bl/ItVa9R6JQKriY0coZpUj4TAjUlwsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772768296; c=relaxed/simple; bh=lWPe6HzHlWF7Ajkoe7X0eQUQeWdZYLj0utrBAnEF+Ps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SxWFqRqXNESUBLIdTUPz/VzkcQps5PA7ASav3/q+IKHN8TzusmRqAeZ5xuflX29TmbDvC76i5mcDkdz3ApoSCkBn/8E2n7Vtr+4kFHZv2goTmW2nZRQ3RnoDB+AIklmbG9I4r97WaNkKkDDzbzIjMjXtp/QtQobgW37EkxkoZ0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oriXQEJP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oriXQEJP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02EBEC2BC9E; Fri, 6 Mar 2026 03:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772768296; bh=lWPe6HzHlWF7Ajkoe7X0eQUQeWdZYLj0utrBAnEF+Ps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oriXQEJPL9UhlIql8Q6MQYF5AUij6jK5QaSqC/8SA31+mrAvdPv4Uy5ZAoAs6/exa +FX3n55p2+RpgT4tcVtSk2rp7shIalloT7rkMVdcgnNN8M0NLBfC+6hhJZxVad0NRG HgmnkfWL6pRI1HjNnA37HOinaXyYR7V6PBoNwlg0UkLGwGYdW6WcVHwb/rmt9eXNs/ ce5072RvPXAyb9ZGbmPQDb12gjfAysU6sdR0rkNYuVCt9uR2dXjXZUPZo2v1pISwNM GXDCcyRmkvVfwyIypd+LTsyAR5p/EEb7g6PuPeBmAyrvGUZTr9D6HwABmElAt6Fs4S NFcc/7Nvgb82Q== From: Eric Biggers To: linux-kernel@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel , kunit-dev@googlegroups.com, Eric Biggers Subject: [PATCH 2/3] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Date: Thu, 5 Mar 2026 19:35:56 -0800 Message-ID: <20260306033557.250499-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306033557.250499-1-ebiggers@kernel.org> References: <20260306033557.250499-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that crc_kunit uses the standard "depends on" pattern, enabling the full set of CRC tests is a bit difficult, mainly due to CRC7 being rarely used. Add a kconfig option to make it easier. It is visible only when KUNIT, so hopefully the extra prompt won't be too annoying. Signed-off-by: Eric Biggers --- lib/crc/Kconfig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/crc/Kconfig b/lib/crc/Kconfig index 9ddfd1a29757..cca228879bb5 100644 --- a/lib/crc/Kconfig +++ b/lib/crc/Kconfig @@ -105,10 +105,24 @@ config CRC_KUNIT_TEST Unit tests for the CRC library functions. =20 This is intended to help people writing architecture-specific optimized versions. If unsure, say N. =20 +config CRC_ENABLE_ALL_FOR_KUNIT + tristate "Enable all CRC functions for KUnit test" + depends on KUNIT + select CRC7 + select CRC16 + select CRC_T10DIF + select CRC32 + select CRC64 + help + Enable all CRC functions that have test code in CRC_KUNIT_TEST. + + Enable this only if you'd like the CRC KUnit test suite to test all + the CRC variants, even ones that wouldn't otherwise need to be built. + config CRC_BENCHMARK bool "Benchmark for the CRC functions" depends on CRC_KUNIT_TEST help Include benchmarks in the KUnit test suite for the CRC functions. --=20 2.53.0 From nobody Thu Apr 9 18:53:54 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E6736C5A4; Fri, 6 Mar 2026 03:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772768296; cv=none; b=r/3/YtVRNi1/EF6MGmCTHmd4dFVYCCjnoBrjK6XerspC2Pz8E0WfUG+wHFp2YGlAUw0bLM+IacS+Y0SA93TXM38u2AZN+NDpdyBvgi5TVNNkmoG3agwr+VqniVGdcUlkxc5g89rYLiKsiZpiPuRiXVSe8o9h6bvLYiuW0J4LxhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772768296; c=relaxed/simple; bh=GOaBsCpqI/oIzE5UIqkG63R4UPYgquErrFVbpCT1olc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PEjuN+FHvrGBRLAO3BugQZm6uNqtfdIIEJtlNsQXs7cuNxO69SvNxn/ZJxLXsalFc74jkIOMTChy0GMq6vUimb8bxm1L+D9/aBhkiYKtVj9BtDQvlscUVtCxWFzzULF9SgfsCVXcZm1uzlejj1FdbaW/1cOQ4R1/wj98Gxgrq9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XC6Zukg5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XC6Zukg5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B447C2BCB0; Fri, 6 Mar 2026 03:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772768296; bh=GOaBsCpqI/oIzE5UIqkG63R4UPYgquErrFVbpCT1olc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XC6Zukg5Q8ahnFiMzNRSiML/IBBLKtGx1o5dCHV03BkrvN8T5kS0nKGdg8e5TwFaE 8w4Hu8Ptlf5LxaXa48eaqsYIK05TMbv5tu2ST3QBtGEingorAaV8+yJxynFr5m2r6j Dpc/5OxQSi3Qs+NTuPn6fVomFPPIoIpQaT6wRYFUhEFd3NblYi7X9u8MOWblELCAcv JpSXr2lm/vSdVhpUnJJCQDaF5CWVejS1V7vmFVtcEG/0R9z7IKxPAcVq/RTCi/ANQg hy8JQ4Uwv6mE5Ux0M/cdGPY2Q1hxrNl/sSx0mUhgb4bXGalfg2QN2SJNfkJKw+vMnB Pnm1OqvgJ268w== From: Eric Biggers To: linux-kernel@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel , kunit-dev@googlegroups.com, Eric Biggers Subject: [PATCH 3/3] lib/crc: tests: Add a .kunitconfig file Date: Thu, 5 Mar 2026 19:35:57 -0800 Message-ID: <20260306033557.250499-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306033557.250499-1-ebiggers@kernel.org> References: <20260306033557.250499-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a .kunitconfig file to the lib/crc/ directory so that the CRC library tests can be run more easily using kunit.py. Example with UML: tools/testing/kunit/kunit.py run --kunitconfig=3Dlib/crc Example with QEMU: tools/testing/kunit/kunit.py run --kunitconfig=3Dlib/crc --arch=3Darm64= --make_options LLVM=3D1 Signed-off-by: Eric Biggers --- lib/crc/.kunitconfig | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/crc/.kunitconfig diff --git a/lib/crc/.kunitconfig b/lib/crc/.kunitconfig new file mode 100644 index 000000000000..0a3671ba573f --- /dev/null +++ b/lib/crc/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=3Dy +CONFIG_CRC_ENABLE_ALL_FOR_KUNIT=3Dy +CONFIG_CRC_KUNIT_TEST=3Dy --=20 2.53.0