]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib/crypto: sha256: Use underlying functions instead of crypto_simd_usable()
authorEric Biggers <ebiggers@kernel.org>
Thu, 31 Jul 2025 22:35:10 +0000 (15:35 -0700)
committerEric Biggers <ebiggers@kernel.org>
Tue, 26 Aug 2025 16:52:27 +0000 (12:52 -0400)
Since sha256_kunit tests the fallback code paths without using
crypto_simd_disabled_for_test, make the SHA-256 code just use the
underlying may_use_simd() and irq_fpu_usable() functions directly
instead of crypto_simd_usable().  This eliminates an unnecessary layer.

While doing this, also add likely() annotations, and fix a minor
inconsistency where the static keys in the sha256.h files were in a
different place than in the corresponding sha1.h and sha512.h files.

Link: https://lore.kernel.org/r/20250731223510.136650-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
lib/crypto/arm/sha256.h
lib/crypto/arm64/sha256.h
lib/crypto/riscv/sha256.h
lib/crypto/x86/sha256.h

index da75cbdc51d413c2efc3143bc7e7c369071fb213..eab713e650f33ed3eb6840aef7a72f3652b92cc9 100644 (file)
@@ -5,7 +5,10 @@
  * Copyright 2025 Google LLC
  */
 #include <asm/neon.h>
-#include <crypto/internal/simd.h>
+#include <asm/simd.h>
+
+static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
+static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
 
 asmlinkage void sha256_block_data_order(struct sha256_block_state *state,
                                        const u8 *data, size_t nblocks);
@@ -14,14 +17,11 @@ asmlinkage void sha256_block_data_order_neon(struct sha256_block_state *state,
 asmlinkage void sha256_ce_transform(struct sha256_block_state *state,
                                    const u8 *data, size_t nblocks);
 
-static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
-static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
-
 static void sha256_blocks(struct sha256_block_state *state,
                          const u8 *data, size_t nblocks)
 {
        if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
-           static_branch_likely(&have_neon) && crypto_simd_usable()) {
+           static_branch_likely(&have_neon) && likely(may_use_simd())) {
                kernel_neon_begin();
                if (static_branch_likely(&have_ce))
                        sha256_ce_transform(state, data, nblocks);
index a211966c124a967f4b7a4e71669a1ba422bb28b2..d95f1077c32bdfc8bf7c407af683eb1a7df337a4 100644 (file)
@@ -5,9 +5,12 @@
  * Copyright 2025 Google LLC
  */
 #include <asm/neon.h>
-#include <crypto/internal/simd.h>
+#include <asm/simd.h>
 #include <linux/cpufeature.h>
 
+static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
+static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
+
 asmlinkage void sha256_block_data_order(struct sha256_block_state *state,
                                        const u8 *data, size_t nblocks);
 asmlinkage void sha256_block_neon(struct sha256_block_state *state,
@@ -15,14 +18,11 @@ asmlinkage void sha256_block_neon(struct sha256_block_state *state,
 asmlinkage size_t __sha256_ce_transform(struct sha256_block_state *state,
                                        const u8 *data, size_t nblocks);
 
-static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
-static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
-
 static void sha256_blocks(struct sha256_block_state *state,
                          const u8 *data, size_t nblocks)
 {
        if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
-           static_branch_likely(&have_neon) && crypto_simd_usable()) {
+           static_branch_likely(&have_neon) && likely(may_use_simd())) {
                if (static_branch_likely(&have_ce)) {
                        do {
                                size_t rem;
index c0f79c18f11998ed0450da0b3029bbf404471f43..f36f68d2e88cc7be108181aa7bd7a9ba42910802 100644 (file)
@@ -9,19 +9,19 @@
  * Author: Jerry Shih <jerry.shih@sifive.com>
  */
 
+#include <asm/simd.h>
 #include <asm/vector.h>
-#include <crypto/internal/simd.h>
+
+static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions);
 
 asmlinkage void
 sha256_transform_zvknha_or_zvknhb_zvkb(struct sha256_block_state *state,
                                       const u8 *data, size_t nblocks);
 
-static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions);
-
 static void sha256_blocks(struct sha256_block_state *state,
                          const u8 *data, size_t nblocks)
 {
-       if (static_branch_likely(&have_extensions) && crypto_simd_usable()) {
+       if (static_branch_likely(&have_extensions) && likely(may_use_simd())) {
                kernel_vector_begin();
                sha256_transform_zvknha_or_zvknhb_zvkb(state, data, nblocks);
                kernel_vector_end();
index 669bc06538b67e768b4ea2eb616e5241e608d099..c852396ef31908029d8bc4d45a0cff49c787b05d 100644 (file)
@@ -5,7 +5,6 @@
  * Copyright 2025 Google LLC
  */
 #include <asm/fpu/api.h>
-#include <crypto/internal/simd.h>
 #include <linux/static_call.h>
 
 DEFINE_STATIC_CALL(sha256_blocks_x86, sha256_blocks_generic);
@@ -16,7 +15,7 @@ DEFINE_STATIC_CALL(sha256_blocks_x86, sha256_blocks_generic);
        static void c_fn(struct sha256_block_state *state, const u8 *data, \
                         size_t nblocks)                                   \
        {                                                                  \
-               if (likely(crypto_simd_usable())) {                        \
+               if (likely(irq_fpu_usable())) {                            \
                        kernel_fpu_begin();                                \
                        asm_fn(state, data, nblocks);                      \
                        kernel_fpu_end();                                  \