Skip to content

Commit 2051da8

Browse files
committed
arm64/crc-t10dif: expose CRC-T10DIF function through lib
Move the arm64 CRC-T10DIF assembly code into the lib directory and wire it up to the library interface. This allows it to be used without going through the crypto API. It remains usable via the crypto API too via the shash algorithms that use the library interface. Thus all the arch-specific "shash" code becomes unnecessary and is removed. Note: to see the diff from arch/arm64/crypto/crct10dif-ce-glue.c to arch/arm64/lib/crc-t10dif-glue.c, view this commit with 'git show -M10'. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20241202012056.209768-7-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 1684e82 commit 2051da8

File tree

9 files changed

+86
-148
lines changed

9 files changed

+86
-148
lines changed

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config ARM64
2222
select ARCH_HAS_CACHE_LINE_SIZE
2323
select ARCH_HAS_CC_PLATFORM
2424
select ARCH_HAS_CRC32
25+
select ARCH_HAS_CRC_T10DIF if KERNEL_MODE_NEON
2526
select ARCH_HAS_CURRENT_STACK_POINTER
2627
select ARCH_HAS_DEBUG_VIRTUAL
2728
select ARCH_HAS_DEBUG_VM_PGTABLE

arch/arm64/configs/defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,6 @@ CONFIG_CRYPTO_SM3_ARM64_CE=m
16981698
CONFIG_CRYPTO_AES_ARM64_CE_BLK=y
16991699
CONFIG_CRYPTO_AES_ARM64_BS=m
17001700
CONFIG_CRYPTO_AES_ARM64_CE_CCM=y
1701-
CONFIG_CRYPTO_CRCT10DIF_ARM64_CE=m
17021701
CONFIG_CRYPTO_DEV_SUN8I_CE=m
17031702
CONFIG_CRYPTO_DEV_FSL_CAAM=m
17041703
CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM=m

arch/arm64/crypto/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,5 @@ config CRYPTO_SM4_ARM64_CE_GCM
312312
- PMULL (Polynomial Multiply Long) instructions
313313
- NEON (Advanced SIMD) extensions
314314

315-
config CRYPTO_CRCT10DIF_ARM64_CE
316-
tristate "CRCT10DIF (PMULL)"
317-
depends on KERNEL_MODE_NEON && CRC_T10DIF
318-
select CRYPTO_HASH
319-
help
320-
CRC16 CRC algorithm used for the T10 (SCSI) Data Integrity Field (DIF)
321-
322-
Architecture: arm64 using
323-
- PMULL (Polynomial Multiply Long) instructions
324-
325315
endmenu
326316

arch/arm64/crypto/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ ghash-ce-y := ghash-ce-glue.o ghash-ce-core.o
4444
obj-$(CONFIG_CRYPTO_POLYVAL_ARM64_CE) += polyval-ce.o
4545
polyval-ce-y := polyval-ce-glue.o polyval-ce-core.o
4646

47-
obj-$(CONFIG_CRYPTO_CRCT10DIF_ARM64_CE) += crct10dif-ce.o
48-
crct10dif-ce-y := crct10dif-ce-core.o crct10dif-ce-glue.o
49-
5047
obj-$(CONFIG_CRYPTO_AES_ARM64_CE) += aes-ce-cipher.o
5148
aes-ce-cipher-y := aes-ce-core.o aes-ce-glue.o
5249

arch/arm64/crypto/crct10dif-ce-glue.c

Lines changed: 0 additions & 132 deletions
This file was deleted.

arch/arm64/lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o
1616
obj-$(CONFIG_CRC32_ARCH) += crc32-arm64.o
1717
crc32-arm64-y := crc32.o crc32-glue.o
1818

19+
obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-arm64.o
20+
crc-t10dif-arm64-y := crc-t10dif-glue.o crc-t10dif-core.o
21+
1922
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
2023

2124
obj-$(CONFIG_ARM64_MTE) += mte.o

arch/arm64/lib/crc-t10dif-glue.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Accelerated CRC-T10DIF using arm64 NEON and Crypto Extensions instructions
4+
*
5+
* Copyright (C) 2016 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
6+
*/
7+
8+
#include <linux/cpufeature.h>
9+
#include <linux/crc-t10dif.h>
10+
#include <linux/init.h>
11+
#include <linux/kernel.h>
12+
#include <linux/module.h>
13+
#include <linux/string.h>
14+
15+
#include <crypto/internal/simd.h>
16+
17+
#include <asm/neon.h>
18+
#include <asm/simd.h>
19+
20+
static DEFINE_STATIC_KEY_FALSE(have_asimd);
21+
static DEFINE_STATIC_KEY_FALSE(have_pmull);
22+
23+
#define CRC_T10DIF_PMULL_CHUNK_SIZE 16U
24+
25+
asmlinkage void crc_t10dif_pmull_p8(u16 init_crc, const u8 *buf, size_t len,
26+
u8 out[16]);
27+
asmlinkage u16 crc_t10dif_pmull_p64(u16 init_crc, const u8 *buf, size_t len);
28+
29+
u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)
30+
{
31+
if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE) {
32+
if (static_branch_likely(&have_pmull)) {
33+
if (crypto_simd_usable()) {
34+
kernel_neon_begin();
35+
crc = crc_t10dif_pmull_p64(crc, data, length);
36+
kernel_neon_end();
37+
return crc;
38+
}
39+
} else if (length > CRC_T10DIF_PMULL_CHUNK_SIZE &&
40+
static_branch_likely(&have_asimd) &&
41+
crypto_simd_usable()) {
42+
u8 buf[16];
43+
44+
kernel_neon_begin();
45+
crc_t10dif_pmull_p8(crc, data, length, buf);
46+
kernel_neon_end();
47+
48+
crc = 0;
49+
data = buf;
50+
length = sizeof(buf);
51+
}
52+
}
53+
return crc_t10dif_generic(crc, data, length);
54+
}
55+
EXPORT_SYMBOL(crc_t10dif_arch);
56+
57+
static int __init crc_t10dif_arm64_init(void)
58+
{
59+
if (cpu_have_named_feature(ASIMD)) {
60+
static_branch_enable(&have_asimd);
61+
if (cpu_have_named_feature(PMULL))
62+
static_branch_enable(&have_pmull);
63+
}
64+
return 0;
65+
}
66+
arch_initcall(crc_t10dif_arm64_init);
67+
68+
static void __exit crc_t10dif_arm64_exit(void)
69+
{
70+
}
71+
module_exit(crc_t10dif_arm64_exit);
72+
73+
bool crc_t10dif_is_optimized(void)
74+
{
75+
return static_key_enabled(&have_asimd);
76+
}
77+
EXPORT_SYMBOL(crc_t10dif_is_optimized);
78+
79+
MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
80+
MODULE_DESCRIPTION("CRC-T10DIF using arm64 NEON and Crypto Extensions");
81+
MODULE_LICENSE("GPL v2");

tools/testing/selftests/arm64/fp/kernel-test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static void handle_kick_signal(int sig, siginfo_t *info, void *context)
4646
}
4747

4848
static char *drivers[] = {
49-
"crct10dif-arm64-ce",
50-
/* "crct10dif-arm64-neon", - Same priority as generic */
49+
"crct10dif-arm64",
5150
"sha1-ce",
5251
"sha224-arm64",
5352
"sha224-arm64-neon",

0 commit comments

Comments
 (0)