Skip to content

Commit 190c253

Browse files
author
Eric Biggers
committed
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>
1 parent da4fd65 commit 190c253

9 files changed

Lines changed: 14 additions & 56 deletions

File tree

arch/powerpc/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ config PPC
127127
select ARCH_ENABLE_MEMORY_HOTPLUG
128128
select ARCH_ENABLE_MEMORY_HOTREMOVE
129129
select ARCH_HAS_COPY_MC if PPC64
130-
select ARCH_HAS_CRC32 if PPC64 && ALTIVEC
131-
select ARCH_HAS_CRC_T10DIF if PPC64 && ALTIVEC
132130
select ARCH_HAS_CURRENT_STACK_POINTER
133131
select ARCH_HAS_DEBUG_VIRTUAL
134132
select ARCH_HAS_DEBUG_VM_PGTABLE

arch/powerpc/lib/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,4 @@ CFLAGS_xor_vmx.o += -mhard-float -maltivec $(call cc-option,-mabi=altivec)
8080
# Enable <altivec.h>
8181
CFLAGS_xor_vmx.o += -isystem $(shell $(CC) -print-file-name=include)
8282

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-
8983
obj-$(CONFIG_PPC64) += $(obj64-y)

lib/crc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ config CRC_T10DIF_ARCH
5252
depends on CRC_T10DIF && CRC_OPTIMIZATIONS
5353
default y if ARM && KERNEL_MODE_NEON
5454
default y if ARM64 && KERNEL_MODE_NEON
55+
default y if PPC64 && ALTIVEC
5556

5657
config CRC32
5758
tristate
@@ -70,6 +71,7 @@ config CRC32_ARCH
7071
default y if ARM64
7172
default y if LOONGARCH
7273
default y if MIPS && CPU_MIPSR6
74+
default y if PPC64 && ALTIVEC
7375

7476
config CRC64
7577
tristate

lib/crc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ifeq ($(CONFIG_CRC_T10DIF_ARCH),y)
1515
CFLAGS_crc-t10dif-main.o += -I$(src)/$(SRCARCH)
1616
crc-t10dif-$(CONFIG_ARM) += arm/crc-t10dif-core.o
1717
crc-t10dif-$(CONFIG_ARM64) += arm64/crc-t10dif-core.o
18+
crc-t10dif-$(CONFIG_PPC) += powerpc/crct10dif-vpmsum_asm.o
1819
endif
1920

2021
obj-$(CONFIG_CRC32) += crc32.o
@@ -23,6 +24,7 @@ ifeq ($(CONFIG_CRC32_ARCH),y)
2324
CFLAGS_crc32-main.o += -I$(src)/$(SRCARCH)
2425
crc32-$(CONFIG_ARM) += arm/crc32-core.o
2526
crc32-$(CONFIG_ARM64) += arm64/crc32-core.o
27+
crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o
2628
endif
2729

2830
obj-$(CONFIG_CRC64) += crc64.o
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
#include <asm/switch_to.h>
1010
#include <crypto/internal/simd.h>
1111
#include <linux/cpufeature.h>
12-
#include <linux/crc-t10dif.h>
1312
#include <linux/jump_label.h>
14-
#include <linux/kernel.h>
15-
#include <linux/module.h>
1613
#include <linux/preempt.h>
1714
#include <linux/uaccess.h>
1815

@@ -25,7 +22,7 @@ static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto);
2522

2623
u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
2724

28-
u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len)
25+
static inline u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len)
2926
{
3027
unsigned int prealign;
3128
unsigned int tail;
@@ -62,22 +59,11 @@ u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len)
6259

6360
return crc & 0xffff;
6461
}
65-
EXPORT_SYMBOL(crc_t10dif_arch);
6662

67-
static int __init crc_t10dif_powerpc_init(void)
63+
#define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch
64+
static inline void crc_t10dif_mod_init_arch(void)
6865
{
6966
if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
7067
(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
7168
static_branch_enable(&have_vec_crypto);
72-
return 0;
7369
}
74-
subsys_initcall(crc_t10dif_powerpc_init);
75-
76-
static void __exit crc_t10dif_powerpc_exit(void)
77-
{
78-
}
79-
module_exit(crc_t10dif_powerpc_exit);
80-
81-
MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
82-
MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions");
83-
MODULE_LICENSE("GPL");
Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
#include <asm/switch_to.h>
33
#include <crypto/internal/simd.h>
44
#include <linux/cpufeature.h>
5-
#include <linux/crc32.h>
65
#include <linux/jump_label.h>
7-
#include <linux/kernel.h>
8-
#include <linux/module.h>
96
#include <linux/preempt.h>
107
#include <linux/uaccess.h>
118

@@ -16,15 +13,12 @@
1613

1714
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto);
1815

19-
u32 __crc32c_vpmsum(u32 crc, const u8 *p, size_t len);
16+
#define crc32_le_arch crc32_le_base /* not implemented on this arch */
17+
#define crc32_be_arch crc32_be_base /* not implemented on this arch */
2018

21-
u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
22-
{
23-
return crc32_le_base(crc, p, len);
24-
}
25-
EXPORT_SYMBOL(crc32_le_arch);
19+
u32 __crc32c_vpmsum(u32 crc, const u8 *p, size_t len);
2620

27-
u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
21+
static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
2822
{
2923
unsigned int prealign;
3024
unsigned int tail;
@@ -58,36 +52,18 @@ u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
5852

5953
return crc;
6054
}
61-
EXPORT_SYMBOL(crc32c_arch);
62-
63-
u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
64-
{
65-
return crc32_be_base(crc, p, len);
66-
}
67-
EXPORT_SYMBOL(crc32_be_arch);
6855

69-
static int __init crc32_powerpc_init(void)
56+
#define crc32_mod_init_arch crc32_mod_init_arch
57+
static inline void crc32_mod_init_arch(void)
7058
{
7159
if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
7260
(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
7361
static_branch_enable(&have_vec_crypto);
74-
return 0;
75-
}
76-
subsys_initcall(crc32_powerpc_init);
77-
78-
static void __exit crc32_powerpc_exit(void)
79-
{
8062
}
81-
module_exit(crc32_powerpc_exit);
8263

83-
u32 crc32_optimizations(void)
64+
static inline u32 crc32_optimizations_arch(void)
8465
{
8566
if (static_key_enabled(&have_vec_crypto))
8667
return CRC32C_OPTIMIZATION;
8768
return 0;
8869
}
89-
EXPORT_SYMBOL(crc32_optimizations);
90-
91-
MODULE_AUTHOR("Anton Blanchard <anton@samba.org>");
92-
MODULE_DESCRIPTION("CRC32C using vector polynomial multiply-sum instructions");
93-
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)