Skip to content

Commit 1684e82

Browse files
committed
arm/crc-t10dif: expose CRC-T10DIF function through lib
Move the arm 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/arm/crypto/crct10dif-ce-glue.c to arch/arm/lib/crc-t10dif-glue.c, view this commit with 'git show -M10'. Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent ed4bc98 commit 1684e82

File tree

7 files changed

+84
-137
lines changed

7 files changed

+84
-137
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config ARM
88
select ARCH_HAS_CPU_CACHE_ALIASING
99
select ARCH_HAS_CPU_FINALIZE_INIT if MMU
1010
select ARCH_HAS_CRC32 if KERNEL_MODE_NEON
11+
select ARCH_HAS_CRC_T10DIF if KERNEL_MODE_NEON
1112
select ARCH_HAS_CURRENT_STACK_POINTER
1213
select ARCH_HAS_DEBUG_VIRTUAL if MMU
1314
select ARCH_HAS_DMA_ALLOC if MMU

arch/arm/crypto/Kconfig

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,5 @@ config CRYPTO_CHACHA20_NEON
222222
Architecture: arm using:
223223
- NEON (Advanced SIMD) extensions
224224

225-
config CRYPTO_CRCT10DIF_ARM_CE
226-
tristate "CRCT10DIF"
227-
depends on KERNEL_MODE_NEON
228-
depends on CRC_T10DIF
229-
select CRYPTO_HASH
230-
help
231-
CRC16 CRC algorithm used for the T10 (SCSI) Data Integrity Field (DIF)
232-
233-
Architecture: arm using:
234-
- PMULL (Polynomial Multiply Long) instructions
235-
236225
endmenu
237226

arch/arm/crypto/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ obj-$(CONFIG_CRYPTO_AES_ARM_CE) += aes-arm-ce.o
2020
obj-$(CONFIG_CRYPTO_SHA1_ARM_CE) += sha1-arm-ce.o
2121
obj-$(CONFIG_CRYPTO_SHA2_ARM_CE) += sha2-arm-ce.o
2222
obj-$(CONFIG_CRYPTO_GHASH_ARM_CE) += ghash-arm-ce.o
23-
obj-$(CONFIG_CRYPTO_CRCT10DIF_ARM_CE) += crct10dif-arm-ce.o
2423

2524
aes-arm-y := aes-cipher-core.o aes-cipher-glue.o
2625
aes-arm-bs-y := aes-neonbs-core.o aes-neonbs-glue.o
@@ -36,7 +35,6 @@ sha1-arm-ce-y := sha1-ce-core.o sha1-ce-glue.o
3635
sha2-arm-ce-y := sha2-ce-core.o sha2-ce-glue.o
3736
aes-arm-ce-y := aes-ce-core.o aes-ce-glue.o
3837
ghash-arm-ce-y := ghash-ce-core.o ghash-ce-glue.o
39-
crct10dif-arm-ce-y := crct10dif-ce-core.o crct10dif-ce-glue.o
4038
chacha-neon-y := chacha-scalar-core.o chacha-glue.o
4139
chacha-neon-$(CONFIG_KERNEL_MODE_NEON) += chacha-neon-core.o
4240
poly1305-arm-y := poly1305-core.o poly1305-glue.o

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

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

arch/arm/lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
4848

4949
obj-$(CONFIG_CRC32_ARCH) += crc32-arm.o
5050
crc32-arm-y := crc32-glue.o crc32-core.o
51+
52+
obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-arm.o
53+
crc-t10dif-arm-y := crc-t10dif-glue.o crc-t10dif-core.o
File renamed without changes.

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

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

0 commit comments

Comments
 (0)