Skip to content

Commit 7439cfe

Browse files
committed
powerpc/crc-t10dif: expose CRC-T10DIF function through lib
Move the powerpc 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/powerpc/crypto/crct10dif-vpmsum_glue.c to arch/powerpc/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-8-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 2051da8 commit 7439cfe

File tree

8 files changed

+23
-71
lines changed

8 files changed

+23
-71
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ config PPC
128128
select ARCH_ENABLE_MEMORY_HOTREMOVE
129129
select ARCH_HAS_COPY_MC if PPC64
130130
select ARCH_HAS_CRC32 if PPC64 && ALTIVEC
131+
select ARCH_HAS_CRC_T10DIF if PPC64 && ALTIVEC
131132
select ARCH_HAS_CURRENT_STACK_POINTER
132133
select ARCH_HAS_DEBUG_VIRTUAL
133134
select ARCH_HAS_DEBUG_VM_PGTABLE

arch/powerpc/configs/powernv_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ CONFIG_XMON=y
320320
CONFIG_CRYPTO_TEST=m
321321
CONFIG_CRYPTO_PCBC=m
322322
CONFIG_CRYPTO_HMAC=y
323-
CONFIG_CRYPTO_CRCT10DIF_VPMSUM=m
324323
CONFIG_CRYPTO_MD5_PPC=m
325324
CONFIG_CRYPTO_MICHAEL_MIC=m
326325
CONFIG_CRYPTO_SHA1_PPC=m

arch/powerpc/configs/ppc64_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ CONFIG_CRYPTO_MICHAEL_MIC=m
389389
CONFIG_CRYPTO_SHA256=y
390390
CONFIG_CRYPTO_WP512=m
391391
CONFIG_CRYPTO_LZO=m
392-
CONFIG_CRYPTO_CRCT10DIF_VPMSUM=m
393392
CONFIG_CRYPTO_VPMSUM_TESTER=m
394393
CONFIG_CRYPTO_MD5_PPC=m
395394
CONFIG_CRYPTO_SHA1_PPC=m

arch/powerpc/crypto/Kconfig

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,10 @@ config CRYPTO_CURVE25519_PPC64
1313
Architecture: PowerPC64
1414
- Little-endian
1515

16-
config CRYPTO_CRCT10DIF_VPMSUM
17-
tristate "CRC32T10DIF"
18-
depends on PPC64 && ALTIVEC && CRC_T10DIF
19-
select CRYPTO_HASH
20-
help
21-
CRC16 CRC algorithm used for the T10 (SCSI) Data Integrity Field (DIF)
22-
23-
Architecture: powerpc64 using
24-
- AltiVec extensions
25-
26-
Enable on POWER8 and newer processors for improved performance.
27-
2816
config CRYPTO_VPMSUM_TESTER
2917
tristate "CRC32c and CRC32T10DIF hardware acceleration tester"
30-
depends on CRYPTO_CRCT10DIF_VPMSUM && CRYPTO_CRC32C && CRC32_ARCH
18+
depends on CRYPTO_CRC32C && CRC32_ARCH
19+
depends on CRYPTO_CRCT10DIF && CRC_T10DIF_ARCH
3120
help
3221
Stress test for CRC32c and CRCT10DIF algorithms implemented with
3322
powerpc64 AltiVec extensions (POWER8 vpmsum instructions).

arch/powerpc/crypto/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ obj-$(CONFIG_CRYPTO_MD5_PPC) += md5-ppc.o
1010
obj-$(CONFIG_CRYPTO_SHA1_PPC) += sha1-powerpc.o
1111
obj-$(CONFIG_CRYPTO_SHA1_PPC_SPE) += sha1-ppc-spe.o
1212
obj-$(CONFIG_CRYPTO_SHA256_PPC_SPE) += sha256-ppc-spe.o
13-
obj-$(CONFIG_CRYPTO_CRCT10DIF_VPMSUM) += crct10dif-vpmsum.o
1413
obj-$(CONFIG_CRYPTO_VPMSUM_TESTER) += crc-vpmsum_test.o
1514
obj-$(CONFIG_CRYPTO_AES_GCM_P10) += aes-gcm-p10-crypto.o
1615
obj-$(CONFIG_CRYPTO_CHACHA20_P10) += chacha-p10-crypto.o
@@ -23,7 +22,6 @@ md5-ppc-y := md5-asm.o md5-glue.o
2322
sha1-powerpc-y := sha1-powerpc-asm.o sha1.o
2423
sha1-ppc-spe-y := sha1-spe-asm.o sha1-spe-glue.o
2524
sha256-ppc-spe-y := sha256-spe-asm.o sha256-spe-glue.o
26-
crct10dif-vpmsum-y := crct10dif-vpmsum_asm.o crct10dif-vpmsum_glue.o
2725
aes-gcm-p10-crypto-y := aes-gcm-p10-glue.o aes-gcm-p10.o ghashp10-ppc.o aesp10-ppc.o
2826
chacha-p10-crypto-y := chacha-p10-glue.o chacha-p10le-8x.o
2927
poly1305-p10-crypto-y := poly1305-p10-glue.o poly1305-p10le_64.o

arch/powerpc/lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@ CFLAGS_xor_vmx.o += -isystem $(shell $(CC) -print-file-name=include)
8181
obj-$(CONFIG_CRC32_ARCH) += crc32-powerpc.o
8282
crc32-powerpc-y := crc32-glue.o crc32c-vpmsum_asm.o
8383

84+
obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-powerpc.o
85+
crc-t10dif-powerpc-y := crc-t10dif-glue.o crct10dif-vpmsum_asm.o
86+
8487
obj-$(CONFIG_PPC64) += $(obj64-y)

arch/powerpc/crypto/crct10dif-vpmsum_glue.c renamed to arch/powerpc/lib/crc-t10dif-glue.c

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
#include <linux/crc-t10dif.h>
10-
#include <crypto/internal/hash.h>
1110
#include <crypto/internal/simd.h>
1211
#include <linux/init.h>
1312
#include <linux/module.h>
@@ -22,15 +21,18 @@
2221

2322
#define VECTOR_BREAKPOINT 64
2423

24+
static DEFINE_STATIC_KEY_FALSE(have_vec_crypto);
25+
2526
u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
2627

27-
static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
28+
u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len)
2829
{
2930
unsigned int prealign;
3031
unsigned int tail;
3132
u32 crc = crci;
3233

33-
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || !crypto_simd_usable())
34+
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) ||
35+
!static_branch_likely(&have_vec_crypto) || !crypto_simd_usable())
3436
return crc_t10dif_generic(crc, p, len);
3537

3638
if ((unsigned long)p & VMX_ALIGN_MASK) {
@@ -60,67 +62,28 @@ static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
6062

6163
return crc & 0xffff;
6264
}
65+
EXPORT_SYMBOL(crc_t10dif_arch);
6366

64-
static int crct10dif_vpmsum_init(struct shash_desc *desc)
65-
{
66-
u16 *crc = shash_desc_ctx(desc);
67-
68-
*crc = 0;
69-
return 0;
70-
}
71-
72-
static int crct10dif_vpmsum_update(struct shash_desc *desc, const u8 *data,
73-
unsigned int length)
74-
{
75-
u16 *crc = shash_desc_ctx(desc);
76-
77-
*crc = crct10dif_vpmsum(*crc, data, length);
78-
79-
return 0;
80-
}
81-
82-
83-
static int crct10dif_vpmsum_final(struct shash_desc *desc, u8 *out)
67+
static int __init crc_t10dif_powerpc_init(void)
8468
{
85-
u16 *crcp = shash_desc_ctx(desc);
86-
87-
*(u16 *)out = *crcp;
69+
if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
70+
(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
71+
static_branch_enable(&have_vec_crypto);
8872
return 0;
8973
}
74+
arch_initcall(crc_t10dif_powerpc_init);
9075

91-
static struct shash_alg alg = {
92-
.init = crct10dif_vpmsum_init,
93-
.update = crct10dif_vpmsum_update,
94-
.final = crct10dif_vpmsum_final,
95-
.descsize = CRC_T10DIF_DIGEST_SIZE,
96-
.digestsize = CRC_T10DIF_DIGEST_SIZE,
97-
.base = {
98-
.cra_name = "crct10dif",
99-
.cra_driver_name = "crct10dif-vpmsum",
100-
.cra_priority = 200,
101-
.cra_blocksize = CRC_T10DIF_BLOCK_SIZE,
102-
.cra_module = THIS_MODULE,
103-
}
104-
};
105-
106-
static int __init crct10dif_vpmsum_mod_init(void)
76+
static void __exit crc_t10dif_powerpc_exit(void)
10777
{
108-
if (!cpu_has_feature(CPU_FTR_ARCH_207S))
109-
return -ENODEV;
110-
111-
return crypto_register_shash(&alg);
11278
}
79+
module_exit(crc_t10dif_powerpc_exit);
11380

114-
static void __exit crct10dif_vpmsum_mod_fini(void)
81+
bool crc_t10dif_is_optimized(void)
11582
{
116-
crypto_unregister_shash(&alg);
83+
return static_key_enabled(&have_vec_crypto);
11784
}
118-
119-
module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crct10dif_vpmsum_mod_init);
120-
module_exit(crct10dif_vpmsum_mod_fini);
85+
EXPORT_SYMBOL(crc_t10dif_is_optimized);
12186

12287
MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
12388
MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions");
12489
MODULE_LICENSE("GPL");
125-
MODULE_ALIAS_CRYPTO("crct10dif");
126-
MODULE_ALIAS_CRYPTO("crct10dif-vpmsum");

arch/powerpc/crypto/crct10dif-vpmsum_asm.S renamed to arch/powerpc/lib/crct10dif-vpmsum_asm.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,4 @@
842842
.octa 0x0000000000000000000000018bb70000
843843

844844
#define CRC_FUNCTION_NAME __crct10dif_vpmsum
845-
#include "../lib/crc32-vpmsum_core.S"
845+
#include "crc32-vpmsum_core.S"

0 commit comments

Comments
 (0)