Skip to content

Commit b10749d

Browse files
author
Eric Biggers
committed
lib/crc: x86: Migrate optimized CRC code into lib/crc/
Move the x86-optimized CRC code from arch/x86/lib/crc* into its new location in lib/crc/x86/, and wire it up in the new way. This new way of organizing the CRC code eliminates the need to artificially split the code for each CRC variant into separate arch and generic modules, enabling better inlining and dead code elimination. For more details, see "lib/crc: Prepare for arch-optimized code in subdirs of lib/crc/". Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com> Acked-by: Ingo Molnar <mingo@kernel.org> Acked-by: "Jason A. Donenfeld" <Jason@zx2c4.com> Link: https://lore.kernel.org/r/20250607200454.73587-12-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 9b2d720 commit b10749d

14 files changed

Lines changed: 20 additions & 69 deletions

arch/x86/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ config X86
7979
select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
8080
select ARCH_HAS_CPU_FINALIZE_INIT
8181
select ARCH_HAS_CPU_PASID if IOMMU_SVA
82-
select ARCH_HAS_CRC32
83-
select ARCH_HAS_CRC64 if X86_64
84-
select ARCH_HAS_CRC_T10DIF
8582
select ARCH_HAS_CURRENT_STACK_POINTER
8683
select ARCH_HAS_DEBUG_VIRTUAL
8784
select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE

arch/x86/lib/Makefile

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
4040
lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
4141
lib-$(CONFIG_MITIGATION_RETPOLINE) += retpoline.o
4242

43-
obj-$(CONFIG_CRC32_ARCH) += crc32-x86.o
44-
crc32-x86-y := crc32.o crc32-pclmul.o
45-
crc32-x86-$(CONFIG_64BIT) += crc32c-3way.o
46-
47-
obj-$(CONFIG_CRC64_ARCH) += crc64-x86.o
48-
crc64-x86-y := crc64.o crc64-pclmul.o
49-
50-
obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-x86.o
51-
crc-t10dif-x86-y := crc-t10dif.o crc16-msb-pclmul.o
52-
5343
obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o
5444
obj-y += iomem.o
5545

lib/crc/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ config CRC_T10DIF_ARCH
5454
default y if ARM64 && KERNEL_MODE_NEON
5555
default y if PPC64 && ALTIVEC
5656
default y if RISCV && RISCV_ISA_ZBC
57+
default y if X86
5758

5859
config CRC32
5960
tristate
@@ -76,6 +77,7 @@ config CRC32_ARCH
7677
default y if RISCV && RISCV_ISA_ZBC
7778
default y if S390
7879
default y if SPARC64
80+
default y if X86
7981

8082
config CRC64
8183
tristate
@@ -90,6 +92,7 @@ config CRC64_ARCH
9092
bool
9193
depends on CRC64 && CRC_OPTIMIZATIONS
9294
default y if RISCV && RISCV_ISA_ZBC && 64BIT
95+
default y if X86_64
9396

9497
config CRC_OPTIMIZATIONS
9598
bool "Enable optimized CRC implementations" if EXPERT

lib/crc/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ crc-t10dif-$(CONFIG_ARM) += arm/crc-t10dif-core.o
1717
crc-t10dif-$(CONFIG_ARM64) += arm64/crc-t10dif-core.o
1818
crc-t10dif-$(CONFIG_PPC) += powerpc/crct10dif-vpmsum_asm.o
1919
crc-t10dif-$(CONFIG_RISCV) += riscv/crc16_msb.o
20+
crc-t10dif-$(CONFIG_X86) += x86/crc16-msb-pclmul.o
2021
endif
2122

2223
obj-$(CONFIG_CRC32) += crc32.o
@@ -29,13 +30,16 @@ crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o
2930
crc32-$(CONFIG_RISCV) += riscv/crc32_lsb.o riscv/crc32_msb.o
3031
crc32-$(CONFIG_S390) += s390/crc32le-vx.o s390/crc32be-vx.o
3132
crc32-$(CONFIG_SPARC) += sparc/crc32c_asm.o
33+
crc32-$(CONFIG_X86) += x86/crc32-pclmul.o
34+
crc32-$(CONFIG_X86_64) += x86/crc32c-3way.o
3235
endif
3336

3437
obj-$(CONFIG_CRC64) += crc64.o
3538
crc64-y := crc64-main.o
3639
ifeq ($(CONFIG_CRC64_ARCH),y)
3740
CFLAGS_crc64-main.o += -I$(src)/$(SRCARCH)
3841
crc64-$(CONFIG_RISCV) += riscv/crc64_lsb.o riscv/crc64_msb.o
42+
crc64-$(CONFIG_X86) += x86/crc64-pclmul.o
3943
endif
4044

4145
obj-y += tests/
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,24 @@
55
* Copyright 2024 Google LLC
66
*/
77

8-
#include <linux/crc-t10dif.h>
9-
#include <linux/module.h>
108
#include "crc-pclmul-template.h"
119

1210
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq);
1311

1412
DECLARE_CRC_PCLMUL_FUNCS(crc16_msb, u16);
1513

16-
u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len)
14+
static inline u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len)
1715
{
1816
CRC_PCLMUL(crc, p, len, crc16_msb, crc16_msb_0x8bb7_consts,
1917
have_pclmulqdq);
2018
return crc_t10dif_generic(crc, p, len);
2119
}
22-
EXPORT_SYMBOL(crc_t10dif_arch);
2320

24-
static int __init crc_t10dif_x86_init(void)
21+
#define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch
22+
static inline void crc_t10dif_mod_init_arch(void)
2523
{
2624
if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) {
2725
static_branch_enable(&have_pclmulqdq);
2826
INIT_CRC_PCLMUL(crc16_msb);
2927
}
30-
return 0;
3128
}
32-
subsys_initcall(crc_t10dif_x86_init);
33-
34-
static void __exit crc_t10dif_x86_exit(void)
35-
{
36-
}
37-
module_exit(crc_t10dif_x86_exit);
38-
39-
MODULE_DESCRIPTION("CRC-T10DIF using [V]PCLMULQDQ instructions");
40-
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)