-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc/crc32: expose CRC32 functions through lib
Move the powerpc CRC32C assembly code into the lib directory and wire it up to the library interface. This allows it to be used without going through the crypto API. It remains usable via the crypto API too via the shash algorithms that use the library interface. Thus all the arch-specific "shash" code becomes unnecessary and is removed. Note: to see the diff from arch/powerpc/crypto/crc32c-vpmsum_glue.c to arch/powerpc/lib/crc32-glue.c, view this commit with 'git show -M10'. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20241202010844.144356-9-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
- Loading branch information
Eric Biggers
committed
Dec 2, 2024
1 parent
289c270
commit 372ff60
Showing
11 changed files
with
98 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <linux/crc32.h> | ||
#include <crypto/internal/simd.h> | ||
#include <linux/init.h> | ||
#include <linux/module.h> | ||
#include <linux/kernel.h> | ||
#include <linux/cpufeature.h> | ||
#include <asm/simd.h> | ||
#include <asm/switch_to.h> | ||
|
||
#define VMX_ALIGN 16 | ||
#define VMX_ALIGN_MASK (VMX_ALIGN-1) | ||
|
||
#define VECTOR_BREAKPOINT 512 | ||
|
||
static DEFINE_STATIC_KEY_FALSE(have_vec_crypto); | ||
|
||
u32 __crc32c_vpmsum(u32 crc, const u8 *p, size_t len); | ||
|
||
u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) | ||
{ | ||
return crc32_le_base(crc, p, len); | ||
} | ||
EXPORT_SYMBOL(crc32_le_arch); | ||
|
||
u32 crc32c_le_arch(u32 crc, const u8 *p, size_t len) | ||
{ | ||
unsigned int prealign; | ||
unsigned int tail; | ||
|
||
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || | ||
!static_branch_likely(&have_vec_crypto) || !crypto_simd_usable()) | ||
return crc32c_le_base(crc, p, len); | ||
|
||
if ((unsigned long)p & VMX_ALIGN_MASK) { | ||
prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK); | ||
crc = crc32c_le_base(crc, p, prealign); | ||
len -= prealign; | ||
p += prealign; | ||
} | ||
|
||
if (len & ~VMX_ALIGN_MASK) { | ||
preempt_disable(); | ||
pagefault_disable(); | ||
enable_kernel_altivec(); | ||
crc = __crc32c_vpmsum(crc, p, len & ~VMX_ALIGN_MASK); | ||
disable_kernel_altivec(); | ||
pagefault_enable(); | ||
preempt_enable(); | ||
} | ||
|
||
tail = len & VMX_ALIGN_MASK; | ||
if (tail) { | ||
p += len & ~VMX_ALIGN_MASK; | ||
crc = crc32c_le_base(crc, p, tail); | ||
} | ||
|
||
return crc; | ||
} | ||
EXPORT_SYMBOL(crc32c_le_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); | ||
|
||
static int __init crc32_powerpc_init(void) | ||
{ | ||
if (cpu_has_feature(CPU_FTR_ARCH_207S) && | ||
(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO)) | ||
static_branch_enable(&have_vec_crypto); | ||
return 0; | ||
} | ||
arch_initcall(crc32_powerpc_init); | ||
|
||
static void __exit crc32_powerpc_exit(void) | ||
{ | ||
} | ||
module_exit(crc32_powerpc_exit); | ||
|
||
u32 crc32_optimizations(void) | ||
{ | ||
if (static_key_enabled(&have_vec_crypto)) | ||
return CRC32C_OPTIMIZATION; | ||
return 0; | ||
} | ||
EXPORT_SYMBOL(crc32_optimizations); | ||
|
||
MODULE_AUTHOR("Anton Blanchard <anton@samba.org>"); | ||
MODULE_DESCRIPTION("CRC32C using vector polynomial multiply-sum instructions"); | ||
MODULE_LICENSE("GPL"); |
File renamed without changes.
File renamed without changes.