From 7ef377c4d4abb7a2a74fc319dc1bce46f2449af7 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 13 Apr 2025 08:43:50 -0700 Subject: [PATCH 01/16] lib/crc: make the CPU feature static keys __ro_after_init All of the CRC library's CPU feature static_keys are initialized by initcalls and never change afterwards, so there's no need for them to be in the regular .data section. Put them in .data..ro_after_init instead. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Acked-by: Heiko Carstens # s390 Link: https://lore.kernel.org/r/20250413154350.10819-1-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/arm/lib/crc-t10dif-glue.c | 4 ++-- arch/arm/lib/crc32-glue.c | 4 ++-- arch/arm64/lib/crc-t10dif-glue.c | 4 ++-- arch/loongarch/lib/crc32-loongarch.c | 2 +- arch/mips/lib/crc32-mips.c | 2 +- arch/powerpc/lib/crc-t10dif-glue.c | 2 +- arch/powerpc/lib/crc32-glue.c | 2 +- arch/s390/lib/crc32-glue.c | 2 +- arch/sparc/lib/crc32_glue.c | 2 +- arch/x86/lib/crc-t10dif-glue.c | 2 +- arch/x86/lib/crc32-glue.c | 4 ++-- arch/x86/lib/crc64-glue.c | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/arch/arm/lib/crc-t10dif-glue.c b/arch/arm/lib/crc-t10dif-glue.c index 6efad3d78284..382437094bdd 100644 --- a/arch/arm/lib/crc-t10dif-glue.c +++ b/arch/arm/lib/crc-t10dif-glue.c @@ -16,8 +16,8 @@ #include #include -static DEFINE_STATIC_KEY_FALSE(have_neon); -static DEFINE_STATIC_KEY_FALSE(have_pmull); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pmull); #define CRC_T10DIF_PMULL_CHUNK_SIZE 16U diff --git a/arch/arm/lib/crc32-glue.c b/arch/arm/lib/crc32-glue.c index 4340351dbde8..7ef7db9c0de7 100644 --- a/arch/arm/lib/crc32-glue.c +++ b/arch/arm/lib/crc32-glue.c @@ -18,8 +18,8 @@ #include #include -static DEFINE_STATIC_KEY_FALSE(have_crc32); -static DEFINE_STATIC_KEY_FALSE(have_pmull); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pmull); #define PMULL_MIN_LEN 64 /* min size of buffer for pmull functions */ diff --git a/arch/arm64/lib/crc-t10dif-glue.c b/arch/arm64/lib/crc-t10dif-glue.c index bacd18f23168..99d0b5668a28 100644 --- a/arch/arm64/lib/crc-t10dif-glue.c +++ b/arch/arm64/lib/crc-t10dif-glue.c @@ -17,8 +17,8 @@ #include #include -static DEFINE_STATIC_KEY_FALSE(have_asimd); -static DEFINE_STATIC_KEY_FALSE(have_pmull); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_asimd); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pmull); #define CRC_T10DIF_PMULL_CHUNK_SIZE 16U diff --git a/arch/loongarch/lib/crc32-loongarch.c b/arch/loongarch/lib/crc32-loongarch.c index c44ee4f32557..8e6d1f517e73 100644 --- a/arch/loongarch/lib/crc32-loongarch.c +++ b/arch/loongarch/lib/crc32-loongarch.c @@ -26,7 +26,7 @@ do { \ #define CRC32(crc, value, size) _CRC32(crc, value, size, crc) #define CRC32C(crc, value, size) _CRC32(crc, value, size, crcc) -static DEFINE_STATIC_KEY_FALSE(have_crc32); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) { diff --git a/arch/mips/lib/crc32-mips.c b/arch/mips/lib/crc32-mips.c index 676a4b3e290b..84df361e7181 100644 --- a/arch/mips/lib/crc32-mips.c +++ b/arch/mips/lib/crc32-mips.c @@ -62,7 +62,7 @@ do { \ #define CRC32C(crc, value, size) \ _CRC32(crc, value, size, crc32c) -static DEFINE_STATIC_KEY_FALSE(have_crc32); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) { diff --git a/arch/powerpc/lib/crc-t10dif-glue.c b/arch/powerpc/lib/crc-t10dif-glue.c index f411b0120cc5..ddd5c4088f50 100644 --- a/arch/powerpc/lib/crc-t10dif-glue.c +++ b/arch/powerpc/lib/crc-t10dif-glue.c @@ -21,7 +21,7 @@ #define VECTOR_BREAKPOINT 64 -static DEFINE_STATIC_KEY_FALSE(have_vec_crypto); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto); u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len); diff --git a/arch/powerpc/lib/crc32-glue.c b/arch/powerpc/lib/crc32-glue.c index dbd10f339183..42f2dd3c85dd 100644 --- a/arch/powerpc/lib/crc32-glue.c +++ b/arch/powerpc/lib/crc32-glue.c @@ -13,7 +13,7 @@ #define VECTOR_BREAKPOINT 512 -static DEFINE_STATIC_KEY_FALSE(have_vec_crypto); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto); u32 __crc32c_vpmsum(u32 crc, const u8 *p, size_t len); diff --git a/arch/s390/lib/crc32-glue.c b/arch/s390/lib/crc32-glue.c index 124214a27340..8f20a8e595c3 100644 --- a/arch/s390/lib/crc32-glue.c +++ b/arch/s390/lib/crc32-glue.c @@ -18,7 +18,7 @@ #define VX_ALIGNMENT 16L #define VX_ALIGN_MASK (VX_ALIGNMENT - 1) -static DEFINE_STATIC_KEY_FALSE(have_vxrs); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vxrs); /* * DEFINE_CRC32_VX() - Define a CRC-32 function using the vector extension diff --git a/arch/sparc/lib/crc32_glue.c b/arch/sparc/lib/crc32_glue.c index a70752c729cf..d34e7cc7e1a1 100644 --- a/arch/sparc/lib/crc32_glue.c +++ b/arch/sparc/lib/crc32_glue.c @@ -17,7 +17,7 @@ #include #include -static DEFINE_STATIC_KEY_FALSE(have_crc32c_opcode); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32c_opcode); u32 crc32_le_arch(u32 crc, const u8 *data, size_t len) { diff --git a/arch/x86/lib/crc-t10dif-glue.c b/arch/x86/lib/crc-t10dif-glue.c index f89c335cde3c..d073b3678edc 100644 --- a/arch/x86/lib/crc-t10dif-glue.c +++ b/arch/x86/lib/crc-t10dif-glue.c @@ -9,7 +9,7 @@ #include #include "crc-pclmul-template.h" -static DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); DECLARE_CRC_PCLMUL_FUNCS(crc16_msb, u16); diff --git a/arch/x86/lib/crc32-glue.c b/arch/x86/lib/crc32-glue.c index e3f93b17ac3f..e6a6285cfca8 100644 --- a/arch/x86/lib/crc32-glue.c +++ b/arch/x86/lib/crc32-glue.c @@ -11,8 +11,8 @@ #include #include "crc-pclmul-template.h" -static DEFINE_STATIC_KEY_FALSE(have_crc32); -static DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); DECLARE_CRC_PCLMUL_FUNCS(crc32_lsb, u32); diff --git a/arch/x86/lib/crc64-glue.c b/arch/x86/lib/crc64-glue.c index b0e1b719ecbf..1214ee726c16 100644 --- a/arch/x86/lib/crc64-glue.c +++ b/arch/x86/lib/crc64-glue.c @@ -9,7 +9,7 @@ #include #include "crc-pclmul-template.h" -static DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); DECLARE_CRC_PCLMUL_FUNCS(crc64_msb, u64); DECLARE_CRC_PCLMUL_FUNCS(crc64_lsb, u64); From 93b988cf8e4c68b823e70a02e4c7c39eaa0053be Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Thu, 17 Apr 2025 14:30:56 +0200 Subject: [PATCH 02/16] s390/crc32: Remove have_vxrs static key Replace the have_vxrs static key with a cpu_has_vx() call. cpu_has_vx() resolves into a compile time constant (true) if the kernel is compiled for z13 or newer. Otherwise it generates an unconditional one instruction branch, which is patched based on CPU alternatives. In any case the generated code is at least as good as before and avoids static key handling. Signed-off-by: Heiko Carstens Link: https://lore.kernel.org/r/20250417125318.12521F12-hca@linux.ibm.com/ Signed-off-by: Eric Biggers --- arch/s390/lib/crc32-glue.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/s390/lib/crc32-glue.c b/arch/s390/lib/crc32-glue.c index 8f20a8e595c3..649ed7e8b99c 100644 --- a/arch/s390/lib/crc32-glue.c +++ b/arch/s390/lib/crc32-glue.c @@ -18,8 +18,6 @@ #define VX_ALIGNMENT 16L #define VX_ALIGN_MASK (VX_ALIGNMENT - 1) -static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vxrs); - /* * DEFINE_CRC32_VX() - Define a CRC-32 function using the vector extension * @@ -34,8 +32,7 @@ static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vxrs); unsigned long prealign, aligned, remaining; \ DECLARE_KERNEL_FPU_ONSTACK16(vxstate); \ \ - if (datalen < VX_MIN_LEN + VX_ALIGN_MASK || \ - !static_branch_likely(&have_vxrs)) \ + if (datalen < VX_MIN_LEN + VX_ALIGN_MASK || !cpu_has_vx()) \ return ___crc32_sw(crc, data, datalen); \ \ if ((unsigned long)data & VX_ALIGN_MASK) { \ @@ -66,8 +63,6 @@ DEFINE_CRC32_VX(crc32c_arch, crc32c_le_vgfm_16, crc32c_base) static int __init crc32_s390_init(void) { - if (cpu_have_feature(S390_CPU_FEATURE_VXRS)) - static_branch_enable(&have_vxrs); return 0; } arch_initcall(crc32_s390_init); @@ -79,10 +74,11 @@ module_exit(crc32_s390_exit); u32 crc32_optimizations(void) { - if (static_key_enabled(&have_vxrs)) + if (cpu_has_vx()) { return CRC32_LE_OPTIMIZATION | CRC32_BE_OPTIMIZATION | CRC32C_OPTIMIZATION; + } return 0; } EXPORT_SYMBOL(crc32_optimizations); From fea9ad4dde9bf6c65e72da0d4c1ae7969d0bb8bd Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 17 Apr 2025 09:38:29 -0700 Subject: [PATCH 03/16] s390/crc32: Remove no-op module init and exit functions Now that the crc32-s390 module init function is a no-op, there is no need to define it. Remove it. The removal of the init function also makes the exit function unnecessary, so remove that too. Acked-by: Heiko Carstens Link: https://lore.kernel.org/r/20250417163829.4599-1-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/s390/lib/crc32-glue.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/arch/s390/lib/crc32-glue.c b/arch/s390/lib/crc32-glue.c index 649ed7e8b99c..3c4b344417c1 100644 --- a/arch/s390/lib/crc32-glue.c +++ b/arch/s390/lib/crc32-glue.c @@ -61,17 +61,6 @@ DEFINE_CRC32_VX(crc32_le_arch, crc32_le_vgfm_16, crc32_le_base) DEFINE_CRC32_VX(crc32_be_arch, crc32_be_vgfm_16, crc32_be_base) DEFINE_CRC32_VX(crc32c_arch, crc32c_le_vgfm_16, crc32c_base) -static int __init crc32_s390_init(void) -{ - return 0; -} -arch_initcall(crc32_s390_init); - -static void __exit crc32_s390_exit(void) -{ -} -module_exit(crc32_s390_exit); - u32 crc32_optimizations(void) { if (cpu_has_vx()) { From 6cc25e4b7c819c183a21d6b9a4bcec84229131d1 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:32 -0700 Subject: [PATCH 04/16] arm/crc: drop "glue" from filenames The use of the term "glue" in filenames is a Crypto API-ism that rarely shows up elsewhere in lib/ or arch/*/lib/. I think adopting it there was a mistake. The library just uses standard functions, so the amount of code that could be considered "glue" is quite small. And while often the C functions just wrap the assembly functions, there are also cases like crc32c_arch() in arch/x86/lib/crc32-glue.c that blur the line by in-lining the actual implementation into the C function. That's not "glue code", but rather the actual code. Therefore, let's drop "glue" from the filenames and instead use e.g. crc32.c instead of crc32-glue.c. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250424002038.179114-2-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/arm/lib/Makefile | 4 ++-- arch/arm/lib/{crc-t10dif-glue.c => crc-t10dif.c} | 0 arch/arm/lib/{crc32-glue.c => crc32.c} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename arch/arm/lib/{crc-t10dif-glue.c => crc-t10dif.c} (100%) rename arch/arm/lib/{crc32-glue.c => crc32.c} (100%) diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 007874320937..d05dd672bcd9 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -47,7 +47,7 @@ endif obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o obj-$(CONFIG_CRC32_ARCH) += crc32-arm.o -crc32-arm-y := crc32-glue.o crc32-core.o +crc32-arm-y := crc32.o crc32-core.o obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-arm.o -crc-t10dif-arm-y := crc-t10dif-glue.o crc-t10dif-core.o +crc-t10dif-arm-y := crc-t10dif.o crc-t10dif-core.o diff --git a/arch/arm/lib/crc-t10dif-glue.c b/arch/arm/lib/crc-t10dif.c similarity index 100% rename from arch/arm/lib/crc-t10dif-glue.c rename to arch/arm/lib/crc-t10dif.c diff --git a/arch/arm/lib/crc32-glue.c b/arch/arm/lib/crc32.c similarity index 100% rename from arch/arm/lib/crc32-glue.c rename to arch/arm/lib/crc32.c From db6108d3ac91b7f09df366e0627d81803c703513 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:33 -0700 Subject: [PATCH 05/16] arm64/crc: drop "glue" from filenames The use of the term "glue" in filenames is a Crypto API-ism that rarely shows up elsewhere in lib/ or arch/*/lib/. I think adopting it there was a mistake. The library just uses standard functions, so the amount of code that could be considered "glue" is quite small. And while often the C functions just wrap the assembly functions, there are also cases like crc32c_arch() in arch/x86/lib/crc32-glue.c that blur the line by in-lining the actual implementation into the C function. That's not "glue code", but rather the actual code. Therefore, let's drop "glue" from the filenames and instead use e.g. crc32.c instead of crc32-glue.c. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250424002038.179114-3-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/arm64/lib/Makefile | 4 ++-- arch/arm64/lib/{crc-t10dif-glue.c => crc-t10dif.c} | 0 arch/arm64/lib/{crc32.S => crc32-core.S} | 0 arch/arm64/lib/{crc32-glue.c => crc32.c} | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename arch/arm64/lib/{crc-t10dif-glue.c => crc-t10dif.c} (100%) rename arch/arm64/lib/{crc32.S => crc32-core.S} (100%) rename arch/arm64/lib/{crc32-glue.c => crc32.c} (100%) diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile index 4d49dff721a8..d97e290619bc 100644 --- a/arch/arm64/lib/Makefile +++ b/arch/arm64/lib/Makefile @@ -14,10 +14,10 @@ endif lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o obj-$(CONFIG_CRC32_ARCH) += crc32-arm64.o -crc32-arm64-y := crc32.o crc32-glue.o +crc32-arm64-y := crc32.o crc32-core.o obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-arm64.o -crc-t10dif-arm64-y := crc-t10dif-glue.o crc-t10dif-core.o +crc-t10dif-arm64-y := crc-t10dif.o crc-t10dif-core.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/arm64/lib/crc-t10dif-glue.c b/arch/arm64/lib/crc-t10dif.c similarity index 100% rename from arch/arm64/lib/crc-t10dif-glue.c rename to arch/arm64/lib/crc-t10dif.c diff --git a/arch/arm64/lib/crc32.S b/arch/arm64/lib/crc32-core.S similarity index 100% rename from arch/arm64/lib/crc32.S rename to arch/arm64/lib/crc32-core.S diff --git a/arch/arm64/lib/crc32-glue.c b/arch/arm64/lib/crc32.c similarity index 100% rename from arch/arm64/lib/crc32-glue.c rename to arch/arm64/lib/crc32.c From 436490e86814ae409c1586fc2a8045455f735418 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:34 -0700 Subject: [PATCH 06/16] powerpc/crc: drop "glue" from filenames The use of the term "glue" in filenames is a Crypto API-ism that rarely shows up elsewhere in lib/ or arch/*/lib/. I think adopting it there was a mistake. The library just uses standard functions, so the amount of code that could be considered "glue" is quite small. And while often the C functions just wrap the assembly functions, there are also cases like crc32c_arch() in arch/x86/lib/crc32-glue.c that blur the line by in-lining the actual implementation into the C function. That's not "glue code", but rather the actual code. Therefore, let's drop "glue" from the filenames and instead use e.g. crc32.c instead of crc32-glue.c. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250424002038.179114-4-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/powerpc/lib/Makefile | 4 ++-- arch/powerpc/lib/{crc-t10dif-glue.c => crc-t10dif.c} | 0 arch/powerpc/lib/{crc32-glue.c => crc32.c} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename arch/powerpc/lib/{crc-t10dif-glue.c => crc-t10dif.c} (100%) rename arch/powerpc/lib/{crc32-glue.c => crc32.c} (100%) diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index dd8a4b52a0cc..27f8a0143860 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile @@ -79,9 +79,9 @@ CFLAGS_xor_vmx.o += -mhard-float -maltivec $(call cc-option,-mabi=altivec) CFLAGS_xor_vmx.o += -isystem $(shell $(CC) -print-file-name=include) obj-$(CONFIG_CRC32_ARCH) += crc32-powerpc.o -crc32-powerpc-y := crc32-glue.o crc32c-vpmsum_asm.o +crc32-powerpc-y := crc32.o crc32c-vpmsum_asm.o obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-powerpc.o -crc-t10dif-powerpc-y := crc-t10dif-glue.o crct10dif-vpmsum_asm.o +crc-t10dif-powerpc-y := crc-t10dif.o crct10dif-vpmsum_asm.o obj-$(CONFIG_PPC64) += $(obj64-y) diff --git a/arch/powerpc/lib/crc-t10dif-glue.c b/arch/powerpc/lib/crc-t10dif.c similarity index 100% rename from arch/powerpc/lib/crc-t10dif-glue.c rename to arch/powerpc/lib/crc-t10dif.c diff --git a/arch/powerpc/lib/crc32-glue.c b/arch/powerpc/lib/crc32.c similarity index 100% rename from arch/powerpc/lib/crc32-glue.c rename to arch/powerpc/lib/crc32.c From b4fa54d654b3531261d1fde3cb73ceae7a98806f Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:35 -0700 Subject: [PATCH 07/16] powerpc/crc: rename crc32-vpmsum_core.S to crc-vpmsum-template.S Rename crc32-vpmsum_core.S to crc-vpmsum-template.S to properly convey that (a) it actually generates code for both 32-bit and 16-bit CRCs, not just 32-bit CRCs; and (b) it has "template" semantics, like x86's crc-pclmul-template.S, in the sense that it's included by other files. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250424002038.179114-5-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/powerpc/lib/{crc32-vpmsum_core.S => crc-vpmsum-template.S} | 0 arch/powerpc/lib/crc32c-vpmsum_asm.S | 2 +- arch/powerpc/lib/crct10dif-vpmsum_asm.S | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename arch/powerpc/lib/{crc32-vpmsum_core.S => crc-vpmsum-template.S} (100%) diff --git a/arch/powerpc/lib/crc32-vpmsum_core.S b/arch/powerpc/lib/crc-vpmsum-template.S similarity index 100% rename from arch/powerpc/lib/crc32-vpmsum_core.S rename to arch/powerpc/lib/crc-vpmsum-template.S diff --git a/arch/powerpc/lib/crc32c-vpmsum_asm.S b/arch/powerpc/lib/crc32c-vpmsum_asm.S index bf442004ea1f..1b35c55cce0a 100644 --- a/arch/powerpc/lib/crc32c-vpmsum_asm.S +++ b/arch/powerpc/lib/crc32c-vpmsum_asm.S @@ -839,4 +839,4 @@ #define CRC_FUNCTION_NAME __crc32c_vpmsum #define REFLECT -#include "crc32-vpmsum_core.S" +#include "crc-vpmsum-template.S" diff --git a/arch/powerpc/lib/crct10dif-vpmsum_asm.S b/arch/powerpc/lib/crct10dif-vpmsum_asm.S index f0b93a0fe168..47a6266d89a8 100644 --- a/arch/powerpc/lib/crct10dif-vpmsum_asm.S +++ b/arch/powerpc/lib/crct10dif-vpmsum_asm.S @@ -842,4 +842,4 @@ .octa 0x0000000000000000000000018bb70000 #define CRC_FUNCTION_NAME __crct10dif_vpmsum -#include "crc32-vpmsum_core.S" +#include "crc-vpmsum-template.S" From fa7ed85c9bdcd408fa5e85577a64a4d2a10dd807 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:36 -0700 Subject: [PATCH 08/16] s390/crc: drop "glue" from filenames The use of the term "glue" in filenames is a Crypto API-ism that does not show up elsewhere in lib/. I think adopting it there was a mistake. The library just uses standard functions, so the amount of code that could be considered "glue" is quite small. And while often the C functions just wrap the assembly functions, there are also cases like crc32c_arch() in arch/x86/lib/crc32-glue.c that blur the line by in-lining the actual implementation into the C function. That's not "glue code", but rather the actual code. Therefore, let's drop "glue" from the filenames and instead use e.g. crc32.c instead of crc32-glue.c. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Acked-by: Heiko Carstens Link: https://lore.kernel.org/r/20250424002038.179114-6-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/s390/lib/Makefile | 2 +- arch/s390/lib/{crc32-glue.c => crc32.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename arch/s390/lib/{crc32-glue.c => crc32.c} (100%) diff --git a/arch/s390/lib/Makefile b/arch/s390/lib/Makefile index 14bbfe50033c..271a1c407121 100644 --- a/arch/s390/lib/Makefile +++ b/arch/s390/lib/Makefile @@ -26,4 +26,4 @@ lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o obj-$(CONFIG_EXPOLINE_EXTERN) += expoline.o obj-$(CONFIG_CRC32_ARCH) += crc32-s390.o -crc32-s390-y := crc32-glue.o crc32le-vx.o crc32be-vx.o +crc32-s390-y := crc32.o crc32le-vx.o crc32be-vx.o diff --git a/arch/s390/lib/crc32-glue.c b/arch/s390/lib/crc32.c similarity index 100% rename from arch/s390/lib/crc32-glue.c rename to arch/s390/lib/crc32.c From ee858d83c59d95e08551a9dc270bedca4b72137d Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:37 -0700 Subject: [PATCH 09/16] sparc/crc: drop "glue" from filenames The use of the term "glue" in filenames is a Crypto API-ism that rarely shows up elsewhere in lib/ or arch/*/lib/. I think adopting it there was a mistake. The library just uses standard functions, so the amount of code that could be considered "glue" is quite small. And while often the C functions just wrap the assembly functions, there are also cases like crc32c_arch() in arch/x86/lib/crc32-glue.c that blur the line by in-lining the actual implementation into the C function. That's not "glue code", but rather the actual code. Therefore, let's drop "glue" from the filenames and instead use e.g. crc32.c instead of crc32-glue.c. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250424002038.179114-7-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/sparc/lib/Makefile | 2 +- arch/sparc/lib/{crc32_glue.c => crc32.c} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename arch/sparc/lib/{crc32_glue.c => crc32.c} (97%) diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile index 5724d0f356eb..ef8860eb3f3d 100644 --- a/arch/sparc/lib/Makefile +++ b/arch/sparc/lib/Makefile @@ -54,4 +54,4 @@ obj-$(CONFIG_SPARC64) += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o obj-$(CONFIG_SPARC64) += PeeCeeI.o obj-$(CONFIG_CRC32_ARCH) += crc32-sparc.o -crc32-sparc-y := crc32_glue.o crc32c_asm.o +crc32-sparc-y := crc32.o crc32c_asm.o diff --git a/arch/sparc/lib/crc32_glue.c b/arch/sparc/lib/crc32.c similarity index 97% rename from arch/sparc/lib/crc32_glue.c rename to arch/sparc/lib/crc32.c index d34e7cc7e1a1..428fd5588e93 100644 --- a/arch/sparc/lib/crc32_glue.c +++ b/arch/sparc/lib/crc32.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Glue code for CRC32C optimized for sparc64 crypto opcodes. +/* CRC32c (Castagnoli), sparc64 crc32c opcode accelerated * * This is based largely upon arch/x86/crypto/crc32c-intel.c * From 35984c730dea1a9fdd5d931f298849605850856a Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 23 Apr 2025 17:20:38 -0700 Subject: [PATCH 10/16] x86/crc: drop "glue" from filenames The use of the term "glue" in filenames is a Crypto API-ism that rarely shows up elsewhere in lib/ or arch/*/lib/. I think adopting it there was a mistake. The library just uses standard functions, so the amount of code that could be considered "glue" is quite small. And while often the C functions just wrap the assembly functions, there are also cases like crc32c_arch() in arch/x86/lib/crc32-glue.c that blur the line by in-lining the actual implementation into the C function. That's not "glue code", but rather the actual code. Therefore, let's drop "glue" from the filenames and instead use e.g. crc32.c instead of crc32-glue.c. Reviewed-by: "Martin K. Petersen" Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250424002038.179114-8-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/x86/lib/Makefile | 6 +++--- arch/x86/lib/{crc-t10dif-glue.c => crc-t10dif.c} | 0 arch/x86/lib/{crc32-glue.c => crc32.c} | 0 arch/x86/lib/{crc64-glue.c => crc64.c} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename arch/x86/lib/{crc-t10dif-glue.c => crc-t10dif.c} (100%) rename arch/x86/lib/{crc32-glue.c => crc32.c} (100%) rename arch/x86/lib/{crc64-glue.c => crc64.c} (100%) diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 1c50352eb49f..7cf8681cba0f 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -39,14 +39,14 @@ lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o lib-$(CONFIG_MITIGATION_RETPOLINE) += retpoline.o obj-$(CONFIG_CRC32_ARCH) += crc32-x86.o -crc32-x86-y := crc32-glue.o crc32-pclmul.o +crc32-x86-y := crc32.o crc32-pclmul.o crc32-x86-$(CONFIG_64BIT) += crc32c-3way.o obj-$(CONFIG_CRC64_ARCH) += crc64-x86.o -crc64-x86-y := crc64-glue.o crc64-pclmul.o +crc64-x86-y := crc64.o crc64-pclmul.o obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-x86.o -crc-t10dif-x86-y := crc-t10dif-glue.o crc16-msb-pclmul.o +crc-t10dif-x86-y := crc-t10dif.o crc16-msb-pclmul.o obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o obj-y += iomem.o diff --git a/arch/x86/lib/crc-t10dif-glue.c b/arch/x86/lib/crc-t10dif.c similarity index 100% rename from arch/x86/lib/crc-t10dif-glue.c rename to arch/x86/lib/crc-t10dif.c diff --git a/arch/x86/lib/crc32-glue.c b/arch/x86/lib/crc32.c similarity index 100% rename from arch/x86/lib/crc32-glue.c rename to arch/x86/lib/crc32.c diff --git a/arch/x86/lib/crc64-glue.c b/arch/x86/lib/crc64.c similarity index 100% rename from arch/x86/lib/crc64-glue.c rename to arch/x86/lib/crc64.c From 46e3311607d6c18a760fba4afbd5d24d42abb0f3 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 28 Apr 2025 09:24:58 -0700 Subject: [PATCH 11/16] crypto: crc32 - remove "generic" from file and module names Since crc32_generic.c and crc32c_generic.c now expose both the generic and architecture-optimized implementations via the crypto_shash API, rather than just the generic implementations as they originally did, remove the "generic" part of the filenames and module names: crypto/crc32-generic.c => crypto/crc32.c crypto/crc32c-generic.c => crypto/crc32c.c crc32-generic.ko => crc32-cryptoapi.ko crc32c-generic.ko => crc32c-cryptoapi.ko The reason for adding the -cryptoapi suffixes to the module names is to avoid a module name collision with crc32.ko which is the library API. We could instead rename the library module to libcrc32.ko. However, while lib/crypto/ uses that convention, the rest of lib/ doesn't. Since the library API is the primary API for CRC-32, I'd like to keep the unsuffixed name for it and make the Crypto API modules use a suffix. Acked-by: Arnd Bergmann Link: https://lore.kernel.org/r/20250428162458.29732-1-ebiggers@kernel.org Signed-off-by: Eric Biggers --- crypto/Makefile | 10 ++++++---- crypto/{crc32_generic.c => crc32.c} | 0 crypto/{crc32c_generic.c => crc32c.c} | 0 3 files changed, 6 insertions(+), 4 deletions(-) rename crypto/{crc32_generic.c => crc32.c} (100%) rename crypto/{crc32c_generic.c => crc32c.c} (100%) diff --git a/crypto/Makefile b/crypto/Makefile index 0e6ab5ffd3f7..186f968baa39 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -152,10 +152,12 @@ obj-$(CONFIG_CRYPTO_CHACHA20) += chacha_generic.o obj-$(CONFIG_CRYPTO_POLY1305) += poly1305_generic.o obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o -obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o -obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o -CFLAGS_crc32c_generic.o += -DARCH=$(ARCH) -CFLAGS_crc32_generic.o += -DARCH=$(ARCH) +obj-$(CONFIG_CRYPTO_CRC32C) += crc32c-cryptoapi.o +crc32c-cryptoapi-y := crc32c.o +CFLAGS_crc32c.o += -DARCH=$(ARCH) +obj-$(CONFIG_CRYPTO_CRC32) += crc32-cryptoapi.o +crc32-cryptoapi-y := crc32.o +CFLAGS_crc32.o += -DARCH=$(ARCH) obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o obj-$(CONFIG_CRYPTO_KRB5ENC) += krb5enc.o obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o diff --git a/crypto/crc32_generic.c b/crypto/crc32.c similarity index 100% rename from crypto/crc32_generic.c rename to crypto/crc32.c diff --git a/crypto/crc32c_generic.c b/crypto/crc32c.c similarity index 100% rename from crypto/crc32c_generic.c rename to crypto/crc32c.c From 648c7fb16f609c53d2659fefb5088af619485ab4 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 9 May 2025 20:59:59 -0700 Subject: [PATCH 12/16] lib/crc: make arch-optimized code use subsys_initcall Make the architecture-optimized CRC code do its CPU feature checks in subsys_initcalls instead of arch_initcalls. This makes it consistent with arch/*/lib/crypto/ and ensures that it runs after initcalls that possibly could be a prerequisite for kernel-mode FPU, such as x86's xfd_update_static_branch() and loongarch's init_euen_mask(). Note: as far as I can tell, x86's xfd_update_static_branch() isn't *actually* needed for kernel-mode FPU. loongarch's init_euen_mask() is needed to enable save/restore of the vector registers, but loongarch doesn't yet have any CRC or crypto code that uses vector registers anyway. Regardless, let's be consistent with arch/*/lib/crypto/ and robust against any potential future dependency on an arch_initcall. Link: https://lore.kernel.org/r/20250510035959.87995-1-ebiggers@kernel.org Signed-off-by: Eric Biggers --- arch/arm/lib/crc-t10dif.c | 2 +- arch/arm/lib/crc32.c | 2 +- arch/arm64/lib/crc-t10dif.c | 2 +- arch/loongarch/lib/crc32-loongarch.c | 2 +- arch/mips/lib/crc32-mips.c | 2 +- arch/powerpc/lib/crc-t10dif.c | 2 +- arch/powerpc/lib/crc32.c | 2 +- arch/sparc/lib/crc32.c | 2 +- arch/x86/lib/crc-t10dif.c | 2 +- arch/x86/lib/crc32.c | 2 +- arch/x86/lib/crc64.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/arm/lib/crc-t10dif.c b/arch/arm/lib/crc-t10dif.c index 382437094bdd..1093f8ec13b0 100644 --- a/arch/arm/lib/crc-t10dif.c +++ b/arch/arm/lib/crc-t10dif.c @@ -60,7 +60,7 @@ static int __init crc_t10dif_arm_init(void) } return 0; } -arch_initcall(crc_t10dif_arm_init); +subsys_initcall(crc_t10dif_arm_init); static void __exit crc_t10dif_arm_exit(void) { diff --git a/arch/arm/lib/crc32.c b/arch/arm/lib/crc32.c index 7ef7db9c0de7..f2bef8849c7c 100644 --- a/arch/arm/lib/crc32.c +++ b/arch/arm/lib/crc32.c @@ -103,7 +103,7 @@ static int __init crc32_arm_init(void) static_branch_enable(&have_pmull); return 0; } -arch_initcall(crc32_arm_init); +subsys_initcall(crc32_arm_init); static void __exit crc32_arm_exit(void) { diff --git a/arch/arm64/lib/crc-t10dif.c b/arch/arm64/lib/crc-t10dif.c index 99d0b5668a28..c2ffe4fdb59d 100644 --- a/arch/arm64/lib/crc-t10dif.c +++ b/arch/arm64/lib/crc-t10dif.c @@ -61,7 +61,7 @@ static int __init crc_t10dif_arm64_init(void) } return 0; } -arch_initcall(crc_t10dif_arm64_init); +subsys_initcall(crc_t10dif_arm64_init); static void __exit crc_t10dif_arm64_exit(void) { diff --git a/arch/loongarch/lib/crc32-loongarch.c b/arch/loongarch/lib/crc32-loongarch.c index 8e6d1f517e73..b37cd8537b45 100644 --- a/arch/loongarch/lib/crc32-loongarch.c +++ b/arch/loongarch/lib/crc32-loongarch.c @@ -114,7 +114,7 @@ static int __init crc32_loongarch_init(void) static_branch_enable(&have_crc32); return 0; } -arch_initcall(crc32_loongarch_init); +subsys_initcall(crc32_loongarch_init); static void __exit crc32_loongarch_exit(void) { diff --git a/arch/mips/lib/crc32-mips.c b/arch/mips/lib/crc32-mips.c index 84df361e7181..45e4d2c9fbf5 100644 --- a/arch/mips/lib/crc32-mips.c +++ b/arch/mips/lib/crc32-mips.c @@ -163,7 +163,7 @@ static int __init crc32_mips_init(void) static_branch_enable(&have_crc32); return 0; } -arch_initcall(crc32_mips_init); +subsys_initcall(crc32_mips_init); static void __exit crc32_mips_exit(void) { diff --git a/arch/powerpc/lib/crc-t10dif.c b/arch/powerpc/lib/crc-t10dif.c index ddd5c4088f50..4253842cc50d 100644 --- a/arch/powerpc/lib/crc-t10dif.c +++ b/arch/powerpc/lib/crc-t10dif.c @@ -71,7 +71,7 @@ static int __init crc_t10dif_powerpc_init(void) static_branch_enable(&have_vec_crypto); return 0; } -arch_initcall(crc_t10dif_powerpc_init); +subsys_initcall(crc_t10dif_powerpc_init); static void __exit crc_t10dif_powerpc_exit(void) { diff --git a/arch/powerpc/lib/crc32.c b/arch/powerpc/lib/crc32.c index 42f2dd3c85dd..77e5a37006f0 100644 --- a/arch/powerpc/lib/crc32.c +++ b/arch/powerpc/lib/crc32.c @@ -72,7 +72,7 @@ static int __init crc32_powerpc_init(void) static_branch_enable(&have_vec_crypto); return 0; } -arch_initcall(crc32_powerpc_init); +subsys_initcall(crc32_powerpc_init); static void __exit crc32_powerpc_exit(void) { diff --git a/arch/sparc/lib/crc32.c b/arch/sparc/lib/crc32.c index 428fd5588e93..40d4720a42a1 100644 --- a/arch/sparc/lib/crc32.c +++ b/arch/sparc/lib/crc32.c @@ -74,7 +74,7 @@ static int __init crc32_sparc_init(void) pr_info("Using sparc64 crc32c opcode optimized CRC32C implementation\n"); return 0; } -arch_initcall(crc32_sparc_init); +subsys_initcall(crc32_sparc_init); static void __exit crc32_sparc_exit(void) { diff --git a/arch/x86/lib/crc-t10dif.c b/arch/x86/lib/crc-t10dif.c index d073b3678edc..db7ce59c31ac 100644 --- a/arch/x86/lib/crc-t10dif.c +++ b/arch/x86/lib/crc-t10dif.c @@ -29,7 +29,7 @@ static int __init crc_t10dif_x86_init(void) } return 0; } -arch_initcall(crc_t10dif_x86_init); +subsys_initcall(crc_t10dif_x86_init); static void __exit crc_t10dif_x86_exit(void) { diff --git a/arch/x86/lib/crc32.c b/arch/x86/lib/crc32.c index e6a6285cfca8..d09343e2cea9 100644 --- a/arch/x86/lib/crc32.c +++ b/arch/x86/lib/crc32.c @@ -88,7 +88,7 @@ static int __init crc32_x86_init(void) } return 0; } -arch_initcall(crc32_x86_init); +subsys_initcall(crc32_x86_init); static void __exit crc32_x86_exit(void) { diff --git a/arch/x86/lib/crc64.c b/arch/x86/lib/crc64.c index 1214ee726c16..351a09f5813e 100644 --- a/arch/x86/lib/crc64.c +++ b/arch/x86/lib/crc64.c @@ -39,7 +39,7 @@ static int __init crc64_x86_init(void) } return 0; } -arch_initcall(crc64_x86_init); +subsys_initcall(crc64_x86_init); static void __exit crc64_x86_exit(void) { From e8d72b766adcde14188e68968f3cd05f4321691d Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 10 May 2025 22:21:51 -0700 Subject: [PATCH 13/16] MAINTAINERS: add crc_kunit.c back to CRC LIBRARY Restore lib/tests/crc_kunit.c to CRC LIBRARY following the rename in commit db6fe4d61ece ("lib: Move KUnit tests into tests/ subdirectory") which made it no longer match the file pattern lib/crc*. Reviewed-by: Kees Cook Link: https://lore.kernel.org/r/20250511052151.420228-1-ebiggers@kernel.org Signed-off-by: Eric Biggers --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index c59316109e3f..ac70e19c53cf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6253,6 +6253,7 @@ F: Documentation/staging/crc* F: arch/*/lib/crc* F: include/linux/crc* F: lib/crc* +F: lib/tests/crc_kunit.c F: scripts/gen-crc-consts.py CREATIVE SB0540 From 0769ebe279c0f07f5f01ef2dca9f425803039755 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 12 May 2025 19:21:14 -0700 Subject: [PATCH 14/16] w1: ds2406: use crc16() instead of crc16_byte() loop Instead of looping through each byte and calling crc16_byte(), instead just call crc16() on the whole buffer. No functional change. Acked-by: Krzysztof Kozlowski Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250513022115.39109-2-ebiggers@kernel.org Signed-off-by: Eric Biggers --- drivers/w1/slaves/w1_ds2406.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2406.c b/drivers/w1/slaves/w1_ds2406.c index 1cae9b243ff8..76026d615111 100644 --- a/drivers/w1/slaves/w1_ds2406.c +++ b/drivers/w1/slaves/w1_ds2406.c @@ -29,8 +29,6 @@ static ssize_t w1_f12_read_state( { u8 w1_buf[6] = {W1_F12_FUNC_READ_STATUS, 7, 0, 0, 0, 0}; struct w1_slave *sl = kobj_to_w1_slave(kobj); - u16 crc = 0; - int i; ssize_t rtnval = 1; if (off != 0) @@ -47,9 +45,7 @@ static ssize_t w1_f12_read_state( w1_write_block(sl->master, w1_buf, 3); w1_read_block(sl->master, w1_buf+3, 3); - for (i = 0; i < 6; i++) - crc = crc16_byte(crc, w1_buf[i]); - if (crc == 0xb001) /* good read? */ + if (crc16(0, w1_buf, sizeof(w1_buf)) == 0xb001) /* good read? */ *buf = ((w1_buf[3]>>5)&3)|0x30; else rtnval = -EIO; @@ -66,8 +62,6 @@ static ssize_t w1_f12_write_output( { struct w1_slave *sl = kobj_to_w1_slave(kobj); u8 w1_buf[6] = {W1_F12_FUNC_WRITE_STATUS, 7, 0, 0, 0, 0}; - u16 crc = 0; - int i; ssize_t rtnval = 1; if (count != 1 || off != 0) @@ -83,9 +77,7 @@ static ssize_t w1_f12_write_output( w1_buf[3] = (((*buf)&3)<<5)|0x1F; w1_write_block(sl->master, w1_buf, 4); w1_read_block(sl->master, w1_buf+4, 2); - for (i = 0; i < 6; i++) - crc = crc16_byte(crc, w1_buf[i]); - if (crc == 0xb001) /* good read? */ + if (crc16(0, w1_buf, sizeof(w1_buf)) == 0xb001) /* good read? */ w1_write_8(sl->master, 0xFF); else rtnval = -EIO; From 3937f6db6e932c560a0f9ee2cd2a4fdcc314dadf Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 12 May 2025 19:21:15 -0700 Subject: [PATCH 15/16] lib/crc16: unexport crc16_table and crc16_byte() Now that neither crc16_table nor crc16_byte() is used outside lib/crc16.c, fold them into lib/crc16.c. Acked-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20250513022115.39109-3-ebiggers@kernel.org Signed-off-by: Eric Biggers --- include/linux/crc16.h | 9 +-------- lib/crc16.c | 9 ++++----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/linux/crc16.h b/include/linux/crc16.h index 9fa74529b317..b861d969b161 100644 --- a/include/linux/crc16.h +++ b/include/linux/crc16.h @@ -15,14 +15,7 @@ #include -extern u16 const crc16_table[256]; - -extern u16 crc16(u16 crc, const u8 *buffer, size_t len); - -static inline u16 crc16_byte(u16 crc, const u8 data) -{ - return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff]; -} +u16 crc16(u16 crc, const u8 *p, size_t len); #endif /* __CRC16_H */ diff --git a/lib/crc16.c b/lib/crc16.c index 5c3a803c01e0..9c71eda9bf4b 100644 --- a/lib/crc16.c +++ b/lib/crc16.c @@ -8,7 +8,7 @@ #include /** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ -u16 const crc16_table[256] = { +static const u16 crc16_table[256] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, @@ -42,20 +42,19 @@ u16 const crc16_table[256] = { 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 }; -EXPORT_SYMBOL(crc16_table); /** * crc16 - compute the CRC-16 for the data buffer * @crc: previous CRC value - * @buffer: data pointer + * @p: data pointer * @len: number of bytes in the buffer * * Returns the updated CRC value. */ -u16 crc16(u16 crc, u8 const *buffer, size_t len) +u16 crc16(u16 crc, const u8 *p, size_t len) { while (len--) - crc = crc16_byte(crc, *buffer++); + crc = (crc >> 8) ^ crc16_table[(crc & 0xff) ^ *p++]; return crc; } EXPORT_SYMBOL(crc16); From 289c99bec7eed918ab37c62cbb29a2e3f58fb1fb Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 13 May 2025 22:24:09 -0700 Subject: [PATCH 16/16] lib/crc32: add SPDX license identifier lib/crc32.c and include/linux/crc32.h got missed by the bulk SPDX conversion because of the nonstandard explanation of the license. However, crc32.c clearly states that it's licensed under the GNU General Public License, Version 2. And the comment in crc32.h clearly indicates that it's meant to have the same license as crc32.c. Therefore, apply SPDX-License-Identifier: GPL-2.0-only to both files. Reviewed-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Link: https://lore.kernel.org/r/20250514052409.194822-1-ebiggers@kernel.org Signed-off-by: Eric Biggers --- include/linux/crc32.h | 5 +---- lib/crc32.c | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/linux/crc32.h b/include/linux/crc32.h index 69c2e8bb3782..569dc13f139f 100644 --- a/include/linux/crc32.h +++ b/include/linux/crc32.h @@ -1,7 +1,4 @@ -/* - * crc32.h - * See linux/lib/crc32.c for license and changes - */ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _LINUX_CRC32_H #define _LINUX_CRC32_H diff --git a/lib/crc32.c b/lib/crc32.c index fddd424ff224..e690026f44f7 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Aug 8, 2011 Bob Pearson with help from Joakim Tjernlund and George Spelvin * cleaned up code to current version of sparse and added the slicing-by-8 @@ -19,9 +20,6 @@ * drivers/net/smc9194.c uses seed ~0, doesn't xor with ~0. * fs/jffs2 uses seed 0, doesn't xor with ~0. * fs/partitions/efi.c uses seed ~0, xor's with ~0. - * - * This source code is licensed under the GNU General Public License, - * Version 2. See the file COPYING for more details. */ /* see: Documentation/staging/crc32.rst for a description of algorithms */