Skip to contentSkip to conversation

crypto: add virtio poll mode driver

PATCH Superseded Jay Zhou 1 participant 9 messages Mar 31, 2018

Subsystems (3)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
author
#1 lore raw

PATCH v4 1/7 crypto/virtio: add virtio related fundamental functions

In reply to Jay Zhou

Since there does not have the common virtio library, we have to put these files here. They are basically the same with virtio net related files with some minor changes.

Meanwhile, adding virtio crypto PMD related release note for 18.05.

---
 config/common_base                     |  14 +
 doc/guides/rel_notes/release_18_05.rst |   4 +
 drivers/crypto/virtio/virtio_logs.h    |  91 +++++++
 drivers/crypto/virtio/virtio_pci.c     | 460 +++++++++++++++++++++++++++++++++
 drivers/crypto/virtio/virtio_pci.h     | 253 ++++++++++++++++++
 drivers/crypto/virtio/virtio_ring.h    | 137 ++++++++++
 drivers/crypto/virtio/virtqueue.c      |  43 +++
 drivers/crypto/virtio/virtqueue.h      | 172 ++++++++++++
 8 files changed, 1174 insertions(+)
 create mode 100644 drivers/crypto/virtio/virtio_logs.h
 create mode 100644 drivers/crypto/virtio/virtio_pci.c
 create mode 100644 drivers/crypto/virtio/virtio_pci.h
 create mode 100644 drivers/crypto/virtio/virtio_ring.h
 create mode 100644 drivers/crypto/virtio/virtqueue.c
 create mode 100644 drivers/crypto/virtio/virtqueue.h
config/common_base +14 -0
index ee10b44..91d3102 100644
@@ -486,6 +486,20 @@ CONFIG_RTE_LIBRTE_PMD_QAT_DEBUG_DRIVER=n
 CONFIG_RTE_QAT_PMD_MAX_NB_SESSIONS=2048
 
 #
+# Compile PMD for virtio crypto devices
+#
+CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO=n
+#
+# Number of maximum virtio crypto devices
+#
+CONFIG_RTE_MAX_VIRTIO_CRYPTO=32
+#
+# Number of sessions to create in the session memory pool
+# on a single virtio crypto device.
+#
+CONFIG_RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS=1024
+
+#
 # Compile PMD for AESNI backed device
 #
 CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n
doc/guides/rel_notes/release_18_05.rst +4 -0
index 3923dc2..32c39d5 100644
@@ -41,6 +41,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added Virtio Crypto PMD.**
+
+  Added new Virtio Crypto PMD, which provides AES-CBC ciphering and AES-CBC
+  with HMAC-SHA1 algorithm-chaining.
 
 API Changes
 -----------
drivers/crypto/virtio/virtio_logs.h new file +91 -0

91 lines not on this page · raw message

drivers/crypto/virtio/virtio_pci.c new file +460 -0

460 lines not on this page · raw message

drivers/crypto/virtio/virtio_pci.h new file +253 -0

253 lines not on this page · raw message

drivers/crypto/virtio/virtio_ring.h new file +137 -0

137 lines not on this page · raw message

drivers/crypto/virtio/virtqueue.c new file +43 -0

43 lines not on this page · raw message

drivers/crypto/virtio/virtqueue.h new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH v4 3/7 crypto/virtio: core code of virtio crypto PMD

In reply to Jay Zhou

The virtio crypto device has two types of queues, data
queue and control queue. It has one data queue at least and has one and only one control queue. For example, if a virtio crypto device has N queues, then [0, N-2] is the data queue index, N-1 is the control queue index.
The virtio crypto PMD provides poll mode driver support for the virtio crypto device.
The cryptodev is created at the virtio crypto pci device probing stage. For now, it only supports the session-oriented API implementation, the supported symmetrical algorithms are AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. The function virtio_crypto_sym_configure_session() is used to create a session, then virtio_crypto_pkt_tx_burst() can be used to burst transfer packets and virtio_crypto_pkt_rx_burst() can be used to burst receive packets.

---
 drivers/crypto/virtio/virtio_crypto_capabilities.h |   51 +
 drivers/crypto/virtio/virtio_cryptodev.c           | 1508 ++++++++++++++++++++
 drivers/crypto/virtio/virtio_cryptodev.h           |   66 +
 drivers/crypto/virtio/virtio_rxtx.c                |  541 +++++++
 4 files changed, 2166 insertions(+)
 create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
 create mode 100644 drivers/crypto/virtio/virtio_cryptodev.c
 create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
 create mode 100644 drivers/crypto/virtio/virtio_rxtx.c
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +51 -0
new file mode 100644
index 0000000..03c30de
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD.
+ */
+
+#ifndef _VIRTIO_CRYPTO_CAPABILITIES_H_
+#define _VIRTIO_CRYPTO_CAPABILITIES_H_
+
+#define VIRTIO_SYM_CAPABILITIES					\
+	{	/* SHA1 HMAC */						\
+		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,			\
+		{.sym = {						\
+			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,	\
+			{.auth = {					\
+				.algo = RTE_CRYPTO_AUTH_SHA1_HMAC,	\
+				.block_size = 64,			\
+				.key_size = {				\
+					.min = 1,			\
+					.max = 64,			\
+					.increment = 1			\
+				},					\
+				.digest_size = {			\
+					.min = 1,			\
+					.max = 20,			\
+					.increment = 1			\
+				},					\
+				.iv_size = { 0 }			\
+			}, }						\
+		}, }							\
+	},								\
+	{	/* AES CBC */						\
+		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,			\
+		{.sym = {						\
+			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,	\
+			{.cipher = {					\
+				.algo = RTE_CRYPTO_CIPHER_AES_CBC,	\
+				.block_size = 16,			\
+				.key_size = {				\
+					.min = 16,			\
+					.max = 32,			\
+					.increment = 8			\
+				},					\
+				.iv_size = {				\
+					.min = 16,			\
+					.max = 16,			\
+					.increment = 0			\
+				}					\
+			}, }						\
+		}, }							\
+	}
+
+#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c new file +1508 -0

1,508 lines not on this page · raw message

drivers/crypto/virtio/virtio_cryptodev.h new file +66 -0

66 lines not on this page · raw message

drivers/crypto/virtio/virtio_rxtx.c new file +541 -0

541 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#5 lore raw

PATCH v4 5/7 doc: add virtio crypto PMD guide

In reply to Jay Zhou
---
 doc/guides/cryptodevs/features/virtio.ini |  26 +++++++
 doc/guides/cryptodevs/index.rst           |   1 +
 doc/guides/cryptodevs/virtio.rst          | 117 ++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 doc/guides/cryptodevs/features/virtio.ini
 create mode 100644 doc/guides/cryptodevs/virtio.rst
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
new file mode 100644
index 0000000..168fc17
@@ -0,0 +1,26 @@
+; Supported features of the 'virtio' crypto driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Symmetric crypto       = Y
+Sym operation chaining = Y
+
+;
+; Supported crypto algorithms of the 'virtio' crypto driver.
+;
+[Cipher]
+AES CBC (128)  = Y
+AES CBC (192)  = Y
+AES CBC (256)  = Y
+
+;
+; Supported authentication algorithms of the 'virtio' crypto driver.
+;
+[Auth]
+SHA1 HMAC      = Y
+
+;
+; Supported AEAD algorithms of the 'virtio' crypto driver.
+;
+[AEAD]
doc/guides/cryptodevs/index.rst +1 -0
index 558c926..ef16ab3 100644
@@ -22,4 +22,5 @@ Crypto Device Drivers
     scheduler
     snow3g
     qat
+    virtio
     zuc
doc/guides/cryptodevs/virtio.rst new file +117 -0

117 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v4 2/7 crypto/virtio: add crypto related session structure

In reply to Jay Zhou

This structure will be used in the following patches, especially at creating and destroying crypto sessions.

---
 drivers/crypto/virtio/virtio_crypto_algs.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +27 -0
new file mode 100644
index 0000000..5f1e9df
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD.
+ */
+
+#ifndef _VIRTIO_CRYPTO_ALGS_H_
+#define _VIRTIO_CRYPTO_ALGS_H_
+
+#include <rte_memory.h>
+#include <linux/virtio_crypto.h>
+
+struct virtio_crypto_session {
+	uint64_t session_id;
+
+	struct {
+		uint16_t offset;
+		uint16_t length;
+	} iv;
+
+	struct {
+		uint32_t length;
+		phys_addr_t phys_addr;
+	} aad;
+
+	struct virtio_crypto_op_ctrl_req ctrl;
+};
+
+#endif /* _VIRTIO_CRYPTO_ALGS_H_ */
Signature · 1 line
1.8.3.1

Jay Zhou

author
#0 lore raw

v4 cover crypto: add virtio poll mode driver

This patch series introduce virtio crypto poll mode driver.

Since it is limited by the vhost crypto backend of the virtio-crypto, this patch series only supports a limited subset of crypto services. Only the following algorithms are tested:

Cipher algorithms:
- RTE_CRYPTO_CIPHER_AES_CBC (128-bit, 192-bit and 256-bit keys)

Cipher then hash algorithms:
- RTE_CRYPTO_CIPHER_AES_CBC with RTE_CRYPTO_AUTH_SHA1_HMAC

The qemu side has supported vhost crypto and the vhost user crypto server side patches had been sent to DPDK community, pls see

[PATCH v2 00/10] lib/librte_vhost: introduce new vhost user crypto backend support
https://dpdk.org/ml/archives/dev/2018-February/091594.html

Firstly run DPDK vhost crypto sample as a server side and build QEMU with vhost crypto enabled.
QEMU can then be started using the following parameters:

qemu-system-x86_64 \
    [...] \
        -chardev socket,id=charcrypto0,path=/path/to/your/socket \
        -object cryptodev-vhost-user,id=cryptodev0,chardev=charcrypto0 \
        -device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0
    [...]

Bind the uio_generic driver for the virtio-crypto device. For example, 0000:00:04.0 is the domain, bus, device and function number of the virtio-crypto device:

    modprobe uio_pci_generic
    echo -n 0000:00:04.0 > /sys/bus/pci/drivers/virtio-pci/unbind
    echo "1af4 1054" > /sys/bus/pci/drivers/uio_pci_generic/new_id

The front-end virtio crypto PMD driver can be installed:
cd to the top-level DPDK directory
sed -i 's,\(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO\)=n,\1=y,' config/common_base make config T=x86_64-native-linuxapp-gcc
make install T=x86_64-native-linuxapp-gcc

The unit test cases can be compiled as below:
cd to the top-level DPDK directory
export RTE_TARGET=x86_64-native-linuxapp-gcc export RTE_SDK=pwd
cd to test/test
make
./test (MUST reserve enough huge pages memory) type the command "cryptodev_virtio_autotest" to test

The result should be like this:
RTE>>cryptodev_virtio_autotest
+ ------------------------------------------------------- +
+ Test Suite : Crypto VIRTIO Unit Test Suite
+ ------------------------------------------------------- +
0) TestCase AES-128-CBC Encryption PASS
1) TestCase AES-128-CBC Decryption PASS
2) TestCase AES-192-CBC Encryption PASS
3) TestCase AES-192-CBC Decryption PASS
4) TestCase AES-256-CBC Encryption PASS
5) TestCase AES-256-CBC Decryption PASS
6) TestCase AES-256-CBC OOP Encryption PASS
7) TestCase AES-256-CBC OOP Decryption PASS
8) TestCase AES-128-CTR Encryption PASS
9) TestCase AES-128-CTR Decryption PASS
10) TestCase AES-192-CTR Encryption PASS
11) TestCase AES-192-CTR Decryption PASS
12) TestCase AES-256-CTR Encryption PASS
13) TestCase AES-256-CTR Decryption PASS
+ TestCase [ 0] : test_AES_cipheronly_virtio_all succeeded
+ ------------------------------------------------------- +
+ Test Suite Summary

 + Tests Total :        1
 + Tests Skipped :      0
 + Tests Executed :     1
 + Tests Unsupported:   0
 + Tests Passed :       1
 + Tests Failed :       0

+ ------------------------------------------------------- +
Test OK

The performance can be tested as below:

reserve enough huge pages
cd to the top-level DPDK directory
export RTE_TARGET=x86_64-native-linuxapp-gcc
export RTE_SDK=pwd
cd to app/test-crypto-perf
type the command "make" to compile
run the tests with the following command:

./dpdk-test-crypto-perf -l 0,1 -- --devtype crypto_virtio \
--ptest throughput --optype cipher-then-auth --cipher-algo aes-cbc \
--cipher-op encrypt --cipher-key-sz 16 --auth-algo sha1-hmac \
--auth-op generate --auth-key-sz 64 --digest-sz 12 \
--total-ops 100000000 --burst-sz 64 --buffer-sz 2048

Please help to review, thanks!

Changes in v4:
- using dynamic logging [Pablo]
- elaborate on the core code [Pablo]
- delete algorithms which can not be tested [Pablo]
- rebased on dpdk-next-crypto [Pablo]
- fix doc compilation error [Pablo]
- add release note for this PMD [Pablo]
- add R-b from Fan Zhang
- fix some typos

Changes in v3:
- set up capabilities for virtio crypto PMD [Fan]
- delete AES-CTR unit test cases since vhost_user crypto backend does not support [Fan]
- fix a variable uninitialized in virtio_crypto_queue_setup() [Xin, Fan]
- fix a bug in virtqueue_dequeue_burst_rx()

Changes in v2:
- using pre-allocated mempool instead of rte_malloc to improve performance [Fan]
- split the patch into a patchset [Fan]
- using linux/virtio_crypto.h instead of creating a copy of the file [Fan]
- update doc/guides/cryptodevs for describing virtio crypto PMD [Fan]
- update copyright
- delete virtio legacy mode code since virtio-crypto conforms to virtio-1.0
- refine the function and variable names
- fix errors and warnings reported by checkpatch

Jay Zhou (7):
crypto/virtio: add virtio related fundamental functions crypto/virtio: add crypto related session structure crypto/virtio: core code of virtio crypto PMD crypto/virtio: add makefile
doc: add virtio crypto PMD guide
test/crypto: add function tests for virtio crypto PMD
MAINTAINERS: add myself as virtio crypto PMD maintainer

 MAINTAINERS                                        |    6 +
 config/common_base                                 |   14 +
 doc/guides/cryptodevs/features/virtio.ini          |   26 +
 doc/guides/cryptodevs/index.rst                    |    1 +
 doc/guides/cryptodevs/virtio.rst                   |  117 ++
 doc/guides/rel_notes/release_18_05.rst             |    4 +
 drivers/crypto/Makefile                            |    1 +
 drivers/crypto/virtio/Makefile                     |   31 +
 .../virtio/rte_pmd_virtio_crypto_version.map       |    3 +
 drivers/crypto/virtio/virtio_crypto_algs.h         |   27 +
 drivers/crypto/virtio/virtio_crypto_capabilities.h |   51 +
 drivers/crypto/virtio/virtio_cryptodev.c           | 1508 ++++++++++++++++++++
 drivers/crypto/virtio/virtio_cryptodev.h           |   66 +
 drivers/crypto/virtio/virtio_logs.h                |   91 ++
 drivers/crypto/virtio/virtio_pci.c                 |  460 ++++++
 drivers/crypto/virtio/virtio_pci.h                 |  253 ++++
 drivers/crypto/virtio/virtio_ring.h                |  137 ++
 drivers/crypto/virtio/virtio_rxtx.c                |  541 +++++++
 drivers/crypto/virtio/virtqueue.c                  |   43 +
 drivers/crypto/virtio/virtqueue.h                  |  172 +++
 mk/rte.app.mk                                      |    1 +
 test/test/test_cryptodev.c                         |   49 +
 test/test/test_cryptodev.h                         |    1 +
 test/test/test_cryptodev_aes_test_vectors.h        |   24 +-
 test/test/test_cryptodev_blockcipher.c             |    9 +-
 test/test/test_cryptodev_blockcipher.h             |    1 +
 26 files changed, 3628 insertions(+), 9 deletions(-)
 create mode 100644 doc/guides/cryptodevs/features/virtio.ini
 create mode 100644 doc/guides/cryptodevs/virtio.rst
 create mode 100644 drivers/crypto/virtio/Makefile
 create mode 100644 drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map
 create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
 create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
 create mode 100644 drivers/crypto/virtio/virtio_cryptodev.c
 create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
 create mode 100644 drivers/crypto/virtio/virtio_logs.h
 create mode 100644 drivers/crypto/virtio/virtio_pci.c
 create mode 100644 drivers/crypto/virtio/virtio_pci.h
 create mode 100644 drivers/crypto/virtio/virtio_ring.h
 create mode 100644 drivers/crypto/virtio/virtio_rxtx.c
 create mode 100644 drivers/crypto/virtio/virtqueue.c
 create mode 100644 drivers/crypto/virtio/virtqueue.h

--
1.8.3.1

author
#6 lore raw

PATCH v4 6/7 test/crypto: add function tests for virtio crypto PMD

Only RTE_CRYPTO_CIPHER_AES_CBC cipher
algorithm are tested as unit test, it is supported both by the cryptodev-backend-builtin and cryptodev-vhost-user of qemu side.

---
 test/test/test_cryptodev.c                  | 49 +++++++++++++++++++++++++++++
 test/test/test_cryptodev.h                  |  1 +
 test/test/test_cryptodev_aes_test_vectors.h | 24 +++++++++-----
 test/test/test_cryptodev_blockcipher.c      |  9 +++++-
 test/test/test_cryptodev_blockcipher.h      |  1 +
 5 files changed, 75 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +49 -0
index 1417482..357e1df 100644
@@ -1765,6 +1765,26 @@ struct crypto_unittest_params {
 }
 
 static int
+test_AES_cipheronly_virtio_all(void)
+{
+	struct crypto_testsuite_params *ts_params = &testsuite_params;
+	int status;
+
+	status = test_blockcipher_all_tests(ts_params->mbuf_pool,
+		ts_params->op_mpool,
+		ts_params->session_mpool,
+		ts_params->valid_devs[0],
+		rte_cryptodev_driver_id_get(
+		RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)),
+		BLKCIPHER_AES_CIPHERONLY_TYPE);
+
+	TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+	return TEST_SUCCESS;
+}
+
+
+static int
 test_AES_chain_dpaa_sec_all(void)
 {
 	struct crypto_testsuite_params *ts_params = &testsuite_params;
@@ -8767,6 +8787,18 @@ struct test_crypto_vector {
 	}
 };
 
+static struct unit_test_suite cryptodev_virtio_testsuite  = {
+	.suite_name = "Crypto VIRTIO Unit Test Suite",
+	.setup = testsuite_setup,
+	.teardown = testsuite_teardown,
+	.unit_test_cases = {
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_AES_cipheronly_virtio_all),
+
+		TEST_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
 	.suite_name = "Crypto Device AESNI MB Unit Test Suite",
 	.setup = testsuite_setup,
@@ -9664,6 +9696,22 @@ struct test_crypto_vector {
 }
 
 static int
+test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
+{
+	gbl_driver_id =	rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
+
+	if (gbl_driver_id == -1) {
+		RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
+				"CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
+				"in config file to run this testsuite.\n");
+		return TEST_FAILED;
+	}
+
+	return unit_test_suite_runner(&cryptodev_virtio_testsuite);
+}
+
+static int
 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
 {
 	gbl_driver_id =	rte_cryptodev_driver_id_get(
@@ -9879,3 +9927,4 @@ struct test_crypto_vector {
 REGISTER_TEST_COMMAND(cryptodev_sw_mrvl_autotest, test_cryptodev_mrvl);
 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
+REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
index 8cdc087..c311277 100644
@@ -61,6 +61,7 @@
 #define CRYPTODEV_NAME_DPAA2_SEC_PMD	crypto_dpaa2_sec
 #define CRYPTODEV_NAME_SCHEDULER_PMD	crypto_scheduler
 #define CRYPTODEV_NAME_MRVL_PMD		crypto_mrvl
+#define CRYPTODEV_NAME_VIRTIO_PMD   crypto_virtio
 
 /**
  * Write (spread) data from buffer to mbuf data
test/test/test_cryptodev_aes_test_vectors.h +16 -8
index 3577ef4..cac7cda 100644
@@ -1526,7 +1526,8 @@
 			BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_MRVL
+			BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-128-CBC Decryption",
@@ -1538,7 +1539,8 @@
 			BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_MRVL
+			BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-192-CBC Encryption",
@@ -1549,7 +1551,8 @@
 			BLOCKCIPHER_TEST_TARGET_PMD_MB |
 			BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC
+			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1570,7 +1573,8 @@
 			BLOCKCIPHER_TEST_TARGET_PMD_MB |
 			BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC
+			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1590,7 +1594,8 @@
 			BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_MRVL
+			BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-256-CBC Decryption",
@@ -1602,7 +1607,8 @@
 			BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_MRVL
+			BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-256-CBC OOP Encryption",
@@ -1612,7 +1618,8 @@
 		.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
 			BLOCKCIPHER_TEST_TARGET_PMD_QAT |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC
+			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-256-CBC OOP Decryption",
@@ -1622,7 +1629,8 @@
 		.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
 			BLOCKCIPHER_TEST_TARGET_PMD_QAT |
 			BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
-			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC
+			BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
+			BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
 	},
 	{
 		.test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
index ed06618..9eee350 100644
@@ -68,6 +68,8 @@
 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
 	int mrvl_pmd = rte_cryptodev_driver_id_get(
 			RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
+	int virtio_pmd = rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
 
 	int nb_segs = 1;
 
@@ -94,7 +96,8 @@
 			driver_id == qat_pmd ||
 			driver_id == openssl_pmd ||
 			driver_id == armv8_pmd ||
-			driver_id == mrvl_pmd) { /* Fall through */
+			driver_id == mrvl_pmd ||
+			driver_id == virtio_pmd) { /* Fall through */
 		digest_len = tdata->digest.len;
 	} else if (driver_id == aesni_mb_pmd ||
 			driver_id == scheduler_pmd) {
@@ -569,6 +572,8 @@
 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
 	int mrvl_pmd = rte_cryptodev_driver_id_get(
 			RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
+	int virtio_pmd = rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
 
 	switch (test_type) {
 	case BLKCIPHER_AES_CHAIN_TYPE:
@@ -631,6 +636,8 @@
 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
 	else if (driver_id == mrvl_pmd)
 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MRVL;
+	else if (driver_id == virtio_pmd)
+		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO;
 	else
 		TEST_ASSERT(0, "Unrecognized cryptodev type");
 
test/test/test_cryptodev_blockcipher.h +1 -0
index edbdaab..49a35bd 100644
@@ -27,6 +27,7 @@
 #define BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC	0x0020 /* DPAA2_SEC flag */
 #define BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC	0x0040 /* DPAA_SEC flag */
 #define BLOCKCIPHER_TEST_TARGET_PMD_MRVL	0x0080 /* Marvell flag */
+#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO	0x0100 /* VIRTIO flag */
 
 #define BLOCKCIPHER_TEST_OP_CIPHER	(BLOCKCIPHER_TEST_OP_ENCRYPT | \
 					BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH v4 4/7 crypto/virtio: add makefile

In reply to Jay Zhou

The virtio crypto PMD driver can be compiled now.

---
 drivers/crypto/Makefile                            |  1 +
 drivers/crypto/virtio/Makefile                     | 31 ++++++++++++++++++++++
 .../virtio/rte_pmd_virtio_crypto_version.map       |  3 +++
 mk/rte.app.mk                                      |  1 +
 4 files changed, 36 insertions(+)
 create mode 100644 drivers/crypto/virtio/Makefile
 create mode 100644 drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map
drivers/crypto/Makefile +1 -0
index 26e503e..e48bbdd 100644
@@ -20,5 +20,6 @@ endif
 ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y)
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec
 endif
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio
 
 include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/virtio/Makefile new file +31 -0
new file mode 100644
index 0000000..c4727ea
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_virtio_crypto.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+EXPORT_MAP := rte_pmd_virtio_crypto_version.map
+
+LIBABIVER := 1
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtqueue.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio_rxtx.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio_cryptodev.c
+
+# this lib depends upon:
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += lib/librte_eal
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += lib/librte_mempool lib/librte_mbuf
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += lib/librte_cryptodev
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map new file +3 -0
new file mode 100644
index 0000000..de8e412
@@ -0,0 +1,3 @@
+DPDK_18.05 {
+	local: *;
+};
mk/rte.app.mk +1 -0
index 94525dc..d7ddda4 100644
@@ -204,6 +204,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM)   += -L$(AESNI_MULTI_BUFFER_LIB_PATH)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_OPENSSL)     += -lrte_pmd_openssl -lcrypto
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO) += -lrte_pmd_null_crypto
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_QAT)         += -lrte_pmd_qat -lcrypto
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += -lrte_pmd_virtio_crypto -lcrypto
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G)      += -lrte_pmd_snow3g
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SNOW3G)      += -L$(LIBSSO_SNOW3G_PATH)/build -lsso_snow3g
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_KASUMI)      += -lrte_pmd_kasumi
Signature · 1 line
1.8.3.1
author
#7 lore raw

PATCH v4 7/7 MAINTAINERS: add myself as virtio crypto PMD maintainer

In reply to Jay Zhou
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index 75d3e92..24c5af8 100644
@@ -718,6 +718,12 @@ F: drivers/crypto/snow3g/
 F: doc/guides/cryptodevs/snow3g.rst
 F: doc/guides/cryptodevs/features/snow3g.ini
 
+Virtio
+M: Jay Zhou <[email protected]>
+F: drivers/crypto/virtio/
+F: doc/guides/cryptodevs/virtio.rst
+F: doc/guides/cryptodevs/features/virtio.ini
+
 ZUC
 M: Pablo de Lara <[email protected]>
 F: drivers/crypto/zuc/
Signature · 1 line
1.8.3.1
#8 lore raw
In reply to Jay Zhou

I find that my dpdk-next-crypto repo is not the newest, I'll send a new version. Sorry about that.

Regards,
Jay

Quoted 194 lines

-----Original Message-----
From: Zhoujian (jay)
Sent: Saturday, March 31, 2018 3:49 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Gonglei (Arei) <[email protected]>; [email protected]; Huangweidong (C) <[email protected]>; wangxin (U) <[email protected]>; longpeng <[email protected]>; Zhoujian (jay) <[email protected]>
Subject: [PATCH v4 0/7] crypto: add virtio poll mode driver

This patch series introduce virtio crypto poll mode driver.

Since it is limited by the vhost crypto backend of the virtio-crypto, this patch series only supports a limited subset of crypto services. Only the following algorithms are tested:

Cipher algorithms:
- RTE_CRYPTO_CIPHER_AES_CBC (128-bit, 192-bit and 256-bit keys)

Cipher then hash algorithms:
- RTE_CRYPTO_CIPHER_AES_CBC with RTE_CRYPTO_AUTH_SHA1_HMAC

The qemu side has supported vhost crypto and the vhost user crypto server side patches had been sent to DPDK community, pls see

[PATCH v2 00/10] lib/librte_vhost: introduce new vhost user crypto backend support https://dpdk.org/ml/archives/dev/2018-February/091594.html

Firstly run DPDK vhost crypto sample as a server side and build QEMU with vhost crypto enabled.
QEMU can then be started using the following parameters:

qemu-system-x86_64 \
    [...] \
        -chardev socket,id=charcrypto0,path=/path/to/your/socket \
        -object cryptodev-vhost-user,id=cryptodev0,chardev=charcrypto0 \
        -device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0
    [...]

Bind the uio_generic driver for the virtio-crypto device.
For example, 0000:00:04.0 is the domain, bus, device and function number of the virtio-crypto device:

    modprobe uio_pci_generic
    echo -n 0000:00:04.0 > /sys/bus/pci/drivers/virtio-pci/unbind
    echo "1af4 1054" > /sys/bus/pci/drivers/uio_pci_generic/new_id

The front-end virtio crypto PMD driver can be installed:
cd to the top-level DPDK directory
sed -i 's,\(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO\)=n,\1=y,'
config/common_base
make config T=x86_64-native-linuxapp-gcc
make install T=x86_64-native-linuxapp-gcc

The unit test cases can be compiled as below:
cd to the top-level DPDK directory
export RTE_TARGET=x86_64-native-linuxapp-gcc export RTE_SDK=pwd
cd to test/test
make
./test (MUST reserve enough huge pages memory) type the command "cryptodev_virtio_autotest" to test

The result should be like this:
RTE>>cryptodev_virtio_autotest
+ ------------------------------------------------------- + + Test Suite :
Crypto VIRTIO Unit Test Suite + -------------------------------------------- ----------- +
0) TestCase AES-128-CBC Encryption PASS
1) TestCase AES-128-CBC Decryption PASS
2) TestCase AES-192-CBC Encryption PASS
3) TestCase AES-192-CBC Decryption PASS
4) TestCase AES-256-CBC Encryption PASS
5) TestCase AES-256-CBC Decryption PASS
6) TestCase AES-256-CBC OOP Encryption PASS
7) TestCase AES-256-CBC OOP Decryption PASS
8) TestCase AES-128-CTR Encryption PASS
9) TestCase AES-128-CTR Decryption PASS
10) TestCase AES-192-CTR Encryption PASS
11) TestCase AES-192-CTR Decryption PASS
12) TestCase AES-256-CTR Encryption PASS
13) TestCase AES-256-CTR Decryption PASS + TestCase [ 0] :
test_AES_cipheronly_virtio_all succeeded + --------------------------------- ---------------------- + + Test Suite Summary

 + Tests Total :        1
 + Tests Skipped :      0
 + Tests Executed :     1
 + Tests Unsupported:   0
 + Tests Passed :       1
 + Tests Failed :       0

+ ------------------------------------------------------- + Test OK

The performance can be tested as below:

reserve enough huge pages
cd to the top-level DPDK directory
export RTE_TARGET=x86_64-native-linuxapp-gcc
export RTE_SDK=pwd
cd to app/test-crypto-perf
type the command "make" to compile
run the tests with the following command:

./dpdk-test-crypto-perf -l 0,1 -- --devtype crypto_virtio \
--ptest throughput --optype cipher-then-auth --cipher-algo aes-cbc \
--cipher-op encrypt --cipher-key-sz 16 --auth-algo sha1-hmac \
--auth-op generate --auth-key-sz 64 --digest-sz 12 \
--total-ops 100000000 --burst-sz 64 --buffer-sz 2048

Please help to review, thanks!

Changes in v4:
- using dynamic logging [Pablo]
- elaborate on the core code [Pablo]
- delete algorithms which can not be tested [Pablo]
- rebased on dpdk-next-crypto [Pablo]
- fix doc compilation error [Pablo]
- add release note for this PMD [Pablo]
- add R-b from Fan Zhang
- fix some typos

Changes in v3:
- set up capabilities for virtio crypto PMD [Fan]
- delete AES-CTR unit test cases since vhost_user crypto backend does not support [Fan]
- fix a variable uninitialized in virtio_crypto_queue_setup() [Xin, Fan]
- fix a bug in virtqueue_dequeue_burst_rx()

Changes in v2:
- using pre-allocated mempool instead of rte_malloc to improve performance
[Fan]
- split the patch into a patchset [Fan]
- using linux/virtio_crypto.h instead of creating a copy of the file [Fan]
- update doc/guides/cryptodevs for describing virtio crypto PMD [Fan]
- update copyright
- delete virtio legacy mode code since virtio-crypto conforms to virtio-1.0
- refine the function and variable names
- fix errors and warnings reported by checkpatch

Jay Zhou (7):
crypto/virtio: add virtio related fundamental functions crypto/virtio: add crypto related session structure crypto/virtio: core code of virtio crypto PMD crypto/virtio: add makefile
doc: add virtio crypto PMD guide
test/crypto: add function tests for virtio crypto PMD
MAINTAINERS: add myself as virtio crypto PMD maintainer

 MAINTAINERS                                        |    6 +
 config/common_base                                 |   14 +
 doc/guides/cryptodevs/features/virtio.ini          |   26 +
 doc/guides/cryptodevs/index.rst                    |    1 +
 doc/guides/cryptodevs/virtio.rst                   |  117 ++
 doc/guides/rel_notes/release_18_05.rst             |    4 +
 drivers/crypto/Makefile                            |    1 +
 drivers/crypto/virtio/Makefile                     |   31 +
 .../virtio/rte_pmd_virtio_crypto_version.map       |    3 +
 drivers/crypto/virtio/virtio_crypto_algs.h         |   27 +
 drivers/crypto/virtio/virtio_crypto_capabilities.h |   51 +
 drivers/crypto/virtio/virtio_cryptodev.c           | 1508
++++++++++++++++++++
 drivers/crypto/virtio/virtio_cryptodev.h           |   66 +
 drivers/crypto/virtio/virtio_logs.h                |   91 ++
 drivers/crypto/virtio/virtio_pci.c                 |  460 ++++++
 drivers/crypto/virtio/virtio_pci.h                 |  253 ++++
 drivers/crypto/virtio/virtio_ring.h                |  137 ++
 drivers/crypto/virtio/virtio_rxtx.c                |  541 +++++++
 drivers/crypto/virtio/virtqueue.c                  |   43 +
 drivers/crypto/virtio/virtqueue.h                  |  172 +++
 mk/rte.app.mk                                      |    1 +
 test/test/test_cryptodev.c                         |   49 +
 test/test/test_cryptodev.h                         |    1 +
 test/test/test_cryptodev_aes_test_vectors.h        |   24 +-
 test/test/test_cryptodev_blockcipher.c             |    9 +-
 test/test/test_cryptodev_blockcipher.h             |    1 +
 26 files changed, 3628 insertions(+), 9 deletions(-)  create mode 100644
doc/guides/cryptodevs/features/virtio.ini
 create mode 100644 doc/guides/cryptodevs/virtio.rst  create mode 100644
drivers/crypto/virtio/Makefile  create mode 100644
drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map
 create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
 create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
 create mode 100644 drivers/crypto/virtio/virtio_cryptodev.c
 create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
 create mode 100644 drivers/crypto/virtio/virtio_logs.h
 create mode 100644 drivers/crypto/virtio/virtio_pci.c
 create mode 100644 drivers/crypto/virtio/virtio_pci.h
 create mode 100644 drivers/crypto/virtio/virtio_ring.h
 create mode 100644 drivers/crypto/virtio/virtio_rxtx.c
 create mode 100644 drivers/crypto/virtio/virtqueue.c  create mode 100644

drivers/crypto/virtio/virtqueue.h

--
1.8.3.1