Skip to content

Commit ed4bc98

Browse files
committed
x86/crc-t10dif: expose CRC-T10DIF function through lib
Move the x86 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. 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 21dda37 commit ed4bc98

File tree

7 files changed

+55
-156
lines changed

7 files changed

+55
-156
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ config X86
7777
select ARCH_HAS_CPU_FINALIZE_INIT
7878
select ARCH_HAS_CPU_PASID if IOMMU_SVA
7979
select ARCH_HAS_CRC32
80+
select ARCH_HAS_CRC_T10DIF if X86_64
8081
select ARCH_HAS_CURRENT_STACK_POINTER
8182
select ARCH_HAS_DEBUG_VIRTUAL
8283
select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE

arch/x86/crypto/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,4 @@ config CRYPTO_GHASH_CLMUL_NI_INTEL
492492
Architecture: x86_64 using:
493493
- CLMUL-NI (carry-less multiplication new instructions)
494494

495-
config CRYPTO_CRCT10DIF_PCLMUL
496-
tristate "CRCT10DIF (PCLMULQDQ)"
497-
depends on X86 && 64BIT && CRC_T10DIF
498-
select CRYPTO_HASH
499-
help
500-
CRC16 CRC algorithm used for the T10 (SCSI) Data Integrity Field (DIF)
501-
502-
Architecture: x86_64 using:
503-
- PCLMULQDQ (carry-less multiplication)
504-
505495
endmenu

arch/x86/crypto/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ ghash-clmulni-intel-y := ghash-clmulni-intel_asm.o ghash-clmulni-intel_glue.o
7575
obj-$(CONFIG_CRYPTO_POLYVAL_CLMUL_NI) += polyval-clmulni.o
7676
polyval-clmulni-y := polyval-clmulni_asm.o polyval-clmulni_glue.o
7777

78-
obj-$(CONFIG_CRYPTO_CRCT10DIF_PCLMUL) += crct10dif-pclmul.o
79-
crct10dif-pclmul-y := crct10dif-pcl-asm_64.o crct10dif-pclmul_glue.o
80-
8178
obj-$(CONFIG_CRYPTO_POLY1305_X86_64) += poly1305-x86_64.o
8279
poly1305-x86_64-y := poly1305-x86_64-cryptogams.o poly1305_glue.o
8380
targets += poly1305-x86_64-cryptogams.S

arch/x86/crypto/crct10dif-pclmul_glue.c

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

arch/x86/lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ obj-$(CONFIG_CRC32_ARCH) += crc32-x86.o
4242
crc32-x86-y := crc32-glue.o crc32-pclmul.o
4343
crc32-x86-$(CONFIG_64BIT) += crc32c-3way.o
4444

45+
obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-x86.o
46+
crc-t10dif-x86-y := crc-t10dif-glue.o crct10dif-pcl-asm_64.o
47+
4548
obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o
4649
obj-y += iomem.o
4750

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* CRC-T10DIF using PCLMULQDQ instructions
4+
*
5+
* Copyright 2024 Google LLC
6+
*/
7+
8+
#include <asm/cpufeatures.h>
9+
#include <asm/simd.h>
10+
#include <crypto/internal/simd.h>
11+
#include <linux/crc-t10dif.h>
12+
#include <linux/module.h>
13+
14+
static DEFINE_STATIC_KEY_FALSE(have_pclmulqdq);
15+
16+
asmlinkage u16 crc_t10dif_pcl(u16 init_crc, const u8 *buf, size_t len);
17+
18+
u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len)
19+
{
20+
if (len >= 16 &&
21+
static_key_enabled(&have_pclmulqdq) && crypto_simd_usable()) {
22+
kernel_fpu_begin();
23+
crc = crc_t10dif_pcl(crc, p, len);
24+
kernel_fpu_end();
25+
return crc;
26+
}
27+
return crc_t10dif_generic(crc, p, len);
28+
}
29+
EXPORT_SYMBOL(crc_t10dif_arch);
30+
31+
static int __init crc_t10dif_x86_init(void)
32+
{
33+
if (boot_cpu_has(X86_FEATURE_PCLMULQDQ))
34+
static_branch_enable(&have_pclmulqdq);
35+
return 0;
36+
}
37+
arch_initcall(crc_t10dif_x86_init);
38+
39+
static void __exit crc_t10dif_x86_exit(void)
40+
{
41+
}
42+
module_exit(crc_t10dif_x86_exit);
43+
44+
bool crc_t10dif_is_optimized(void)
45+
{
46+
return static_key_enabled(&have_pclmulqdq);
47+
}
48+
EXPORT_SYMBOL(crc_t10dif_is_optimized);
49+
50+
MODULE_DESCRIPTION("CRC-T10DIF using PCLMULQDQ instructions");
51+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)