Skip to content

Commit b594381

Browse files
author
Eric Biggers
committed
lib/crc: riscv: Migrate optimized CRC code into lib/crc/
Move the riscv-optimized CRC code from arch/riscv/lib/crc* into its new location in lib/crc/riscv/, 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-9-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 190c253 commit b594381

15 files changed

Lines changed: 13 additions & 38 deletions

arch/riscv/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ config RISCV
2424
select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
2525
select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
2626
select ARCH_HAS_BINFMT_FLAT
27-
select ARCH_HAS_CRC32 if RISCV_ISA_ZBC
28-
select ARCH_HAS_CRC64 if 64BIT && RISCV_ISA_ZBC
29-
select ARCH_HAS_CRC_T10DIF if RISCV_ISA_ZBC
3027
select ARCH_HAS_CURRENT_STACK_POINTER
3128
select ARCH_HAS_DEBUG_VIRTUAL if MMU
3229
select ARCH_HAS_DEBUG_VM_PGTABLE

arch/riscv/lib/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ endif
1616
lib-$(CONFIG_MMU) += uaccess.o
1717
lib-$(CONFIG_64BIT) += tishift.o
1818
lib-$(CONFIG_RISCV_ISA_ZICBOZ) += clear_page.o
19-
obj-$(CONFIG_CRC32_ARCH) += crc32-riscv.o
20-
crc32-riscv-y := crc32.o crc32_msb.o crc32_lsb.o
21-
obj-$(CONFIG_CRC64_ARCH) += crc64-riscv.o
22-
crc64-riscv-y := crc64.o crc64_msb.o crc64_lsb.o
23-
obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-riscv.o
24-
crc-t10dif-riscv-y := crc-t10dif.o crc16_msb.o
2519
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
2620
lib-$(CONFIG_RISCV_ISA_V) += xor.o
2721
lib-$(CONFIG_RISCV_ISA_V) += riscv_v_helpers.o

lib/crc/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ config CRC_T10DIF_ARCH
5353
default y if ARM && KERNEL_MODE_NEON
5454
default y if ARM64 && KERNEL_MODE_NEON
5555
default y if PPC64 && ALTIVEC
56+
default y if RISCV && RISCV_ISA_ZBC
5657

5758
config CRC32
5859
tristate
@@ -72,6 +73,7 @@ config CRC32_ARCH
7273
default y if LOONGARCH
7374
default y if MIPS && CPU_MIPSR6
7475
default y if PPC64 && ALTIVEC
76+
default y if RISCV && RISCV_ISA_ZBC
7577

7678
config CRC64
7779
tristate
@@ -85,6 +87,7 @@ config ARCH_HAS_CRC64
8587
config CRC64_ARCH
8688
bool
8789
depends on CRC64 && CRC_OPTIMIZATIONS
90+
default y if RISCV && RISCV_ISA_ZBC && 64BIT
8891

8992
config CRC_OPTIMIZATIONS
9093
bool "Enable optimized CRC implementations" if EXPERT

lib/crc/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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
1818
crc-t10dif-$(CONFIG_PPC) += powerpc/crct10dif-vpmsum_asm.o
19+
crc-t10dif-$(CONFIG_RISCV) += riscv/crc16_msb.o
1920
endif
2021

2122
obj-$(CONFIG_CRC32) += crc32.o
@@ -25,12 +26,14 @@ CFLAGS_crc32-main.o += -I$(src)/$(SRCARCH)
2526
crc32-$(CONFIG_ARM) += arm/crc32-core.o
2627
crc32-$(CONFIG_ARM64) += arm64/crc32-core.o
2728
crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o
29+
crc32-$(CONFIG_RISCV) += riscv/crc32_lsb.o riscv/crc32_msb.o
2830
endif
2931

3032
obj-$(CONFIG_CRC64) += crc64.o
3133
crc64-y := crc64-main.o
3234
ifeq ($(CONFIG_CRC64_ARCH),y)
3335
CFLAGS_crc64-main.o += -I$(src)/$(SRCARCH)
36+
crc64-$(CONFIG_RISCV) += riscv/crc64_lsb.o riscv/crc64_msb.o
3437
endif
3538

3639
obj-y += tests/
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77

88
#include <asm/hwcap.h>
99
#include <asm/alternative-macros.h>
10-
#include <linux/crc-t10dif.h>
11-
#include <linux/module.h>
1210

1311
#include "crc-clmul.h"
1412

15-
u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len)
13+
static inline u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len)
1614
{
1715
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBC))
1816
return crc16_msb_clmul(crc, p, len, &crc16_msb_0x8bb7_consts);
1917
return crc_t10dif_generic(crc, p, len);
2018
}
21-
EXPORT_SYMBOL(crc_t10dif_arch);
22-
23-
MODULE_DESCRIPTION("RISC-V optimized CRC-T10DIF function");
24-
MODULE_LICENSE("GPL");
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,38 @@
77

88
#include <asm/hwcap.h>
99
#include <asm/alternative-macros.h>
10-
#include <linux/crc32.h>
11-
#include <linux/module.h>
1210

1311
#include "crc-clmul.h"
1412

15-
u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
13+
static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
1614
{
1715
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBC))
1816
return crc32_lsb_clmul(crc, p, len,
1917
&crc32_lsb_0xedb88320_consts);
2018
return crc32_le_base(crc, p, len);
2119
}
22-
EXPORT_SYMBOL(crc32_le_arch);
2320

24-
u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
21+
static inline u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
2522
{
2623
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBC))
2724
return crc32_msb_clmul(crc, p, len,
2825
&crc32_msb_0x04c11db7_consts);
2926
return crc32_be_base(crc, p, len);
3027
}
31-
EXPORT_SYMBOL(crc32_be_arch);
3228

33-
u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
29+
static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
3430
{
3531
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBC))
3632
return crc32_lsb_clmul(crc, p, len,
3733
&crc32_lsb_0x82f63b78_consts);
3834
return crc32c_base(crc, p, len);
3935
}
40-
EXPORT_SYMBOL(crc32c_arch);
4136

42-
u32 crc32_optimizations(void)
37+
static inline u32 crc32_optimizations_arch(void)
4338
{
4439
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBC))
4540
return CRC32_LE_OPTIMIZATION |
4641
CRC32_BE_OPTIMIZATION |
4742
CRC32C_OPTIMIZATION;
4843
return 0;
4944
}
50-
EXPORT_SYMBOL(crc32_optimizations);
51-
52-
MODULE_DESCRIPTION("RISC-V optimized CRC32 functions");
53-
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)