]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
powerpc/crc-t10dif: expose CRC-T10DIF function through lib
authorEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2024 01:20:51 +0000 (17:20 -0800)
committerEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2024 01:23:13 +0000 (17:23 -0800)
Move the powerpc CRC-T10DIF 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/crct10dif-vpmsum_glue.c
to arch/powerpc/lib/crc-t10dif-glue.c, view this commit with
'git show -M10'.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20241202012056.209768-8-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
arch/powerpc/Kconfig
arch/powerpc/configs/powernv_defconfig
arch/powerpc/configs/ppc64_defconfig
arch/powerpc/crypto/Kconfig
arch/powerpc/crypto/Makefile
arch/powerpc/lib/Makefile
arch/powerpc/lib/crc-t10dif-glue.c [moved from arch/powerpc/crypto/crct10dif-vpmsum_glue.c with 50% similarity]
arch/powerpc/lib/crct10dif-vpmsum_asm.S [moved from arch/powerpc/crypto/crct10dif-vpmsum_asm.S with 99% similarity]

index b5050a09a27f85f313ba279ed7111ffd00725c32..da0ac6697ac570eed1a2fad4cbca2fd05d02ae2a 100644 (file)
@@ -128,6 +128,7 @@ config PPC
        select ARCH_ENABLE_MEMORY_HOTREMOVE
        select ARCH_HAS_COPY_MC                 if PPC64
        select ARCH_HAS_CRC32                   if PPC64 && ALTIVEC
+       select ARCH_HAS_CRC_T10DIF              if PPC64 && ALTIVEC
        select ARCH_HAS_CURRENT_STACK_POINTER
        select ARCH_HAS_DEBUG_VIRTUAL
        select ARCH_HAS_DEBUG_VM_PGTABLE
index 4a7ddea05b4db7c943c72a761628783e7cbec544..6b6d7467fecfded2180cf2091beec94f708f8a8d 100644 (file)
@@ -320,7 +320,6 @@ CONFIG_XMON=y
 CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_PCBC=m
 CONFIG_CRYPTO_HMAC=y
-CONFIG_CRYPTO_CRCT10DIF_VPMSUM=m
 CONFIG_CRYPTO_MD5_PPC=m
 CONFIG_CRYPTO_MICHAEL_MIC=m
 CONFIG_CRYPTO_SHA1_PPC=m
index 58e5f4488da467b8c69467c88bbc25728fc61c0e..15101f5c32381d94144a5ff9314e29711b817b58 100644 (file)
@@ -389,7 +389,6 @@ CONFIG_CRYPTO_MICHAEL_MIC=m
 CONFIG_CRYPTO_SHA256=y
 CONFIG_CRYPTO_WP512=m
 CONFIG_CRYPTO_LZO=m
-CONFIG_CRYPTO_CRCT10DIF_VPMSUM=m
 CONFIG_CRYPTO_VPMSUM_TESTER=m
 CONFIG_CRYPTO_MD5_PPC=m
 CONFIG_CRYPTO_SHA1_PPC=m
index 2d89e35b3cddd0efed4511af710bf9509ed55e6c..45376f1a43bdb563fd4c36c8384f6578bd907b96 100644 (file)
@@ -13,21 +13,10 @@ config CRYPTO_CURVE25519_PPC64
          Architecture: PowerPC64
          - Little-endian
 
-config CRYPTO_CRCT10DIF_VPMSUM
-       tristate "CRC32T10DIF"
-       depends on PPC64 && ALTIVEC && CRC_T10DIF
-       select CRYPTO_HASH
-       help
-         CRC16 CRC algorithm used for the T10 (SCSI) Data Integrity Field (DIF)
-
-         Architecture: powerpc64 using
-         - AltiVec extensions
-
-         Enable on POWER8 and newer processors for improved performance.
-
 config CRYPTO_VPMSUM_TESTER
        tristate "CRC32c and CRC32T10DIF hardware acceleration tester"
-       depends on CRYPTO_CRCT10DIF_VPMSUM && CRYPTO_CRC32C && CRC32_ARCH
+       depends on CRYPTO_CRC32C && CRC32_ARCH
+       depends on CRYPTO_CRCT10DIF && CRC_T10DIF_ARCH
        help
          Stress test for CRC32c and CRCT10DIF algorithms implemented with
          powerpc64 AltiVec extensions (POWER8 vpmsum instructions).
index 54486192273c24856a6e1b2b0447061ca6175c66..d2238ac7e52ced8bf8294f08e9adc01c476262ef 100644 (file)
@@ -10,7 +10,6 @@ obj-$(CONFIG_CRYPTO_MD5_PPC) += md5-ppc.o
 obj-$(CONFIG_CRYPTO_SHA1_PPC) += sha1-powerpc.o
 obj-$(CONFIG_CRYPTO_SHA1_PPC_SPE) += sha1-ppc-spe.o
 obj-$(CONFIG_CRYPTO_SHA256_PPC_SPE) += sha256-ppc-spe.o
-obj-$(CONFIG_CRYPTO_CRCT10DIF_VPMSUM) += crct10dif-vpmsum.o
 obj-$(CONFIG_CRYPTO_VPMSUM_TESTER) += crc-vpmsum_test.o
 obj-$(CONFIG_CRYPTO_AES_GCM_P10) += aes-gcm-p10-crypto.o
 obj-$(CONFIG_CRYPTO_CHACHA20_P10) += chacha-p10-crypto.o
@@ -23,7 +22,6 @@ md5-ppc-y := md5-asm.o md5-glue.o
 sha1-powerpc-y := sha1-powerpc-asm.o sha1.o
 sha1-ppc-spe-y := sha1-spe-asm.o sha1-spe-glue.o
 sha256-ppc-spe-y := sha256-spe-asm.o sha256-spe-glue.o
-crct10dif-vpmsum-y := crct10dif-vpmsum_asm.o crct10dif-vpmsum_glue.o
 aes-gcm-p10-crypto-y := aes-gcm-p10-glue.o aes-gcm-p10.o ghashp10-ppc.o aesp10-ppc.o
 chacha-p10-crypto-y := chacha-p10-glue.o chacha-p10le-8x.o
 poly1305-p10-crypto-y := poly1305-p10-glue.o poly1305-p10le_64.o
index da9381a1c95b3174524d06ec90dab227a7d5f710..dd8a4b52a0ccb34b9f8f6b9c456f6fa805f95779 100644 (file)
@@ -81,4 +81,7 @@ 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
 
+obj-$(CONFIG_CRC_T10DIF_ARCH) += crc-t10dif-powerpc.o
+crc-t10dif-powerpc-y := crc-t10dif-glue.o crct10dif-vpmsum_asm.o
+
 obj-$(CONFIG_PPC64) += $(obj64-y)
similarity index 50%
rename from arch/powerpc/crypto/crct10dif-vpmsum_glue.c
rename to arch/powerpc/lib/crc-t10dif-glue.c
index 1dc8b691517811503fb91528c692f16f3dd6000c..730850dbc51d7aaa094a1ff4c4281da5933d81b5 100644 (file)
@@ -7,7 +7,6 @@
  */
 
 #include <linux/crc-t10dif.h>
-#include <crypto/internal/hash.h>
 #include <crypto/internal/simd.h>
 #include <linux/init.h>
 #include <linux/module.h>
 
 #define VECTOR_BREAKPOINT      64
 
+static DEFINE_STATIC_KEY_FALSE(have_vec_crypto);
+
 u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
 
-static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
+u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len)
 {
        unsigned int prealign;
        unsigned int tail;
        u32 crc = crci;
 
-       if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || !crypto_simd_usable())
+       if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) ||
+           !static_branch_likely(&have_vec_crypto) || !crypto_simd_usable())
                return crc_t10dif_generic(crc, p, len);
 
        if ((unsigned long)p & VMX_ALIGN_MASK) {
@@ -60,67 +62,28 @@ static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
 
        return crc & 0xffff;
 }
+EXPORT_SYMBOL(crc_t10dif_arch);
 
-static int crct10dif_vpmsum_init(struct shash_desc *desc)
-{
-       u16 *crc = shash_desc_ctx(desc);
-
-       *crc = 0;
-       return 0;
-}
-
-static int crct10dif_vpmsum_update(struct shash_desc *desc, const u8 *data,
-                           unsigned int length)
-{
-       u16 *crc = shash_desc_ctx(desc);
-
-       *crc = crct10dif_vpmsum(*crc, data, length);
-
-       return 0;
-}
-
-
-static int crct10dif_vpmsum_final(struct shash_desc *desc, u8 *out)
+static int __init crc_t10dif_powerpc_init(void)
 {
-       u16 *crcp = shash_desc_ctx(desc);
-
-       *(u16 *)out = *crcp;
+       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(crc_t10dif_powerpc_init);
 
-static struct shash_alg alg = {
-       .init           = crct10dif_vpmsum_init,
-       .update         = crct10dif_vpmsum_update,
-       .final          = crct10dif_vpmsum_final,
-       .descsize       = CRC_T10DIF_DIGEST_SIZE,
-       .digestsize     = CRC_T10DIF_DIGEST_SIZE,
-       .base           = {
-               .cra_name               = "crct10dif",
-               .cra_driver_name        = "crct10dif-vpmsum",
-               .cra_priority           = 200,
-               .cra_blocksize          = CRC_T10DIF_BLOCK_SIZE,
-               .cra_module             = THIS_MODULE,
-       }
-};
-
-static int __init crct10dif_vpmsum_mod_init(void)
+static void __exit crc_t10dif_powerpc_exit(void)
 {
-       if (!cpu_has_feature(CPU_FTR_ARCH_207S))
-               return -ENODEV;
-
-       return crypto_register_shash(&alg);
 }
+module_exit(crc_t10dif_powerpc_exit);
 
-static void __exit crct10dif_vpmsum_mod_fini(void)
+bool crc_t10dif_is_optimized(void)
 {
-       crypto_unregister_shash(&alg);
+       return static_key_enabled(&have_vec_crypto);
 }
-
-module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crct10dif_vpmsum_mod_init);
-module_exit(crct10dif_vpmsum_mod_fini);
+EXPORT_SYMBOL(crc_t10dif_is_optimized);
 
 MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
 MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_CRYPTO("crct10dif");
-MODULE_ALIAS_CRYPTO("crct10dif-vpmsum");
similarity index 99%
rename from arch/powerpc/crypto/crct10dif-vpmsum_asm.S
rename to arch/powerpc/lib/crct10dif-vpmsum_asm.S
index 0a52261bf859970325b2efb9f4664114087f7c75..f0b93a0fe168aa65ab459b01ded6e3e5a600cd1e 100644 (file)
        .octa 0x0000000000000000000000018bb70000
 
 #define CRC_FUNCTION_NAME __crct10dif_vpmsum
-#include "../lib/crc32-vpmsum_core.S"
+#include "crc32-vpmsum_core.S"