Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/crypto: sha256: Use underlying functions instead of crypto_simd_usable()

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>

+15 -16
+5 -5
lib/crypto/arm/sha256.h
··· 5 5 * Copyright 2025 Google LLC 6 6 */ 7 7 #include <asm/neon.h> 8 - #include <crypto/internal/simd.h> 8 + #include <asm/simd.h> 9 + 10 + static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 11 + static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce); 9 12 10 13 asmlinkage void sha256_block_data_order(struct sha256_block_state *state, 11 14 const u8 *data, size_t nblocks); ··· 17 14 asmlinkage void sha256_ce_transform(struct sha256_block_state *state, 18 15 const u8 *data, size_t nblocks); 19 16 20 - static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 21 - static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce); 22 - 23 17 static void sha256_blocks(struct sha256_block_state *state, 24 18 const u8 *data, size_t nblocks) 25 19 { 26 20 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && 27 - static_branch_likely(&have_neon) && crypto_simd_usable()) { 21 + static_branch_likely(&have_neon) && likely(may_use_simd())) { 28 22 kernel_neon_begin(); 29 23 if (static_branch_likely(&have_ce)) 30 24 sha256_ce_transform(state, data, nblocks);
+5 -5
lib/crypto/arm64/sha256.h
··· 5 5 * Copyright 2025 Google LLC 6 6 */ 7 7 #include <asm/neon.h> 8 - #include <crypto/internal/simd.h> 8 + #include <asm/simd.h> 9 9 #include <linux/cpufeature.h> 10 + 11 + static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 12 + static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce); 10 13 11 14 asmlinkage void sha256_block_data_order(struct sha256_block_state *state, 12 15 const u8 *data, size_t nblocks); ··· 18 15 asmlinkage size_t __sha256_ce_transform(struct sha256_block_state *state, 19 16 const u8 *data, size_t nblocks); 20 17 21 - static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 22 - static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce); 23 - 24 18 static void sha256_blocks(struct sha256_block_state *state, 25 19 const u8 *data, size_t nblocks) 26 20 { 27 21 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && 28 - static_branch_likely(&have_neon) && crypto_simd_usable()) { 22 + static_branch_likely(&have_neon) && likely(may_use_simd())) { 29 23 if (static_branch_likely(&have_ce)) { 30 24 do { 31 25 size_t rem;
+4 -4
lib/crypto/riscv/sha256.h
··· 9 9 * Author: Jerry Shih <jerry.shih@sifive.com> 10 10 */ 11 11 12 + #include <asm/simd.h> 12 13 #include <asm/vector.h> 13 - #include <crypto/internal/simd.h> 14 + 15 + static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions); 14 16 15 17 asmlinkage void 16 18 sha256_transform_zvknha_or_zvknhb_zvkb(struct sha256_block_state *state, 17 19 const u8 *data, size_t nblocks); 18 20 19 - static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions); 20 - 21 21 static void sha256_blocks(struct sha256_block_state *state, 22 22 const u8 *data, size_t nblocks) 23 23 { 24 - if (static_branch_likely(&have_extensions) && crypto_simd_usable()) { 24 + if (static_branch_likely(&have_extensions) && likely(may_use_simd())) { 25 25 kernel_vector_begin(); 26 26 sha256_transform_zvknha_or_zvknhb_zvkb(state, data, nblocks); 27 27 kernel_vector_end();
+1 -2
lib/crypto/x86/sha256.h
··· 5 5 * Copyright 2025 Google LLC 6 6 */ 7 7 #include <asm/fpu/api.h> 8 - #include <crypto/internal/simd.h> 9 8 #include <linux/static_call.h> 10 9 11 10 DEFINE_STATIC_CALL(sha256_blocks_x86, sha256_blocks_generic); ··· 15 16 static void c_fn(struct sha256_block_state *state, const u8 *data, \ 16 17 size_t nblocks) \ 17 18 { \ 18 - if (likely(crypto_simd_usable())) { \ 19 + if (likely(irq_fpu_usable())) { \ 19 20 kernel_fpu_begin(); \ 20 21 asm_fn(state, data, nblocks); \ 21 22 kernel_fpu_end(); \