Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+20 -69
-3
arch/x86/Kconfig
··· 79 79 select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION 80 80 select ARCH_HAS_CPU_FINALIZE_INIT 81 81 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 85 82 select ARCH_HAS_CURRENT_STACK_POINTER 86 83 select ARCH_HAS_DEBUG_VIRTUAL 87 84 select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE
-10
arch/x86/lib/Makefile
··· 40 40 lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o 41 41 lib-$(CONFIG_MITIGATION_RETPOLINE) += retpoline.o 42 42 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 - 53 43 obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o 54 44 obj-y += iomem.o 55 45
arch/x86/lib/crc-pclmul-consts.h lib/crc/x86/crc-pclmul-consts.h
arch/x86/lib/crc-pclmul-template.S lib/crc/x86/crc-pclmul-template.S
arch/x86/lib/crc-pclmul-template.h lib/crc/x86/crc-pclmul-template.h
+3 -15
arch/x86/lib/crc-t10dif.c lib/crc/x86/crc-t10dif.h
··· 5 5 * Copyright 2024 Google LLC 6 6 */ 7 7 8 - #include <linux/crc-t10dif.h> 9 - #include <linux/module.h> 10 8 #include "crc-pclmul-template.h" 11 9 12 10 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); 13 11 14 12 DECLARE_CRC_PCLMUL_FUNCS(crc16_msb, u16); 15 13 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) 17 15 { 18 16 CRC_PCLMUL(crc, p, len, crc16_msb, crc16_msb_0x8bb7_consts, 19 17 have_pclmulqdq); 20 18 return crc_t10dif_generic(crc, p, len); 21 19 } 22 - EXPORT_SYMBOL(crc_t10dif_arch); 23 20 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) 25 23 { 26 24 if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) { 27 25 static_branch_enable(&have_pclmulqdq); 28 26 INIT_CRC_PCLMUL(crc16_msb); 29 27 } 30 - return 0; 31 28 } 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");
arch/x86/lib/crc16-msb-pclmul.S lib/crc/x86/crc16-msb-pclmul.S
arch/x86/lib/crc32-pclmul.S lib/crc/x86/crc32-pclmul.S
+6 -24
arch/x86/lib/crc32.c lib/crc/x86/crc32.h
··· 7 7 * Copyright 2024 Google LLC 8 8 */ 9 9 10 - #include <linux/crc32.h> 11 - #include <linux/module.h> 12 10 #include "crc-pclmul-template.h" 13 11 14 12 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); ··· 14 16 15 17 DECLARE_CRC_PCLMUL_FUNCS(crc32_lsb, u32); 16 18 17 - u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 19 + static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 18 20 { 19 21 CRC_PCLMUL(crc, p, len, crc32_lsb, crc32_lsb_0xedb88320_consts, 20 22 have_pclmulqdq); 21 23 return crc32_le_base(crc, p, len); 22 24 } 23 - EXPORT_SYMBOL(crc32_le_arch); 24 25 25 26 #ifdef CONFIG_X86_64 26 27 #define CRC32_INST "crc32q %1, %q0" ··· 35 38 36 39 asmlinkage u32 crc32c_x86_3way(u32 crc, const u8 *buffer, size_t len); 37 40 38 - u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 41 + static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 39 42 { 40 43 size_t num_longs; 41 44 ··· 67 70 68 71 return crc; 69 72 } 70 - EXPORT_SYMBOL(crc32c_arch); 71 73 72 - u32 crc32_be_arch(u32 crc, const u8 *p, size_t len) 73 - { 74 - return crc32_be_base(crc, p, len); 75 - } 76 - EXPORT_SYMBOL(crc32_be_arch); 74 + #define crc32_be_arch crc32_be_base /* not implemented on this arch */ 77 75 78 - static int __init crc32_x86_init(void) 76 + #define crc32_mod_init_arch crc32_mod_init_arch 77 + static inline void crc32_mod_init_arch(void) 79 78 { 80 79 if (boot_cpu_has(X86_FEATURE_XMM4_2)) 81 80 static_branch_enable(&have_crc32); ··· 79 86 static_branch_enable(&have_pclmulqdq); 80 87 INIT_CRC_PCLMUL(crc32_lsb); 81 88 } 82 - return 0; 83 89 } 84 - subsys_initcall(crc32_x86_init); 85 90 86 - static void __exit crc32_x86_exit(void) 87 - { 88 - } 89 - module_exit(crc32_x86_exit); 90 - 91 - u32 crc32_optimizations(void) 91 + static inline u32 crc32_optimizations_arch(void) 92 92 { 93 93 u32 optimizations = 0; 94 94 ··· 91 105 optimizations |= CRC32_LE_OPTIMIZATION; 92 106 return optimizations; 93 107 } 94 - EXPORT_SYMBOL(crc32_optimizations); 95 - 96 - MODULE_DESCRIPTION("x86-optimized CRC32 functions"); 97 - MODULE_LICENSE("GPL");
arch/x86/lib/crc32c-3way.S lib/crc/x86/crc32c-3way.S
arch/x86/lib/crc64-pclmul.S lib/crc/x86/crc64-pclmul.S
+4 -17
arch/x86/lib/crc64.c lib/crc/x86/crc64.h
··· 5 5 * Copyright 2025 Google LLC 6 6 */ 7 7 8 - #include <linux/crc64.h> 9 - #include <linux/module.h> 10 8 #include "crc-pclmul-template.h" 11 9 12 10 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); ··· 12 14 DECLARE_CRC_PCLMUL_FUNCS(crc64_msb, u64); 13 15 DECLARE_CRC_PCLMUL_FUNCS(crc64_lsb, u64); 14 16 15 - u64 crc64_be_arch(u64 crc, const u8 *p, size_t len) 17 + static inline u64 crc64_be_arch(u64 crc, const u8 *p, size_t len) 16 18 { 17 19 CRC_PCLMUL(crc, p, len, crc64_msb, crc64_msb_0x42f0e1eba9ea3693_consts, 18 20 have_pclmulqdq); 19 21 return crc64_be_generic(crc, p, len); 20 22 } 21 - EXPORT_SYMBOL_GPL(crc64_be_arch); 22 23 23 - u64 crc64_nvme_arch(u64 crc, const u8 *p, size_t len) 24 + static inline u64 crc64_nvme_arch(u64 crc, const u8 *p, size_t len) 24 25 { 25 26 CRC_PCLMUL(crc, p, len, crc64_lsb, crc64_lsb_0x9a6c9329ac4bc9b5_consts, 26 27 have_pclmulqdq); 27 28 return crc64_nvme_generic(crc, p, len); 28 29 } 29 - EXPORT_SYMBOL_GPL(crc64_nvme_arch); 30 30 31 - static int __init crc64_x86_init(void) 31 + #define crc64_mod_init_arch crc64_mod_init_arch 32 + static inline void crc64_mod_init_arch(void) 32 33 { 33 34 if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) { 34 35 static_branch_enable(&have_pclmulqdq); 35 36 INIT_CRC_PCLMUL(crc64_msb); 36 37 INIT_CRC_PCLMUL(crc64_lsb); 37 38 } 38 - return 0; 39 39 } 40 - subsys_initcall(crc64_x86_init); 41 - 42 - static void __exit crc64_x86_exit(void) 43 - { 44 - } 45 - module_exit(crc64_x86_exit); 46 - 47 - MODULE_DESCRIPTION("CRC64 using [V]PCLMULQDQ instructions"); 48 - MODULE_LICENSE("GPL");
+3
lib/crc/Kconfig
··· 54 54 default y if ARM64 && KERNEL_MODE_NEON 55 55 default y if PPC64 && ALTIVEC 56 56 default y if RISCV && RISCV_ISA_ZBC 57 + default y if X86 57 58 58 59 config CRC32 59 60 tristate ··· 77 76 default y if RISCV && RISCV_ISA_ZBC 78 77 default y if S390 79 78 default y if SPARC64 79 + default y if X86 80 80 81 81 config CRC64 82 82 tristate ··· 92 90 bool 93 91 depends on CRC64 && CRC_OPTIMIZATIONS 94 92 default y if RISCV && RISCV_ISA_ZBC && 64BIT 93 + default y if X86_64 95 94 96 95 config CRC_OPTIMIZATIONS 97 96 bool "Enable optimized CRC implementations" if EXPERT
+4
lib/crc/Makefile
··· 17 17 crc-t10dif-$(CONFIG_ARM64) += arm64/crc-t10dif-core.o 18 18 crc-t10dif-$(CONFIG_PPC) += powerpc/crct10dif-vpmsum_asm.o 19 19 crc-t10dif-$(CONFIG_RISCV) += riscv/crc16_msb.o 20 + crc-t10dif-$(CONFIG_X86) += x86/crc16-msb-pclmul.o 20 21 endif 21 22 22 23 obj-$(CONFIG_CRC32) += crc32.o ··· 30 29 crc32-$(CONFIG_RISCV) += riscv/crc32_lsb.o riscv/crc32_msb.o 31 30 crc32-$(CONFIG_S390) += s390/crc32le-vx.o s390/crc32be-vx.o 32 31 crc32-$(CONFIG_SPARC) += sparc/crc32c_asm.o 32 + crc32-$(CONFIG_X86) += x86/crc32-pclmul.o 33 + crc32-$(CONFIG_X86_64) += x86/crc32c-3way.o 33 34 endif 34 35 35 36 obj-$(CONFIG_CRC64) += crc64.o ··· 39 36 ifeq ($(CONFIG_CRC64_ARCH),y) 40 37 CFLAGS_crc64-main.o += -I$(src)/$(SRCARCH) 41 38 crc64-$(CONFIG_RISCV) += riscv/crc64_lsb.o riscv/crc64_msb.o 39 + crc64-$(CONFIG_X86) += x86/crc64-pclmul.o 42 40 endif 43 41 44 42 obj-y += tests/