From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Subject: [PATCH v2 3/6] crypto: compile out crypto_boot_test_finished when tests disabled
Date: Thu, 10 Nov 2022 00:13:43 -0800 [thread overview]
Message-ID: <20221110081346.336046-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20221110081346.336046-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
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>
---
crypto/algapi.c | 10 ++++++++--
crypto/api.c | 8 +++++---
crypto/internal.h | 13 ++++++++++++-
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/crypto/algapi.c b/crypto/algapi.c
index a8fa7c3f51be9..fbb4a88251bc8 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -451,7 +451,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))
- larval->test_started = static_key_enabled(&crypto_boot_test_finished);
+ larval->test_started = crypto_boot_test_finished();
up_write(&crypto_alg_sem);
if (IS_ERR(larval))
@@ -1246,6 +1246,11 @@ void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret,
EXPORT_SYMBOL_GPL(crypto_stats_skcipher_decrypt);
#endif
+#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
+static void __init crypto_start_tests(void)
+{
+}
+#else
static void __init crypto_start_tests(void)
{
for (;;) {
@@ -1281,8 +1286,9 @@ static void __init crypto_start_tests(void)
crypto_wait_for_test(larval);
}
- static_branch_enable(&crypto_boot_test_finished);
+ static_branch_enable(&__crypto_boot_test_finished);
}
+#endif /* !CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
static int __init crypto_algapi_init(void)
{
diff --git a/crypto/api.c b/crypto/api.c
index 64f2d365a8e94..3f002fe0336fc 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -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);
@@ -205,7 +207,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(
diff --git a/crypto/internal.h b/crypto/internal.h
index c08385571853e..a3bc1fbcefde7 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -47,7 +47,18 @@ 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;
+}
+#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);
+}
+#endif
#ifdef CONFIG_PROC_FS
void __init crypto_init_proc(void);
--
2.38.1
next prev parent reply other threads:[~2022-11-10 8:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 8:13 [PATCH v2 0/6] crypto: reduce overhead when self-tests disabled Eric Biggers
2022-11-10 8:13 ` [PATCH v2 1/6] crypto: optimize algorithm registration " Eric Biggers
2022-11-10 19:42 ` Eric Biggers
2022-11-11 4:06 ` Herbert Xu
2022-11-10 8:13 ` [PATCH v2 2/6] crypto: optimize registration of internal algorithms Eric Biggers
2022-11-10 8:13 ` Eric Biggers [this message]
2022-11-10 8:13 ` [PATCH v2 4/6] crypto: skip kdf_sp800108 self-test when tests disabled Eric Biggers
2022-11-10 8:13 ` [PATCH v2 5/6] crypto: silence noisy kdf_sp800108 self-test Eric Biggers
2022-11-10 8:13 ` [PATCH v2 6/6] crypto: compile out test-related algboss code when tests disabled Eric Biggers
2022-11-11 4:14 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221110081346.336046-4-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).