public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements
@ 2026-04-21 21:05 Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 1/8] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers

This series backports improvements to the KUnit testing for the crypto
and CRC libraries to 6.18, including:

- Finish fixing the test kconfig options to follow standard conventions
- Add kunitconfig files
- Make the tests be included in 'kunit.py run --alltests'

The crypto patches were adjusted to drop parts that pertain to tests
added in later kernels.

While stable backports are normally limited to "fixes", I think it's
worth also backporting the kunitconfig files and the all_tests.config
support, since these are safe test-only changes that are helpful for
testing 6.18.  For example, this should make KernelCI run all these
tests on 6.18, as it uses 'kunit.py run --alltests'.

Eric Biggers (8):
  lib/crc: tests: Make crc_kunit test only the enabled CRC variants
  lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT
  lib/crc: tests: Add a .kunitconfig file
  kunit: configs: Enable all CRC tests in all_tests.config
  lib/crypto: tests: Add a .kunitconfig file
  lib/crypto: tests: Introduce CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT
  kunit: configs: Enable all crypto library tests in all_tests.config
  lib/crypto: tests: Drop the default to CRYPTO_SELFTESTS

 lib/crc/.kunitconfig                         |  3 ++
 lib/crc/Kconfig                              | 17 ++++++++---
 lib/crc/tests/crc_kunit.c                    | 28 +++++++++++++----
 lib/crypto/.kunitconfig                      | 11 +++++++
 lib/crypto/tests/Kconfig                     | 32 +++++++++++++++-----
 tools/testing/kunit/configs/all_tests.config |  4 +++
 6 files changed, 78 insertions(+), 17 deletions(-)
 create mode 100644 lib/crc/.kunitconfig
 create mode 100644 lib/crypto/.kunitconfig


base-commit: 47a33eea6d5145d53e42315381ef28286c2218fb
-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6.18 1/8] lib/crc: tests: Make crc_kunit test only the enabled CRC variants
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 2/8] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Eric Biggers
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers

commit 85c9f3a2b805eb96d899da7bcc38a16459aa3c16 upstream.

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
Link: https://lore.kernel.org/r/20260306033557.250499-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 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 70e7a6016de32..9ddfd1a297576 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.
 
 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.
 
 	  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 9a450e25ac811..9428cd9136253 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=%zu: %llu MB/s\n",
 			   len, div64_u64((u64)len * num_iters * 1000, t));
 	}
 }
 
-/* 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)
 
 static void crc7_be_benchmark(struct kunit *test)
 {
 	crc_benchmark(test, crc7_be_wrapper);
 }
+#endif /* CONFIG_CRC7 */
 
-/* crc16 */
-
+#if IS_REACHABLE(CONFIG_CRC16)
 static u64 crc16_wrapper(u64 crc, const u8 *p, size_t len)
 {
 	return crc16(crc, p, len);
 }
 
@@ -316,13 +315,13 @@ static void crc16_test(struct kunit *test)
 
 static void crc16_benchmark(struct kunit *test)
 {
 	crc_benchmark(test, crc16_wrapper);
 }
+#endif /* CONFIG_CRC16 */
 
-/* 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);
 }
 
@@ -340,10 +339,13 @@ static void crc_t10dif_test(struct kunit *test)
 
 static void crc_t10dif_benchmark(struct kunit *test)
 {
 	crc_benchmark(test, crc_t10dif_wrapper);
 }
+#endif /* CONFIG_CRC_T10DIF */
+
+#if IS_REACHABLE(CONFIG_CRC32)
 
 /* crc32_le */
 
 static u64 crc32_le_wrapper(u64 crc, const u8 *p, size_t len)
 {
@@ -412,10 +414,13 @@ static void crc32c_test(struct kunit *test)
 
 static void crc32c_benchmark(struct kunit *test)
 {
 	crc_benchmark(test, crc32c_wrapper);
 }
+#endif /* CONFIG_CRC32 */
+
+#if IS_REACHABLE(CONFIG_CRC64)
 
 /* crc64_be */
 
 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)
 
 static void crc64_nvme_benchmark(struct kunit *test)
 {
 	crc_benchmark(test, crc64_nvme_wrapper);
 }
+#endif /* CONFIG_CRC64 */
 
 static struct kunit_case crc_test_cases[] = {
+#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
 	{},
 };
 
 static struct kunit_suite crc_test_suite = {
 	.name = "crc",
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 2/8] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 1/8] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 3/8] lib/crc: tests: Add a .kunitconfig file Eric Biggers
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers

commit cdf22aeaad8430905c3aa3b3d0f2686c65395c22 upstream.

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.

Link: https://lore.kernel.org/r/20260306033557.250499-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crc/Kconfig | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/crc/Kconfig b/lib/crc/Kconfig
index 9ddfd1a297576..cca228879bb5a 100644
--- a/lib/crc/Kconfig
+++ b/lib/crc/Kconfig
@@ -105,10 +105,24 @@ config CRC_KUNIT_TEST
 	  Unit tests for the CRC library functions.
 
 	  This is intended to help people writing architecture-specific
 	  optimized versions.  If unsure, say N.
 
+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.
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 3/8] lib/crc: tests: Add a .kunitconfig file
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 1/8] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 2/8] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 4/8] kunit: configs: Enable all CRC tests in all_tests.config Eric Biggers
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers

commit c13cee2fc7f137dd25ed50c63eddcc578624f204 upstream.

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=lib/crc

Example with QEMU:

    tools/testing/kunit/kunit.py run --kunitconfig=lib/crc --arch=arm64 --make_options LLVM=1

Link: https://lore.kernel.org/r/20260306033557.250499-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 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 0000000000000..0a3671ba573f0
--- /dev/null
+++ b/lib/crc/.kunitconfig
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_CRC_ENABLE_ALL_FOR_KUNIT=y
+CONFIG_CRC_KUNIT_TEST=y
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 4/8] kunit: configs: Enable all CRC tests in all_tests.config
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
                   ` (2 preceding siblings ...)
  2026-04-21 21:05 ` [PATCH 6.18 3/8] lib/crc: tests: Add a .kunitconfig file Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 5/8] lib/crypto: tests: Add a .kunitconfig file Eric Biggers
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers, Ard Biesheuvel

commit 44ff3791d6295f7b51dd2711aad6a03dd79aef22 upstream.

The new option CONFIG_CRC_ENABLE_ALL_FOR_KUNIT enables all the CRC code
that has KUnit tests, causing CONFIG_KUNIT_ALL_TESTS to enable all these
tests.  Add this option to all_tests.config so that kunit.py will run
them when passed the --alltests option.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20260314172224.15152-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 tools/testing/kunit/configs/all_tests.config | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/kunit/configs/all_tests.config b/tools/testing/kunit/configs/all_tests.config
index 422e186cf3cf1..c1d3659a41cf0 100644
--- a/tools/testing/kunit/configs/all_tests.config
+++ b/tools/testing/kunit/configs/all_tests.config
@@ -44,10 +44,12 @@ CONFIG_REGMAP_BUILD=y
 
 CONFIG_AUDIT=y
 
 CONFIG_PRIME_NUMBERS=y
 
+CONFIG_CRC_ENABLE_ALL_FOR_KUNIT=y
+
 CONFIG_SECURITY=y
 CONFIG_SECURITY_APPARMOR=y
 CONFIG_SECURITY_LANDLOCK=y
 
 CONFIG_SOUND=y
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 5/8] lib/crypto: tests: Add a .kunitconfig file
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
                   ` (3 preceding siblings ...)
  2026-04-21 21:05 ` [PATCH 6.18 4/8] kunit: configs: Enable all CRC tests in all_tests.config Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 6/8] lib/crypto: tests: Introduce CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT Eric Biggers
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers, Ard Biesheuvel

commit 20d6f07004d639967dcb00994d56ce6d16118e9e upstream.

Add a .kunitconfig file to the lib/crypto/ directory so that the crypto
library tests can be run more easily using kunit.py.  Example with UML:

    tools/testing/kunit/kunit.py run --kunitconfig=lib/crypto

Example with QEMU:

    tools/testing/kunit/kunit.py run --kunitconfig=lib/crypto --arch=arm64 --make_options LLVM=1

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20260301040140.490310-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/.kunitconfig | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 lib/crypto/.kunitconfig

diff --git a/lib/crypto/.kunitconfig b/lib/crypto/.kunitconfig
new file mode 100644
index 0000000000000..e38ccb5a4327e
--- /dev/null
+++ b/lib/crypto/.kunitconfig
@@ -0,0 +1,23 @@
+CONFIG_KUNIT=y
+
+# These kconfig options select all the CONFIG_CRYPTO_LIB_* symbols that have a
+# corresponding KUnit test.  Those symbols cannot be directly enabled here,
+# since they are hidden symbols.
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_SHA1=y
+CONFIG_CRYPTO_SHA256=y
+CONFIG_CRYPTO_SHA512=y
+CONFIG_INET=y
+CONFIG_IPV6=y
+CONFIG_NET=y
+CONFIG_NETDEVICES=y
+CONFIG_WIREGUARD=y
+
+CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST=y
+CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST=y
+CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST=y
+CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST=y
+CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST=y
+CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST=y
+CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST=y
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 6/8] lib/crypto: tests: Introduce CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
                   ` (4 preceding siblings ...)
  2026-04-21 21:05 ` [PATCH 6.18 5/8] lib/crypto: tests: Add a .kunitconfig file Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 7/8] kunit: configs: Enable all crypto library tests in all_tests.config Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 8/8] lib/crypto: tests: Drop the default to CRYPTO_SELFTESTS Eric Biggers
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers

commit ed1767442d919f57aaf83d69c33853da2644d902 upstream.

For kunit.py to run all the crypto library tests when passed the
--alltests option, tools/testing/kunit/configs/all_tests.config needs to
enable options that satisfy the test dependencies.

This is the same as what lib/crypto/.kunitconfig already does.
However, the strategy that lib/crypto/.kunitconfig currently uses to
select all the hidden library options isn't going to scale up well when
it needs to be repeated in two places.

Instead let's go ahead and introduce an option
CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT that depends on KUNIT and selects all
the crypto library options that have corresponding KUnit tests.

Update lib/crypto/.kunitconfig to use this option.

Link: https://lore.kernel.org/r/20260314035927.51351-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/.kunitconfig  | 14 +-------------
 lib/crypto/tests/Kconfig | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/lib/crypto/.kunitconfig b/lib/crypto/.kunitconfig
index e38ccb5a4327e..2edc7fc23aab7 100644
--- a/lib/crypto/.kunitconfig
+++ b/lib/crypto/.kunitconfig
@@ -1,20 +1,8 @@
 CONFIG_KUNIT=y
 
-# These kconfig options select all the CONFIG_CRYPTO_LIB_* symbols that have a
-# corresponding KUnit test.  Those symbols cannot be directly enabled here,
-# since they are hidden symbols.
-CONFIG_CRYPTO=y
-CONFIG_CRYPTO_MD5=y
-CONFIG_CRYPTO_SHA1=y
-CONFIG_CRYPTO_SHA256=y
-CONFIG_CRYPTO_SHA512=y
-CONFIG_INET=y
-CONFIG_IPV6=y
-CONFIG_NET=y
-CONFIG_NETDEVICES=y
-CONFIG_WIREGUARD=y
+CONFIG_CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT=y
 
 CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST=y
 CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST=y
 CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST=y
 CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST=y
diff --git a/lib/crypto/tests/Kconfig b/lib/crypto/tests/Kconfig
index 7f033f4c14918..73200134916e8 100644
--- a/lib/crypto/tests/Kconfig
+++ b/lib/crypto/tests/Kconfig
@@ -64,10 +64,28 @@ config CRYPTO_LIB_SHA512_KUNIT_TEST
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions
 	  and their corresponding HMACs.
 
+config CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT
+	tristate "Enable all crypto library code for KUnit tests"
+	depends on KUNIT
+	select CRYPTO_LIB_CURVE25519
+	select CRYPTO_LIB_MD5
+	select CRYPTO_LIB_POLY1305
+	select CRYPTO_LIB_SHA1
+	select CRYPTO_LIB_SHA256
+	select CRYPTO_LIB_SHA512
+	help
+	  Enable all the crypto library code that has KUnit tests.
+
+	  Enable this only if you'd like to test all the crypto library code,
+	  even code that wouldn't otherwise need to be built.
+
+	  You'll still need to enable the tests themselves, either individually
+	  or using KUNIT_ALL_TESTS.
+
 config CRYPTO_LIB_BENCHMARK_VISIBLE
 	bool
 
 config CRYPTO_LIB_BENCHMARK
 	bool "Include benchmarks in KUnit tests for cryptographic functions"
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 7/8] kunit: configs: Enable all crypto library tests in all_tests.config
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
                   ` (5 preceding siblings ...)
  2026-04-21 21:05 ` [PATCH 6.18 6/8] lib/crypto: tests: Introduce CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  2026-04-21 21:05 ` [PATCH 6.18 8/8] lib/crypto: tests: Drop the default to CRYPTO_SELFTESTS Eric Biggers
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers

commit 8d547482231fef30d0d6440629b73560ad3e937c upstream.

The new option CONFIG_CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT enables all the
crypto library code that has KUnit tests, causing CONFIG_KUNIT_ALL_TESTS
to enable all these tests.  Add this option to all_tests.config so that
kunit.py will run them when passed the --alltests option.

Link: https://lore.kernel.org/r/20260314035927.51351-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 tools/testing/kunit/configs/all_tests.config | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/kunit/configs/all_tests.config b/tools/testing/kunit/configs/all_tests.config
index c1d3659a41cf0..bccc2c77196d5 100644
--- a/tools/testing/kunit/configs/all_tests.config
+++ b/tools/testing/kunit/configs/all_tests.config
@@ -42,10 +42,12 @@ CONFIG_DAMON_PADDR=y
 
 CONFIG_REGMAP_BUILD=y
 
 CONFIG_AUDIT=y
 
+CONFIG_CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT=y
+
 CONFIG_PRIME_NUMBERS=y
 
 CONFIG_CRC_ENABLE_ALL_FOR_KUNIT=y
 
 CONFIG_SECURITY=y
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6.18 8/8] lib/crypto: tests: Drop the default to CRYPTO_SELFTESTS
  2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
                   ` (6 preceding siblings ...)
  2026-04-21 21:05 ` [PATCH 6.18 7/8] kunit: configs: Enable all crypto library tests in all_tests.config Eric Biggers
@ 2026-04-21 21:05 ` Eric Biggers
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Biggers @ 2026-04-21 21:05 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, kunit-dev, Eric Biggers, Ard Biesheuvel

commit 6d80749becf8fc5ffa004194e578f79b558235ef upstream.

Defaulting the crypto KUnit tests to KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
instead of simply KUNIT_ALL_TESTS was originally intended to make it
easy to enable all the crypto KUnit tests.  This additional default is
nonstandard for KUnit tests, though, and it can cause all the KUnit
tests to be built-in unexpectedly if CRYPTO_SELFTESTS is set.  It also
constitutes a back-reference to crypto/ from lib/crypto/, which is
something that we should be avoiding in order to get clean layering.

Now that we provide a lib/crypto/.kunitconfig file that enables all
crypto KUnit tests, let's consider that to be the supported way to
enable all these tests, and drop the default of CRYPTO_SELFTESTS.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20260317040626.5697-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/tests/Kconfig | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/crypto/tests/Kconfig b/lib/crypto/tests/Kconfig
index 73200134916e8..a91815ec9b3ad 100644
--- a/lib/crypto/tests/Kconfig
+++ b/lib/crypto/tests/Kconfig
@@ -1,68 +1,68 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 config CRYPTO_LIB_BLAKE2S_KUNIT_TEST
 	tristate "KUnit tests for BLAKE2s" if !KUNIT_ALL_TESTS
 	depends on KUNIT
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	# No need to depend on CRYPTO_LIB_BLAKE2S here, as that option doesn't
 	# exist; the BLAKE2s code is always built-in for the /dev/random driver.
 	help
 	  KUnit tests for the BLAKE2s cryptographic hash function.
 
 config CRYPTO_LIB_CURVE25519_KUNIT_TEST
 	tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS
 	depends on KUNIT && CRYPTO_LIB_CURVE25519
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the Curve25519 Diffie-Hellman function.
 
 config CRYPTO_LIB_MD5_KUNIT_TEST
 	tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS
 	depends on KUNIT && CRYPTO_LIB_MD5
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the MD5 cryptographic hash function and its
 	  corresponding HMAC.
 
 config CRYPTO_LIB_POLY1305_KUNIT_TEST
 	tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS
 	depends on KUNIT && CRYPTO_LIB_POLY1305
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the Poly1305 library functions.
 
 config CRYPTO_LIB_SHA1_KUNIT_TEST
 	tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS
 	depends on KUNIT && CRYPTO_LIB_SHA1
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the SHA-1 cryptographic hash function and its
 	  corresponding HMAC.
 
 # Option is named *_SHA256_KUNIT_TEST, though both SHA-224 and SHA-256 tests are
 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256).
 config CRYPTO_LIB_SHA256_KUNIT_TEST
 	tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS
 	depends on KUNIT && CRYPTO_LIB_SHA256
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions
 	  and their corresponding HMACs.
 
 # Option is named *_SHA512_KUNIT_TEST, though both SHA-384 and SHA-512 tests are
 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512).
 config CRYPTO_LIB_SHA512_KUNIT_TEST
 	tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS
 	depends on KUNIT && CRYPTO_LIB_SHA512
-	default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
+	default KUNIT_ALL_TESTS
 	select CRYPTO_LIB_BENCHMARK_VISIBLE
 	help
 	  KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions
 	  and their corresponding HMACs.
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-04-21 21:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 21:05 [PATCH 6.18 0/8] Backport crypto and CRC KUnit improvements Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 1/8] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 2/8] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 3/8] lib/crc: tests: Add a .kunitconfig file Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 4/8] kunit: configs: Enable all CRC tests in all_tests.config Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 5/8] lib/crypto: tests: Add a .kunitconfig file Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 6/8] lib/crypto: tests: Introduce CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 7/8] kunit: configs: Enable all crypto library tests in all_tests.config Eric Biggers
2026-04-21 21:05 ` [PATCH 6.18 8/8] lib/crypto: tests: Drop the default to CRYPTO_SELFTESTS Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox