* [PATCH] lib/crypto: sha512: Use underlying functions instead of crypto_simd_usable()
@ 2025-07-31 22:36 Eric Biggers
2025-08-11 17:58 ` Eric Biggers
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2025-07-31 22:36 UTC (permalink / raw)
To: linux-crypto
Cc: Ard Biesheuvel, Jason A . Donenfeld, linux-arm-kernel, x86,
Eric Biggers
Since sha512_kunit tests the fallback code paths without using
crypto_simd_disabled_for_test, make the SHA-512 code just use the
underlying may_use_simd() and irq_fpu_usable() functions directly
instead of crypto_simd_usable(). This eliminates an unnecessary layer.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crypto/arm/sha512.h | 5 ++---
lib/crypto/arm64/sha512.h | 5 ++---
lib/crypto/riscv/sha512.h | 4 +---
lib/crypto/x86/sha512.h | 4 +---
4 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/lib/crypto/arm/sha512.h b/lib/crypto/arm/sha512.h
index f147b6490d6cd..cc2447acd5621 100644
--- a/lib/crypto/arm/sha512.h
+++ b/lib/crypto/arm/sha512.h
@@ -2,13 +2,12 @@
/*
* arm32-optimized SHA-512 block function
*
* 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);
asmlinkage void sha512_block_data_order(struct sha512_block_state *state,
const u8 *data, size_t nblocks);
@@ -17,11 +16,11 @@ asmlinkage void sha512_block_data_order_neon(struct sha512_block_state *state,
static void sha512_blocks(struct sha512_block_state *state,
const u8 *data, size_t nblocks)
{
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
- static_branch_likely(&have_neon) && likely(crypto_simd_usable())) {
+ static_branch_likely(&have_neon) && likely(may_use_simd())) {
kernel_neon_begin();
sha512_block_data_order_neon(state, data, nblocks);
kernel_neon_end();
} else {
sha512_block_data_order(state, data, nblocks);
diff --git a/lib/crypto/arm64/sha512.h b/lib/crypto/arm64/sha512.h
index 6abb40b467f2e..7539ea3fef10d 100644
--- a/lib/crypto/arm64/sha512.h
+++ b/lib/crypto/arm64/sha512.h
@@ -2,13 +2,12 @@
/*
* arm64-optimized SHA-512 block function
*
* 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_sha512_insns);
asmlinkage void sha512_block_data_order(struct sha512_block_state *state,
@@ -19,11 +18,11 @@ asmlinkage size_t __sha512_ce_transform(struct sha512_block_state *state,
static void sha512_blocks(struct sha512_block_state *state,
const u8 *data, size_t nblocks)
{
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
static_branch_likely(&have_sha512_insns) &&
- likely(crypto_simd_usable())) {
+ likely(may_use_simd())) {
do {
size_t rem;
kernel_neon_begin();
rem = __sha512_ce_transform(state, data, nblocks);
diff --git a/lib/crypto/riscv/sha512.h b/lib/crypto/riscv/sha512.h
index 9d0abede322f7..59dc0294a9a7e 100644
--- a/lib/crypto/riscv/sha512.h
+++ b/lib/crypto/riscv/sha512.h
@@ -9,22 +9,20 @@
* 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 sha512_transform_zvknhb_zvkb(struct sha512_block_state *state,
const u8 *data, size_t nblocks);
static void sha512_blocks(struct sha512_block_state *state,
const u8 *data, size_t nblocks)
{
- if (static_branch_likely(&have_extensions) &&
- likely(crypto_simd_usable())) {
+ if (static_branch_likely(&have_extensions) && likely(may_use_simd())) {
kernel_vector_begin();
sha512_transform_zvknhb_zvkb(state, data, nblocks);
kernel_vector_end();
} else {
sha512_blocks_generic(state, data, nblocks);
diff --git a/lib/crypto/x86/sha512.h b/lib/crypto/x86/sha512.h
index c13503d9d57d9..be2c8fc122469 100644
--- a/lib/crypto/x86/sha512.h
+++ b/lib/crypto/x86/sha512.h
@@ -2,24 +2,22 @@
/*
* x86-optimized SHA-512 block function
*
* Copyright 2025 Google LLC
*/
-
#include <asm/fpu/api.h>
-#include <crypto/internal/simd.h>
#include <linux/static_call.h>
DEFINE_STATIC_CALL(sha512_blocks_x86, sha512_blocks_generic);
#define DEFINE_X86_SHA512_FN(c_fn, asm_fn) \
asmlinkage void asm_fn(struct sha512_block_state *state, \
const u8 *data, size_t nblocks); \
static void c_fn(struct sha512_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(); \
} else { \
sha512_blocks_generic(state, data, nblocks); \
base-commit: d6084bb815c453de27af8071a23163a711586a6c
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/crypto: sha512: Use underlying functions instead of crypto_simd_usable()
2025-07-31 22:36 [PATCH] lib/crypto: sha512: Use underlying functions instead of crypto_simd_usable() Eric Biggers
@ 2025-08-11 17:58 ` Eric Biggers
0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2025-08-11 17:58 UTC (permalink / raw)
To: linux-crypto; +Cc: Ard Biesheuvel, Jason A . Donenfeld, linux-arm-kernel, x86
On Thu, Jul 31, 2025 at 03:36:51PM -0700, Eric Biggers wrote:
> Since sha512_kunit tests the fallback code paths without using
> crypto_simd_disabled_for_test, make the SHA-512 code just use the
> underlying may_use_simd() and irq_fpu_usable() functions directly
> instead of crypto_simd_usable(). This eliminates an unnecessary layer.
>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
> lib/crypto/arm/sha512.h | 5 ++---
> lib/crypto/arm64/sha512.h | 5 ++---
> lib/crypto/riscv/sha512.h | 4 +---
> lib/crypto/x86/sha512.h | 4 +---
> 4 files changed, 6 insertions(+), 12 deletions(-)
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next
- Eric
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-11 17:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-31 22:36 [PATCH] lib/crypto: sha512: Use underlying functions instead of crypto_simd_usable() Eric Biggers
2025-08-11 17:58 ` Eric Biggers
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).