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

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

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

+14 -56
-2
arch/powerpc/Kconfig
··· 127 127 select ARCH_ENABLE_MEMORY_HOTPLUG 128 128 select ARCH_ENABLE_MEMORY_HOTREMOVE 129 129 select ARCH_HAS_COPY_MC if PPC64 130 - select ARCH_HAS_CRC32 if PPC64 && ALTIVEC 131 - select ARCH_HAS_CRC_T10DIF if PPC64 && ALTIVEC 132 130 select ARCH_HAS_CURRENT_STACK_POINTER 133 131 select ARCH_HAS_DEBUG_VIRTUAL 134 132 select ARCH_HAS_DEBUG_VM_PGTABLE
-6
arch/powerpc/lib/Makefile
··· 80 80 # Enable <altivec.h> 81 81 CFLAGS_xor_vmx.o += -isystem $(shell $(CC) -print-file-name=include) 82 82 83 - obj-$(CONFIG_CRC32_ARCH) += crc32-powerpc.o 84 - crc32-powerpc-y := crc32.o crc32c-vpmsum_asm.o 85 - 86 - obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-powerpc.o 87 - crc-t10dif-powerpc-y := crc-t10dif.o crct10dif-vpmsum_asm.o 88 - 89 83 obj-$(CONFIG_PPC64) += $(obj64-y)
+3 -17
arch/powerpc/lib/crc-t10dif.c lib/crc/powerpc/crc-t10dif.h
··· 9 9 #include <asm/switch_to.h> 10 10 #include <crypto/internal/simd.h> 11 11 #include <linux/cpufeature.h> 12 - #include <linux/crc-t10dif.h> 13 12 #include <linux/jump_label.h> 14 - #include <linux/kernel.h> 15 - #include <linux/module.h> 16 13 #include <linux/preempt.h> 17 14 #include <linux/uaccess.h> 18 15 ··· 22 25 23 26 u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len); 24 27 25 - u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len) 28 + static inline u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len) 26 29 { 27 30 unsigned int prealign; 28 31 unsigned int tail; ··· 59 62 60 63 return crc & 0xffff; 61 64 } 62 - EXPORT_SYMBOL(crc_t10dif_arch); 63 65 64 - static int __init crc_t10dif_powerpc_init(void) 66 + #define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch 67 + static inline void crc_t10dif_mod_init_arch(void) 65 68 { 66 69 if (cpu_has_feature(CPU_FTR_ARCH_207S) && 67 70 (cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO)) 68 71 static_branch_enable(&have_vec_crypto); 69 - return 0; 70 72 } 71 - subsys_initcall(crc_t10dif_powerpc_init); 72 - 73 - static void __exit crc_t10dif_powerpc_exit(void) 74 - { 75 - } 76 - module_exit(crc_t10dif_powerpc_exit); 77 - 78 - MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>"); 79 - MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions"); 80 - MODULE_LICENSE("GPL");
arch/powerpc/lib/crc-vpmsum-template.S lib/crc/powerpc/crc-vpmsum-template.S
+7 -31
arch/powerpc/lib/crc32.c lib/crc/powerpc/crc32.h
··· 2 2 #include <asm/switch_to.h> 3 3 #include <crypto/internal/simd.h> 4 4 #include <linux/cpufeature.h> 5 - #include <linux/crc32.h> 6 5 #include <linux/jump_label.h> 7 - #include <linux/kernel.h> 8 - #include <linux/module.h> 9 6 #include <linux/preempt.h> 10 7 #include <linux/uaccess.h> 11 8 ··· 13 16 14 17 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto); 15 18 19 + #define crc32_le_arch crc32_le_base /* not implemented on this arch */ 20 + #define crc32_be_arch crc32_be_base /* not implemented on this arch */ 21 + 16 22 u32 __crc32c_vpmsum(u32 crc, const u8 *p, size_t len); 17 23 18 - u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 19 - { 20 - return crc32_le_base(crc, p, len); 21 - } 22 - EXPORT_SYMBOL(crc32_le_arch); 23 - 24 - u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 24 + static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 25 25 { 26 26 unsigned int prealign; 27 27 unsigned int tail; ··· 52 58 53 59 return crc; 54 60 } 55 - EXPORT_SYMBOL(crc32c_arch); 56 61 57 - u32 crc32_be_arch(u32 crc, const u8 *p, size_t len) 58 - { 59 - return crc32_be_base(crc, p, len); 60 - } 61 - EXPORT_SYMBOL(crc32_be_arch); 62 - 63 - static int __init crc32_powerpc_init(void) 62 + #define crc32_mod_init_arch crc32_mod_init_arch 63 + static inline void crc32_mod_init_arch(void) 64 64 { 65 65 if (cpu_has_feature(CPU_FTR_ARCH_207S) && 66 66 (cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO)) 67 67 static_branch_enable(&have_vec_crypto); 68 - return 0; 69 68 } 70 - subsys_initcall(crc32_powerpc_init); 71 69 72 - static void __exit crc32_powerpc_exit(void) 73 - { 74 - } 75 - module_exit(crc32_powerpc_exit); 76 - 77 - u32 crc32_optimizations(void) 70 + static inline u32 crc32_optimizations_arch(void) 78 71 { 79 72 if (static_key_enabled(&have_vec_crypto)) 80 73 return CRC32C_OPTIMIZATION; 81 74 return 0; 82 75 } 83 - EXPORT_SYMBOL(crc32_optimizations); 84 - 85 - MODULE_AUTHOR("Anton Blanchard <anton@samba.org>"); 86 - MODULE_DESCRIPTION("CRC32C using vector polynomial multiply-sum instructions"); 87 - MODULE_LICENSE("GPL");
arch/powerpc/lib/crc32c-vpmsum_asm.S lib/crc/powerpc/crc32c-vpmsum_asm.S
arch/powerpc/lib/crct10dif-vpmsum_asm.S lib/crc/powerpc/crct10dif-vpmsum_asm.S
+2
lib/crc/Kconfig
··· 52 52 depends on CRC_T10DIF && CRC_OPTIMIZATIONS 53 53 default y if ARM && KERNEL_MODE_NEON 54 54 default y if ARM64 && KERNEL_MODE_NEON 55 + default y if PPC64 && ALTIVEC 55 56 56 57 config CRC32 57 58 tristate ··· 71 70 default y if ARM64 72 71 default y if LOONGARCH 73 72 default y if MIPS && CPU_MIPSR6 73 + default y if PPC64 && ALTIVEC 74 74 75 75 config CRC64 76 76 tristate
+2
lib/crc/Makefile
··· 15 15 CFLAGS_crc-t10dif-main.o += -I$(src)/$(SRCARCH) 16 16 crc-t10dif-$(CONFIG_ARM) += arm/crc-t10dif-core.o 17 17 crc-t10dif-$(CONFIG_ARM64) += arm64/crc-t10dif-core.o 18 + crc-t10dif-$(CONFIG_PPC) += powerpc/crct10dif-vpmsum_asm.o 18 19 endif 19 20 20 21 obj-$(CONFIG_CRC32) += crc32.o ··· 24 23 CFLAGS_crc32-main.o += -I$(src)/$(SRCARCH) 25 24 crc32-$(CONFIG_ARM) += arm/crc32-core.o 26 25 crc32-$(CONFIG_ARM64) += arm64/crc32-core.o 26 + crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o 27 27 endif 28 28 29 29 obj-$(CONFIG_CRC64) += crc64.o