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

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>

+14 -17
+8 -7
arch/arm64/crypto/sm3-ce-glue.c
··· 5 5 * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org> 6 6 */ 7 7 8 - #include <asm/neon.h> 9 8 #include <crypto/internal/hash.h> 10 9 #include <crypto/sm3.h> 11 10 #include <crypto/sm3_base.h> 12 11 #include <linux/cpufeature.h> 13 12 #include <linux/kernel.h> 14 13 #include <linux/module.h> 14 + 15 + #include <asm/simd.h> 15 16 16 17 MODULE_DESCRIPTION("SM3 secure hash using ARMv8 Crypto Extensions"); 17 18 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); ··· 26 25 { 27 26 int remain; 28 27 29 - kernel_neon_begin(); 30 - remain = sm3_base_do_update_blocks(desc, data, len, sm3_ce_transform); 31 - kernel_neon_end(); 28 + scoped_ksimd() { 29 + remain = sm3_base_do_update_blocks(desc, data, len, sm3_ce_transform); 30 + } 32 31 return remain; 33 32 } 34 33 35 34 static int sm3_ce_finup(struct shash_desc *desc, const u8 *data, 36 35 unsigned int len, u8 *out) 37 36 { 38 - kernel_neon_begin(); 39 - sm3_base_do_finup(desc, data, len, sm3_ce_transform); 40 - kernel_neon_end(); 37 + scoped_ksimd() { 38 + sm3_base_do_finup(desc, data, len, sm3_ce_transform); 39 + } 41 40 return sm3_base_finish(desc, out); 42 41 } 43 42
+6 -10
arch/arm64/crypto/sm3-neon-glue.c
··· 5 5 * Copyright (C) 2022 Tianjia Zhang <tianjia.zhang@linux.alibaba.com> 6 6 */ 7 7 8 - #include <asm/neon.h> 8 + #include <asm/simd.h> 9 9 #include <crypto/internal/hash.h> 10 10 #include <crypto/sm3.h> 11 11 #include <crypto/sm3_base.h> ··· 20 20 static int sm3_neon_update(struct shash_desc *desc, const u8 *data, 21 21 unsigned int len) 22 22 { 23 - int remain; 24 - 25 - kernel_neon_begin(); 26 - remain = sm3_base_do_update_blocks(desc, data, len, sm3_neon_transform); 27 - kernel_neon_end(); 28 - return remain; 23 + scoped_ksimd() 24 + return sm3_base_do_update_blocks(desc, data, len, 25 + sm3_neon_transform); 29 26 } 30 27 31 28 static int sm3_neon_finup(struct shash_desc *desc, const u8 *data, 32 29 unsigned int len, u8 *out) 33 30 { 34 - kernel_neon_begin(); 35 - sm3_base_do_finup(desc, data, len, sm3_neon_transform); 36 - kernel_neon_end(); 31 + scoped_ksimd() 32 + sm3_base_do_finup(desc, data, len, sm3_neon_transform); 37 33 return sm3_base_finish(desc, out); 38 34 } 39 35