Skip to content

Commit 06bd9c9

Browse files
ebiggersherbertx
authored andcommitted
crypto: api - compile out crypto_boot_test_finished when tests disabled
The crypto_boot_test_finished static key is unnecessary when self-tests are disabled in the kconfig, so optimize it out accordingly, along with the entirety of crypto_start_tests(). This mainly avoids the overhead of an unnecessary static_branch_enable() on every boot. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9cadd73 commit 06bd9c9

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

crypto/algapi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ int crypto_register_alg(struct crypto_alg *alg)
454454
down_write(&crypto_alg_sem);
455455
larval = __crypto_register_alg(alg, &algs_to_put);
456456
if (!IS_ERR_OR_NULL(larval)) {
457-
test_started = static_key_enabled(&crypto_boot_test_finished);
457+
test_started = crypto_boot_test_finished();
458458
larval->test_started = test_started;
459459
}
460460
up_write(&crypto_alg_sem);
@@ -1253,6 +1253,9 @@ EXPORT_SYMBOL_GPL(crypto_stats_skcipher_decrypt);
12531253

12541254
static void __init crypto_start_tests(void)
12551255
{
1256+
if (IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS))
1257+
return;
1258+
12561259
for (;;) {
12571260
struct crypto_larval *larval = NULL;
12581261
struct crypto_alg *q;
@@ -1286,7 +1289,7 @@ static void __init crypto_start_tests(void)
12861289
crypto_wait_for_test(larval);
12871290
}
12881291

1289-
static_branch_enable(&crypto_boot_test_finished);
1292+
set_crypto_boot_test_finished();
12901293
}
12911294

12921295
static int __init crypto_algapi_init(void)

crypto/api.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
3131
BLOCKING_NOTIFIER_HEAD(crypto_chain);
3232
EXPORT_SYMBOL_GPL(crypto_chain);
3333

34-
DEFINE_STATIC_KEY_FALSE(crypto_boot_test_finished);
35-
EXPORT_SYMBOL_GPL(crypto_boot_test_finished);
34+
#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
35+
DEFINE_STATIC_KEY_FALSE(__crypto_boot_test_finished);
36+
EXPORT_SYMBOL_GPL(__crypto_boot_test_finished);
37+
#endif
3638

3739
static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
3840

@@ -202,7 +204,7 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
202204
struct crypto_larval *larval = (void *)alg;
203205
long timeout;
204206

205-
if (!static_branch_likely(&crypto_boot_test_finished))
207+
if (!crypto_boot_test_finished())
206208
crypto_start_test(larval);
207209

208210
timeout = wait_for_completion_killable_timeout(

crypto/internal.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,25 @@ extern struct list_head crypto_alg_list;
4747
extern struct rw_semaphore crypto_alg_sem;
4848
extern struct blocking_notifier_head crypto_chain;
4949

50-
DECLARE_STATIC_KEY_FALSE(crypto_boot_test_finished);
50+
#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
51+
static inline bool crypto_boot_test_finished(void)
52+
{
53+
return true;
54+
}
55+
static inline void set_crypto_boot_test_finished(void)
56+
{
57+
}
58+
#else
59+
DECLARE_STATIC_KEY_FALSE(__crypto_boot_test_finished);
60+
static inline bool crypto_boot_test_finished(void)
61+
{
62+
return static_branch_likely(&__crypto_boot_test_finished);
63+
}
64+
static inline void set_crypto_boot_test_finished(void)
65+
{
66+
static_branch_enable(&__crypto_boot_test_finished);
67+
}
68+
#endif /* !CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
5169

5270
#ifdef CONFIG_PROC_FS
5371
void __init crypto_init_proc(void);

0 commit comments

Comments
 (0)