crypto/arm64: sm3 - Switch to 'ksimd' scoped guard API

Switch to the more abstract 'scoped_ksimd()' API, which will be modified
in a future patch to transparently allocate a kernel mode FP/SIMD state
buffer on the stack, so that kernel mode FP/SIMD code remains
preemptible in principle, but without the memory overhead that adds 528
bytes to the size of struct task_struct.

Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
Ard Biesheuvel 2025-10-01 13:47:45 +02:00
parent a6b4084455
commit ab9615b501
2 changed files with 14 additions and 17 deletions

View File

@ -5,7 +5,6 @@
* Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org> * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
*/ */
#include <asm/neon.h>
#include <crypto/internal/hash.h> #include <crypto/internal/hash.h>
#include <crypto/sm3.h> #include <crypto/sm3.h>
#include <crypto/sm3_base.h> #include <crypto/sm3_base.h>
@ -13,6 +12,8 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <asm/simd.h>
MODULE_DESCRIPTION("SM3 secure hash using ARMv8 Crypto Extensions"); MODULE_DESCRIPTION("SM3 secure hash using ARMv8 Crypto Extensions");
MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
@ -25,18 +26,18 @@ static int sm3_ce_update(struct shash_desc *desc, const u8 *data,
{ {
int remain; int remain;
kernel_neon_begin(); scoped_ksimd() {
remain = sm3_base_do_update_blocks(desc, data, len, sm3_ce_transform); remain = sm3_base_do_update_blocks(desc, data, len, sm3_ce_transform);
kernel_neon_end(); }
return remain; return remain;
} }
static int sm3_ce_finup(struct shash_desc *desc, const u8 *data, static int sm3_ce_finup(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out) unsigned int len, u8 *out)
{ {
kernel_neon_begin(); scoped_ksimd() {
sm3_base_do_finup(desc, data, len, sm3_ce_transform); sm3_base_do_finup(desc, data, len, sm3_ce_transform);
kernel_neon_end(); }
return sm3_base_finish(desc, out); return sm3_base_finish(desc, out);
} }

View File

@ -5,7 +5,7 @@
* Copyright (C) 2022 Tianjia Zhang <tianjia.zhang@linux.alibaba.com> * Copyright (C) 2022 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
*/ */
#include <asm/neon.h> #include <asm/simd.h>
#include <crypto/internal/hash.h> #include <crypto/internal/hash.h>
#include <crypto/sm3.h> #include <crypto/sm3.h>
#include <crypto/sm3_base.h> #include <crypto/sm3_base.h>
@ -20,20 +20,16 @@ asmlinkage void sm3_neon_transform(struct sm3_state *sst, u8 const *src,
static int sm3_neon_update(struct shash_desc *desc, const u8 *data, static int sm3_neon_update(struct shash_desc *desc, const u8 *data,
unsigned int len) unsigned int len)
{ {
int remain; scoped_ksimd()
return sm3_base_do_update_blocks(desc, data, len,
kernel_neon_begin(); sm3_neon_transform);
remain = sm3_base_do_update_blocks(desc, data, len, sm3_neon_transform);
kernel_neon_end();
return remain;
} }
static int sm3_neon_finup(struct shash_desc *desc, const u8 *data, static int sm3_neon_finup(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out) unsigned int len, u8 *out)
{ {
kernel_neon_begin(); scoped_ksimd()
sm3_base_do_finup(desc, data, len, sm3_neon_transform); sm3_base_do_finup(desc, data, len, sm3_neon_transform);
kernel_neon_end();
return sm3_base_finish(desc, out); return sm3_base_finish(desc, out);
} }