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

lib/crc: arm64: Migrate optimized CRC code into lib/crc/

Move the arm64-optimized CRC code from arch/arm64/lib/crc* into its new
location in lib/crc/arm64/, 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-5-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+11 -42
-2
arch/arm64/Kconfig
··· 21 21 select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE 22 22 select ARCH_HAS_CACHE_LINE_SIZE 23 23 select ARCH_HAS_CC_PLATFORM 24 - select ARCH_HAS_CRC32 25 - select ARCH_HAS_CRC_T10DIF if KERNEL_MODE_NEON 26 24 select ARCH_HAS_CURRENT_STACK_POINTER 27 25 select ARCH_HAS_DEBUG_VIRTUAL 28 26 select ARCH_HAS_DEBUG_VM_PGTABLE
-6
arch/arm64/lib/Makefile
··· 16 16 17 17 lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o 18 18 19 - obj-$(CONFIG_CRC32_ARCH) += crc32-arm64.o 20 - crc32-arm64-y := crc32.o crc32-core.o 21 - 22 - obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-arm64.o 23 - crc-t10dif-arm64-y := crc-t10dif.o crc-t10dif-core.o 24 - 25 19 obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o 26 20 27 21 obj-$(CONFIG_ARM64_MTE) += mte.o
arch/arm64/lib/crc-t10dif-core.S lib/crc/arm64/crc-t10dif-core.S
+3 -19
arch/arm64/lib/crc-t10dif.c lib/crc/arm64/crc-t10dif.h
··· 6 6 */ 7 7 8 8 #include <linux/cpufeature.h> 9 - #include <linux/crc-t10dif.h> 10 - #include <linux/init.h> 11 - #include <linux/kernel.h> 12 - #include <linux/module.h> 13 - #include <linux/string.h> 14 9 15 10 #include <crypto/internal/simd.h> 16 11 ··· 21 26 u8 out[16]); 22 27 asmlinkage u16 crc_t10dif_pmull_p64(u16 init_crc, const u8 *buf, size_t len); 23 28 24 - u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length) 29 + static inline u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length) 25 30 { 26 31 if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE) { 27 32 if (static_branch_likely(&have_pmull)) { ··· 45 50 } 46 51 return crc_t10dif_generic(crc, data, length); 47 52 } 48 - EXPORT_SYMBOL(crc_t10dif_arch); 49 53 50 - static int __init crc_t10dif_arm64_init(void) 54 + #define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch 55 + static inline void crc_t10dif_mod_init_arch(void) 51 56 { 52 57 if (cpu_have_named_feature(ASIMD)) { 53 58 static_branch_enable(&have_asimd); 54 59 if (cpu_have_named_feature(PMULL)) 55 60 static_branch_enable(&have_pmull); 56 61 } 57 - return 0; 58 62 } 59 - subsys_initcall(crc_t10dif_arm64_init); 60 - 61 - static void __exit crc_t10dif_arm64_exit(void) 62 - { 63 - } 64 - module_exit(crc_t10dif_arm64_exit); 65 - 66 - MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); 67 - MODULE_DESCRIPTION("CRC-T10DIF using arm64 NEON and Crypto Extensions"); 68 - MODULE_LICENSE("GPL v2");
arch/arm64/lib/crc32-core.S lib/crc/arm64/crc32-core.S
+4 -15
arch/arm64/lib/crc32.c lib/crc/arm64/crc32.h
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 3 - #include <linux/crc32.h> 4 - #include <linux/linkage.h> 5 - #include <linux/module.h> 6 - 7 3 #include <asm/alternative.h> 8 4 #include <asm/cpufeature.h> 9 5 #include <asm/neon.h> ··· 18 22 asmlinkage u32 crc32c_le_arm64_4way(u32 crc, unsigned char const *p, size_t len); 19 23 asmlinkage u32 crc32_be_arm64_4way(u32 crc, unsigned char const *p, size_t len); 20 24 21 - u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 25 + static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 22 26 { 23 27 if (!alternative_has_cap_likely(ARM64_HAS_CRC32)) 24 28 return crc32_le_base(crc, p, len); ··· 37 41 38 42 return crc32_le_arm64(crc, p, len); 39 43 } 40 - EXPORT_SYMBOL(crc32_le_arch); 41 44 42 - u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 45 + static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 43 46 { 44 47 if (!alternative_has_cap_likely(ARM64_HAS_CRC32)) 45 48 return crc32c_base(crc, p, len); ··· 57 62 58 63 return crc32c_le_arm64(crc, p, len); 59 64 } 60 - EXPORT_SYMBOL(crc32c_arch); 61 65 62 - u32 crc32_be_arch(u32 crc, const u8 *p, size_t len) 66 + static inline u32 crc32_be_arch(u32 crc, const u8 *p, size_t len) 63 67 { 64 68 if (!alternative_has_cap_likely(ARM64_HAS_CRC32)) 65 69 return crc32_be_base(crc, p, len); ··· 77 83 78 84 return crc32_be_arm64(crc, p, len); 79 85 } 80 - EXPORT_SYMBOL(crc32_be_arch); 81 86 82 - u32 crc32_optimizations(void) 87 + static inline u32 crc32_optimizations_arch(void) 83 88 { 84 89 if (alternative_has_cap_likely(ARM64_HAS_CRC32)) 85 90 return CRC32_LE_OPTIMIZATION | ··· 86 93 CRC32C_OPTIMIZATION; 87 94 return 0; 88 95 } 89 - EXPORT_SYMBOL(crc32_optimizations); 90 - 91 - MODULE_LICENSE("GPL"); 92 - MODULE_DESCRIPTION("arm64-optimized CRC32 functions");
+2
lib/crc/Kconfig
··· 51 51 bool 52 52 depends on CRC_T10DIF && CRC_OPTIMIZATIONS 53 53 default y if ARM && KERNEL_MODE_NEON 54 + default y if ARM64 && KERNEL_MODE_NEON 54 55 55 56 config CRC32 56 57 tristate ··· 67 66 bool 68 67 depends on CRC32 && CRC_OPTIMIZATIONS 69 68 default y if ARM && KERNEL_MODE_NEON 69 + default y if ARM64 70 70 71 71 config CRC64 72 72 tristate
+2
lib/crc/Makefile
··· 14 14 ifeq ($(CONFIG_CRC_T10DIF_ARCH),y) 15 15 CFLAGS_crc-t10dif-main.o += -I$(src)/$(SRCARCH) 16 16 crc-t10dif-$(CONFIG_ARM) += arm/crc-t10dif-core.o 17 + crc-t10dif-$(CONFIG_ARM64) += arm64/crc-t10dif-core.o 17 18 endif 18 19 19 20 obj-$(CONFIG_CRC32) += crc32.o ··· 22 21 ifeq ($(CONFIG_CRC32_ARCH),y) 23 22 CFLAGS_crc32-main.o += -I$(src)/$(SRCARCH) 24 23 crc32-$(CONFIG_ARM) += arm/crc32-core.o 24 + crc32-$(CONFIG_ARM64) += arm64/crc32-core.o 25 25 endif 26 26 27 27 obj-$(CONFIG_CRC64) += crc64.o