crypto: api - compile out crypto_boot_test_finished when tests disabled
authorEric Biggers <ebiggers@google.com>
Mon, 14 Nov 2022 00:12:35 +0000 (16:12 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 25 Nov 2022 09:39:18 +0000 (17:39 +0800)
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>
crypto/algapi.c
crypto/api.c
crypto/internal.h

index 851b247f043d35b0d856bfbcd2259de1eb20c4c0..d08f864f08beef69e787473faa03ea67998a05c0 100644 (file)
@@ -454,7 +454,7 @@ int crypto_register_alg(struct crypto_alg *alg)
        down_write(&crypto_alg_sem);
        larval = __crypto_register_alg(alg, &algs_to_put);
        if (!IS_ERR_OR_NULL(larval)) {
-               test_started = static_key_enabled(&crypto_boot_test_finished);
+               test_started = crypto_boot_test_finished();
                larval->test_started = test_started;
        }
        up_write(&crypto_alg_sem);
@@ -1253,6 +1253,9 @@ EXPORT_SYMBOL_GPL(crypto_stats_skcipher_decrypt);
 
 static void __init crypto_start_tests(void)
 {
+       if (IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS))
+               return;
+
        for (;;) {
                struct crypto_larval *larval = NULL;
                struct crypto_alg *q;
@@ -1286,7 +1289,7 @@ static void __init crypto_start_tests(void)
                crypto_wait_for_test(larval);
        }
 
-       static_branch_enable(&crypto_boot_test_finished);
+       set_crypto_boot_test_finished();
 }
 
 static int __init crypto_algapi_init(void)
index 52ce10a353660e73c3077caed14ff4ff6cd98052..b022702f643672ea6ad2873bb1b95b5bc828ade2 100644 (file)
@@ -31,8 +31,10 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
 BLOCKING_NOTIFIER_HEAD(crypto_chain);
 EXPORT_SYMBOL_GPL(crypto_chain);
 
-DEFINE_STATIC_KEY_FALSE(crypto_boot_test_finished);
-EXPORT_SYMBOL_GPL(crypto_boot_test_finished);
+#ifndef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
+DEFINE_STATIC_KEY_FALSE(__crypto_boot_test_finished);
+EXPORT_SYMBOL_GPL(__crypto_boot_test_finished);
+#endif
 
 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
 
@@ -202,7 +204,7 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
        struct crypto_larval *larval = (void *)alg;
        long timeout;
 
-       if (!static_branch_likely(&crypto_boot_test_finished))
+       if (!crypto_boot_test_finished())
                crypto_start_test(larval);
 
        timeout = wait_for_completion_killable_timeout(
index c08385571853ee677fc415022980c889917191a4..932f0aafddc32dc3974e71bdb8d0f37ad9e3aa80 100644 (file)
@@ -47,7 +47,25 @@ extern struct list_head crypto_alg_list;
 extern struct rw_semaphore crypto_alg_sem;
 extern struct blocking_notifier_head crypto_chain;
 
-DECLARE_STATIC_KEY_FALSE(crypto_boot_test_finished);
+#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
+static inline bool crypto_boot_test_finished(void)
+{
+       return true;
+}
+static inline void set_crypto_boot_test_finished(void)
+{
+}
+#else
+DECLARE_STATIC_KEY_FALSE(__crypto_boot_test_finished);
+static inline bool crypto_boot_test_finished(void)
+{
+       return static_branch_likely(&__crypto_boot_test_finished);
+}
+static inline void set_crypto_boot_test_finished(void)
+{
+       static_branch_enable(&__crypto_boot_test_finished);
+}
+#endif /* !CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
 
 #ifdef CONFIG_PROC_FS
 void __init crypto_init_proc(void);