Commit bce58166 authored by Eric Biggers's avatar Eric Biggers
Browse files

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

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.

Link: https://lore.kernel.org/r/20250731223651.136939-1-ebiggers@kernel.org


Signed-off-by: default avatarEric Biggers <ebiggers@kernel.org>
parent 640d31ea
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -4,9 +4,8 @@
 *
 * 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);

@@ -19,7 +18,7 @@ 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();
+2 −3
Original line number Diff line number Diff line
@@ -4,9 +4,8 @@
 *
 * 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);
@@ -21,7 +20,7 @@ static void sha512_blocks(struct sha512_block_state *state,
{
	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;

+1 −3
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@

#include <asm/simd.h>
#include <asm/vector.h>
#include <crypto/internal/simd.h>

static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions);

@@ -21,8 +20,7 @@ asmlinkage void sha512_transform_zvknhb_zvkb(struct sha512_block_state *state,
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();
+1 −3
Original line number Diff line number Diff line
@@ -4,9 +4,7 @@
 *
 * 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);
@@ -17,7 +15,7 @@ DEFINE_STATIC_CALL(sha512_blocks_x86, sha512_blocks_generic);
	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();                                  \