]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/crc: arm: Migrate optimized CRC code into lib/crc/
authorEric Biggers <ebiggers@kernel.org>
Sat, 7 Jun 2025 20:04:45 +0000 (13:04 -0700)
committerEric Biggers <ebiggers@kernel.org>
Mon, 30 Jun 2025 16:31:57 +0000 (09:31 -0700)
Move the arm-optimized CRC code from arch/arm/lib/crc* into its new
location in lib/crc/arm/, 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-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
arch/arm/Kconfig
arch/arm/lib/Makefile
lib/crc/Kconfig
lib/crc/Makefile
lib/crc/arm/crc-t10dif-core.S [moved from arch/arm/lib/crc-t10dif-core.S with 100% similarity]
lib/crc/arm/crc-t10dif.h [moved from arch/arm/lib/crc-t10dif.c with 70% similarity]
lib/crc/arm/crc32-core.S [moved from arch/arm/lib/crc32-core.S with 100% similarity]
lib/crc/arm/crc32.h [moved from arch/arm/lib/crc32.c with 69% similarity]

index 3072731fe09c5911996d2e5fcc384c424f72f638..c531b49aa98ea4fd343161c42640cbdffebc01c4 100644 (file)
@@ -8,8 +8,6 @@ config ARM
        select ARCH_HAS_CACHE_LINE_SIZE if OF
        select ARCH_HAS_CPU_CACHE_ALIASING
        select ARCH_HAS_CPU_FINALIZE_INIT if MMU
-       select ARCH_HAS_CRC32 if KERNEL_MODE_NEON
-       select ARCH_HAS_CRC_T10DIF if KERNEL_MODE_NEON
        select ARCH_HAS_CURRENT_STACK_POINTER
        select ARCH_HAS_DEBUG_VIRTUAL if MMU
        select ARCH_HAS_DMA_ALLOC if MMU
index 91ea0e29107afc13edbc5ae5a7bdc9834c3fba42..d1b9ea20236486b4dd9ccdfbca61ceb51e8e403b 100644 (file)
@@ -47,9 +47,3 @@ ifeq ($(CONFIG_KERNEL_MODE_NEON),y)
 endif
 
 obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
-
-obj-$(CONFIG_CRC32_ARCH) += crc32-arm.o
-crc32-arm-y := crc32.o crc32-core.o
-
-obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-arm.o
-crc-t10dif-arm-y := crc-t10dif.o crc-t10dif-core.o
index 04c7aeb0fc8e6fcfced51179b9ad508f9632717c..6375f9cca81cf6b88a51a24883576ffce017da2f 100644 (file)
@@ -50,6 +50,7 @@ config ARCH_HAS_CRC_T10DIF
 config CRC_T10DIF_ARCH
        bool
        depends on CRC_T10DIF && CRC_OPTIMIZATIONS
+       default y if ARM && KERNEL_MODE_NEON
 
 config CRC32
        tristate
@@ -64,6 +65,7 @@ config ARCH_HAS_CRC32
 config CRC32_ARCH
        bool
        depends on CRC32 && CRC_OPTIMIZATIONS
+       default y if ARM && KERNEL_MODE_NEON
 
 config CRC64
        tristate
index 926edc3b035f6351d9ee0f6c550556c5f8a99525..c72d351be6cb8929a4cf5331ce550d5bbc43e140 100644 (file)
@@ -13,12 +13,14 @@ obj-$(CONFIG_CRC_T10DIF) += crc-t10dif.o
 crc-t10dif-y := crc-t10dif-main.o
 ifeq ($(CONFIG_CRC_T10DIF_ARCH),y)
 CFLAGS_crc-t10dif-main.o += -I$(src)/$(SRCARCH)
+crc-t10dif-$(CONFIG_ARM) += arm/crc-t10dif-core.o
 endif
 
 obj-$(CONFIG_CRC32) += crc32.o
 crc32-y := crc32-main.o
 ifeq ($(CONFIG_CRC32_ARCH),y)
 CFLAGS_crc32-main.o += -I$(src)/$(SRCARCH)
+crc32-$(CONFIG_ARM) += arm/crc32-core.o
 endif
 
 obj-$(CONFIG_CRC64) += crc64.o
similarity index 70%
rename from arch/arm/lib/crc-t10dif.c
rename to lib/crc/arm/crc-t10dif.h
index 1093f8ec13b0bef9efd6d53834706c01eb48c3bf..2edf7e9681d05a7dba846df903caa943db4b3b91 100644 (file)
@@ -5,12 +5,6 @@
  * Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
  */
 
-#include <linux/crc-t10dif.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/string.h>
-
 #include <crypto/internal/simd.h>
 
 #include <asm/neon.h>
@@ -25,7 +19,7 @@ asmlinkage u16 crc_t10dif_pmull64(u16 init_crc, const u8 *buf, size_t len);
 asmlinkage void crc_t10dif_pmull8(u16 init_crc, const u8 *buf, size_t len,
                                  u8 out[16]);
 
-u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)
+static inline u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)
 {
        if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE) {
                if (static_branch_likely(&have_pmull)) {
@@ -49,24 +43,13 @@ u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)
        }
        return crc_t10dif_generic(crc, data, length);
 }
-EXPORT_SYMBOL(crc_t10dif_arch);
 
-static int __init crc_t10dif_arm_init(void)
+#define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch
+static inline void crc_t10dif_mod_init_arch(void)
 {
        if (elf_hwcap & HWCAP_NEON) {
                static_branch_enable(&have_neon);
                if (elf_hwcap2 & HWCAP2_PMULL)
                        static_branch_enable(&have_pmull);
        }
-       return 0;
 }
-subsys_initcall(crc_t10dif_arm_init);
-
-static void __exit crc_t10dif_arm_exit(void)
-{
-}
-module_exit(crc_t10dif_arm_exit);
-
-MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
-MODULE_DESCRIPTION("Accelerated CRC-T10DIF using ARM NEON and Crypto Extensions");
-MODULE_LICENSE("GPL v2");
similarity index 69%
rename from arch/arm/lib/crc32.c
rename to lib/crc/arm/crc32.h
index f2bef8849c7c3aa9fba300b2872d72e975c17181..018007e162a2b61345b768893d91cbeb52ef6ddb 100644 (file)
@@ -6,11 +6,6 @@
  */
 
 #include <linux/cpufeature.h>
-#include <linux/crc32.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/string.h>
 
 #include <crypto/internal/simd.h>
 
@@ -29,14 +24,14 @@ asmlinkage u32 crc32_armv8_le(u32 init_crc, const u8 buf[], u32 len);
 asmlinkage u32 crc32c_pmull_le(const u8 buf[], u32 len, u32 init_crc);
 asmlinkage u32 crc32c_armv8_le(u32 init_crc, const u8 buf[], u32 len);
 
-static u32 crc32_le_scalar(u32 crc, const u8 *p, size_t len)
+static inline u32 crc32_le_scalar(u32 crc, const u8 *p, size_t len)
 {
        if (static_branch_likely(&have_crc32))
                return crc32_armv8_le(crc, p, len);
        return crc32_le_base(crc, p, len);
 }
 
-u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
+static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
 {
        if (len >= PMULL_MIN_LEN + 15 &&
            static_branch_likely(&have_pmull) && crypto_simd_usable()) {
@@ -57,16 +52,15 @@ u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
        }
        return crc32_le_scalar(crc, p, len);
 }
-EXPORT_SYMBOL(crc32_le_arch);
 
-static u32 crc32c_scalar(u32 crc, const u8 *p, size_t len)
+static inline u32 crc32c_scalar(u32 crc, const u8 *p, size_t len)
 {
        if (static_branch_likely(&have_crc32))
                return crc32c_armv8_le(crc, p, len);
        return crc32c_base(crc, p, len);
 }
 
-u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
+static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
 {
        if (len >= PMULL_MIN_LEN + 15 &&
            static_branch_likely(&have_pmull) && crypto_simd_usable()) {
@@ -87,37 +81,21 @@ u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
        }
        return crc32c_scalar(crc, p, len);
 }
-EXPORT_SYMBOL(crc32c_arch);
 
-u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
-{
-       return crc32_be_base(crc, p, len);
-}
-EXPORT_SYMBOL(crc32_be_arch);
+#define crc32_be_arch crc32_be_base /* not implemented on this arch */
 
-static int __init crc32_arm_init(void)
+#define crc32_mod_init_arch crc32_mod_init_arch
+static inline void crc32_mod_init_arch(void)
 {
        if (elf_hwcap2 & HWCAP2_CRC32)
                static_branch_enable(&have_crc32);
        if (elf_hwcap2 & HWCAP2_PMULL)
                static_branch_enable(&have_pmull);
-       return 0;
 }
-subsys_initcall(crc32_arm_init);
 
-static void __exit crc32_arm_exit(void)
-{
-}
-module_exit(crc32_arm_exit);
-
-u32 crc32_optimizations(void)
+static inline u32 crc32_optimizations_arch(void)
 {
        if (elf_hwcap2 & (HWCAP2_CRC32 | HWCAP2_PMULL))
                return CRC32_LE_OPTIMIZATION | CRC32C_OPTIMIZATION;
        return 0;
 }
-EXPORT_SYMBOL(crc32_optimizations);
-
-MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
-MODULE_DESCRIPTION("Accelerated CRC32(C) using ARM CRC, NEON and Crypto Extensions");
-MODULE_LICENSE("GPL v2");