mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] RISC-V CRC-T10DIF optimization with zbc extension and CRC-T10DIF selftest
@ 2024-11-13 10:40 Zhihang Shao
  2024-11-13 10:40 ` [PATCH 1/2] lib/crct10diftest.c add selftests for crct10dif Zhihang Shao
  2024-11-13 10:40 ` [PATCH 2/2] " Zhihang Shao
  0 siblings, 2 replies; 6+ messages in thread
From: Zhihang Shao @ 2024-11-13 10:40 UTC (permalink / raw)
  To: herbert
  Cc: davem, palmer, paul.walmsley, aou, akpm, linux-crypto,
	linux-riscv, linux-kernel

Compared to other architectures, RISC-V still lacks accerlerated implementations 
for some encryption and checksum algorithms. 
This patchset aims to add optimization for crc-t10dif algorithm with zbc extension.
To verify the correctness and measure performance of the optimization, 
the selftest is also included as part of patchset.

Zhihang Shao (2):
  lib/crct10diftest.c add selftests for crct10dif
  riscv: Optimize crct10dif with zbc extension

 arch/riscv/crypto/Kconfig               |  14 +
 arch/riscv/crypto/Makefile              |   4 +
 arch/riscv/crypto/crct10dif-riscv-zbc.c | 182 +++++++
 lib/Kconfig                             |   9 +
 lib/Makefile                            |   1 +
 lib/crct10diftest.c                     | 687 ++++++++++++++++++++++++
 6 files changed, 897 insertions(+)
 create mode 100644 arch/riscv/crypto/crct10dif-riscv-zbc.c
 create mode 100644 lib/crct10diftest.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] lib/crct10diftest.c add selftests for crct10dif
  2024-11-13 10:40 [PATCH 0/2] RISC-V CRC-T10DIF optimization with zbc extension and CRC-T10DIF selftest Zhihang Shao
@ 2024-11-13 10:40 ` Zhihang Shao
  2024-11-13 13:46   ` Eric Biggers
  2024-11-13 10:40 ` [PATCH 2/2] " Zhihang Shao
  1 sibling, 1 reply; 6+ messages in thread
From: Zhihang Shao @ 2024-11-13 10:40 UTC (permalink / raw)
  To: herbert
  Cc: davem, palmer, paul.walmsley, aou, akpm, linux-crypto,
	linux-riscv, linux-kernel

Add selftests for kernel's implementation of CRC-T10DIF algorithm.
The test data includes 100 randomly generated test-cases.
The selftest file is similar to what is done in lib/crc32test.c, and is
used to verify the correctness and measure performance improvement of
the CRC-T10DIF algorithm with zbc extension optimization.

Signed-off-by: Zhihang Shao <zhihang.shao.iscas@gmail.com>
---
 lib/Kconfig         |   9 +
 lib/Makefile        |   1 +
 lib/crct10diftest.c | 687 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 697 insertions(+)
 create mode 100644 lib/crct10diftest.c

diff --git a/lib/Kconfig b/lib/Kconfig
index b38849af6f13..e0e488fd1307 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -187,6 +187,15 @@ config CRC32_SELFTEST
 	  and crc32_be over byte strings with random alignment and length
 	  and computes the total elapsed time and number of bytes processed.
 
+config CRCT10DIF_SELFTEST
+	tristate "CRCT10DIF perform self test on init"
+	depends on CRC_T10DIF
+	help
+	  This option enables the CRCT10DIF library functions to perform a
+	  self test on initialization. The self test computes crc_t10dif_update
+	  over byte strings with random alignment and length
+	  and computes the total elapsed time and number of bytes processed.
+
 choice
 	prompt "CRC32 implementation"
 	depends on CRC32
diff --git a/lib/Makefile b/lib/Makefile
index 773adf88af41..6dac65a3778c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -161,6 +161,7 @@ obj-$(CONFIG_CRC_ITU_T)	+= crc-itu-t.o
 obj-$(CONFIG_CRC32)	+= crc32.o
 obj-$(CONFIG_CRC64)     += crc64.o
 obj-$(CONFIG_CRC32_SELFTEST)	+= crc32test.o
+obj-$(CONFIG_CRCT10DIF_SELFTEST)	+= crct10diftest.o
 obj-$(CONFIG_CRC4)	+= crc4.o
 obj-$(CONFIG_CRC7)	+= crc7.o
 obj-$(CONFIG_LIBCRC32C)	+= libcrc32c.o
diff --git a/lib/crct10diftest.c b/lib/crct10diftest.c
new file mode 100644
index 000000000000..9541892eb12c
--- /dev/null
+++ b/lib/crct10diftest.c
@@ -0,0 +1,687 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * CRC-T10DIF selftests
+ *
+ * Copyright (C) 2024 Institute of Software, CAS.
+ */
+#include <linux/crc-t10dif.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/time.h>
+
+static struct crc_test {
+	u16 crc; /* random starting crc*/
+	u16 start; /* random 6 bit offset in buf*/
+	u16 length; /* random 11 bit length of test*/
+	u16 crct10dif; /* expected crc_t10dif result*/
+} tests[] = {
+	{0xdead, 0x0009, 0x0030, 0x8419},
+	{0x37c8, 0x0014, 0x03f0, 0xf4b5},
+	{0x8f45, 0x002d, 0x03b0, 0x6937},
+	{0x4201, 0x0020, 0x0719, 0x665e},
+	{0xe102, 0x0037, 0x0599, 0xb45b},
+	{0xa65d, 0x0008, 0x024d, 0x95d3},
+	{0xadba, 0x0001, 0x0799, 0xbb14},
+	{0x4407, 0x0038, 0x06a3, 0xb401},
+	{0x5188, 0x000c, 0x03f5, 0xf00c},
+	{0x5120, 0x0025, 0x0255, 0x858b},
+	{0x6a92, 0x0006, 0x0559, 0x159a},
+	{0xfa66, 0x0032, 0x0561, 0x0916},
+	{0x40a9, 0x003a, 0x0179, 0x0eb5},
+	{0x3c82, 0x0006, 0x02f0, 0x598c},
+	{0xbe07, 0x000a, 0x0085, 0xb228},
+	{0x7942, 0x0029, 0x033b, 0x0cc4},
+	{0x1275, 0x0030, 0x041b, 0x87b3},
+	{0xb715, 0x0030, 0x03fa, 0xcda8},
+	{0x7476, 0x0013, 0x063b, 0x51e8},
+	{0xa5c5, 0x001c, 0x0245, 0x53af},
+	{0x3e97, 0x003e, 0x0575, 0xdacf},
+	{0xdf84, 0x0025, 0x0556, 0x1154},
+	{0x72ef, 0x001b, 0x079b, 0x07b3},
+	{0x6d04, 0x0016, 0x06fc, 0x8cdf},
+	{0xe206, 0x0017, 0x030e, 0xe609},
+	{0xc188, 0x0008, 0x02c3, 0x504b},
+	{0x705b, 0x003f, 0x04db, 0xcf7c},
+	{0x3c9b, 0x0021, 0x048f, 0x09f9},
+	{0x32df, 0x0004, 0x064c, 0x73fb},
+	{0x0269, 0x0022, 0x07f0, 0xa49e},
+	{0x717d, 0x000b, 0x018b, 0x2ba0},
+	{0xc261, 0x0007, 0x05fb, 0x726e},
+	{0x239f, 0x000a, 0x0582, 0xa055},
+	{0x6812, 0x0006, 0x0325, 0x6399},
+	{0x8145, 0x0001, 0x068e, 0x8a81},
+	{0xaf22, 0x001d, 0x0113, 0xeb59},
+	{0xb521, 0x001f, 0x0465, 0x0648},
+	{0x8b01, 0x0015, 0x04e4, 0xdbf6},
+	{0xf3e0, 0x002f, 0x0300, 0x01b3},
+	{0xa6f6, 0x003c, 0x02a8, 0x56f4},
+	{0x7a06, 0x002b, 0x07bc, 0x5df1},
+	{0x9071, 0x0022, 0x0286, 0x6d8a},
+	{0x8ae3, 0x0015, 0x0796, 0x4fa0},
+	{0x9432, 0x0029, 0x0406, 0xfb2d},
+	{0x3808, 0x002c, 0x00df, 0xb9b6},
+	{0xb4c1, 0x0003, 0x0788, 0x3e7e},
+	{0xbc32, 0x0008, 0x06e3, 0x9c4f},
+	{0xd384, 0x000c, 0x05be, 0x6505},
+	{0x51b7, 0x003a, 0x07a3, 0x4216},
+	{0xa85c, 0x0029, 0x03de, 0xdcfe},
+	{0x933e, 0x0034, 0x0544, 0xecac},
+	{0xcc1e, 0x000b, 0x00c5, 0x832b},
+	{0x99b7, 0x0024, 0x0730, 0x9541},
+	{0x9f67, 0x0038, 0x071a, 0x762b},
+	{0x2140, 0x003e, 0x06c1, 0xe6b5},
+	{0x0f8a, 0x003f, 0x024f, 0xfcdd},
+	{0xc9fa, 0x0032, 0x0369, 0x9192},
+	{0x5c1c, 0x0007, 0x0596, 0x074a},
+	{0xfabb, 0x001a, 0x06cb, 0xd699},
+	{0x9c25, 0x0010, 0x0300, 0x3571},
+	{0xf934, 0x0030, 0x0455, 0xd0ce},
+	{0x18e8, 0x002f, 0x0434, 0x8c42},
+	{0xd16d, 0x0036, 0x06ed, 0x247a},
+	{0x9f75, 0x003d, 0x0238, 0x2508},
+	{0xe32f, 0x0021, 0x03c6, 0x358a},
+	{0xbce8, 0x001c, 0x06a6, 0x11bd},
+	{0x9436, 0x0031, 0x067d, 0x4512},
+	{0xcd02, 0x003d, 0x0638, 0x2bef},
+	{0xdbad, 0x000d, 0x06d2, 0x4e67},
+	{0x65fd, 0x0006, 0x06be, 0xf178},
+	{0x05fc, 0x002b, 0x0062, 0x509d},
+	{0xcee8, 0x001a, 0x06e1, 0xccb1},
+	{0xe03c, 0x0027, 0x0163, 0x2633},
+	{0x6c03, 0x0009, 0x04c8, 0xfec2},
+	{0x657b, 0x0006, 0x0096, 0x1c5a},
+	{0x1cc3, 0x000e, 0x00b3, 0xd233},
+	{0x815c, 0x0005, 0x0506, 0xc241},
+	{0xaa8c, 0x0004, 0x06c3, 0x0e76},
+	{0x7970, 0x0025, 0x05fa, 0x4d7a},
+	{0x91c0, 0x001c, 0x0270, 0x40af},
+	{0x4f83, 0x0014, 0x0720, 0x9d03},
+	{0x0bdd, 0x0029, 0x03c1, 0xac55},
+	{0x372f, 0x0017, 0x03d5, 0x41d2},
+	{0x8325, 0x0009, 0x0463, 0x2add},
+	{0xf40e, 0x002a, 0x03da, 0x45ea},
+	{0x552e, 0x001e, 0x0723, 0x225a},
+	{0x41c3, 0x001d, 0x06f7, 0x1d61},
+	{0x09f9, 0x0027, 0x057f, 0x5cc0},
+	{0xfd3b, 0x0020, 0x0504, 0x8048},
+	{0xb889, 0x0005, 0x0271, 0x43e0},
+	{0xbd1c, 0x0007, 0x03aa, 0x7253},
+	{0xbad0, 0x000e, 0x04c3, 0x9855},
+	{0xc978, 0x001d, 0x0579, 0x2ab0},
+	{0x3b3b, 0x001c, 0x0545, 0x521a},
+	{0x41b9, 0x003c, 0x0082, 0x49b7},
+	{0x15a3, 0x0002, 0x0530, 0xf48a},
+	{0xeaa2, 0x0034, 0x03f8, 0x3aad},
+	{0x8af9, 0x0029, 0x02e3, 0x4b3d},
+	{0xb4b0, 0x000d, 0x0056, 0xecee},
+	{0x669b, 0x0019, 0x065f, 0x28d8},
+};
+
+static const u8 __aligned(8) test_buf[] __initconst = {
+	0x4d, 0x87, 0x5f, 0x10, 0x90, 0xd5, 0x31, 0x96,
+	0x3f, 0x5a, 0x50, 0xc7, 0x30, 0x80, 0x5f, 0x2c,
+	0x78, 0xf0, 0xa2, 0xb5, 0xfb, 0xf9, 0x83, 0x14,
+	0xe9, 0xb6, 0xaa, 0xe6, 0x39, 0x12, 0x0b, 0x87,
+	0x99, 0x6a, 0x97, 0x2a, 0x3f, 0xc8, 0xc0, 0x7e,
+	0x22, 0x10, 0x45, 0x52, 0x90, 0xa4, 0x7e, 0x08,
+	0x94, 0x21, 0xbe, 0x8f, 0x1a, 0x41, 0xa3, 0x04,
+	0xf7, 0x4d, 0xea, 0x30, 0x5f, 0xf5, 0xb7, 0xf9,
+	0x60, 0x4e, 0x23, 0x9f, 0x16, 0xe3, 0x1e, 0x38,
+	0xf3, 0x63, 0x8b, 0x84, 0x08, 0x09, 0x8c, 0x9c,
+	0x2a, 0x4a, 0x2c, 0x45, 0x8b, 0xcf, 0x49, 0x82,
+	0x1d, 0x33, 0xb3, 0x7c, 0x29, 0x6a, 0x75, 0x89,
+	0xb9, 0x98, 0x28, 0xcf, 0x7b, 0x46, 0x08, 0x6f,
+	0xaa, 0x93, 0xf3, 0xb2, 0x9c, 0x7f, 0x4e, 0xc7,
+	0xca, 0x7a, 0x0c, 0x55, 0x4a, 0x55, 0xd8, 0x67,
+	0x88, 0x8b, 0xe3, 0xb1, 0xf5, 0x59, 0x3a, 0xae,
+	0xf1, 0x63, 0x7e, 0x6d, 0xa9, 0x86, 0xdc, 0x53,
+	0x19, 0xcf, 0x05, 0xb5, 0x4e, 0x54, 0x7c, 0x18,
+	0xce, 0x88, 0x6e, 0x18, 0xdd, 0x46, 0x7f, 0x66,
+	0xd1, 0x63, 0x17, 0xc6, 0xb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, 0x96, 0x6e, 0xe3, 0xe4, 0xc2, 0x32,
+	0x89, 0x12, 0xe9, 0xf3, 0x42, 0x49, 0x98, 0x85,
+	0x0e, 0xe7, 0xf5, 0x83, 0x9b, 0x34, 0xac, 0x61,
+	0xa3, 0x6b, 0xdd, 0x09, 0x36, 0x9f, 0x47, 0x13,
+	0x88, 0xdd, 0x81, 0x6b, 0xc1, 0x43, 0x9e, 0x4b,
+	0x56, 0x87, 0x3e, 0x98, 0xd0, 0xd6, 0x1e, 0xde,
+	0xbd, 0x13, 0x61, 0x58, 0x48, 0x0d, 0xb9, 0xeb,
+};
+
+static int __init crct10dif_test_init(void)
+{
+	int i;
+	int errors = 0;
+	int bytes = 0;
+	u64 nsec;
+	unsigned long flags;
+
+	static u16 crc;
+
+	for (i = 0; i < 100; i++) {
+		bytes += tests[i].length;
+		crc ^= crc_t10dif_generic(tests[i].crc, test_buf +
+		tests[i].start, tests[i].length);
+	}
+
+	local_irq_save(flags);
+
+	nsec = ktime_get_ns();
+
+	for (i = 0; i < 100; i++) {
+		if (tests[i].crct10dif != crc_t10dif_update(
+			tests[i].crc,
+			test_buf + tests[i].start,
+			tests[i].length))
+			errors++;
+	}
+
+	nsec = ktime_get_ns() - nsec;
+
+	local_irq_restore(flags);
+
+	if (errors)
+		pr_warn("crct10dif: %d self tests failed\n", errors);
+	else
+		pr_info("crct10dif: self tests passed, processed %d bytes in %lld nsec\n",
+		bytes, nsec);
+
+	return 0;
+}
+
+static void __exit crct10dif_test_exit(void)
+{
+	pr_info("CRC-T10DIF test module unloaded.\n");
+}
+
+module_init(crct10dif_test_init);
+module_exit(crct10dif_test_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("CRC-T10DIF Test Module");
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] riscv: Optimize crct10dif with zbc extension
  2024-11-13 10:40 [PATCH 0/2] RISC-V CRC-T10DIF optimization with zbc extension and CRC-T10DIF selftest Zhihang Shao
  2024-11-13 10:40 ` [PATCH 1/2] lib/crct10diftest.c add selftests for crct10dif Zhihang Shao
@ 2024-11-13 10:40 ` Zhihang Shao
  2024-11-14  7:04   ` Chunyan Zhang
  1 sibling, 1 reply; 6+ messages in thread
From: Zhihang Shao @ 2024-11-13 10:40 UTC (permalink / raw)
  To: herbert
  Cc: davem, palmer, paul.walmsley, aou, akpm, linux-crypto,
	linux-riscv, linux-kernel

The current CRC-T10DIF algorithm is based on table-lookup optimization.
Given the previous work on optimizing crc32 calculations with zbc
extension, it is believed that this will be equally effective for
accelerating crc-t10dif.
Therefore, this patch offers a implementation of crc-t10dif using zbc
extension. This can detect whether the current runtime environment
supports zbc feature and, if so, uses it to accelerate crc-t10dif
calculations.

This patch is tested on QEMU VM with the kernel CRC-T10DIF selftests.

Signed-off-by: Zhihang Shao <zhihang.shao.iscas@gmail.com>
---
 arch/riscv/crypto/Kconfig               |  14 ++
 arch/riscv/crypto/Makefile              |   4 +
 arch/riscv/crypto/crct10dif-riscv-zbc.c | 182 ++++++++++++++++++++++++
 lib/crct10diftest.c                     |   4 +-
 4 files changed, 202 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/crypto/crct10dif-riscv-zbc.c

diff --git a/arch/riscv/crypto/Kconfig b/arch/riscv/crypto/Kconfig
index ad58dad9a580..69751ff5573e 100644
--- a/arch/riscv/crypto/Kconfig
+++ b/arch/riscv/crypto/Kconfig
@@ -29,6 +29,20 @@ config CRYPTO_CHACHA_RISCV64
 	  Architecture: riscv64 using:
 	  - Zvkb vector crypto extension
 
+config CRYPTO_CRCT10DIF_RISCV
+       tristate "Checksum: CRCT10DIF"
+       depends on TOOLCHAIN_HAS_ZBC
+       depends on MMU
+       depends on RISCV_ALTERNATIVE
+       default y
+       help
+         CRCT10DIF checksum with Zbc extension optimized
+	 To accelerate CRCT10DIF checksum, choose Y here.
+
+         Architecture: riscv using:
+          - Zbc extension
+
+
 config CRYPTO_GHASH_RISCV64
 	tristate "Hash functions: GHASH"
 	depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO
diff --git a/arch/riscv/crypto/Makefile b/arch/riscv/crypto/Makefile
index 247c7bc7288c..6f849f4dc4cc 100644
--- a/arch/riscv/crypto/Makefile
+++ b/arch/riscv/crypto/Makefile
@@ -7,6 +7,9 @@ aes-riscv64-y := aes-riscv64-glue.o aes-riscv64-zvkned.o \
 obj-$(CONFIG_CRYPTO_CHACHA_RISCV64) += chacha-riscv64.o
 chacha-riscv64-y := chacha-riscv64-glue.o chacha-riscv64-zvkb.o
 
+obj-$(CONFIG_CRYPTO_CRCT10DIF_RISCV) += crct10dif-riscv.o
+crct10dif-riscv-y := crct10dif-riscv-zbc.o
+
 obj-$(CONFIG_CRYPTO_GHASH_RISCV64) += ghash-riscv64.o
 ghash-riscv64-y := ghash-riscv64-glue.o ghash-riscv64-zvkg.o
 
@@ -21,3 +24,4 @@ sm3-riscv64-y := sm3-riscv64-glue.o sm3-riscv64-zvksh-zvkb.o
 
 obj-$(CONFIG_CRYPTO_SM4_RISCV64) += sm4-riscv64.o
 sm4-riscv64-y := sm4-riscv64-glue.o sm4-riscv64-zvksed-zvkb.o
+
diff --git a/arch/riscv/crypto/crct10dif-riscv-zbc.c b/arch/riscv/crypto/crct10dif-riscv-zbc.c
new file mode 100644
index 000000000000..01571b4286f1
--- /dev/null
+++ b/arch/riscv/crypto/crct10dif-riscv-zbc.c
@@ -0,0 +1,182 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Accelerated CRC-T10DIF implementation with RISC-V Zbc extension.
+ *
+ * Copyright (C) 2024 Institute of Software, CAS.
+ */
+
+#include <asm/alternative-macros.h>
+#include <asm/byteorder.h>
+#include <asm/hwcap.h>
+
+#include <crypto/internal/hash.h>
+
+#include <linux/byteorder/generic.h>
+#include <linux/crc-t10dif.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/types.h>
+
+static u16 crc_t10dif_generic_zbc(u16 crc, unsigned char const *p, size_t len);
+
+#define CRCT10DIF_POLY 0x8bb7
+
+#if __riscv_xlen == 64
+#define STEP_ORDER 3
+
+#define CRCT10DIF_POLY_QT_BE 0xf65a57f81d33a48a
+
+static inline u64 crct10dif_prep(u16 crc, unsigned long const *ptr)
+{
+	return ((u64)crc << 48) ^ (__force u64)__cpu_to_be64(*ptr);
+}
+
+#elif __riscv_xlen == 32
+#define STEP_ORDER 2
+#define CRCT10DIF_POLY_QT_BE 0xf65a57f8
+
+static inline u32 crct10dif_prep(u16 crc, unsigned long const *ptr)
+{
+	return ((u32)crc << 16) ^ (__force u32)__cpu_to_be32(*ptr);
+}
+
+#else
+#error "Unexpected __riscv_xlen"
+#endif
+
+static inline u16 crct10dif_zbc(unsigned long s)
+{
+	u16 crc;
+
+	asm volatile   (".option push\n"
+			".option arch,+zbc\n"
+			"clmulh %0, %1, %2\n"
+			"xor    %0, %0, %1\n"
+			"clmul  %0, %0, %3\n"
+			".option pop\n"
+			: "=&r" (crc)
+			: "r"(s),
+			  "r"(CRCT10DIF_POLY_QT_BE),
+			  "r"(CRCT10DIF_POLY)
+			:);
+
+	return crc;
+}
+
+#define STEP (1 << STEP_ORDER)
+#define OFFSET_MASK (STEP - 1)
+
+static inline u16 crct10dif_unaligned(u16 crc, unsigned char const *p, size_t len)
+{
+	size_t bits = len * 8;
+	unsigned long s = 0;
+	u16 crc_low = 0;
+
+	for (int i = 0; i < len; i++)
+		s = *p++ | (s << 8);
+
+	if (len < sizeof(u16)) {
+		s ^= crc >> (16 - bits);
+		crc_low = crc << bits;
+	} else {
+		s ^= (unsigned long)crc << (bits - 16);
+	}
+
+	crc = crct10dif_zbc(s);
+	crc ^= crc_low;
+
+	return crc;
+}
+
+static u16 crc_t10dif_generic_zbc(u16 crc, unsigned char const *p, size_t len)
+{
+	size_t offset, head_len, tail_len;
+	unsigned long const *p_ul;
+	unsigned long s;
+
+	offset = (unsigned long)p & OFFSET_MASK;
+	if (offset && len) {
+		head_len = min(STEP - offset, len);
+		crc = crct10dif_unaligned(crc, p, head_len);
+		p += head_len;
+		len -= head_len;
+	}
+
+	tail_len = len & OFFSET_MASK;
+	len = len >> STEP_ORDER;
+	p_ul = (unsigned long const *)p;
+
+	for (int i = 0; i < len; i++) {
+		s = crct10dif_prep(crc, p_ul);
+		crc = crct10dif_zbc(s);
+		p_ul++;
+	}
+
+	p = (unsigned char const *)p_ul;
+	if (tail_len)
+		crc = crct10dif_unaligned(crc, p, tail_len);
+
+	return crc;
+}
+
+static int crc_t10dif_init(struct shash_desc *desc)
+{
+	u16 *crc = shash_desc_ctx(desc);
+
+	*crc = 0;
+
+	return 0;
+}
+
+static int crc_t10dif_final(struct shash_desc *desc, u8 *out)
+{
+	u16 *crc = shash_desc_ctx(desc);
+
+	*(u16 *)out = *crc;
+
+	return 0;
+}
+
+static int crc_t10dif_update_zbc(struct shash_desc *desc, const u8 *data,
+				unsigned int length)
+{
+	u16 *crc = shash_desc_ctx(desc);
+
+	*crc = crc_t10dif_generic_zbc(*crc, data, length);
+
+	return 0;
+}
+
+static struct shash_alg crc_t10dif_alg = {
+	.digestsize		= CRC_T10DIF_DIGEST_SIZE,
+	.init			= crc_t10dif_init,
+	.update			= crc_t10dif_update_zbc,
+	.final			= crc_t10dif_final,
+	.descsize		= CRC_T10DIF_DIGEST_SIZE,
+
+	.base.cra_name		= "crct10dif",
+	.base.cra_driver_name	= "crct10dif-riscv-zbc",
+	.base.cra_priority	= 150,
+	.base.cra_blocksize	= CRC_T10DIF_BLOCK_SIZE,
+	.base.cra_module	= THIS_MODULE,
+};
+
+static int __init crc_t10dif_mod_init(void)
+{
+	if (riscv_isa_extension_available(NULL, ZBC))
+		return crypto_register_shash(&crc_t10dif_alg);
+
+	return -ENODEV;
+}
+
+static void __exit crc_t10dif_mod_exit(void)
+{
+	crypto_unregister_shash(&crc_t10dif_alg);
+}
+
+module_init(crc_t10dif_mod_init);
+module_exit(crc_t10dif_mod_exit);
+
+MODULE_DESCRIPTION("CRC-T10DIF using RISC-V ZBC Extension");
+MODULE_ALIAS_CRYPTO("crct10dif");
+MODULE_LICENSE("GPL");
diff --git a/lib/crct10diftest.c b/lib/crct10diftest.c
index 9541892eb12c..ac642191e6e8 100644
--- a/lib/crct10diftest.c
+++ b/lib/crct10diftest.c
@@ -666,9 +666,9 @@ static int __init crct10dif_test_init(void)
 
 	local_irq_restore(flags);
 
-	if (errors) 
+	if (errors)
 		pr_warn("crct10dif: %d self tests failed\n", errors);
-	else 
+	else
 		pr_info("crct10dif: self tests passed, processed %d bytes in %lld nsec\n",
 		bytes, nsec);
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] lib/crct10diftest.c add selftests for crct10dif
  2024-11-13 10:40 ` [PATCH 1/2] lib/crct10diftest.c add selftests for crct10dif Zhihang Shao
@ 2024-11-13 13:46   ` Eric Biggers
  2024-11-14 14:42     ` [PATCH v2] riscv: Optimize crct10dif with zbc extension Zhihang Shao
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Biggers @ 2024-11-13 13:46 UTC (permalink / raw)
  To: Zhihang Shao
  Cc: herbert, davem, palmer, paul.walmsley, aou, akpm, linux-crypto,
	linux-riscv, linux-kernel

On Wed, Nov 13, 2024 at 10:40:35AM +0000, Zhihang Shao wrote:
> Add selftests for kernel's implementation of CRC-T10DIF algorithm.
> The test data includes 100 randomly generated test-cases.
> The selftest file is similar to what is done in lib/crc32test.c, and is
> used to verify the correctness and measure performance improvement of
> the CRC-T10DIF algorithm with zbc extension optimization.
> 
> Signed-off-by: Zhihang Shao <zhihang.shao.iscas@gmail.com>
> ---
>  lib/Kconfig         |   9 +
>  lib/Makefile        |   1 +
>  lib/crct10diftest.c | 687 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 697 insertions(+)
>  create mode 100644 lib/crct10diftest.c

crc_t10dif_update() goes through the crypto API, so for now you should be able
to just use the crypto self-tests instead, i.e. boot a kernel with
CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y.

I am planning to fix the crct10dif library to be optimized directly (without
going through the crypto API), like what I am doing for crc32.  At that point a
crct10dif library test will be needed, and I'll add one then.

There are also several issues with the existing crc32 test which you're copying,
and which I'd like to address when adding a new test.  For example, the test
does not cover short lengths, and it runs the tests with IRQs disabled which
makes optimized code not used on many architectures.

- Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] riscv: Optimize crct10dif with zbc extension
  2024-11-13 10:40 ` [PATCH 2/2] " Zhihang Shao
@ 2024-11-14  7:04   ` Chunyan Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Chunyan Zhang @ 2024-11-14  7:04 UTC (permalink / raw)
  To: Zhihang Shao
  Cc: herbert, davem, palmer, paul.walmsley, aou, akpm, linux-crypto,
	linux-riscv, linux-kernel

On Wed, 13 Nov 2024 at 19:06, Zhihang Shao <zhihang.shao.iscas@gmail.com> wrote:
>
> The current CRC-T10DIF algorithm is based on table-lookup optimization.
> Given the previous work on optimizing crc32 calculations with zbc
> extension, it is believed that this will be equally effective for
> accelerating crc-t10dif.
> Therefore, this patch offers a implementation of crc-t10dif using zbc
> extension. This can detect whether the current runtime environment
> supports zbc feature and, if so, uses it to accelerate crc-t10dif
> calculations.
>
> This patch is tested on QEMU VM with the kernel CRC-T10DIF selftests.
>
> Signed-off-by: Zhihang Shao <zhihang.shao.iscas@gmail.com>
> ---
>  arch/riscv/crypto/Kconfig               |  14 ++
>  arch/riscv/crypto/Makefile              |   4 +
>  arch/riscv/crypto/crct10dif-riscv-zbc.c | 182 ++++++++++++++++++++++++
>  lib/crct10diftest.c                     |   4 +-
>  4 files changed, 202 insertions(+), 2 deletions(-)
>  create mode 100644 arch/riscv/crypto/crct10dif-riscv-zbc.c
>
> diff --git a/arch/riscv/crypto/Kconfig b/arch/riscv/crypto/Kconfig
> index ad58dad9a580..69751ff5573e 100644
> --- a/arch/riscv/crypto/Kconfig
> +++ b/arch/riscv/crypto/Kconfig
> @@ -29,6 +29,20 @@ config CRYPTO_CHACHA_RISCV64
>           Architecture: riscv64 using:
>           - Zvkb vector crypto extension
>
> +config CRYPTO_CRCT10DIF_RISCV
> +       tristate "Checksum: CRCT10DIF"
> +       depends on TOOLCHAIN_HAS_ZBC
> +       depends on MMU
> +       depends on RISCV_ALTERNATIVE
> +       default y
> +       help
> +         CRCT10DIF checksum with Zbc extension optimized
> +        To accelerate CRCT10DIF checksum, choose Y here.

This line should be aligned with two characters.

> +
> +         Architecture: riscv using:
> +          - Zbc extension

Same here.

> +
> +

More than one redundant empty line should be removed.

>  config CRYPTO_GHASH_RISCV64
>         tristate "Hash functions: GHASH"
>         depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO
> diff --git a/arch/riscv/crypto/Makefile b/arch/riscv/crypto/Makefile
> index 247c7bc7288c..6f849f4dc4cc 100644
> --- a/arch/riscv/crypto/Makefile
> +++ b/arch/riscv/crypto/Makefile
> @@ -7,6 +7,9 @@ aes-riscv64-y := aes-riscv64-glue.o aes-riscv64-zvkned.o \
>  obj-$(CONFIG_CRYPTO_CHACHA_RISCV64) += chacha-riscv64.o
>  chacha-riscv64-y := chacha-riscv64-glue.o chacha-riscv64-zvkb.o
>
> +obj-$(CONFIG_CRYPTO_CRCT10DIF_RISCV) += crct10dif-riscv.o
> +crct10dif-riscv-y := crct10dif-riscv-zbc.o
> +
>  obj-$(CONFIG_CRYPTO_GHASH_RISCV64) += ghash-riscv64.o
>  ghash-riscv64-y := ghash-riscv64-glue.o ghash-riscv64-zvkg.o
>
> @@ -21,3 +24,4 @@ sm3-riscv64-y := sm3-riscv64-glue.o sm3-riscv64-zvksh-zvkb.o
>
>  obj-$(CONFIG_CRYPTO_SM4_RISCV64) += sm4-riscv64.o
>  sm4-riscv64-y := sm4-riscv64-glue.o sm4-riscv64-zvksed-zvkb.o
> +
> diff --git a/arch/riscv/crypto/crct10dif-riscv-zbc.c b/arch/riscv/crypto/crct10dif-riscv-zbc.c
> new file mode 100644
> index 000000000000..01571b4286f1
> --- /dev/null
> +++ b/arch/riscv/crypto/crct10dif-riscv-zbc.c
> @@ -0,0 +1,182 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Accelerated CRC-T10DIF implementation with RISC-V Zbc extension.
> + *
> + * Copyright (C) 2024 Institute of Software, CAS.
> + */
> +
> +#include <asm/alternative-macros.h>
> +#include <asm/byteorder.h>
> +#include <asm/hwcap.h>
> +
> +#include <crypto/internal/hash.h>
> +
> +#include <linux/byteorder/generic.h>
> +#include <linux/crc-t10dif.h>
> +#include <linux/minmax.h>
> +#include <linux/module.h>
> +#include <linux/types.h>
> +
> +static u16 crc_t10dif_generic_zbc(u16 crc, unsigned char const *p, size_t len);
> +
> +#define CRCT10DIF_POLY 0x8bb7
> +
> +#if __riscv_xlen == 64
> +#define STEP_ORDER 3
> +
> +#define CRCT10DIF_POLY_QT_BE 0xf65a57f81d33a48a
> +
> +static inline u64 crct10dif_prep(u16 crc, unsigned long const *ptr)
> +{
> +       return ((u64)crc << 48) ^ (__force u64)__cpu_to_be64(*ptr);
> +}
> +
> +#elif __riscv_xlen == 32
> +#define STEP_ORDER 2
> +#define CRCT10DIF_POLY_QT_BE 0xf65a57f8
> +
> +static inline u32 crct10dif_prep(u16 crc, unsigned long const *ptr)
> +{
> +       return ((u32)crc << 16) ^ (__force u32)__cpu_to_be32(*ptr);
> +}
> +
> +#else
> +#error "Unexpected __riscv_xlen"
> +#endif
> +
> +static inline u16 crct10dif_zbc(unsigned long s)
> +{
> +       u16 crc;
> +
> +       asm volatile   (".option push\n"
> +                       ".option arch,+zbc\n"
> +                       "clmulh %0, %1, %2\n"
> +                       "xor    %0, %0, %1\n"
> +                       "clmul  %0, %0, %3\n"
> +                       ".option pop\n"
> +                       : "=&r" (crc)
> +                       : "r"(s),
> +                         "r"(CRCT10DIF_POLY_QT_BE),
> +                         "r"(CRCT10DIF_POLY)
> +                       :);
> +
> +       return crc;
> +}
> +
> +#define STEP (1 << STEP_ORDER)
> +#define OFFSET_MASK (STEP - 1)
> +
> +static inline u16 crct10dif_unaligned(u16 crc, unsigned char const *p, size_t len)
> +{
> +       size_t bits = len * 8;
> +       unsigned long s = 0;
> +       u16 crc_low = 0;
> +
> +       for (int i = 0; i < len; i++)
> +               s = *p++ | (s << 8);
> +
> +       if (len < sizeof(u16)) {
> +               s ^= crc >> (16 - bits);
> +               crc_low = crc << bits;
> +       } else {
> +               s ^= (unsigned long)crc << (bits - 16);
> +       }
> +
> +       crc = crct10dif_zbc(s);
> +       crc ^= crc_low;
> +
> +       return crc;
> +}
> +
> +static u16 crc_t10dif_generic_zbc(u16 crc, unsigned char const *p, size_t len)
> +{
> +       size_t offset, head_len, tail_len;
> +       unsigned long const *p_ul;
> +       unsigned long s;
> +
> +       offset = (unsigned long)p & OFFSET_MASK;
> +       if (offset && len) {
> +               head_len = min(STEP - offset, len);
> +               crc = crct10dif_unaligned(crc, p, head_len);
> +               p += head_len;
> +               len -= head_len;
> +       }
> +
> +       tail_len = len & OFFSET_MASK;
> +       len = len >> STEP_ORDER;
> +       p_ul = (unsigned long const *)p;
> +
> +       for (int i = 0; i < len; i++) {
> +               s = crct10dif_prep(crc, p_ul);
> +               crc = crct10dif_zbc(s);
> +               p_ul++;
> +       }
> +
> +       p = (unsigned char const *)p_ul;
> +       if (tail_len)
> +               crc = crct10dif_unaligned(crc, p, tail_len);
> +
> +       return crc;
> +}
> +
> +static int crc_t10dif_init(struct shash_desc *desc)
> +{
> +       u16 *crc = shash_desc_ctx(desc);
> +
> +       *crc = 0;
> +
> +       return 0;
> +}
> +
> +static int crc_t10dif_final(struct shash_desc *desc, u8 *out)
> +{
> +       u16 *crc = shash_desc_ctx(desc);
> +
> +       *(u16 *)out = *crc;
> +
> +       return 0;
> +}
> +
> +static int crc_t10dif_update_zbc(struct shash_desc *desc, const u8 *data,
> +                               unsigned int length)
> +{
> +       u16 *crc = shash_desc_ctx(desc);
> +
> +       *crc = crc_t10dif_generic_zbc(*crc, data, length);
> +
> +       return 0;
> +}
> +
> +static struct shash_alg crc_t10dif_alg = {
> +       .digestsize             = CRC_T10DIF_DIGEST_SIZE,
> +       .init                   = crc_t10dif_init,
> +       .update                 = crc_t10dif_update_zbc,
> +       .final                  = crc_t10dif_final,
> +       .descsize               = CRC_T10DIF_DIGEST_SIZE,
> +
> +       .base.cra_name          = "crct10dif",
> +       .base.cra_driver_name   = "crct10dif-riscv-zbc",
> +       .base.cra_priority      = 150,
> +       .base.cra_blocksize     = CRC_T10DIF_BLOCK_SIZE,
> +       .base.cra_module        = THIS_MODULE,
> +};
> +
> +static int __init crc_t10dif_mod_init(void)
> +{
> +       if (riscv_isa_extension_available(NULL, ZBC))
> +               return crypto_register_shash(&crc_t10dif_alg);
> +
> +       return -ENODEV;
> +}
> +
> +static void __exit crc_t10dif_mod_exit(void)
> +{
> +       crypto_unregister_shash(&crc_t10dif_alg);
> +}
> +
> +module_init(crc_t10dif_mod_init);
> +module_exit(crc_t10dif_mod_exit);
> +
> +MODULE_DESCRIPTION("CRC-T10DIF using RISC-V ZBC Extension");
> +MODULE_ALIAS_CRYPTO("crct10dif");
> +MODULE_LICENSE("GPL");
> diff --git a/lib/crct10diftest.c b/lib/crct10diftest.c
> index 9541892eb12c..ac642191e6e8 100644
> --- a/lib/crct10diftest.c
> +++ b/lib/crct10diftest.c
> @@ -666,9 +666,9 @@ static int __init crct10dif_test_init(void)
>
>         local_irq_restore(flags);
>
> -       if (errors)
> +       if (errors)

This change should be removed from this patch.

>                 pr_warn("crct10dif: %d self tests failed\n", errors);
> -       else
> +       else

Same here.

>                 pr_info("crct10dif: self tests passed, processed %d bytes in %lld nsec\n",
>                 bytes, nsec);
>
> --
> 2.34.1
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] riscv: Optimize crct10dif with zbc extension
  2024-11-13 13:46   ` Eric Biggers
@ 2024-11-14 14:42     ` Zhihang Shao
  0 siblings, 0 replies; 6+ messages in thread
From: Zhihang Shao @ 2024-11-14 14:42 UTC (permalink / raw)
  To: zhangchunyan, ebiggers
  Cc: akpm, aou, davem, herbert, linux-crypto, linux-kernel,
	linux-riscv, palmer, paul.walmsley, zhihang.shao.iscas

The current CRC-T10DIF algorithm is based on table-lookup optimization.
Given the previous work on optimizing crc32 calculations with zbc
extension, it is believed that this will be equally effective for
accelerating crc-t10dif.
Therefore, this patch offers an implementation of crc-t10dif using zbc
extension. This can detect whether the current runtime environment
supports zbc feature and, if so, uses it to accelerate crc-t10dif
calculations.

This patch is tested on QEMU VM with the crypto self-tests both rv64 and
rv32.

Signed-off-by: Zhihang Shao <zhihang.shao.iscas@gmail.com>

---
v2:
- Use crypto self-tests instead. (Eric)
- Fix some format errors in arch/riscv/crypto/Kconfig. (Chunyan)
---
 arch/riscv/crypto/Kconfig               |  13 ++
 arch/riscv/crypto/Makefile              |   4 +
 arch/riscv/crypto/crct10dif-riscv-zbc.c | 182 ++++++++++++++++++++++++
 3 files changed, 199 insertions(+)
 create mode 100644 arch/riscv/crypto/crct10dif-riscv-zbc.c

diff --git a/arch/riscv/crypto/Kconfig b/arch/riscv/crypto/Kconfig
index ad58dad9a580..12107bc50bb1 100644
--- a/arch/riscv/crypto/Kconfig
+++ b/arch/riscv/crypto/Kconfig
@@ -29,6 +29,19 @@ config CRYPTO_CHACHA_RISCV64
 	  Architecture: riscv64 using:
 	  - Zvkb vector crypto extension
 
+config CRYPTO_CRCT10DIF_RISCV
+	tristate "Checksum: CRCT10DIF"
+	depends on TOOLCHAIN_HAS_ZBC
+	depends on MMU
+	depends on RISCV_ALTERNATIVE
+	default y
+	help
+	  CRCT10DIF checksum with Zbc extension optimized
+	  To accelerate CRCT10DIF checksum, choose Y here.
+
+	  Architecture: riscv using:
+	  - Zbc extension
+
 config CRYPTO_GHASH_RISCV64
 	tristate "Hash functions: GHASH"
 	depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO
diff --git a/arch/riscv/crypto/Makefile b/arch/riscv/crypto/Makefile
index 247c7bc7288c..6f849f4dc4cc 100644
--- a/arch/riscv/crypto/Makefile
+++ b/arch/riscv/crypto/Makefile
@@ -7,6 +7,9 @@ aes-riscv64-y := aes-riscv64-glue.o aes-riscv64-zvkned.o \
 obj-$(CONFIG_CRYPTO_CHACHA_RISCV64) += chacha-riscv64.o
 chacha-riscv64-y := chacha-riscv64-glue.o chacha-riscv64-zvkb.o
 
+obj-$(CONFIG_CRYPTO_CRCT10DIF_RISCV) += crct10dif-riscv.o
+crct10dif-riscv-y := crct10dif-riscv-zbc.o
+
 obj-$(CONFIG_CRYPTO_GHASH_RISCV64) += ghash-riscv64.o
 ghash-riscv64-y := ghash-riscv64-glue.o ghash-riscv64-zvkg.o
 
@@ -21,3 +24,4 @@ sm3-riscv64-y := sm3-riscv64-glue.o sm3-riscv64-zvksh-zvkb.o
 
 obj-$(CONFIG_CRYPTO_SM4_RISCV64) += sm4-riscv64.o
 sm4-riscv64-y := sm4-riscv64-glue.o sm4-riscv64-zvksed-zvkb.o
+
diff --git a/arch/riscv/crypto/crct10dif-riscv-zbc.c b/arch/riscv/crypto/crct10dif-riscv-zbc.c
new file mode 100644
index 000000000000..01571b4286f1
--- /dev/null
+++ b/arch/riscv/crypto/crct10dif-riscv-zbc.c
@@ -0,0 +1,182 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Accelerated CRC-T10DIF implementation with RISC-V Zbc extension.
+ *
+ * Copyright (C) 2024 Institute of Software, CAS.
+ */
+
+#include <asm/alternative-macros.h>
+#include <asm/byteorder.h>
+#include <asm/hwcap.h>
+
+#include <crypto/internal/hash.h>
+
+#include <linux/byteorder/generic.h>
+#include <linux/crc-t10dif.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/types.h>
+
+static u16 crc_t10dif_generic_zbc(u16 crc, unsigned char const *p, size_t len);
+
+#define CRCT10DIF_POLY 0x8bb7
+
+#if __riscv_xlen == 64
+#define STEP_ORDER 3
+
+#define CRCT10DIF_POLY_QT_BE 0xf65a57f81d33a48a
+
+static inline u64 crct10dif_prep(u16 crc, unsigned long const *ptr)
+{
+	return ((u64)crc << 48) ^ (__force u64)__cpu_to_be64(*ptr);
+}
+
+#elif __riscv_xlen == 32
+#define STEP_ORDER 2
+#define CRCT10DIF_POLY_QT_BE 0xf65a57f8
+
+static inline u32 crct10dif_prep(u16 crc, unsigned long const *ptr)
+{
+	return ((u32)crc << 16) ^ (__force u32)__cpu_to_be32(*ptr);
+}
+
+#else
+#error "Unexpected __riscv_xlen"
+#endif
+
+static inline u16 crct10dif_zbc(unsigned long s)
+{
+	u16 crc;
+
+	asm volatile   (".option push\n"
+			".option arch,+zbc\n"
+			"clmulh %0, %1, %2\n"
+			"xor    %0, %0, %1\n"
+			"clmul  %0, %0, %3\n"
+			".option pop\n"
+			: "=&r" (crc)
+			: "r"(s),
+			  "r"(CRCT10DIF_POLY_QT_BE),
+			  "r"(CRCT10DIF_POLY)
+			:);
+
+	return crc;
+}
+
+#define STEP (1 << STEP_ORDER)
+#define OFFSET_MASK (STEP - 1)
+
+static inline u16 crct10dif_unaligned(u16 crc, unsigned char const *p, size_t len)
+{
+	size_t bits = len * 8;
+	unsigned long s = 0;
+	u16 crc_low = 0;
+
+	for (int i = 0; i < len; i++)
+		s = *p++ | (s << 8);
+
+	if (len < sizeof(u16)) {
+		s ^= crc >> (16 - bits);
+		crc_low = crc << bits;
+	} else {
+		s ^= (unsigned long)crc << (bits - 16);
+	}
+
+	crc = crct10dif_zbc(s);
+	crc ^= crc_low;
+
+	return crc;
+}
+
+static u16 crc_t10dif_generic_zbc(u16 crc, unsigned char const *p, size_t len)
+{
+	size_t offset, head_len, tail_len;
+	unsigned long const *p_ul;
+	unsigned long s;
+
+	offset = (unsigned long)p & OFFSET_MASK;
+	if (offset && len) {
+		head_len = min(STEP - offset, len);
+		crc = crct10dif_unaligned(crc, p, head_len);
+		p += head_len;
+		len -= head_len;
+	}
+
+	tail_len = len & OFFSET_MASK;
+	len = len >> STEP_ORDER;
+	p_ul = (unsigned long const *)p;
+
+	for (int i = 0; i < len; i++) {
+		s = crct10dif_prep(crc, p_ul);
+		crc = crct10dif_zbc(s);
+		p_ul++;
+	}
+
+	p = (unsigned char const *)p_ul;
+	if (tail_len)
+		crc = crct10dif_unaligned(crc, p, tail_len);
+
+	return crc;
+}
+
+static int crc_t10dif_init(struct shash_desc *desc)
+{
+	u16 *crc = shash_desc_ctx(desc);
+
+	*crc = 0;
+
+	return 0;
+}
+
+static int crc_t10dif_final(struct shash_desc *desc, u8 *out)
+{
+	u16 *crc = shash_desc_ctx(desc);
+
+	*(u16 *)out = *crc;
+
+	return 0;
+}
+
+static int crc_t10dif_update_zbc(struct shash_desc *desc, const u8 *data,
+				unsigned int length)
+{
+	u16 *crc = shash_desc_ctx(desc);
+
+	*crc = crc_t10dif_generic_zbc(*crc, data, length);
+
+	return 0;
+}
+
+static struct shash_alg crc_t10dif_alg = {
+	.digestsize		= CRC_T10DIF_DIGEST_SIZE,
+	.init			= crc_t10dif_init,
+	.update			= crc_t10dif_update_zbc,
+	.final			= crc_t10dif_final,
+	.descsize		= CRC_T10DIF_DIGEST_SIZE,
+
+	.base.cra_name		= "crct10dif",
+	.base.cra_driver_name	= "crct10dif-riscv-zbc",
+	.base.cra_priority	= 150,
+	.base.cra_blocksize	= CRC_T10DIF_BLOCK_SIZE,
+	.base.cra_module	= THIS_MODULE,
+};
+
+static int __init crc_t10dif_mod_init(void)
+{
+	if (riscv_isa_extension_available(NULL, ZBC))
+		return crypto_register_shash(&crc_t10dif_alg);
+
+	return -ENODEV;
+}
+
+static void __exit crc_t10dif_mod_exit(void)
+{
+	crypto_unregister_shash(&crc_t10dif_alg);
+}
+
+module_init(crc_t10dif_mod_init);
+module_exit(crc_t10dif_mod_exit);
+
+MODULE_DESCRIPTION("CRC-T10DIF using RISC-V ZBC Extension");
+MODULE_ALIAS_CRYPTO("crct10dif");
+MODULE_LICENSE("GPL");
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-11-14 14:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-13 10:40 [PATCH 0/2] RISC-V CRC-T10DIF optimization with zbc extension and CRC-T10DIF selftest Zhihang Shao
2024-11-13 10:40 ` [PATCH 1/2] lib/crct10diftest.c add selftests for crct10dif Zhihang Shao
2024-11-13 13:46   ` Eric Biggers
2024-11-14 14:42     ` [PATCH v2] riscv: Optimize crct10dif with zbc extension Zhihang Shao
2024-11-13 10:40 ` [PATCH 2/2] " Zhihang Shao
2024-11-14  7:04   ` Chunyan Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®