Skip to content

Commit 6a42ff3

Browse files
committed
Merge tag 'libcrypto-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux
Pull crypto library fixes from Eric Biggers: - Several test fixes: - Fix flakiness in the interrupt context tests in certain VMs - Make the lib/crypto/ KUnit tests depend on the corresponding library options rather than selecting them. This follows the standard KUnit convention, and it fixes an issue where enabling CONFIG_KUNIT_ALL_TESTS pulled in all the crypto library code - Add a kunitconfig file for lib/crypto/ - Fix a couple stale references to "aes-generic" that made it in concurrently with the rename to "aes-lib" - Update the help text for several CRYPTO kconfig options to remove outdated information about users that now use the library instead * tag 'libcrypto-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux: crypto: testmgr - Fix stale references to aes-generic crypto: Clean up help text for CRYPTO_CRC32 crypto: Clean up help text for CRYPTO_CRC32C crypto: Clean up help text for CRYPTO_XXHASH crypto: Clean up help text for CRYPTO_SHA256 crypto: Clean up help text for CRYPTO_BLAKE2B lib/crypto: tests: Add a .kunitconfig file lib/crypto: tests: Depend on library options rather than selecting them kunit: irq: Ensure timer doesn't fire too frequently
2 parents 3988716 + 3875ceb commit 6a42ff3

5 files changed

Lines changed: 76 additions & 50 deletions

File tree

crypto/Kconfig

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,6 @@ config CRYPTO_BLAKE2B
876876
- blake2b-384
877877
- blake2b-512
878878

879-
Used by the btrfs filesystem.
880-
881879
See https://blake2.net for further information.
882880

883881
config CRYPTO_CMAC
@@ -965,7 +963,6 @@ config CRYPTO_SHA256
965963
10118-3), including HMAC support.
966964

967965
This is required for IPsec AH (XFRM_AH) and IPsec ESP (XFRM_ESP).
968-
Used by the btrfs filesystem, Ceph, NFS, and SMB.
969966

970967
config CRYPTO_SHA512
971968
tristate "SHA-384 and SHA-512"
@@ -1039,8 +1036,6 @@ config CRYPTO_XXHASH
10391036

10401037
Extremely fast, working at speeds close to RAM limits.
10411038

1042-
Used by the btrfs filesystem.
1043-
10441039
endmenu
10451040

10461041
menu "CRCs (cyclic redundancy checks)"
@@ -1058,17 +1053,13 @@ config CRYPTO_CRC32C
10581053
on Communications, Vol. 41, No. 6, June 1993, selected for use with
10591054
iSCSI.
10601055

1061-
Used by btrfs, ext4, jbd2, NVMeoF/TCP, and iSCSI.
1062-
10631056
config CRYPTO_CRC32
10641057
tristate "CRC32"
10651058
select CRYPTO_HASH
10661059
select CRC32
10671060
help
10681061
CRC32 CRC algorithm (IEEE 802.3)
10691062

1070-
Used by RoCEv2 and f2fs.
1071-
10721063
endmenu
10731064

10741065
menu "Compression"

crypto/testmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,7 +4132,7 @@ static const struct alg_test_desc alg_test_descs[] = {
41324132
.fips_allowed = 1,
41334133
}, {
41344134
.alg = "authenc(hmac(sha224),cbc(aes))",
4135-
.generic_driver = "authenc(hmac-sha224-lib,cbc(aes-generic))",
4135+
.generic_driver = "authenc(hmac-sha224-lib,cbc(aes-lib))",
41364136
.test = alg_test_aead,
41374137
.suite = {
41384138
.aead = __VECS(hmac_sha224_aes_cbc_tv_temp)
@@ -4194,7 +4194,7 @@ static const struct alg_test_desc alg_test_descs[] = {
41944194
.fips_allowed = 1,
41954195
}, {
41964196
.alg = "authenc(hmac(sha384),cbc(aes))",
4197-
.generic_driver = "authenc(hmac-sha384-lib,cbc(aes-generic))",
4197+
.generic_driver = "authenc(hmac-sha384-lib,cbc(aes-lib))",
41984198
.test = alg_test_aead,
41994199
.suite = {
42004200
.aead = __VECS(hmac_sha384_aes_cbc_tv_temp)

include/kunit/run-in-irq-context.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
#include <linux/hrtimer.h>
1313
#include <linux/workqueue.h>
1414

15-
#define KUNIT_IRQ_TEST_HRTIMER_INTERVAL us_to_ktime(5)
16-
1715
struct kunit_irq_test_state {
1816
bool (*func)(void *test_specific_state);
1917
void *test_specific_state;
2018
bool task_func_reported_failure;
2119
bool hardirq_func_reported_failure;
2220
bool softirq_func_reported_failure;
21+
atomic_t task_func_calls;
2322
atomic_t hardirq_func_calls;
2423
atomic_t softirq_func_calls;
24+
ktime_t interval;
2525
struct hrtimer timer;
2626
struct work_struct bh_work;
2727
};
@@ -30,14 +30,25 @@ static enum hrtimer_restart kunit_irq_test_timer_func(struct hrtimer *timer)
3030
{
3131
struct kunit_irq_test_state *state =
3232
container_of(timer, typeof(*state), timer);
33+
int task_calls, hardirq_calls, softirq_calls;
3334

3435
WARN_ON_ONCE(!in_hardirq());
35-
atomic_inc(&state->hardirq_func_calls);
36+
task_calls = atomic_read(&state->task_func_calls);
37+
hardirq_calls = atomic_inc_return(&state->hardirq_func_calls);
38+
softirq_calls = atomic_read(&state->softirq_func_calls);
39+
40+
/*
41+
* If the timer is firing too often for the softirq or task to ever have
42+
* a chance to run, increase the timer interval. This is needed on very
43+
* slow systems.
44+
*/
45+
if (hardirq_calls >= 20 && (softirq_calls == 0 || task_calls == 0))
46+
state->interval = ktime_add_ns(state->interval, 250);
3647

3748
if (!state->func(state->test_specific_state))
3849
state->hardirq_func_reported_failure = true;
3950

40-
hrtimer_forward_now(&state->timer, KUNIT_IRQ_TEST_HRTIMER_INTERVAL);
51+
hrtimer_forward_now(&state->timer, state->interval);
4152
queue_work(system_bh_wq, &state->bh_work);
4253
return HRTIMER_RESTART;
4354
}
@@ -86,10 +97,14 @@ static inline void kunit_run_irq_test(struct kunit *test, bool (*func)(void *),
8697
struct kunit_irq_test_state state = {
8798
.func = func,
8899
.test_specific_state = test_specific_state,
100+
/*
101+
* Start with a 5us timer interval. If the system can't keep
102+
* up, kunit_irq_test_timer_func() will increase it.
103+
*/
104+
.interval = us_to_ktime(5),
89105
};
90106
unsigned long end_jiffies;
91-
int hardirq_calls, softirq_calls;
92-
bool allctx = false;
107+
int task_calls, hardirq_calls, softirq_calls;
93108

94109
/*
95110
* Set up a hrtimer (the way we access hardirq context) and a work
@@ -104,21 +119,18 @@ static inline void kunit_run_irq_test(struct kunit *test, bool (*func)(void *),
104119
* and hardirq), or 1 second, whichever comes first.
105120
*/
106121
end_jiffies = jiffies + HZ;
107-
hrtimer_start(&state.timer, KUNIT_IRQ_TEST_HRTIMER_INTERVAL,
108-
HRTIMER_MODE_REL_HARD);
109-
for (int task_calls = 0, calls = 0;
110-
((calls < max_iterations) || !allctx) &&
111-
!time_after(jiffies, end_jiffies);
112-
task_calls++) {
122+
hrtimer_start(&state.timer, state.interval, HRTIMER_MODE_REL_HARD);
123+
do {
113124
if (!func(test_specific_state))
114125
state.task_func_reported_failure = true;
115126

127+
task_calls = atomic_inc_return(&state.task_func_calls);
116128
hardirq_calls = atomic_read(&state.hardirq_func_calls);
117129
softirq_calls = atomic_read(&state.softirq_func_calls);
118-
calls = task_calls + hardirq_calls + softirq_calls;
119-
allctx = (task_calls > 0) && (hardirq_calls > 0) &&
120-
(softirq_calls > 0);
121-
}
130+
} while ((task_calls + hardirq_calls + softirq_calls < max_iterations ||
131+
(task_calls == 0 || hardirq_calls == 0 ||
132+
softirq_calls == 0)) &&
133+
!time_after(jiffies, end_jiffies));
122134

123135
/* Cancel the timer and work. */
124136
hrtimer_cancel(&state.timer);

lib/crypto/.kunitconfig

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CONFIG_KUNIT=y
2+
3+
# These kconfig options select all the CONFIG_CRYPTO_LIB_* symbols that have a
4+
# corresponding KUnit test. Those symbols cannot be directly enabled here,
5+
# since they are hidden symbols.
6+
CONFIG_CRYPTO=y
7+
CONFIG_CRYPTO_ADIANTUM=y
8+
CONFIG_CRYPTO_BLAKE2B=y
9+
CONFIG_CRYPTO_CHACHA20POLY1305=y
10+
CONFIG_CRYPTO_HCTR2=y
11+
CONFIG_CRYPTO_MD5=y
12+
CONFIG_CRYPTO_MLDSA=y
13+
CONFIG_CRYPTO_SHA1=y
14+
CONFIG_CRYPTO_SHA256=y
15+
CONFIG_CRYPTO_SHA512=y
16+
CONFIG_CRYPTO_SHA3=y
17+
CONFIG_INET=y
18+
CONFIG_IPV6=y
19+
CONFIG_NET=y
20+
CONFIG_NETDEVICES=y
21+
CONFIG_WIREGUARD=y
22+
23+
CONFIG_CRYPTO_LIB_BLAKE2B_KUNIT_TEST=y
24+
CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST=y
25+
CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST=y
26+
CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST=y
27+
CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST=y
28+
CONFIG_CRYPTO_LIB_NH_KUNIT_TEST=y
29+
CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST=y
30+
CONFIG_CRYPTO_LIB_POLYVAL_KUNIT_TEST=y
31+
CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST=y
32+
CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST=y
33+
CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST=y
34+
CONFIG_CRYPTO_LIB_SHA3_KUNIT_TEST=y

lib/crypto/tests/Kconfig

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
config CRYPTO_LIB_BLAKE2B_KUNIT_TEST
44
tristate "KUnit tests for BLAKE2b" if !KUNIT_ALL_TESTS
5-
depends on KUNIT
5+
depends on KUNIT && CRYPTO_LIB_BLAKE2B
66
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
77
select CRYPTO_LIB_BENCHMARK_VISIBLE
8-
select CRYPTO_LIB_BLAKE2B
98
help
109
KUnit tests for the BLAKE2b cryptographic hash function.
1110

@@ -14,71 +13,64 @@ config CRYPTO_LIB_BLAKE2S_KUNIT_TEST
1413
depends on KUNIT
1514
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
1615
select CRYPTO_LIB_BENCHMARK_VISIBLE
17-
# No need to select CRYPTO_LIB_BLAKE2S here, as that option doesn't
16+
# No need to depend on CRYPTO_LIB_BLAKE2S here, as that option doesn't
1817
# exist; the BLAKE2s code is always built-in for the /dev/random driver.
1918
help
2019
KUnit tests for the BLAKE2s cryptographic hash function.
2120

2221
config CRYPTO_LIB_CURVE25519_KUNIT_TEST
2322
tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS
24-
depends on KUNIT
23+
depends on KUNIT && CRYPTO_LIB_CURVE25519
2524
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
2625
select CRYPTO_LIB_BENCHMARK_VISIBLE
27-
select CRYPTO_LIB_CURVE25519
2826
help
2927
KUnit tests for the Curve25519 Diffie-Hellman function.
3028

3129
config CRYPTO_LIB_MD5_KUNIT_TEST
3230
tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS
33-
depends on KUNIT
31+
depends on KUNIT && CRYPTO_LIB_MD5
3432
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
3533
select CRYPTO_LIB_BENCHMARK_VISIBLE
36-
select CRYPTO_LIB_MD5
3734
help
3835
KUnit tests for the MD5 cryptographic hash function and its
3936
corresponding HMAC.
4037

4138
config CRYPTO_LIB_MLDSA_KUNIT_TEST
4239
tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS
43-
depends on KUNIT
40+
depends on KUNIT && CRYPTO_LIB_MLDSA
4441
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
4542
select CRYPTO_LIB_BENCHMARK_VISIBLE
46-
select CRYPTO_LIB_MLDSA
4743
help
4844
KUnit tests for the ML-DSA digital signature algorithm.
4945

5046
config CRYPTO_LIB_NH_KUNIT_TEST
5147
tristate "KUnit tests for NH" if !KUNIT_ALL_TESTS
52-
depends on KUNIT
48+
depends on KUNIT && CRYPTO_LIB_NH
5349
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
54-
select CRYPTO_LIB_NH
5550
help
5651
KUnit tests for the NH almost-universal hash function.
5752

5853
config CRYPTO_LIB_POLY1305_KUNIT_TEST
5954
tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS
60-
depends on KUNIT
55+
depends on KUNIT && CRYPTO_LIB_POLY1305
6156
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
6257
select CRYPTO_LIB_BENCHMARK_VISIBLE
63-
select CRYPTO_LIB_POLY1305
6458
help
6559
KUnit tests for the Poly1305 library functions.
6660

6761
config CRYPTO_LIB_POLYVAL_KUNIT_TEST
6862
tristate "KUnit tests for POLYVAL" if !KUNIT_ALL_TESTS
69-
depends on KUNIT
63+
depends on KUNIT && CRYPTO_LIB_POLYVAL
7064
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
7165
select CRYPTO_LIB_BENCHMARK_VISIBLE
72-
select CRYPTO_LIB_POLYVAL
7366
help
7467
KUnit tests for the POLYVAL library functions.
7568

7669
config CRYPTO_LIB_SHA1_KUNIT_TEST
7770
tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS
78-
depends on KUNIT
71+
depends on KUNIT && CRYPTO_LIB_SHA1
7972
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
8073
select CRYPTO_LIB_BENCHMARK_VISIBLE
81-
select CRYPTO_LIB_SHA1
8274
help
8375
KUnit tests for the SHA-1 cryptographic hash function and its
8476
corresponding HMAC.
@@ -87,10 +79,9 @@ config CRYPTO_LIB_SHA1_KUNIT_TEST
8779
# included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256).
8880
config CRYPTO_LIB_SHA256_KUNIT_TEST
8981
tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS
90-
depends on KUNIT
82+
depends on KUNIT && CRYPTO_LIB_SHA256
9183
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
9284
select CRYPTO_LIB_BENCHMARK_VISIBLE
93-
select CRYPTO_LIB_SHA256
9485
help
9586
KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions
9687
and their corresponding HMACs.
@@ -99,20 +90,18 @@ config CRYPTO_LIB_SHA256_KUNIT_TEST
9990
# included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512).
10091
config CRYPTO_LIB_SHA512_KUNIT_TEST
10192
tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS
102-
depends on KUNIT
93+
depends on KUNIT && CRYPTO_LIB_SHA512
10394
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
10495
select CRYPTO_LIB_BENCHMARK_VISIBLE
105-
select CRYPTO_LIB_SHA512
10696
help
10797
KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions
10898
and their corresponding HMACs.
10999

110100
config CRYPTO_LIB_SHA3_KUNIT_TEST
111101
tristate "KUnit tests for SHA-3" if !KUNIT_ALL_TESTS
112-
depends on KUNIT
102+
depends on KUNIT && CRYPTO_LIB_SHA3
113103
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
114104
select CRYPTO_LIB_BENCHMARK_VISIBLE
115-
select CRYPTO_LIB_SHA3
116105
help
117106
KUnit tests for the SHA3 cryptographic hash and XOF functions,
118107
including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128 and

0 commit comments

Comments
 (0)