crypto: add virtio poll mode driver
v6 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
[dpdk-dev] [PATCH v4 0/8] vhost: intdroduce vhost user crypto backend
http://dpdk.org/ml/archives/dev/2018-March/094204.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_idThe 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
+ 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 v6:
- split the patches in a more functional way [Pablo]
Changes in v5:
- rebased on the newest dpdk-next-crypto
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 (10):
crypto/virtio: add virtio crypto PMD crypto/virtio: support virtio device init crypto/virtio: support basic PMD ops crypto/virtio: support session related ops crypto/virtio: support crypto enqueue/dequeue burst API crypto/virtio: support stats related ops crypto/virtio: support AES-CBC
crypto/virtio: support HMAC-SHA1
test/crypto: add function tests for virtio crypto PMD
doc: add virtio crypto PMD guide
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 | 6 + 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 | 1490 ++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 62 + 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 | 515 +++++++ drivers/crypto/virtio/virtqueue.c | 43 + drivers/crypto/virtio/virtqueue.h | 172 +++ mk/rte.app.mk | 1 + test/test/test_cryptodev.c | 48 + 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, 3581 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
PATCH v6 1/10 crypto/virtio: add virtio crypto PMD
--- MAINTAINERS | 4 +++ config/common_base | 14 +++++++++ doc/guides/rel_notes/release_18_05.rst | 3 ++ drivers/crypto/Makefile | 1 + drivers/crypto/virtio/Makefile | 28 ++++++++++++++++++ .../virtio/rte_pmd_virtio_crypto_version.map | 3 ++ drivers/crypto/virtio/virtio_cryptodev.c | 34 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 10 +++++++ mk/rte.app.mk | 1 + 9 files changed, 98 insertions(+) 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_cryptodev.c create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
MAINTAINERS +4 -0
@@ -724,6 +724,10 @@ 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/ + ZUC M: Pablo de Lara <[email protected]> F: drivers/crypto/zuc/
config/common_base +14 -0
@@ -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 +3 -0
@@ -53,6 +53,9 @@ New Features :doc:`../cryptodevs/ccp` crypto driver guide for more details on this new driver. +* **Added the virtio crypto PMD.** + + Added a new poll mode driver for virtio crypto devices. API Changes -----------
drivers/crypto/Makefile +1 -0
@@ -21,5 +21,6 @@ ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec endif DIRS-$(CONFIG_RTE_LIBRTE_PMD_CCP) += ccp +DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/virtio/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# 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) += 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
@@ -0,0 +1,3 @@ +DPDK_18.05 { + local: *; +};
drivers/crypto/virtio/virtio_cryptodev.c new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_cryptodev_pmd.h> +#include "virtio_cryptodev.h" + +uint8_t cryptodev_virtio_driver_id; + +static int crypto_virtio_pci_probe ( + struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static int crypto_virtio_pci_remove ( + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static struct rte_pci_driver rte_virtio_crypto_driver = { + .probe = crypto_virtio_pci_probe, + .remove = crypto_virtio_pci_remove +}; + +static struct cryptodev_driver virtio_crypto_drv; + +RTE_PMD_REGISTER_PCI (CRYPTODEV_NAME_VIRTIO_PMD , rte_virtio_crypto_driver); +RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, + rte_virtio_crypto_driver.driver, + cryptodev_virtio_driver_id);
drivers/crypto/virtio/virtio_cryptodev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ + +#ifndef _VIRTIO_CRYPTODEV_H_ +#define _VIRTIO_CRYPTODEV_H_ + +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio + +#endif /* _VIRTIO_CRYPTODEV_H_ */
mk/rte.app.mk +1 -0
@@ -204,6 +204,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM) += -lIPSec_MB _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
Re: [PATCH v6 01/10] crypto/virtio: add virtio crypto PMD
Hi Jay,
Quoted 11 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Tuesday, April 3, 2018 10:43 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v6 01/10]crypto/virtio: add virtio crypto PMD
Could you add some information about the PMD in this commit message?
The information that you shared in the cover letter looks good, but that won't be merged, so it would be good to have something here.
Also, don't forget to include Fan's acks, when creating new versions of the patchset.
Re: [PATCH v6 01/10] crypto/virtio: add virtio crypto PMD
Hi Pablo,
Quoted 24 lines
-----Original Message-----
From: De Lara Guarch, Pablo [mailto:[email protected]]
Sent: Wednesday, April 04, 2018 8:56 PM
To: Zhoujian (jay) <[email protected]>; [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; Gonglei (Arei) <[email protected]>; Zeng, Xin <[email protected]>; Huangweidong (C) <[email protected]>; wangxin (U) <[email protected]>; longpeng <[email protected]>
Subject: RE: [PATCH v6 01/10]crypto/virtio: add virtio crypto PMDHi Jay,
Quoted 11 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Tuesday, April 3, 2018 10:43 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v6 01/10]crypto/virtio: add virtio crypto PMD
Quoted 3 lines
Could you add some information about the PMD in this commit message? The information that you shared in the cover letter looks good, but that won't be merged, so it would be good to have something here.
Yeah, that does make sense.
Quoted 3 lines
Also, don't forget to include Fan's acks, when creating new versions of the patchset.
Okay.
Regards,
Jay
PATCH v6 2/10 crypto/virtio: support virtio device init
In reply to Jay Zhou--- drivers/crypto/virtio/Makefile | 3 + drivers/crypto/virtio/virtio_cryptodev.c | 247 ++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 13 + 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 | 26 ++ drivers/crypto/virtio/virtqueue.c | 43 +++ drivers/crypto/virtio/virtqueue.h | 172 ++++++++++++ 10 files changed, 1442 insertions(+), 3 deletions(-) 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
drivers/crypto/virtio/Makefile +3 -0
@@ -18,6 +18,9 @@ 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:
drivers/crypto/virtio/virtio_cryptodev.c +244 -3
272 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +13 -0
@@ -5,6 +5,19 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ +#include <rte_cryptodev.h> + +/* Features desired/implemented by this driver. */ +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); + +uint16_t virtio_crypto_pkt_rx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); +#endif /* _VIRTIO_CRYPTODEV_H_ */
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/virtio_rxtx.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include "virtio_cryptodev.h" + +uint16_t +virtio_crypto_pkt_rx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_rx =0 ; + +return nb_rx; +} + +uint16_t +virtio_crypto_pkt_tx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_tx =0 ; + +return nb_tx; +}
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
PATCH v6 3/10 crypto/virtio: support basic PMD ops
In reply to Jay Zhou--- drivers/crypto/virtio/virtio_cryptodev.c | 434 ++++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 32 ++- drivers/crypto/virtio/virtio_rxtx.c | 68 +++++ 3 files changed, 525 insertions(+), 9 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +426 -8
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ +#include <rte_errno.h> #include <rte_pci.h> #include <rte_bus_pci.h> #include <rte_cryptodev.h>
@@ -15,6 +16,22 @@int virtio_crypto_logtype_tx;int virtio_crypto_logtype_driver; +static int virtio_crypto_dev_configure (struct rte_cryptodev *dev, +struct rte_cryptodev_config *config); +static int virtio_crypto_dev_start (struct rte_cryptodev *dev); +static void virtio_crypto_dev_stop (struct rte_cryptodev *dev); +static int virtio_crypto_dev_close (struct rte_cryptodev *dev); +static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *dev_info); +static int virtio_crypto_qp_setup (struct rte_cryptodev *dev, +uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, +struct rte_mempool *session_pool); +static int virtio_crypto_qp_release (struct rte_cryptodev *dev, +uint16_t queue_pair_id); +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev); +/* * The set of PCI devices this driver supports */
@@ -26,22 +43,249 @@uint8_t cryptodev_virtio_driver_id; +void virtio_crypto_queue_release (struct virtqueue *vq) +{ +struct virtio_crypto_hw *hw; + +PMD_INIT_FUNC_TRACE (); + +if (vq) { + hw = vq->hw; +/* Select and deactivate the queue */ +VTPCI_OPS (hw)->del_queue (hw, vq); + +rte_memzone_free (vq->mz); +rte_mempool_free (vq->mpool); +rte_free (vq); + } +} + +#define MPOOL_MAX_NAME_SZ 32 + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq) +{ +char vq_name[VIRTQUEUE_MAX_NAME_SZ ]; +char mpool_name[MPOOL_MAX_NAME_SZ ]; +const struct rte_memzone *mz; +unsigned int vq_size, size; +struct virtio_crypto_hw *hw = dev->data->dev_private; +struct virtqueue *vq =NULL ; +uint32_t i =0 ; +uint32_t j; + +PMD_INIT_FUNC_TRACE (); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("setting up queue: %u" , vtpci_queue_idx); + +/* +* Read the virtqueue size from the Queue Size field +* Always power of 2 and if 0 virtqueue does not exist +*/ + vq_size =VTPCI_OPS (hw)->get_queue_num (hw, vtpci_queue_idx); +if (vq_size ==0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue does not exist" ); +return -EINVAL ; + } +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq_size: %u" , vq_size); + +if (!rte_is_power_of_2 (vq_size)) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue size is not powerof 2" ); +return -EINVAL ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_dataqueue%d" , + dev->data->dev_id, vtpci_queue_idx); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_dataqueue%d_mpool" , + dev->data->dev_id, vtpci_queue_idx); + }else if (queue_type ==VTCRYPTO_CTRLQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_controlqueue" , + dev->data->dev_id); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_controlqueue_mpool" , + dev->data->dev_id); + } + size =RTE_ALIGN_CEIL (sizeof (*vq) + + vq_size *sizeof (struct vq_desc_extra ), +RTE_CACHE_LINE_SIZE ); + vq =rte_zmalloc_socket (vq_name, size,RTE_CACHE_LINE_SIZE , + socket_id); +if (vq ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("Can not allocate virtqueue" ); +return -ENOMEM ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +/* pre-allocate a mempool and use it in the data plane to +* improve performance +*/ + vq->mpool =rte_mempool_lookup (mpool_name); +if (vq->mpool ==NULL ) + vq->mpool =rte_mempool_create (mpool_name, + vq_size, +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ,0 , +NULL ,NULL ,NULL ,NULL , socket_id, +0 ); +if (!vq->mpool) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Virtio Crypto PMD " +"Cannot create mempool" ); + goto mpool_create_err; + } +for (i =0 ; i < vq_size; i++) { + vq->vq_descx[i].cookie = +rte_zmalloc ("crypto PMD op cookie pointer" , +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ); +if (vq->vq_descx[i].cookie ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Failed to " +"alloc mem for cookie" ); + goto cookie_alloc_err; + } + } + } + + vq->hw = hw; + vq->dev_id = dev->data->dev_id; + vq->vq_queue_index = vtpci_queue_idx; + vq->vq_nentries = vq_size; + +/* +* Using part of the vring entries is permitted, but the maximum +* is vq_size +*/ +if (nb_desc ==0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; + +/* +* Reserve a memzone for vring elements +*/ + size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN ); +VIRTIO_CRYPTO_INIT_LOG_DBG ("%s vring_size: %d, rounded_vring_size: %d" , + (queue_type ==VTCRYPTO_DATAQ ) ?"dataq" :"ctrlq" , + size, vq->vq_ring_size); + + mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, + socket_id,0 ,VIRTIO_PCI_VRING_ALIGN ); +if (mz ==NULL ) { +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("not enough memory" ); + goto mz_reserve_err; + } + } + +/* +* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, +* and only accepts 32 bit page frame number. +* Check if the allocated physical memory exceeds 16TB. +*/ +if ((mz->phys_addr + vq->vq_ring_size -1 ) + >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT +32 )) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("vring address shouldn't be " +"above 16TB!" ); + goto vring_addr_err; + } + +memset (mz->addr,0 ,sizeof (mz->len)); + vq->mz = mz; + vq->vq_ring_mem = mz->phys_addr; + vq->vq_ring_virt_mem = mz->addr; +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_mem(physical): 0x%" PRIx64, + (uint64_t )mz->phys_addr); +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_virt_mem: 0x%" PRIx64, + (uint64_t )(uintptr_t )mz->addr); + + *pvq = vq; + +return 0 ; + +vring_addr_err: +rte_memzone_free (mz); +mz_reserve_err: +cookie_alloc_err: +rte_mempool_free (vq->mpool); +if (i !=0 ) { +for (j =0 ; j < i; j++) +rte_free (vq->vq_descx[j].cookie); + } +mpool_create_err: +rte_free (vq); +return -ENOMEM ; +} + +static int +virtio_crypto_ctrlq_setup (struct rte_cryptodev *dev,uint16_t queue_idx) +{ +int ret; +struct virtqueue *vq; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +/* if virtio device has started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + +PMD_INIT_FUNC_TRACE (); + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_CTRLQ , queue_idx, +0 ,SOCKET_ID_ANY , &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control vq initialization failed" ); +return ret; + } + + hw->cvq = vq; + +return 0 ; +} + +static void +virtio_crypto_free_queues (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +/* control queue release */ +virtio_crypto_queue_release (hw->cvq); + +/* data queue release */ +for (i =0 ; i < hw->max_dataqueues; i++) +virtio_crypto_queue_release (dev->data->queue_pairs[i]); +} + +static int +virtio_crypto_dev_close(struct rte_cryptodev *dev __rte_unused) +{ +return 0 ; +} +/* * dev_ops for virtio, bare necessities for basic operation */ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {/* Device related operations */ - .dev_configure =NULL , - .dev_start =NULL , - .dev_stop =NULL , - .dev_close =NULL , - .dev_infos_get =NULL , + .dev_configure = virtio_crypto_dev_configure, + .dev_start = virtio_crypto_dev_start, + .dev_stop = virtio_crypto_dev_stop, + .dev_close = virtio_crypto_dev_close, + .dev_infos_get = virtio_crypto_dev_info_get, .stats_get =NULL , .stats_reset =NULL , - .queue_pair_setup =NULL , - .queue_pair_release =NULL , + .queue_pair_setup = virtio_crypto_qp_setup, + .queue_pair_release = virtio_crypto_qp_release, .queue_pair_start =NULL , .queue_pair_stop =NULL , .queue_pair_count =NULL ,
@@ -55,6 +299,51 @@ };static int +virtio_crypto_qp_setup (struct rte_cryptodev *dev,uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, + struct rte_mempool *session_pool __rte_unused) +{ +int ret; +struct virtqueue *vq; + +PMD_INIT_FUNC_TRACE (); + +/* if virtio dev is started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_DATAQ , queue_pair_id, + qp_conf->nb_descriptors, socket_id, &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ( +"virtio crypto data queue initialization failed\n" ); +return ret; + } + + dev->data->queue_pairs[queue_pair_id] = vq; + +return 0 ; +} + +static int +virtio_crypto_qp_release (struct rte_cryptodev *dev,uint16_t queue_pair_id) +{ +struct virtqueue *vq + = (struct virtqueue *)dev->data->queue_pairs[queue_pair_id]; + +PMD_INIT_FUNC_TRACE (); + +if (vq ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_DBG ("vq already freed" ); +return 0 ; + } + +virtio_crypto_queue_release (vq); +return 0 ; +} + +static int virtio_negotiate_features (struct virtio_crypto_hw *hw,uint64_t req_features) {uint64_t host_features;
@@ -191,6 +480,135 @@return 0 ; } +static int +virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (cryptodev->data->dev_started) { +virtio_crypto_dev_stop (cryptodev); +virtio_crypto_dev_close (cryptodev); + } + + cryptodev->dev_ops =NULL ; + cryptodev->enqueue_burst =NULL ; + cryptodev->dequeue_burst =NULL ; + +/* release control queue */ +virtio_crypto_queue_release (hw->cvq); + +rte_free (cryptodev->data); + cryptodev->data =NULL ; + +VIRTIO_CRYPTO_DRV_LOG_INFO ("dev_uninit completed" ); + +return 0 ; +} + +static int +virtio_crypto_dev_configure (struct rte_cryptodev *cryptodev, + struct rte_cryptodev_config *config __rte_unused) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (virtio_crypto_init_device (cryptodev, +VIRTIO_CRYPTO_PMD_GUEST_FEATURES ) <0 ) +return -1 ; + +/* setup control queue +* [0, 1, ... ,(config->max_dataqueues - 1)] are data queues +* config->max_dataqueues is the control queue +*/ +if (virtio_crypto_ctrlq_setup (cryptodev, hw->max_dataqueues) <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control queue setup error" ); +return -1 ; + } +virtio_crypto_ctrlq_start (cryptodev); + +return 0 ; +} + +static void +virtio_crypto_dev_stop (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); +VIRTIO_CRYPTO_DRV_LOG_DBG ("virtio_dev_stop" ); + +vtpci_cryptodev_reset (hw); + +virtio_crypto_dev_free_mbufs (dev); +virtio_crypto_free_queues (dev); + + dev->data->dev_started =0 ; +} + +static int +virtio_crypto_dev_start (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +if (dev->data->dev_started) +return 0 ; + +/* Do final configuration before queue engine starts */ +virtio_crypto_dataq_start (dev); +vtpci_cryptodev_reinit_complete (hw); + + dev->data->dev_started =1 ; + +return 0 ; +} + +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev) +{ +uint32_t i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +for (i =0 ; i < hw->max_dataqueues; i++) { +VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " +"and unused buf" , i); +VIRTQUEUE_DUMP ((struct virtqueue *) + dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("queue_pairs[%d]=%p" , + i, dev->data->queue_pairs[i]); + +virtqueue_detatch_unused (dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("After freeing dataq[%d] used and " +"unused buf" , i); +VIRTQUEUE_DUMP ( + (struct virtqueue *)dev->data->queue_pairs[i]); + } +} + +static void +virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *info) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (info !=NULL ) { + info->driver_id = cryptodev_virtio_driver_id; + info->pci_dev =RTE_DEV_TO_PCI (dev->device); + info->feature_flags = dev->feature_flags; + info->max_nb_queue_pairs = hw->max_dataqueues; + info->sym.max_nb_sessions = +RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + } +} +static int crypto_virtio_pci_probe ( struct rte_pci_driver *pci_drv __rte_unused,struct rte_pci_device *pci_dev)
@@ -229,7 +647,7 @@ static int crypto_virtio_pci_remove(if (cryptodev ==NULL )return -ENODEV ; -return 0 ; +return virtio_crypto_dev_uninit (cryptodev); }static struct rte_pci_driver rte_virtio_crypto_driver = {
drivers/crypto/virtio/virtio_cryptodev.h +31 -1
@@ -5,13 +5,43 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ -#include <rte_cryptodev.h> +#include <linux/virtio_crypto.h> + +#include "virtio_pci.h" +#include "virtio_ring.h" /* Features desired/implemented by this driver. */ #define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 + +struct virtio_crypto_op_cookie { +struct virtio_crypto_op_data_req data_req; +struct virtio_crypto_inhdr inhdr; +struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ]; +}; + +/* +* Control queue function prototype +*/ +void virtio_crypto_ctrlq_start (struct rte_cryptodev *dev); + +/* +* Data queue function prototype +*/ +void virtio_crypto_dataq_start (struct rte_cryptodev *dev); + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq); + +void virtio_crypto_queue_release (struct virtqueue *vq); +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue,struct rte_crypto_op **tx_pkts,uint16_t nb_pkts);
drivers/crypto/virtio/virtio_rxtx.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 4/10 crypto/virtio: support session related ops
In reply to Jay Zhou--- drivers/crypto/virtio/virtio_crypto_algs.h | 27 ++ drivers/crypto/virtio/virtio_cryptodev.c | 728 ++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 7 + 3 files changed, 759 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +27 -0
@@ -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_ */
drivers/crypto/virtio/virtio_cryptodev.c +725 -3
766 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +7 -0
@@ -17,6 +17,13 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +enum virtio_crypto_cmd_id { +VIRTIO_CRYPTO_CMD_CIPHER =0 , +VIRTIO_CRYPTO_CMD_AUTH =1 , +VIRTIO_CRYPTO_CMD_CIPHER_HASH =2 , +VIRTIO_CRYPTO_CMD_HASH_CIPHER =3 +}; +struct virtio_crypto_op_cookie {struct virtio_crypto_op_data_req data_req;struct virtio_crypto_inhdr inhdr;
Signature · 1 line
1.8.3.1
PATCH v6 5/10 crypto/virtio: support crypto enqueue/dequeue burst API
In reply to Jay Zhou--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 441 ++++++++++++++++++++++++++++++- 2 files changed, 433 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -17,6 +17,8 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +extern uint8_t cryptodev_virtio_driver_id; +enum virtio_crypto_cmd_id {VIRTIO_CRYPTO_CMD_CIPHER =0 ,VIRTIO_CRYPTO_CMD_AUTH =1 ,
drivers/crypto/virtio/virtio_rxtx.c +431 -10
463 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 6/10 crypto/virtio: support stats related ops
In reply to Jay Zhou--- drivers/crypto/virtio/virtio_cryptodev.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +64 -2
@@ -29,6 +29,9 @@ static int virtio_crypto_dev_configure(struct rte_cryptodev *dev,static int virtio_crypto_dev_close (struct rte_cryptodev *dev);static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev,struct rte_cryptodev_info *dev_info); +static void virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats); +static void virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev); static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
@@ -499,8 +502,8 @@ int virtio_crypto_queue_setup(struct rte_cryptodev *dev, .dev_close = virtio_crypto_dev_close, .dev_infos_get = virtio_crypto_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = virtio_crypto_dev_stats_get, + .stats_reset = virtio_crypto_dev_stats_reset, .queue_pair_setup = virtio_crypto_qp_setup, .queue_pair_release = virtio_crypto_qp_release,
@@ -516,6 +519,65 @@ int virtio_crypto_queue_setup(struct rte_cryptodev *dev, .qp_detach_session = NULL }; +static void +virtio_crypto_update_stats (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (stats ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("invalid pointer" ); +return ; + } + +for (i =0 ; i < hw->max_dataqueues; i++) { +const struct virtqueue *data_queue + = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + stats->enqueued_count += data_queue->packets_sent_total; + stats->enqueue_err_count += data_queue->packets_sent_failed; + + stats->dequeued_count += data_queue->packets_received_total; + stats->dequeue_err_count + += data_queue->packets_received_failed; + } +} + +static void +virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +PMD_INIT_FUNC_TRACE (); + +virtio_crypto_update_stats (dev, stats); +} + +static void +virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +for (i =0 ; i < hw->max_dataqueues; i++) { +struct virtqueue *data_queue = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + data_queue->packets_sent_total =0 ; + data_queue->packets_sent_failed =0 ; + + data_queue->packets_received_total =0 ; + data_queue->packets_received_failed =0 ; + } +} + static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
Signature · 1 line
1.8.3.1
PATCH v6 7/10 crypto/virtio: support AES-CBC
In reply to Jay Zhou--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 30 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 11 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 \ + { /* 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 +11 -0
@@ -15,6 +15,7 @@#include "virtio_cryptodev.h" #include "virtqueue.h" #include "virtio_crypto_algs.h" +#include "virtio_crypto_capabilities.h" int virtio_crypto_logtype_init;int virtio_crypto_logtype_session;
@@ -58,6 +59,11 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, { .vendor_id = 0, /* sentinel */ }, }; +static const struct rte_cryptodev_capabilities virtio_capabilities[] = { +VIRTIO_SYM_CAPABILITIES , +RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST () +}; +uint8_t cryptodev_virtio_driver_id;#define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -744,6 +750,7 @@ int virtio_crypto_queue_setup(struct rte_cryptodev *dev, hw = cryptodev->data->dev_private; hw->dev_id = cryptodev->data->dev_id; + hw->virtio_dev_capabilities = virtio_capabilities; VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x", cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1131,6 +1138,9 @@ static int virtio_crypto_sym_pad_cipher_param( struct rte_crypto_cipher_xform *cipher_xform) {switch (cipher_xform->algo) { +case RTE_CRYPTO_CIPHER_AES_CBC : + para->algo =VIRTIO_CRYPTO_CIPHER_AES_CBC ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Unsupported " "Cipher alg %u" , cipher_xform->algo);
@@ -1390,6 +1400,7 @@ static int virtio_crypto_sym_configure_session( info->max_nb_queue_pairs = hw->max_dataqueues; info->sym.max_nb_sessions =RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + info->capabilities = hw->virtio_dev_capabilities; } }
Signature · 1 line
1.8.3.1
PATCH v6 8/10 crypto/virtio: support HMAC-SHA1
In reply to Jay Zhou--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 21 +++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +21 -0
@@ -6,6 +6,27 @@#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 = { \
drivers/crypto/virtio/virtio_cryptodev.c +3 -1
@@ -1187,11 +1187,13 @@ static int virtio_crypto_sym_pad_auth_param( }switch (auth_xform->algo) { +case RTE_CRYPTO_AUTH_SHA1_HMAC : + *algo =VIRTIO_CRYPTO_MAC_HMAC_SHA1 ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Undefined Hash algo %u specified" , auth_xform->algo); - *algo =VIRTIO_CRYPTO_NO_MAC ;return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v6 9/10 test/crypto: add function tests for virtio crypto PMD
In reply to Jay ZhouOnly 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 | 48 +++++++++++++++++++++++++++++ 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, 74 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +48 -0
@@ -1820,6 +1820,25 @@ 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;
@@ -8879,6 +8898,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,
@@ -9808,6 +9839,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(
@@ -10040,3 +10087,4 @@ struct test_crypto_vector {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_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND (cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
@@ -62,6 +62,7 @@#define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler#define CRYPTODEV_NAME_MRVL_PMD crypto_mrvl#define CRYPTODEV_NAME_CCP_PMD crypto_ccp +#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
@@ -1544,7 +1544,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
@@ -70,6 +70,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 ;
@@ -97,7 +99,8 @@ driver_id == openssl_pmd || driver_id == armv8_pmd || driver_id == mrvl_pmd || - driver_id == ccp_pmd) { /* Fall through */ + driver_id == ccp_pmd || + driver_id == virtio_pmd) { /* Fall through */ digest_len = tdata->digest.len; } else if (driver_id == aesni_mb_pmd || driver_id == scheduler_pmd) {
@@ -574,6 +577,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 :
@@ -638,6 +643,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
@@ -28,6 +28,7 @@#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_CCP 0x0040/* CCP flag */ +#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO 0x0200/* VIRTIO flag */ #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
PATCH v6 10/10 doc: add virtio crypto PMD guide
In reply to Jay Zhou--- MAINTAINERS | 2 + 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 | 5 +- 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/guides/cryptodevs/features/virtio.ini create mode 100644 doc/guides/cryptodevs/virtio.rst
MAINTAINERS +2 -0
@@ -727,6 +727,8 @@ 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]>
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
@@ -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
@@ -23,4 +23,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
doc/guides/rel_notes/release_18_05.rst +4 -1
@@ -55,7 +55,10 @@ New Features * **Added the virtio crypto PMD.** - Added a new poll mode driver for virtio crypto devices. + Added a new poll mode driver for virtio crypto devices, which provides + AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. See the + :doc:`../cryptodevs/virtio` crypto driver guide for more details on + this new driver. API Changes -----------
Signature · 1 line
1.8.3.1
v7 cover crypto: add virtio poll mode driver
In reply to Jay ZhouThis 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
[dpdk-dev] [PATCH v4 0/8] vhost: intdroduce vhost user crypto backend
http://dpdk.org/ml/archives/dev/2018-March/094204.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_idThe 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
+ 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 v7:
- add detailed commit messages [Pablo]
Changes in v6:
- split the patches in a more functional way [Pablo]
Changes in v5:
- rebased on the newest dpdk-next-crypto
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 (10):
crypto/virtio: add virtio crypto PMD crypto/virtio: support virtio device init crypto/virtio: support basic PMD ops crypto/virtio: support session related ops crypto/virtio: support crypto enqueue/dequeue burst API crypto/virtio: support stats related ops crypto/virtio: support AES-CBC
crypto/virtio: support HMAC-SHA1
test/crypto: add function tests for virtio crypto PMD
doc: add virtio crypto PMD guide
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 | 7 + 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 | 1490 ++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 62 + 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 | 515 +++++++ drivers/crypto/virtio/virtqueue.c | 43 + drivers/crypto/virtio/virtqueue.h | 172 +++ mk/rte.app.mk | 1 + test/test/test_cryptodev.c | 48 + 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, 3582 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
Signature · 1 line
1.8.3.1
PATCH v7 1/10 crypto/virtio: add virtio crypto PMD
The virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
--- MAINTAINERS | 4 +++ config/common_base | 14 +++++++++ doc/guides/rel_notes/release_18_05.rst | 4 +++ drivers/crypto/Makefile | 1 + drivers/crypto/virtio/Makefile | 28 ++++++++++++++++++ .../virtio/rte_pmd_virtio_crypto_version.map | 3 ++ drivers/crypto/virtio/virtio_cryptodev.c | 34 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 10 +++++++ mk/rte.app.mk | 1 + 9 files changed, 99 insertions(+) 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_cryptodev.c create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
MAINTAINERS +4 -0
@@ -724,6 +724,10 @@ 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/ + ZUC M: Pablo de Lara <[email protected]> F: drivers/crypto/zuc/
config/common_base +14 -0
@@ -479,6 +479,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
@@ -70,6 +70,10 @@ New Features * AES-CMAC (128-bit key). +* **Added the virtio crypto PMD.** + + Added a new poll mode driver for virtio crypto devices. + API Changes -----------
drivers/crypto/Makefile +1 -0
@@ -21,5 +21,6 @@ ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec endif DIRS-$(CONFIG_RTE_LIBRTE_PMD_CCP) += ccp +DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/virtio/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# 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) += 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
@@ -0,0 +1,3 @@ +DPDK_18.05 { + local: *; +};
drivers/crypto/virtio/virtio_cryptodev.c new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_cryptodev_pmd.h> +#include "virtio_cryptodev.h" + +uint8_t cryptodev_virtio_driver_id; + +static int crypto_virtio_pci_probe ( + struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static int crypto_virtio_pci_remove ( + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static struct rte_pci_driver rte_virtio_crypto_driver = { + .probe = crypto_virtio_pci_probe, + .remove = crypto_virtio_pci_remove +}; + +static struct cryptodev_driver virtio_crypto_drv; + +RTE_PMD_REGISTER_PCI (CRYPTODEV_NAME_VIRTIO_PMD , rte_virtio_crypto_driver); +RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, + rte_virtio_crypto_driver.driver, + cryptodev_virtio_driver_id);
drivers/crypto/virtio/virtio_cryptodev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ + +#ifndef _VIRTIO_CRYPTODEV_H_ +#define _VIRTIO_CRYPTODEV_H_ + +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio + +#endif /* _VIRTIO_CRYPTODEV_H_ */
mk/rte.app.mk +1 -0
@@ -204,6 +204,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM) += -lIPSec_MB _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
PATCH v7 2/10 crypto/virtio: support virtio device init
In reply to Jay ZhouThis patch implements the initialization of the virtio crypto device. The virtio crypto device conforms to virtio-1.0, so this patch only supports modern mode operation.
The cryptodev is created at the virtio crypto pci device probing stage. The function of virtio_crypto_pkt_tx_burst() is used to burst transfer packets and virtio_crypto_pkt_rx_burst() is used to burst receive packets.
--- drivers/crypto/virtio/Makefile | 3 + drivers/crypto/virtio/virtio_cryptodev.c | 247 ++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 13 + 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 | 26 ++ drivers/crypto/virtio/virtqueue.c | 43 +++ drivers/crypto/virtio/virtqueue.h | 172 ++++++++++++ 10 files changed, 1442 insertions(+), 3 deletions(-) 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
drivers/crypto/virtio/Makefile +3 -0
@@ -18,6 +18,9 @@ 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:
drivers/crypto/virtio/virtio_cryptodev.c +244 -3
272 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +13 -0
@@ -5,6 +5,19 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ +#include <rte_cryptodev.h> + +/* Features desired/implemented by this driver. */ +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); + +uint16_t virtio_crypto_pkt_rx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); +#endif /* _VIRTIO_CRYPTODEV_H_ */
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/virtio_rxtx.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include "virtio_cryptodev.h" + +uint16_t +virtio_crypto_pkt_rx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_rx =0 ; + +return nb_rx; +} + +uint16_t +virtio_crypto_pkt_tx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_tx =0 ; + +return nb_tx; +}
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
PATCH v7 3/10 crypto/virtio: support basic PMD ops
In reply to Jay ZhouThis patch implements the basic operations of virtio crypto PMD, which includes start, stop, close, information getting, queue setup and release of the device.
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.
--- drivers/crypto/virtio/virtio_cryptodev.c | 434 ++++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 32 ++- drivers/crypto/virtio/virtio_rxtx.c | 68 +++++ 3 files changed, 525 insertions(+), 9 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +426 -8
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ +#include <rte_errno.h> #include <rte_pci.h> #include <rte_bus_pci.h> #include <rte_cryptodev.h>
@@ -15,6 +16,22 @@int virtio_crypto_logtype_tx;int virtio_crypto_logtype_driver; +static int virtio_crypto_dev_configure (struct rte_cryptodev *dev, +struct rte_cryptodev_config *config); +static int virtio_crypto_dev_start (struct rte_cryptodev *dev); +static void virtio_crypto_dev_stop (struct rte_cryptodev *dev); +static int virtio_crypto_dev_close (struct rte_cryptodev *dev); +static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *dev_info); +static int virtio_crypto_qp_setup (struct rte_cryptodev *dev, +uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, +struct rte_mempool *session_pool); +static int virtio_crypto_qp_release (struct rte_cryptodev *dev, +uint16_t queue_pair_id); +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev); +/* * The set of PCI devices this driver supports */
@@ -26,22 +43,249 @@uint8_t cryptodev_virtio_driver_id; +void virtio_crypto_queue_release (struct virtqueue *vq) +{ +struct virtio_crypto_hw *hw; + +PMD_INIT_FUNC_TRACE (); + +if (vq) { + hw = vq->hw; +/* Select and deactivate the queue */ +VTPCI_OPS (hw)->del_queue (hw, vq); + +rte_memzone_free (vq->mz); +rte_mempool_free (vq->mpool); +rte_free (vq); + } +} + +#define MPOOL_MAX_NAME_SZ 32 + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq) +{ +char vq_name[VIRTQUEUE_MAX_NAME_SZ ]; +char mpool_name[MPOOL_MAX_NAME_SZ ]; +const struct rte_memzone *mz; +unsigned int vq_size, size; +struct virtio_crypto_hw *hw = dev->data->dev_private; +struct virtqueue *vq =NULL ; +uint32_t i =0 ; +uint32_t j; + +PMD_INIT_FUNC_TRACE (); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("setting up queue: %u" , vtpci_queue_idx); + +/* +* Read the virtqueue size from the Queue Size field +* Always power of 2 and if 0 virtqueue does not exist +*/ + vq_size =VTPCI_OPS (hw)->get_queue_num (hw, vtpci_queue_idx); +if (vq_size ==0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue does not exist" ); +return -EINVAL ; + } +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq_size: %u" , vq_size); + +if (!rte_is_power_of_2 (vq_size)) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue size is not powerof 2" ); +return -EINVAL ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_dataqueue%d" , + dev->data->dev_id, vtpci_queue_idx); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_dataqueue%d_mpool" , + dev->data->dev_id, vtpci_queue_idx); + }else if (queue_type ==VTCRYPTO_CTRLQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_controlqueue" , + dev->data->dev_id); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_controlqueue_mpool" , + dev->data->dev_id); + } + size =RTE_ALIGN_CEIL (sizeof (*vq) + + vq_size *sizeof (struct vq_desc_extra ), +RTE_CACHE_LINE_SIZE ); + vq =rte_zmalloc_socket (vq_name, size,RTE_CACHE_LINE_SIZE , + socket_id); +if (vq ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("Can not allocate virtqueue" ); +return -ENOMEM ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +/* pre-allocate a mempool and use it in the data plane to +* improve performance +*/ + vq->mpool =rte_mempool_lookup (mpool_name); +if (vq->mpool ==NULL ) + vq->mpool =rte_mempool_create (mpool_name, + vq_size, +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ,0 , +NULL ,NULL ,NULL ,NULL , socket_id, +0 ); +if (!vq->mpool) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Virtio Crypto PMD " +"Cannot create mempool" ); + goto mpool_create_err; + } +for (i =0 ; i < vq_size; i++) { + vq->vq_descx[i].cookie = +rte_zmalloc ("crypto PMD op cookie pointer" , +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ); +if (vq->vq_descx[i].cookie ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Failed to " +"alloc mem for cookie" ); + goto cookie_alloc_err; + } + } + } + + vq->hw = hw; + vq->dev_id = dev->data->dev_id; + vq->vq_queue_index = vtpci_queue_idx; + vq->vq_nentries = vq_size; + +/* +* Using part of the vring entries is permitted, but the maximum +* is vq_size +*/ +if (nb_desc ==0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; + +/* +* Reserve a memzone for vring elements +*/ + size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN ); +VIRTIO_CRYPTO_INIT_LOG_DBG ("%s vring_size: %d, rounded_vring_size: %d" , + (queue_type ==VTCRYPTO_DATAQ ) ?"dataq" :"ctrlq" , + size, vq->vq_ring_size); + + mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, + socket_id,0 ,VIRTIO_PCI_VRING_ALIGN ); +if (mz ==NULL ) { +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("not enough memory" ); + goto mz_reserve_err; + } + } + +/* +* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, +* and only accepts 32 bit page frame number. +* Check if the allocated physical memory exceeds 16TB. +*/ +if ((mz->phys_addr + vq->vq_ring_size -1 ) + >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT +32 )) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("vring address shouldn't be " +"above 16TB!" ); + goto vring_addr_err; + } + +memset (mz->addr,0 ,sizeof (mz->len)); + vq->mz = mz; + vq->vq_ring_mem = mz->phys_addr; + vq->vq_ring_virt_mem = mz->addr; +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_mem(physical): 0x%" PRIx64, + (uint64_t )mz->phys_addr); +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_virt_mem: 0x%" PRIx64, + (uint64_t )(uintptr_t )mz->addr); + + *pvq = vq; + +return 0 ; + +vring_addr_err: +rte_memzone_free (mz); +mz_reserve_err: +cookie_alloc_err: +rte_mempool_free (vq->mpool); +if (i !=0 ) { +for (j =0 ; j < i; j++) +rte_free (vq->vq_descx[j].cookie); + } +mpool_create_err: +rte_free (vq); +return -ENOMEM ; +} + +static int +virtio_crypto_ctrlq_setup (struct rte_cryptodev *dev,uint16_t queue_idx) +{ +int ret; +struct virtqueue *vq; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +/* if virtio device has started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + +PMD_INIT_FUNC_TRACE (); + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_CTRLQ , queue_idx, +0 ,SOCKET_ID_ANY , &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control vq initialization failed" ); +return ret; + } + + hw->cvq = vq; + +return 0 ; +} + +static void +virtio_crypto_free_queues (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +/* control queue release */ +virtio_crypto_queue_release (hw->cvq); + +/* data queue release */ +for (i =0 ; i < hw->max_dataqueues; i++) +virtio_crypto_queue_release (dev->data->queue_pairs[i]); +} + +static int +virtio_crypto_dev_close(struct rte_cryptodev *dev __rte_unused) +{ +return 0 ; +} +/* * dev_ops for virtio, bare necessities for basic operation */ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {/* Device related operations */ - .dev_configure =NULL , - .dev_start =NULL , - .dev_stop =NULL , - .dev_close =NULL , - .dev_infos_get =NULL , + .dev_configure = virtio_crypto_dev_configure, + .dev_start = virtio_crypto_dev_start, + .dev_stop = virtio_crypto_dev_stop, + .dev_close = virtio_crypto_dev_close, + .dev_infos_get = virtio_crypto_dev_info_get, .stats_get =NULL , .stats_reset =NULL , - .queue_pair_setup =NULL , - .queue_pair_release =NULL , + .queue_pair_setup = virtio_crypto_qp_setup, + .queue_pair_release = virtio_crypto_qp_release, .queue_pair_start =NULL , .queue_pair_stop =NULL , .queue_pair_count =NULL ,
@@ -55,6 +299,51 @@ };static int +virtio_crypto_qp_setup (struct rte_cryptodev *dev,uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, + struct rte_mempool *session_pool __rte_unused) +{ +int ret; +struct virtqueue *vq; + +PMD_INIT_FUNC_TRACE (); + +/* if virtio dev is started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_DATAQ , queue_pair_id, + qp_conf->nb_descriptors, socket_id, &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ( +"virtio crypto data queue initialization failed\n" ); +return ret; + } + + dev->data->queue_pairs[queue_pair_id] = vq; + +return 0 ; +} + +static int +virtio_crypto_qp_release (struct rte_cryptodev *dev,uint16_t queue_pair_id) +{ +struct virtqueue *vq + = (struct virtqueue *)dev->data->queue_pairs[queue_pair_id]; + +PMD_INIT_FUNC_TRACE (); + +if (vq ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_DBG ("vq already freed" ); +return 0 ; + } + +virtio_crypto_queue_release (vq); +return 0 ; +} + +static int virtio_negotiate_features (struct virtio_crypto_hw *hw,uint64_t req_features) {uint64_t host_features;
@@ -191,6 +480,135 @@return 0 ; } +static int +virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (cryptodev->data->dev_started) { +virtio_crypto_dev_stop (cryptodev); +virtio_crypto_dev_close (cryptodev); + } + + cryptodev->dev_ops =NULL ; + cryptodev->enqueue_burst =NULL ; + cryptodev->dequeue_burst =NULL ; + +/* release control queue */ +virtio_crypto_queue_release (hw->cvq); + +rte_free (cryptodev->data); + cryptodev->data =NULL ; + +VIRTIO_CRYPTO_DRV_LOG_INFO ("dev_uninit completed" ); + +return 0 ; +} + +static int +virtio_crypto_dev_configure (struct rte_cryptodev *cryptodev, + struct rte_cryptodev_config *config __rte_unused) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (virtio_crypto_init_device (cryptodev, +VIRTIO_CRYPTO_PMD_GUEST_FEATURES ) <0 ) +return -1 ; + +/* setup control queue +* [0, 1, ... ,(config->max_dataqueues - 1)] are data queues +* config->max_dataqueues is the control queue +*/ +if (virtio_crypto_ctrlq_setup (cryptodev, hw->max_dataqueues) <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control queue setup error" ); +return -1 ; + } +virtio_crypto_ctrlq_start (cryptodev); + +return 0 ; +} + +static void +virtio_crypto_dev_stop (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); +VIRTIO_CRYPTO_DRV_LOG_DBG ("virtio_dev_stop" ); + +vtpci_cryptodev_reset (hw); + +virtio_crypto_dev_free_mbufs (dev); +virtio_crypto_free_queues (dev); + + dev->data->dev_started =0 ; +} + +static int +virtio_crypto_dev_start (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +if (dev->data->dev_started) +return 0 ; + +/* Do final configuration before queue engine starts */ +virtio_crypto_dataq_start (dev); +vtpci_cryptodev_reinit_complete (hw); + + dev->data->dev_started =1 ; + +return 0 ; +} + +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev) +{ +uint32_t i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +for (i =0 ; i < hw->max_dataqueues; i++) { +VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " +"and unused buf" , i); +VIRTQUEUE_DUMP ((struct virtqueue *) + dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("queue_pairs[%d]=%p" , + i, dev->data->queue_pairs[i]); + +virtqueue_detatch_unused (dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("After freeing dataq[%d] used and " +"unused buf" , i); +VIRTQUEUE_DUMP ( + (struct virtqueue *)dev->data->queue_pairs[i]); + } +} + +static void +virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *info) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (info !=NULL ) { + info->driver_id = cryptodev_virtio_driver_id; + info->pci_dev =RTE_DEV_TO_PCI (dev->device); + info->feature_flags = dev->feature_flags; + info->max_nb_queue_pairs = hw->max_dataqueues; + info->sym.max_nb_sessions = +RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + } +} +static int crypto_virtio_pci_probe ( struct rte_pci_driver *pci_drv __rte_unused,struct rte_pci_device *pci_dev)
@@ -229,7 +647,7 @@ static int crypto_virtio_pci_remove(if (cryptodev ==NULL )return -ENODEV ; -return 0 ; +return virtio_crypto_dev_uninit (cryptodev); }static struct rte_pci_driver rte_virtio_crypto_driver = {
drivers/crypto/virtio/virtio_cryptodev.h +31 -1
@@ -5,13 +5,43 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ -#include <rte_cryptodev.h> +#include <linux/virtio_crypto.h> + +#include "virtio_pci.h" +#include "virtio_ring.h" /* Features desired/implemented by this driver. */ #define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 + +struct virtio_crypto_op_cookie { +struct virtio_crypto_op_data_req data_req; +struct virtio_crypto_inhdr inhdr; +struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ]; +}; + +/* +* Control queue function prototype +*/ +void virtio_crypto_ctrlq_start (struct rte_cryptodev *dev); + +/* +* Data queue function prototype +*/ +void virtio_crypto_dataq_start (struct rte_cryptodev *dev); + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq); + +void virtio_crypto_queue_release (struct virtqueue *vq); +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue,struct rte_crypto_op **tx_pkts,uint16_t nb_pkts);
drivers/crypto/virtio/virtio_rxtx.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 4/10 crypto/virtio: support session related ops
In reply to Jay ZhouThis patch implements session related operations, which includes creating and destroying the session. For now, it only supports the session-oriented API implementation. The control queue used to create or destroy sessions for symmetric algorithms.
--- drivers/crypto/virtio/virtio_crypto_algs.h | 27 ++ drivers/crypto/virtio/virtio_cryptodev.c | 728 ++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 7 + 3 files changed, 759 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +27 -0
@@ -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_ */
drivers/crypto/virtio/virtio_cryptodev.c +725 -3
766 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +7 -0
@@ -17,6 +17,13 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +enum virtio_crypto_cmd_id { +VIRTIO_CRYPTO_CMD_CIPHER =0 , +VIRTIO_CRYPTO_CMD_AUTH =1 , +VIRTIO_CRYPTO_CMD_CIPHER_HASH =2 , +VIRTIO_CRYPTO_CMD_HASH_CIPHER =3 +}; +struct virtio_crypto_op_cookie {struct virtio_crypto_op_data_req data_req;struct virtio_crypto_inhdr inhdr;
Signature · 1 line
1.8.3.1
PATCH v7 5/10 crypto/virtio: support crypto enqueue/dequeue burst API
In reply to Jay ZhouThis patch implements the functions of virtio_crypto_pkt_tx_burst() and virtio_crypto_pkt_rx_burst(). The encryption and decryption requests are placed in the data queue and are ultimately handled by the backend crypto accelerators.
--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 441 ++++++++++++++++++++++++++++++- 2 files changed, 433 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -17,6 +17,8 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +extern uint8_t cryptodev_virtio_driver_id; +enum virtio_crypto_cmd_id {VIRTIO_CRYPTO_CMD_CIPHER =0 ,VIRTIO_CRYPTO_CMD_AUTH =1 ,
drivers/crypto/virtio/virtio_rxtx.c +431 -10
463 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 6/10 crypto/virtio: support stats related ops
In reply to Jay ZhouThis patch implements the statistics of the packets.
--- drivers/crypto/virtio/virtio_cryptodev.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +64 -2
@@ -29,6 +29,9 @@ static int virtio_crypto_dev_configure(struct rte_cryptodev *dev,static int virtio_crypto_dev_close (struct rte_cryptodev *dev);static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev,struct rte_cryptodev_info *dev_info); +static void virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats); +static void virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev); static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
@@ -499,8 +502,8 @@ int virtio_crypto_queue_setup(struct rte_cryptodev *dev, .dev_close = virtio_crypto_dev_close, .dev_infos_get = virtio_crypto_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = virtio_crypto_dev_stats_get, + .stats_reset = virtio_crypto_dev_stats_reset, .queue_pair_setup = virtio_crypto_qp_setup, .queue_pair_release = virtio_crypto_qp_release,
@@ -516,6 +519,65 @@ int virtio_crypto_queue_setup(struct rte_cryptodev *dev, .qp_detach_session = NULL }; +static void +virtio_crypto_update_stats (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (stats ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("invalid pointer" ); +return ; + } + +for (i =0 ; i < hw->max_dataqueues; i++) { +const struct virtqueue *data_queue + = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + stats->enqueued_count += data_queue->packets_sent_total; + stats->enqueue_err_count += data_queue->packets_sent_failed; + + stats->dequeued_count += data_queue->packets_received_total; + stats->dequeue_err_count + += data_queue->packets_received_failed; + } +} + +static void +virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +PMD_INIT_FUNC_TRACE (); + +virtio_crypto_update_stats (dev, stats); +} + +static void +virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +for (i =0 ; i < hw->max_dataqueues; i++) { +struct virtqueue *data_queue = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + data_queue->packets_sent_total =0 ; + data_queue->packets_sent_failed =0 ; + + data_queue->packets_received_total =0 ; + data_queue->packets_received_failed =0 ; + } +} + static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
Signature · 1 line
1.8.3.1
PATCH v7 7/10 crypto/virtio: support AES-CBC
In reply to Jay ZhouThe AES-CBC cipher only algorithm has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 30 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 11 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 \ + { /* 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 +11 -0
@@ -15,6 +15,7 @@#include "virtio_cryptodev.h" #include "virtqueue.h" #include "virtio_crypto_algs.h" +#include "virtio_crypto_capabilities.h" int virtio_crypto_logtype_init;int virtio_crypto_logtype_session;
@@ -58,6 +59,11 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, { .vendor_id = 0, /* sentinel */ }, }; +static const struct rte_cryptodev_capabilities virtio_capabilities[] = { +VIRTIO_SYM_CAPABILITIES , +RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST () +}; +uint8_t cryptodev_virtio_driver_id;#define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -744,6 +750,7 @@ int virtio_crypto_queue_setup(struct rte_cryptodev *dev, hw = cryptodev->data->dev_private; hw->dev_id = cryptodev->data->dev_id; + hw->virtio_dev_capabilities = virtio_capabilities; VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x", cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1131,6 +1138,9 @@ static int virtio_crypto_sym_pad_cipher_param( struct rte_crypto_cipher_xform *cipher_xform) {switch (cipher_xform->algo) { +case RTE_CRYPTO_CIPHER_AES_CBC : + para->algo =VIRTIO_CRYPTO_CIPHER_AES_CBC ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Unsupported " "Cipher alg %u" , cipher_xform->algo);
@@ -1390,6 +1400,7 @@ static int virtio_crypto_sym_configure_session( info->max_nb_queue_pairs = hw->max_dataqueues; info->sym.max_nb_sessions =RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + info->capabilities = hw->virtio_dev_capabilities; } }
Signature · 1 line
1.8.3.1
PATCH v7 8/10 crypto/virtio: support HMAC-SHA1
In reply to Jay ZhouThe AES-CBC with HMAC-SHA1 has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 21 +++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +21 -0
@@ -6,6 +6,27 @@#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 = { \
drivers/crypto/virtio/virtio_cryptodev.c +3 -1
@@ -1187,11 +1187,13 @@ static int virtio_crypto_sym_pad_auth_param( }switch (auth_xform->algo) { +case RTE_CRYPTO_AUTH_SHA1_HMAC : + *algo =VIRTIO_CRYPTO_MAC_HMAC_SHA1 ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Undefined Hash algo %u specified" , auth_xform->algo); - *algo =VIRTIO_CRYPTO_NO_MAC ;return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v7 9/10 test/crypto: add function tests for virtio crypto PMD
In reply to Jay ZhouOnly 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 | 48 +++++++++++++++++++++++++++++ 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, 74 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +48 -0
@@ -1820,6 +1820,25 @@ 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;
@@ -8879,6 +8898,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,
@@ -9808,6 +9839,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(
@@ -10040,3 +10087,4 @@ struct test_crypto_vector {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_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND (cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
@@ -63,6 +63,7 @@#define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler#define CRYPTODEV_NAME_MRVL_PMD crypto_mrvl#define CRYPTODEV_NAME_CCP_PMD crypto_ccp +#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
@@ -1544,7 +1544,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
@@ -70,6 +70,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 ;
@@ -97,7 +99,8 @@ driver_id == openssl_pmd || driver_id == armv8_pmd || driver_id == mrvl_pmd || - driver_id == ccp_pmd) { /* Fall through */ + driver_id == ccp_pmd || + driver_id == virtio_pmd) { /* Fall through */ digest_len = tdata->digest.len; } else if (driver_id == aesni_mb_pmd || driver_id == scheduler_pmd) {
@@ -574,6 +577,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 :
@@ -638,6 +643,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
@@ -28,6 +28,7 @@#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_CCP 0x0040/* CCP flag */ +#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO 0x0200/* VIRTIO flag */ #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
PATCH v7 10/10 doc: add virtio crypto PMD guide
In reply to Jay ZhouThis patch adds the guide for virtio crypto PMD.
--- MAINTAINERS | 2 + 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 | 5 +- 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/guides/cryptodevs/features/virtio.ini create mode 100644 doc/guides/cryptodevs/virtio.rst
MAINTAINERS +2 -0
@@ -727,6 +727,8 @@ 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]>
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
@@ -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
@@ -23,4 +23,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
doc/guides/rel_notes/release_18_05.rst +4 -1
@@ -72,7 +72,10 @@ New Features * **Added the virtio crypto PMD.** - Added a new poll mode driver for virtio crypto devices. + Added a new poll mode driver for virtio crypto devices, which provides + AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. See the + :doc:`../cryptodevs/virtio` crypto driver guide for more details on + this new driver. API Changes
Signature · 1 line
1.8.3.1
v8 cover crypto: add virtio poll mode driver
In reply to Jay ZhouThis 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 merged into dpdk-next-virtio too.
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_idThe 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
+ 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 v8:
- using the virtio_crypto.h in compat lib instead of the linux header file
- add meson build
Changes in v7:
- add detailed commit messages [Pablo]
Changes in v6:
- split the patches in a more functional way [Pablo]
Changes in v5:
- rebased on the newest dpdk-next-crypto
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 (11):
crypto/virtio: add virtio crypto PMD crypto/virtio: support virtio device init crypto/virtio: support basic PMD ops crypto/virtio: support session related ops crypto/virtio: support crypto enqueue/dequeue burst API crypto/virtio: support stats related ops crypto/virtio: support AES-CBC
crypto/virtio: support HMAC-SHA1 crypto/virtio: build with meson
test/crypto: add function tests for virtio crypto PMD
doc: add virtio crypto PMD guide
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 | 7 + drivers/crypto/Makefile | 1 + drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/Makefile | 31 + drivers/crypto/virtio/meson.build | 12 + .../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 | 1504 ++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 62 + drivers/crypto/virtio/virtio_logs.h | 91 ++ drivers/crypto/virtio/virtio_pci.c | 460 ++++++ drivers/crypto/virtio/virtio_pci.h | 252 ++++ drivers/crypto/virtio/virtio_ring.h | 137 ++ drivers/crypto/virtio/virtio_rxtx.c | 515 +++++++ drivers/crypto/virtio/virtqueue.c | 43 + drivers/crypto/virtio/virtqueue.h | 171 +++ mk/rte.app.mk | 1 + test/test/test_cryptodev.c | 48 + 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 + 28 files changed, 3607 insertions(+), 10 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/meson.build 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
Signature · 1 line
1.8.3.1
PATCH v8 1/11 crypto/virtio: add virtio crypto PMD
The virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
--- MAINTAINERS | 4 +++ config/common_base | 14 +++++++++ doc/guides/rel_notes/release_18_05.rst | 4 +++ drivers/crypto/Makefile | 1 + drivers/crypto/virtio/Makefile | 28 +++++++++++++++++ .../virtio/rte_pmd_virtio_crypto_version.map | 3 ++ drivers/crypto/virtio/virtio_cryptodev.c | 36 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 10 ++++++ mk/rte.app.mk | 1 + 9 files changed, 101 insertions(+) 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_cryptodev.c create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
MAINTAINERS +4 -0
@@ -758,6 +758,10 @@ 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/ + ZUC M: Pablo de Lara <[email protected]> F: drivers/crypto/zuc/
config/common_base +14 -0
@@ -493,6 +493,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
@@ -82,6 +82,10 @@ New Features Linux uevent is supported as backend of this device event notification framework. +* **Added the virtio crypto PMD.** + + Added a new poll mode driver for virtio crypto devices. + API Changes -----------
drivers/crypto/Makefile +1 -0
@@ -21,5 +21,6 @@ ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec endif DIRS-$(CONFIG_RTE_LIBRTE_PMD_CCP) += ccp +DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/virtio/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# 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) += 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
@@ -0,0 +1,3 @@ +DPDK_18.05 { + local: *; +};
drivers/crypto/virtio/virtio_cryptodev.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_cryptodev_pmd.h> +#include "virtio_cryptodev.h" + +uint8_t cryptodev_virtio_driver_id; + +static int +crypto_virtio_pci_probe ( + struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static int +crypto_virtio_pci_remove ( + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static struct rte_pci_driver rte_virtio_crypto_driver = { + .probe = crypto_virtio_pci_probe, + .remove = crypto_virtio_pci_remove +}; + +static struct cryptodev_driver virtio_crypto_drv; + +RTE_PMD_REGISTER_PCI (CRYPTODEV_NAME_VIRTIO_PMD , rte_virtio_crypto_driver); +RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, + rte_virtio_crypto_driver.driver, + cryptodev_virtio_driver_id);
drivers/crypto/virtio/virtio_cryptodev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ + +#ifndef _VIRTIO_CRYPTODEV_H_ +#define _VIRTIO_CRYPTODEV_H_ + +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio + +#endif /* _VIRTIO_CRYPTODEV_H_ */
mk/rte.app.mk +1 -0
@@ -208,6 +208,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM) += -lIPSec_MB _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
PATCH v8 2/11 crypto/virtio: support virtio device init
In reply to Jay ZhouThis patch implements the initialization of the virtio crypto device. The virtio crypto device conforms to virtio-1.0, so this patch only supports modern mode operation.
The cryptodev is created at the virtio crypto pci device probing stage. The function of virtio_crypto_pkt_tx_burst() is used to burst transfer packets and virtio_crypto_pkt_rx_burst() is used to burst receive packets.
--- drivers/crypto/virtio/Makefile | 3 + drivers/crypto/virtio/virtio_cryptodev.c | 245 +++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 13 + drivers/crypto/virtio/virtio_logs.h | 91 ++++++ drivers/crypto/virtio/virtio_pci.c | 460 +++++++++++++++++++++++++++++++ drivers/crypto/virtio/virtio_pci.h | 252 +++++++++++++++++ drivers/crypto/virtio/virtio_ring.h | 137 +++++++++ drivers/crypto/virtio/virtio_rxtx.c | 26 ++ drivers/crypto/virtio/virtqueue.c | 43 +++ drivers/crypto/virtio/virtqueue.h | 171 ++++++++++++ 10 files changed, 1439 insertions(+), 2 deletions(-) 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
drivers/crypto/virtio/Makefile +3 -0
@@ -18,6 +18,9 @@ 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:
drivers/crypto/virtio/virtio_cryptodev.c +243 -2
273 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +13 -0
@@ -5,6 +5,19 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ +#include <rte_cryptodev.h> + +/* Features desired/implemented by this driver. */ +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); + +uint16_t virtio_crypto_pkt_rx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); +#endif /* _VIRTIO_CRYPTODEV_H_ */
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 +252 -0
252 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/virtio_rxtx.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include "virtio_cryptodev.h" + +uint16_t +virtio_crypto_pkt_rx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_rx =0 ; + +return nb_rx; +} + +uint16_t +virtio_crypto_pkt_tx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_tx =0 ; + +return nb_tx; +}
drivers/crypto/virtio/virtqueue.c new file +43 -0
43 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 3/11 crypto/virtio: support basic PMD ops
In reply to Jay ZhouThis patch implements the basic operations of virtio crypto PMD, which includes start, stop, close, information getting, queue setup and release of the device.
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.
--- drivers/crypto/virtio/virtio_cryptodev.c | 437 ++++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 32 ++- drivers/crypto/virtio/virtio_rxtx.c | 68 +++++ 3 files changed, 528 insertions(+), 9 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +429 -8
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ +#include <rte_errno.h> #include <rte_pci.h> #include <rte_bus_pci.h> #include <rte_cryptodev.h>
@@ -15,6 +16,22 @@int virtio_crypto_logtype_tx;int virtio_crypto_logtype_driver; +static int virtio_crypto_dev_configure (struct rte_cryptodev *dev, +struct rte_cryptodev_config *config); +static int virtio_crypto_dev_start (struct rte_cryptodev *dev); +static void virtio_crypto_dev_stop (struct rte_cryptodev *dev); +static int virtio_crypto_dev_close (struct rte_cryptodev *dev); +static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *dev_info); +static int virtio_crypto_qp_setup (struct rte_cryptodev *dev, +uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, +struct rte_mempool *session_pool); +static int virtio_crypto_qp_release (struct rte_cryptodev *dev, +uint16_t queue_pair_id); +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev); +/* * The set of PCI devices this driver supports */
@@ -26,22 +43,251 @@uint8_t cryptodev_virtio_driver_id; +void +virtio_crypto_queue_release (struct virtqueue *vq) +{ +struct virtio_crypto_hw *hw; + +PMD_INIT_FUNC_TRACE (); + +if (vq) { + hw = vq->hw; +/* Select and deactivate the queue */ +VTPCI_OPS (hw)->del_queue (hw, vq); + +rte_memzone_free (vq->mz); +rte_mempool_free (vq->mpool); +rte_free (vq); + } +} + +#define MPOOL_MAX_NAME_SZ 32 + +int +virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq) +{ +char vq_name[VIRTQUEUE_MAX_NAME_SZ ]; +char mpool_name[MPOOL_MAX_NAME_SZ ]; +const struct rte_memzone *mz; +unsigned int vq_size, size; +struct virtio_crypto_hw *hw = dev->data->dev_private; +struct virtqueue *vq =NULL ; +uint32_t i =0 ; +uint32_t j; + +PMD_INIT_FUNC_TRACE (); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("setting up queue: %u" , vtpci_queue_idx); + +/* +* Read the virtqueue size from the Queue Size field +* Always power of 2 and if 0 virtqueue does not exist +*/ + vq_size =VTPCI_OPS (hw)->get_queue_num (hw, vtpci_queue_idx); +if (vq_size ==0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue does not exist" ); +return -EINVAL ; + } +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq_size: %u" , vq_size); + +if (!rte_is_power_of_2 (vq_size)) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue size is not powerof 2" ); +return -EINVAL ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_dataqueue%d" , + dev->data->dev_id, vtpci_queue_idx); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_dataqueue%d_mpool" , + dev->data->dev_id, vtpci_queue_idx); + }else if (queue_type ==VTCRYPTO_CTRLQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_controlqueue" , + dev->data->dev_id); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_controlqueue_mpool" , + dev->data->dev_id); + } + size =RTE_ALIGN_CEIL (sizeof (*vq) + + vq_size *sizeof (struct vq_desc_extra ), +RTE_CACHE_LINE_SIZE ); + vq =rte_zmalloc_socket (vq_name, size,RTE_CACHE_LINE_SIZE , + socket_id); +if (vq ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("Can not allocate virtqueue" ); +return -ENOMEM ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +/* pre-allocate a mempool and use it in the data plane to +* improve performance +*/ + vq->mpool =rte_mempool_lookup (mpool_name); +if (vq->mpool ==NULL ) + vq->mpool =rte_mempool_create (mpool_name, + vq_size, +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ,0 , +NULL ,NULL ,NULL ,NULL , socket_id, +0 ); +if (!vq->mpool) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Virtio Crypto PMD " +"Cannot create mempool" ); + goto mpool_create_err; + } +for (i =0 ; i < vq_size; i++) { + vq->vq_descx[i].cookie = +rte_zmalloc ("crypto PMD op cookie pointer" , +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ); +if (vq->vq_descx[i].cookie ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Failed to " +"alloc mem for cookie" ); + goto cookie_alloc_err; + } + } + } + + vq->hw = hw; + vq->dev_id = dev->data->dev_id; + vq->vq_queue_index = vtpci_queue_idx; + vq->vq_nentries = vq_size; + +/* +* Using part of the vring entries is permitted, but the maximum +* is vq_size +*/ +if (nb_desc ==0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; + +/* +* Reserve a memzone for vring elements +*/ + size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN ); +VIRTIO_CRYPTO_INIT_LOG_DBG ("%s vring_size: %d, rounded_vring_size: %d" , + (queue_type ==VTCRYPTO_DATAQ ) ?"dataq" :"ctrlq" , + size, vq->vq_ring_size); + + mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, + socket_id,0 ,VIRTIO_PCI_VRING_ALIGN ); +if (mz ==NULL ) { +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("not enough memory" ); + goto mz_reserve_err; + } + } + +/* +* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, +* and only accepts 32 bit page frame number. +* Check if the allocated physical memory exceeds 16TB. +*/ +if ((mz->phys_addr + vq->vq_ring_size -1 ) + >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT +32 )) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("vring address shouldn't be " +"above 16TB!" ); + goto vring_addr_err; + } + +memset (mz->addr,0 ,sizeof (mz->len)); + vq->mz = mz; + vq->vq_ring_mem = mz->phys_addr; + vq->vq_ring_virt_mem = mz->addr; +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_mem(physical): 0x%" PRIx64, + (uint64_t )mz->phys_addr); +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_virt_mem: 0x%" PRIx64, + (uint64_t )(uintptr_t )mz->addr); + + *pvq = vq; + +return 0 ; + +vring_addr_err: +rte_memzone_free (mz); +mz_reserve_err: +cookie_alloc_err: +rte_mempool_free (vq->mpool); +if (i !=0 ) { +for (j =0 ; j < i; j++) +rte_free (vq->vq_descx[j].cookie); + } +mpool_create_err: +rte_free (vq); +return -ENOMEM ; +} + +static int +virtio_crypto_ctrlq_setup (struct rte_cryptodev *dev,uint16_t queue_idx) +{ +int ret; +struct virtqueue *vq; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +/* if virtio device has started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + +PMD_INIT_FUNC_TRACE (); + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_CTRLQ , queue_idx, +0 ,SOCKET_ID_ANY , &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control vq initialization failed" ); +return ret; + } + + hw->cvq = vq; + +return 0 ; +} + +static void +virtio_crypto_free_queues (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +/* control queue release */ +virtio_crypto_queue_release (hw->cvq); + +/* data queue release */ +for (i =0 ; i < hw->max_dataqueues; i++) +virtio_crypto_queue_release (dev->data->queue_pairs[i]); +} + +static int +virtio_crypto_dev_close(struct rte_cryptodev *dev __rte_unused) +{ +return 0 ; +} +/* * dev_ops for virtio, bare necessities for basic operation */ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {/* Device related operations */ - .dev_configure =NULL , - .dev_start =NULL , - .dev_stop =NULL , - .dev_close =NULL , - .dev_infos_get =NULL , + .dev_configure = virtio_crypto_dev_configure, + .dev_start = virtio_crypto_dev_start, + .dev_stop = virtio_crypto_dev_stop, + .dev_close = virtio_crypto_dev_close, + .dev_infos_get = virtio_crypto_dev_info_get, .stats_get =NULL , .stats_reset =NULL , - .queue_pair_setup =NULL , - .queue_pair_release =NULL , + .queue_pair_setup = virtio_crypto_qp_setup, + .queue_pair_release = virtio_crypto_qp_release, .queue_pair_start =NULL , .queue_pair_stop =NULL , .queue_pair_count =NULL ,
@@ -55,6 +301,51 @@ };static int +virtio_crypto_qp_setup (struct rte_cryptodev *dev,uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, + struct rte_mempool *session_pool __rte_unused) +{ +int ret; +struct virtqueue *vq; + +PMD_INIT_FUNC_TRACE (); + +/* if virtio dev is started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_DATAQ , queue_pair_id, + qp_conf->nb_descriptors, socket_id, &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ( +"virtio crypto data queue initialization failed\n" ); +return ret; + } + + dev->data->queue_pairs[queue_pair_id] = vq; + +return 0 ; +} + +static int +virtio_crypto_qp_release (struct rte_cryptodev *dev,uint16_t queue_pair_id) +{ +struct virtqueue *vq + = (struct virtqueue *)dev->data->queue_pairs[queue_pair_id]; + +PMD_INIT_FUNC_TRACE (); + +if (vq ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_DBG ("vq already freed" ); +return 0 ; + } + +virtio_crypto_queue_release (vq); +return 0 ; +} + +static int virtio_negotiate_features (struct virtio_crypto_hw *hw,uint64_t req_features) {uint64_t host_features;
@@ -192,6 +483,136 @@ }static int +virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (cryptodev->data->dev_started) { +virtio_crypto_dev_stop (cryptodev); +virtio_crypto_dev_close (cryptodev); + } + + cryptodev->dev_ops =NULL ; + cryptodev->enqueue_burst =NULL ; + cryptodev->dequeue_burst =NULL ; + +/* release control queue */ +virtio_crypto_queue_release (hw->cvq); + +rte_free (cryptodev->data); + cryptodev->data =NULL ; + +VIRTIO_CRYPTO_DRV_LOG_INFO ("dev_uninit completed" ); + +return 0 ; +} + +static int +virtio_crypto_dev_configure (struct rte_cryptodev *cryptodev, + struct rte_cryptodev_config *config __rte_unused) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (virtio_crypto_init_device (cryptodev, +VIRTIO_CRYPTO_PMD_GUEST_FEATURES ) <0 ) +return -1 ; + +/* setup control queue +* [0, 1, ... ,(config->max_dataqueues - 1)] are data queues +* config->max_dataqueues is the control queue +*/ +if (virtio_crypto_ctrlq_setup (cryptodev, hw->max_dataqueues) <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control queue setup error" ); +return -1 ; + } +virtio_crypto_ctrlq_start (cryptodev); + +return 0 ; +} + +static void +virtio_crypto_dev_stop (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); +VIRTIO_CRYPTO_DRV_LOG_DBG ("virtio_dev_stop" ); + +vtpci_cryptodev_reset (hw); + +virtio_crypto_dev_free_mbufs (dev); +virtio_crypto_free_queues (dev); + + dev->data->dev_started =0 ; +} + +static int +virtio_crypto_dev_start (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +if (dev->data->dev_started) +return 0 ; + +/* Do final configuration before queue engine starts */ +virtio_crypto_dataq_start (dev); +vtpci_cryptodev_reinit_complete (hw); + + dev->data->dev_started =1 ; + +return 0 ; +} + +static void +virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev) +{ +uint32_t i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +for (i =0 ; i < hw->max_dataqueues; i++) { +VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " +"and unused buf" , i); +VIRTQUEUE_DUMP ((struct virtqueue *) + dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("queue_pairs[%d]=%p" , + i, dev->data->queue_pairs[i]); + +virtqueue_detatch_unused (dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("After freeing dataq[%d] used and " +"unused buf" , i); +VIRTQUEUE_DUMP ( + (struct virtqueue *)dev->data->queue_pairs[i]); + } +} + +static void +virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *info) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (info !=NULL ) { + info->driver_id = cryptodev_virtio_driver_id; + info->pci_dev =RTE_DEV_TO_PCI (dev->device); + info->feature_flags = dev->feature_flags; + info->max_nb_queue_pairs = hw->max_dataqueues; + info->sym.max_nb_sessions = +RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + } +} + +static int crypto_virtio_pci_probe ( struct rte_pci_driver *pci_drv __rte_unused,struct rte_pci_device *pci_dev)
@@ -231,7 +652,7 @@if (cryptodev ==NULL )return -ENODEV ; -return 0 ; +return virtio_crypto_dev_uninit (cryptodev); }static struct rte_pci_driver rte_virtio_crypto_driver = {
drivers/crypto/virtio/virtio_cryptodev.h +31 -1
@@ -5,13 +5,43 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ -#include <rte_cryptodev.h> +#include <virtio_crypto.h> + +#include "virtio_pci.h" +#include "virtio_ring.h" /* Features desired/implemented by this driver. */ #define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 + +struct virtio_crypto_op_cookie { +struct virtio_crypto_op_data_req data_req; +struct virtio_crypto_inhdr inhdr; +struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ]; +}; + +/* +* Control queue function prototype +*/ +void virtio_crypto_ctrlq_start (struct rte_cryptodev *dev); + +/* +* Data queue function prototype +*/ +void virtio_crypto_dataq_start (struct rte_cryptodev *dev); + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq); + +void virtio_crypto_queue_release (struct virtqueue *vq); +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue,struct rte_crypto_op **tx_pkts,uint16_t nb_pkts);
drivers/crypto/virtio/virtio_rxtx.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 4/11 crypto/virtio: support session related ops
In reply to Jay ZhouThis patch implements session related operations, which includes creating and destroying the session. For now, it only supports the session-oriented API implementation. The control queue used to create or destroy sessions for symmetric algorithms.
--- drivers/crypto/virtio/virtio_crypto_algs.h | 27 ++ drivers/crypto/virtio/virtio_cryptodev.c | 737 ++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 7 + 3 files changed, 768 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +27 -0
@@ -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 <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_ */
drivers/crypto/virtio/virtio_cryptodev.c +734 -3
775 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +7 -0
@@ -17,6 +17,13 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +enum virtio_crypto_cmd_id { +VIRTIO_CRYPTO_CMD_CIPHER =0 , +VIRTIO_CRYPTO_CMD_AUTH =1 , +VIRTIO_CRYPTO_CMD_CIPHER_HASH =2 , +VIRTIO_CRYPTO_CMD_HASH_CIPHER =3 +}; +struct virtio_crypto_op_cookie {struct virtio_crypto_op_data_req data_req;struct virtio_crypto_inhdr inhdr;
Signature · 1 line
1.8.3.1
PATCH v8 5/11 crypto/virtio: support crypto enqueue/dequeue burst API
In reply to Jay ZhouThis patch implements the functions of virtio_crypto_pkt_tx_burst() and virtio_crypto_pkt_rx_burst(). The encryption and decryption requests are placed in the data queue and are ultimately handled by the backend crypto accelerators.
--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 441 ++++++++++++++++++++++++++++++- 2 files changed, 433 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -17,6 +17,8 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +extern uint8_t cryptodev_virtio_driver_id; +enum virtio_crypto_cmd_id {VIRTIO_CRYPTO_CMD_CIPHER =0 ,VIRTIO_CRYPTO_CMD_AUTH =1 ,
drivers/crypto/virtio/virtio_rxtx.c +431 -10
463 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 6/11 crypto/virtio: support stats related ops
In reply to Jay ZhouThis patch implements the statistics of the packets.
--- drivers/crypto/virtio/virtio_cryptodev.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +64 -2
@@ -29,6 +29,9 @@ static int virtio_crypto_dev_configure(struct rte_cryptodev *dev,static int virtio_crypto_dev_close (struct rte_cryptodev *dev);static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev,struct rte_cryptodev_info *dev_info); +static void virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats); +static void virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev); static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
@@ -501,8 +504,8 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .dev_close = virtio_crypto_dev_close, .dev_infos_get = virtio_crypto_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = virtio_crypto_dev_stats_get, + .stats_reset = virtio_crypto_dev_stats_reset, .queue_pair_setup = virtio_crypto_qp_setup, .queue_pair_release = virtio_crypto_qp_release,
@@ -518,6 +521,65 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .qp_detach_session = NULL }; +static void +virtio_crypto_update_stats (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (stats ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("invalid pointer" ); +return ; + } + +for (i =0 ; i < hw->max_dataqueues; i++) { +const struct virtqueue *data_queue + = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + stats->enqueued_count += data_queue->packets_sent_total; + stats->enqueue_err_count += data_queue->packets_sent_failed; + + stats->dequeued_count += data_queue->packets_received_total; + stats->dequeue_err_count + += data_queue->packets_received_failed; + } +} + +static void +virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +PMD_INIT_FUNC_TRACE (); + +virtio_crypto_update_stats (dev, stats); +} + +static void +virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +for (i =0 ; i < hw->max_dataqueues; i++) { +struct virtqueue *data_queue = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + data_queue->packets_sent_total =0 ; + data_queue->packets_sent_failed =0 ; + + data_queue->packets_received_total =0 ; + data_queue->packets_received_failed =0 ; + } +} + static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
Signature · 1 line
1.8.3.1
PATCH v8 7/11 crypto/virtio: support AES-CBC
In reply to Jay ZhouThe AES-CBC cipher only algorithm has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 30 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 11 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 \ + { /* 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 +11 -0
@@ -15,6 +15,7 @@#include "virtio_cryptodev.h" #include "virtqueue.h" #include "virtio_crypto_algs.h" +#include "virtio_crypto_capabilities.h" int virtio_crypto_logtype_init;int virtio_crypto_logtype_session;
@@ -58,6 +59,11 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, { .vendor_id = 0, /* sentinel */ }, }; +static const struct rte_cryptodev_capabilities virtio_capabilities[] = { +VIRTIO_SYM_CAPABILITIES , +RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST () +}; +uint8_t cryptodev_virtio_driver_id;#define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -746,6 +752,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, hw = cryptodev->data->dev_private; hw->dev_id = cryptodev->data->dev_id; + hw->virtio_dev_capabilities = virtio_capabilities; VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x", cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1139,6 +1146,9 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_cipher_xform *cipher_xform) {switch (cipher_xform->algo) { +case RTE_CRYPTO_CIPHER_AES_CBC : + para->algo =VIRTIO_CRYPTO_CIPHER_AES_CBC ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Unsupported " "Cipher alg %u" , cipher_xform->algo);
@@ -1402,6 +1412,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, info->max_nb_queue_pairs = hw->max_dataqueues; info->sym.max_nb_sessions =RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + info->capabilities = hw->virtio_dev_capabilities; } }
Signature · 1 line
1.8.3.1
PATCH v8 8/11 crypto/virtio: support HMAC-SHA1
In reply to Jay ZhouThe AES-CBC with HMAC-SHA1 has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 21 +++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +21 -0
@@ -6,6 +6,27 @@#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 = { \
drivers/crypto/virtio/virtio_cryptodev.c +3 -1
@@ -1196,11 +1196,13 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, }switch (auth_xform->algo) { +case RTE_CRYPTO_AUTH_SHA1_HMAC : + *algo =VIRTIO_CRYPTO_MAC_HMAC_SHA1 ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Undefined Hash algo %u specified" , auth_xform->algo); - *algo =VIRTIO_CRYPTO_NO_MAC ;return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v8 9/11 crypto/virtio: build with meson
In reply to Jay Zhou--- drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/meson.build | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/virtio/meson.build
drivers/crypto/meson.build +1 -1
@@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = ['dpaa_sec', 'dpaa2_sec', - 'openssl', 'null', 'qat'] + 'openssl', 'null', 'qat', 'virtio'] std_deps = ['cryptodev'] # cryptodev pulls in all other needed deps config_flag_fmt = 'RTE_LIBRTE_@0@_PMD'
drivers/crypto/virtio/meson.build new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) +if not dep.found() + build = false +endif +deps += ['bus_pci'] +sources = files('virtio_cryptodev.c', 'virtio_pci.c', + 'virtio_rxtx.c', 'virtqueue.c') +ext_deps += dep +pkgconfig_extra_libs += '-lcrypto'
Signature · 1 line
1.8.3.1
PATCH v8 10/11 test/crypto: add function tests for virtio crypto PMD
In reply to Jay ZhouOnly 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 | 48 +++++++++++++++++++++++++++++ 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, 74 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +48 -0
@@ -1820,6 +1820,25 @@ 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;
@@ -8879,6 +8898,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,
@@ -9808,6 +9839,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(
@@ -10040,3 +10087,4 @@ struct test_crypto_vector {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_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND (cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
@@ -63,6 +63,7 @@#define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler#define CRYPTODEV_NAME_MRVL_PMD crypto_mrvl#define CRYPTODEV_NAME_CCP_PMD crypto_ccp +#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
@@ -1544,7 +1544,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
@@ -70,6 +70,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 ;
@@ -97,7 +99,8 @@ driver_id == openssl_pmd || driver_id == armv8_pmd || driver_id == mrvl_pmd || - driver_id == ccp_pmd) { /* Fall through */ + driver_id == ccp_pmd || + driver_id == virtio_pmd) { /* Fall through */ digest_len = tdata->digest.len; } else if (driver_id == aesni_mb_pmd || driver_id == scheduler_pmd) {
@@ -574,6 +577,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 :
@@ -638,6 +643,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
@@ -28,6 +28,7 @@#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_CCP 0x0040/* CCP flag */ +#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO 0x0200/* VIRTIO flag */ #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
PATCH v8 11/11 doc: add virtio crypto PMD guide
In reply to Jay ZhouThis patch adds the guide for virtio crypto PMD.
--- MAINTAINERS | 2 + 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 | 5 +- 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/guides/cryptodevs/features/virtio.ini create mode 100644 doc/guides/cryptodevs/virtio.rst
MAINTAINERS +2 -0
@@ -761,6 +761,8 @@ 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]>
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
@@ -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
@@ -23,4 +23,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
doc/guides/rel_notes/release_18_05.rst +4 -1
@@ -84,7 +84,10 @@ New Features * **Added the virtio crypto PMD.** - Added a new poll mode driver for virtio crypto devices. + Added a new poll mode driver for virtio crypto devices, which provides + AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. See the + :doc:`../cryptodevs/virtio` crypto driver guide for more details on + this new driver. API Changes
Signature · 1 line
1.8.3.1
v9 cover crypto: add virtio poll mode driver
In reply to Jay ZhouThis 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 merged into dpdk-next-virtio too.
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_idThe 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
+ 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 v9:
- fix compilation error when CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO=y and CONFIG_RTE_BUILD_SHARED_LIB=y
Changes in v8:
- using the virtio_crypto.h in compat lib instead of the linux header file
- add meson build
Changes in v7:
- add detailed commit messages [Pablo]
Changes in v6:
- split the patches in a more functional way [Pablo]
Changes in v5:
- rebased on the newest dpdk-next-crypto
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 (11):
crypto/virtio: add virtio crypto PMD crypto/virtio: support virtio device init crypto/virtio: support basic PMD ops crypto/virtio: support session related ops crypto/virtio: support crypto enqueue/dequeue burst API crypto/virtio: support stats related ops crypto/virtio: support AES-CBC
crypto/virtio: support HMAC-SHA1 crypto/virtio: build with meson
test/crypto: add function tests for virtio crypto PMD
doc: add virtio crypto PMD guide
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 | 7 + drivers/crypto/Makefile | 1 + drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/Makefile | 32 + drivers/crypto/virtio/meson.build | 12 + .../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 | 1504 ++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 62 + drivers/crypto/virtio/virtio_logs.h | 91 ++ drivers/crypto/virtio/virtio_pci.c | 462 ++++++ drivers/crypto/virtio/virtio_pci.h | 252 ++++ drivers/crypto/virtio/virtio_ring.h | 137 ++ drivers/crypto/virtio/virtio_rxtx.c | 515 +++++++ drivers/crypto/virtio/virtqueue.c | 43 + drivers/crypto/virtio/virtqueue.h | 171 +++ mk/rte.app.mk | 1 + test/test/test_cryptodev.c | 48 + 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 + 28 files changed, 3610 insertions(+), 10 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/meson.build 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
Signature · 1 line
1.8.3.1
PATCH v9 1/11 crypto/virtio: add virtio crypto PMD
The virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
--- MAINTAINERS | 4 +++ config/common_base | 14 +++++++++ doc/guides/rel_notes/release_18_05.rst | 4 +++ drivers/crypto/Makefile | 1 + drivers/crypto/virtio/Makefile | 29 +++++++++++++++++ .../virtio/rte_pmd_virtio_crypto_version.map | 3 ++ drivers/crypto/virtio/virtio_cryptodev.c | 36 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 10 ++++++ mk/rte.app.mk | 1 + 9 files changed, 102 insertions(+) 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_cryptodev.c create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
MAINTAINERS +4 -0
@@ -758,6 +758,10 @@ 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/ + ZUC M: Pablo de Lara <[email protected]> F: drivers/crypto/zuc/
config/common_base +14 -0
@@ -493,6 +493,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
@@ -82,6 +82,10 @@ New Features Linux uevent is supported as backend of this device event notification framework. +* **Added the virtio crypto PMD.** + + Added a new poll mode driver for virtio crypto devices. + API Changes -----------
drivers/crypto/Makefile +1 -0
@@ -21,5 +21,6 @@ ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec endif DIRS-$(CONFIG_RTE_LIBRTE_PMD_CCP) += ccp +DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/virtio/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +# 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) += virtio_cryptodev.c + +# this lib depends upon: +LDLIBS += -lcrypto +LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool +LDLIBS += -lrte_cryptodev +LDLIBS += -lrte_pci -lrte_bus_pci + +include $(RTE_SDK)/mk/rte.lib.mk
drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map new file +3 -0
@@ -0,0 +1,3 @@ +DPDK_18.05 { + local: *; +};
drivers/crypto/virtio/virtio_cryptodev.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_cryptodev_pmd.h> +#include "virtio_cryptodev.h" + +uint8_t cryptodev_virtio_driver_id; + +static int +crypto_virtio_pci_probe ( + struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static int +crypto_virtio_pci_remove ( + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static struct rte_pci_driver rte_virtio_crypto_driver = { + .probe = crypto_virtio_pci_probe, + .remove = crypto_virtio_pci_remove +}; + +static struct cryptodev_driver virtio_crypto_drv; + +RTE_PMD_REGISTER_PCI (CRYPTODEV_NAME_VIRTIO_PMD , rte_virtio_crypto_driver); +RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, + rte_virtio_crypto_driver.driver, + cryptodev_virtio_driver_id);
drivers/crypto/virtio/virtio_cryptodev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ + +#ifndef _VIRTIO_CRYPTODEV_H_ +#define _VIRTIO_CRYPTODEV_H_ + +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio + +#endif /* _VIRTIO_CRYPTODEV_H_ */
mk/rte.app.mk +1 -0
@@ -208,6 +208,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM) += -lIPSec_MB _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
PATCH v9 2/11 crypto/virtio: support virtio device init
In reply to Jay ZhouThis patch implements the initialization of the virtio crypto device. The virtio crypto device conforms to virtio-1.0, so this patch only supports modern mode operation.
The cryptodev is created at the virtio crypto pci device probing stage. The function of virtio_crypto_pkt_tx_burst() is used to burst transfer packets and virtio_crypto_pkt_rx_burst() is used to burst receive packets.
--- drivers/crypto/virtio/Makefile | 3 + drivers/crypto/virtio/virtio_cryptodev.c | 245 +++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 13 + drivers/crypto/virtio/virtio_logs.h | 91 ++++++ drivers/crypto/virtio/virtio_pci.c | 462 +++++++++++++++++++++++++++++++ drivers/crypto/virtio/virtio_pci.h | 252 +++++++++++++++++ drivers/crypto/virtio/virtio_ring.h | 137 +++++++++ drivers/crypto/virtio/virtio_rxtx.c | 26 ++ drivers/crypto/virtio/virtqueue.c | 43 +++ drivers/crypto/virtio/virtqueue.h | 171 ++++++++++++ 10 files changed, 1441 insertions(+), 2 deletions(-) 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
drivers/crypto/virtio/Makefile +3 -0
@@ -18,6 +18,9 @@ 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:
drivers/crypto/virtio/virtio_cryptodev.c +243 -2
273 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +13 -0
@@ -5,6 +5,19 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ +#include <rte_cryptodev.h> + +/* Features desired/implemented by this driver. */ +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); + +uint16_t virtio_crypto_pkt_rx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); +#endif /* _VIRTIO_CRYPTODEV_H_ */
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 +462 -0
462 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h new file +252 -0
252 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/virtio_rxtx.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include "virtio_cryptodev.h" + +uint16_t +virtio_crypto_pkt_rx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_rx =0 ; + +return nb_rx; +} + +uint16_t +virtio_crypto_pkt_tx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_tx =0 ; + +return nb_tx; +}
drivers/crypto/virtio/virtqueue.c new file +43 -0
43 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v9 3/11 crypto/virtio: support basic PMD ops
In reply to Jay ZhouThis patch implements the basic operations of virtio crypto PMD, which includes start, stop, close, information getting, queue setup and release of the device.
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.
--- drivers/crypto/virtio/virtio_cryptodev.c | 437 ++++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 32 ++- drivers/crypto/virtio/virtio_rxtx.c | 68 +++++ 3 files changed, 528 insertions(+), 9 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +429 -8
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ +#include <rte_errno.h> #include <rte_pci.h> #include <rte_bus_pci.h> #include <rte_cryptodev.h>
@@ -15,6 +16,22 @@int virtio_crypto_logtype_tx;int virtio_crypto_logtype_driver; +static int virtio_crypto_dev_configure (struct rte_cryptodev *dev, +struct rte_cryptodev_config *config); +static int virtio_crypto_dev_start (struct rte_cryptodev *dev); +static void virtio_crypto_dev_stop (struct rte_cryptodev *dev); +static int virtio_crypto_dev_close (struct rte_cryptodev *dev); +static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *dev_info); +static int virtio_crypto_qp_setup (struct rte_cryptodev *dev, +uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, +struct rte_mempool *session_pool); +static int virtio_crypto_qp_release (struct rte_cryptodev *dev, +uint16_t queue_pair_id); +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev); +/* * The set of PCI devices this driver supports */
@@ -26,22 +43,251 @@uint8_t cryptodev_virtio_driver_id; +void +virtio_crypto_queue_release (struct virtqueue *vq) +{ +struct virtio_crypto_hw *hw; + +PMD_INIT_FUNC_TRACE (); + +if (vq) { + hw = vq->hw; +/* Select and deactivate the queue */ +VTPCI_OPS (hw)->del_queue (hw, vq); + +rte_memzone_free (vq->mz); +rte_mempool_free (vq->mpool); +rte_free (vq); + } +} + +#define MPOOL_MAX_NAME_SZ 32 + +int +virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq) +{ +char vq_name[VIRTQUEUE_MAX_NAME_SZ ]; +char mpool_name[MPOOL_MAX_NAME_SZ ]; +const struct rte_memzone *mz; +unsigned int vq_size, size; +struct virtio_crypto_hw *hw = dev->data->dev_private; +struct virtqueue *vq =NULL ; +uint32_t i =0 ; +uint32_t j; + +PMD_INIT_FUNC_TRACE (); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("setting up queue: %u" , vtpci_queue_idx); + +/* +* Read the virtqueue size from the Queue Size field +* Always power of 2 and if 0 virtqueue does not exist +*/ + vq_size =VTPCI_OPS (hw)->get_queue_num (hw, vtpci_queue_idx); +if (vq_size ==0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue does not exist" ); +return -EINVAL ; + } +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq_size: %u" , vq_size); + +if (!rte_is_power_of_2 (vq_size)) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue size is not powerof 2" ); +return -EINVAL ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_dataqueue%d" , + dev->data->dev_id, vtpci_queue_idx); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_dataqueue%d_mpool" , + dev->data->dev_id, vtpci_queue_idx); + }else if (queue_type ==VTCRYPTO_CTRLQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_controlqueue" , + dev->data->dev_id); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_controlqueue_mpool" , + dev->data->dev_id); + } + size =RTE_ALIGN_CEIL (sizeof (*vq) + + vq_size *sizeof (struct vq_desc_extra ), +RTE_CACHE_LINE_SIZE ); + vq =rte_zmalloc_socket (vq_name, size,RTE_CACHE_LINE_SIZE , + socket_id); +if (vq ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("Can not allocate virtqueue" ); +return -ENOMEM ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +/* pre-allocate a mempool and use it in the data plane to +* improve performance +*/ + vq->mpool =rte_mempool_lookup (mpool_name); +if (vq->mpool ==NULL ) + vq->mpool =rte_mempool_create (mpool_name, + vq_size, +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ,0 , +NULL ,NULL ,NULL ,NULL , socket_id, +0 ); +if (!vq->mpool) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Virtio Crypto PMD " +"Cannot create mempool" ); + goto mpool_create_err; + } +for (i =0 ; i < vq_size; i++) { + vq->vq_descx[i].cookie = +rte_zmalloc ("crypto PMD op cookie pointer" , +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ); +if (vq->vq_descx[i].cookie ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Failed to " +"alloc mem for cookie" ); + goto cookie_alloc_err; + } + } + } + + vq->hw = hw; + vq->dev_id = dev->data->dev_id; + vq->vq_queue_index = vtpci_queue_idx; + vq->vq_nentries = vq_size; + +/* +* Using part of the vring entries is permitted, but the maximum +* is vq_size +*/ +if (nb_desc ==0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; + +/* +* Reserve a memzone for vring elements +*/ + size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN ); +VIRTIO_CRYPTO_INIT_LOG_DBG ("%s vring_size: %d, rounded_vring_size: %d" , + (queue_type ==VTCRYPTO_DATAQ ) ?"dataq" :"ctrlq" , + size, vq->vq_ring_size); + + mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, + socket_id,0 ,VIRTIO_PCI_VRING_ALIGN ); +if (mz ==NULL ) { +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("not enough memory" ); + goto mz_reserve_err; + } + } + +/* +* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, +* and only accepts 32 bit page frame number. +* Check if the allocated physical memory exceeds 16TB. +*/ +if ((mz->phys_addr + vq->vq_ring_size -1 ) + >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT +32 )) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("vring address shouldn't be " +"above 16TB!" ); + goto vring_addr_err; + } + +memset (mz->addr,0 ,sizeof (mz->len)); + vq->mz = mz; + vq->vq_ring_mem = mz->phys_addr; + vq->vq_ring_virt_mem = mz->addr; +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_mem(physical): 0x%" PRIx64, + (uint64_t )mz->phys_addr); +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_virt_mem: 0x%" PRIx64, + (uint64_t )(uintptr_t )mz->addr); + + *pvq = vq; + +return 0 ; + +vring_addr_err: +rte_memzone_free (mz); +mz_reserve_err: +cookie_alloc_err: +rte_mempool_free (vq->mpool); +if (i !=0 ) { +for (j =0 ; j < i; j++) +rte_free (vq->vq_descx[j].cookie); + } +mpool_create_err: +rte_free (vq); +return -ENOMEM ; +} + +static int +virtio_crypto_ctrlq_setup (struct rte_cryptodev *dev,uint16_t queue_idx) +{ +int ret; +struct virtqueue *vq; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +/* if virtio device has started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + +PMD_INIT_FUNC_TRACE (); + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_CTRLQ , queue_idx, +0 ,SOCKET_ID_ANY , &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control vq initialization failed" ); +return ret; + } + + hw->cvq = vq; + +return 0 ; +} + +static void +virtio_crypto_free_queues (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +/* control queue release */ +virtio_crypto_queue_release (hw->cvq); + +/* data queue release */ +for (i =0 ; i < hw->max_dataqueues; i++) +virtio_crypto_queue_release (dev->data->queue_pairs[i]); +} + +static int +virtio_crypto_dev_close(struct rte_cryptodev *dev __rte_unused) +{ +return 0 ; +} +/* * dev_ops for virtio, bare necessities for basic operation */ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {/* Device related operations */ - .dev_configure =NULL , - .dev_start =NULL , - .dev_stop =NULL , - .dev_close =NULL , - .dev_infos_get =NULL , + .dev_configure = virtio_crypto_dev_configure, + .dev_start = virtio_crypto_dev_start, + .dev_stop = virtio_crypto_dev_stop, + .dev_close = virtio_crypto_dev_close, + .dev_infos_get = virtio_crypto_dev_info_get, .stats_get =NULL , .stats_reset =NULL , - .queue_pair_setup =NULL , - .queue_pair_release =NULL , + .queue_pair_setup = virtio_crypto_qp_setup, + .queue_pair_release = virtio_crypto_qp_release, .queue_pair_start =NULL , .queue_pair_stop =NULL , .queue_pair_count =NULL ,
@@ -55,6 +301,51 @@ };static int +virtio_crypto_qp_setup (struct rte_cryptodev *dev,uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, + struct rte_mempool *session_pool __rte_unused) +{ +int ret; +struct virtqueue *vq; + +PMD_INIT_FUNC_TRACE (); + +/* if virtio dev is started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_DATAQ , queue_pair_id, + qp_conf->nb_descriptors, socket_id, &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ( +"virtio crypto data queue initialization failed\n" ); +return ret; + } + + dev->data->queue_pairs[queue_pair_id] = vq; + +return 0 ; +} + +static int +virtio_crypto_qp_release (struct rte_cryptodev *dev,uint16_t queue_pair_id) +{ +struct virtqueue *vq + = (struct virtqueue *)dev->data->queue_pairs[queue_pair_id]; + +PMD_INIT_FUNC_TRACE (); + +if (vq ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_DBG ("vq already freed" ); +return 0 ; + } + +virtio_crypto_queue_release (vq); +return 0 ; +} + +static int virtio_negotiate_features (struct virtio_crypto_hw *hw,uint64_t req_features) {uint64_t host_features;
@@ -192,6 +483,136 @@ }static int +virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (cryptodev->data->dev_started) { +virtio_crypto_dev_stop (cryptodev); +virtio_crypto_dev_close (cryptodev); + } + + cryptodev->dev_ops =NULL ; + cryptodev->enqueue_burst =NULL ; + cryptodev->dequeue_burst =NULL ; + +/* release control queue */ +virtio_crypto_queue_release (hw->cvq); + +rte_free (cryptodev->data); + cryptodev->data =NULL ; + +VIRTIO_CRYPTO_DRV_LOG_INFO ("dev_uninit completed" ); + +return 0 ; +} + +static int +virtio_crypto_dev_configure (struct rte_cryptodev *cryptodev, + struct rte_cryptodev_config *config __rte_unused) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (virtio_crypto_init_device (cryptodev, +VIRTIO_CRYPTO_PMD_GUEST_FEATURES ) <0 ) +return -1 ; + +/* setup control queue +* [0, 1, ... ,(config->max_dataqueues - 1)] are data queues +* config->max_dataqueues is the control queue +*/ +if (virtio_crypto_ctrlq_setup (cryptodev, hw->max_dataqueues) <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control queue setup error" ); +return -1 ; + } +virtio_crypto_ctrlq_start (cryptodev); + +return 0 ; +} + +static void +virtio_crypto_dev_stop (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); +VIRTIO_CRYPTO_DRV_LOG_DBG ("virtio_dev_stop" ); + +vtpci_cryptodev_reset (hw); + +virtio_crypto_dev_free_mbufs (dev); +virtio_crypto_free_queues (dev); + + dev->data->dev_started =0 ; +} + +static int +virtio_crypto_dev_start (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +if (dev->data->dev_started) +return 0 ; + +/* Do final configuration before queue engine starts */ +virtio_crypto_dataq_start (dev); +vtpci_cryptodev_reinit_complete (hw); + + dev->data->dev_started =1 ; + +return 0 ; +} + +static void +virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev) +{ +uint32_t i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +for (i =0 ; i < hw->max_dataqueues; i++) { +VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " +"and unused buf" , i); +VIRTQUEUE_DUMP ((struct virtqueue *) + dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("queue_pairs[%d]=%p" , + i, dev->data->queue_pairs[i]); + +virtqueue_detatch_unused (dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("After freeing dataq[%d] used and " +"unused buf" , i); +VIRTQUEUE_DUMP ( + (struct virtqueue *)dev->data->queue_pairs[i]); + } +} + +static void +virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *info) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (info !=NULL ) { + info->driver_id = cryptodev_virtio_driver_id; + info->pci_dev =RTE_DEV_TO_PCI (dev->device); + info->feature_flags = dev->feature_flags; + info->max_nb_queue_pairs = hw->max_dataqueues; + info->sym.max_nb_sessions = +RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + } +} + +static int crypto_virtio_pci_probe ( struct rte_pci_driver *pci_drv __rte_unused,struct rte_pci_device *pci_dev)
@@ -231,7 +652,7 @@if (cryptodev ==NULL )return -ENODEV ; -return 0 ; +return virtio_crypto_dev_uninit (cryptodev); }static struct rte_pci_driver rte_virtio_crypto_driver = {
drivers/crypto/virtio/virtio_cryptodev.h +31 -1
@@ -5,13 +5,43 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ -#include <rte_cryptodev.h> +#include <virtio_crypto.h> + +#include "virtio_pci.h" +#include "virtio_ring.h" /* Features desired/implemented by this driver. */ #define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 + +struct virtio_crypto_op_cookie { +struct virtio_crypto_op_data_req data_req; +struct virtio_crypto_inhdr inhdr; +struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ]; +}; + +/* +* Control queue function prototype +*/ +void virtio_crypto_ctrlq_start (struct rte_cryptodev *dev); + +/* +* Data queue function prototype +*/ +void virtio_crypto_dataq_start (struct rte_cryptodev *dev); + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq); + +void virtio_crypto_queue_release (struct virtqueue *vq); +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue,struct rte_crypto_op **tx_pkts,uint16_t nb_pkts);
drivers/crypto/virtio/virtio_rxtx.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v9 4/11 crypto/virtio: support session related ops
In reply to Jay ZhouThis patch implements session related operations, which includes creating and destroying the session. For now, it only supports the session-oriented API implementation. The control queue used to create or destroy sessions for symmetric algorithms.
--- drivers/crypto/virtio/virtio_crypto_algs.h | 27 ++ drivers/crypto/virtio/virtio_cryptodev.c | 737 ++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 7 + 3 files changed, 768 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +27 -0
@@ -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 <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_ */
drivers/crypto/virtio/virtio_cryptodev.c +734 -3
775 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +7 -0
@@ -17,6 +17,13 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +enum virtio_crypto_cmd_id { +VIRTIO_CRYPTO_CMD_CIPHER =0 , +VIRTIO_CRYPTO_CMD_AUTH =1 , +VIRTIO_CRYPTO_CMD_CIPHER_HASH =2 , +VIRTIO_CRYPTO_CMD_HASH_CIPHER =3 +}; +struct virtio_crypto_op_cookie {struct virtio_crypto_op_data_req data_req;struct virtio_crypto_inhdr inhdr;
Signature · 1 line
1.8.3.1
PATCH v9 5/11 crypto/virtio: support crypto enqueue/dequeue burst API
In reply to Jay ZhouThis patch implements the functions of virtio_crypto_pkt_tx_burst() and virtio_crypto_pkt_rx_burst(). The encryption and decryption requests are placed in the data queue and are ultimately handled by the backend crypto accelerators.
--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 441 ++++++++++++++++++++++++++++++- 2 files changed, 433 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -17,6 +17,8 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +extern uint8_t cryptodev_virtio_driver_id; +enum virtio_crypto_cmd_id {VIRTIO_CRYPTO_CMD_CIPHER =0 ,VIRTIO_CRYPTO_CMD_AUTH =1 ,
drivers/crypto/virtio/virtio_rxtx.c +431 -10
463 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v9 6/11 crypto/virtio: support stats related ops
In reply to Jay ZhouThis patch implements the statistics of the packets.
--- drivers/crypto/virtio/virtio_cryptodev.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +64 -2
@@ -29,6 +29,9 @@ static int virtio_crypto_dev_configure(struct rte_cryptodev *dev,static int virtio_crypto_dev_close (struct rte_cryptodev *dev);static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev,struct rte_cryptodev_info *dev_info); +static void virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats); +static void virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev); static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
@@ -501,8 +504,8 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .dev_close = virtio_crypto_dev_close, .dev_infos_get = virtio_crypto_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = virtio_crypto_dev_stats_get, + .stats_reset = virtio_crypto_dev_stats_reset, .queue_pair_setup = virtio_crypto_qp_setup, .queue_pair_release = virtio_crypto_qp_release,
@@ -518,6 +521,65 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .qp_detach_session = NULL }; +static void +virtio_crypto_update_stats (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (stats ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("invalid pointer" ); +return ; + } + +for (i =0 ; i < hw->max_dataqueues; i++) { +const struct virtqueue *data_queue + = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + stats->enqueued_count += data_queue->packets_sent_total; + stats->enqueue_err_count += data_queue->packets_sent_failed; + + stats->dequeued_count += data_queue->packets_received_total; + stats->dequeue_err_count + += data_queue->packets_received_failed; + } +} + +static void +virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +PMD_INIT_FUNC_TRACE (); + +virtio_crypto_update_stats (dev, stats); +} + +static void +virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +for (i =0 ; i < hw->max_dataqueues; i++) { +struct virtqueue *data_queue = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + data_queue->packets_sent_total =0 ; + data_queue->packets_sent_failed =0 ; + + data_queue->packets_received_total =0 ; + data_queue->packets_received_failed =0 ; + } +} + static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
Signature · 1 line
1.8.3.1
PATCH v9 7/11 crypto/virtio: support AES-CBC
In reply to Jay ZhouThe AES-CBC cipher only algorithm has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 30 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 11 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 \ + { /* 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 +11 -0
@@ -15,6 +15,7 @@#include "virtio_cryptodev.h" #include "virtqueue.h" #include "virtio_crypto_algs.h" +#include "virtio_crypto_capabilities.h" int virtio_crypto_logtype_init;int virtio_crypto_logtype_session;
@@ -58,6 +59,11 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, { .vendor_id = 0, /* sentinel */ }, }; +static const struct rte_cryptodev_capabilities virtio_capabilities[] = { +VIRTIO_SYM_CAPABILITIES , +RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST () +}; +uint8_t cryptodev_virtio_driver_id;#define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -746,6 +752,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, hw = cryptodev->data->dev_private; hw->dev_id = cryptodev->data->dev_id; + hw->virtio_dev_capabilities = virtio_capabilities; VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x", cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1139,6 +1146,9 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_cipher_xform *cipher_xform) {switch (cipher_xform->algo) { +case RTE_CRYPTO_CIPHER_AES_CBC : + para->algo =VIRTIO_CRYPTO_CIPHER_AES_CBC ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Unsupported " "Cipher alg %u" , cipher_xform->algo);
@@ -1402,6 +1412,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, info->max_nb_queue_pairs = hw->max_dataqueues; info->sym.max_nb_sessions =RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + info->capabilities = hw->virtio_dev_capabilities; } }
Signature · 1 line
1.8.3.1
PATCH v9 8/11 crypto/virtio: support HMAC-SHA1
In reply to Jay ZhouThe AES-CBC with HMAC-SHA1 has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 21 +++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +21 -0
@@ -6,6 +6,27 @@#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 = { \
drivers/crypto/virtio/virtio_cryptodev.c +3 -1
@@ -1196,11 +1196,13 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, }switch (auth_xform->algo) { +case RTE_CRYPTO_AUTH_SHA1_HMAC : + *algo =VIRTIO_CRYPTO_MAC_HMAC_SHA1 ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Undefined Hash algo %u specified" , auth_xform->algo); - *algo =VIRTIO_CRYPTO_NO_MAC ;return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v9 9/11 crypto/virtio: build with meson
In reply to Jay Zhou--- drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/meson.build | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/virtio/meson.build
drivers/crypto/meson.build +1 -1
@@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = ['dpaa_sec', 'dpaa2_sec', - 'openssl', 'null', 'qat'] + 'openssl', 'null', 'qat', 'virtio'] std_deps = ['cryptodev'] # cryptodev pulls in all other needed deps config_flag_fmt = 'RTE_LIBRTE_@0@_PMD'
drivers/crypto/virtio/meson.build new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) +if not dep.found() + build = false +endif +deps += ['bus_pci'] +sources = files('virtio_cryptodev.c', 'virtio_pci.c', + 'virtio_rxtx.c', 'virtqueue.c') +ext_deps += dep +pkgconfig_extra_libs += '-lcrypto'
Signature · 1 line
1.8.3.1
Re: [PATCH v9 09/11] crypto/virtio: build with meson
Hi Jay,
Quoted 51 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Sunday, April 15, 2018 9:51 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v9 09/11]crypto/virtio: build with mesonSigned-off-by Jay Zhou <[email protected]>Reviewed-by Fan Zhang <[email protected]>Acked-by Fan Zhang <[email protected]>--- drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/meson.build | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644
drivers/crypto/virtio/meson.builddrivers/crypto/meson.build index renamed from drivers/crypto/meson.build +0
-0736c9f5..63649c9 100644
drivers/crypto/meson.build +1
-1@@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = ['dpaa_sec', 'dpaa2_sec', - 'openssl', 'null', 'qat'] + 'openssl', 'null', 'qat', 'virtio'] std_deps = ['cryptodev'] # cryptodev pulls in all other needed deps
config_flag_fmt= 'RTE_LIBRTE_@0@_PMD'drivers/crypto/virtio/meson.build new file +11
-1@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 HUAWEI +TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) if not dep.found() + build = false +endif +deps += ['bus_pci'] +sources = files('virtio_cryptodev.c', 'virtio_pci.c', + 'virtio_rxtx.c', 'virtqueue.c') +ext_deps += dep +pkgconfig_extra_libs += '-lcrypto' --
Quoted 2 lines
1.8.3.1
Could you add this build from the first patch? Basically, every time you make a change in the Makefile, you should do the same in meson.build.
Thanks,
Pablo
Re: [PATCH v9 09/11] crypto/virtio: build with meson
Hi Pablo,
Quoted 62 lines
-----Original Message-----
From: De Lara Guarch, Pablo [mailto:[email protected]]
Sent: Sunday, April 15, 2018 8:09 PM
To: Zhoujian (jay) <[email protected]>; [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; Gonglei (Arei) <[email protected]>; Zeng, Xin <[email protected]>; Huangweidong (C) <[email protected]>; wangxin (U) <[email protected]>; longpeng <[email protected]>
Subject: RE: [PATCH v9 09/11]crypto/virtio: build with mesonHi Jay,
Quoted 50 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Sunday, April 15, 2018 9:51 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v9 09/11]crypto/virtio: build with mesonSigned-off-by Jay Zhou <[email protected]>Reviewed-by Fan Zhang <[email protected]>Acked-by Fan Zhang <[email protected]>--- drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/meson.build | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644
drivers/crypto/virtio/meson.builddrivers/crypto/meson.build +0
-0index
736c9f5..63649c9 100644drivers/crypto/meson.build +1
-1@@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = ['dpaa_sec', 'dpaa2_sec', - 'openssl', 'null', 'qat'] + 'openssl', 'null', 'qat', 'virtio'] std_deps = ['cryptodev'] # cryptodev pulls in all other needed deps
config_flag_fmt= 'RTE_LIBRTE_@0@_PMD'drivers/crypto/virtio/meson.build new file +9
-0@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 HUAWEI +TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) if not dep.found() + build = false +endif +deps += ['bus_pci'] +sources = files('virtio_cryptodev.c', 'virtio_pci.c', + 'virtio_rxtx.c', 'virtqueue.c')
Quoted 8 lines
Quoted 5 lines
drivers/crypto/virtio/meson.build new file +2
-1+ext_deps += dep +pkgconfig_extra_libs += '-lcrypto' --1.8.3.1
Could you add this build from the first patch? Basically, every time you make a change in the
Makefile, you should do the same in meson.build.
I'll split this patch into two parts and squash them into the first and the second patch. Thanks for your suggestion.
Regards,
Jay
Quoted 3 lines
Thanks,
Pablo
PATCH v9 10/11 test/crypto: add function tests for virtio crypto PMD
In reply to Jay ZhouOnly 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 | 48 +++++++++++++++++++++++++++++ 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, 74 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +48 -0
@@ -1820,6 +1820,25 @@ 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;
@@ -8879,6 +8898,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,
@@ -9808,6 +9839,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(
@@ -10040,3 +10087,4 @@ struct test_crypto_vector {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_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND (cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
@@ -63,6 +63,7 @@#define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler#define CRYPTODEV_NAME_MRVL_PMD crypto_mrvl#define CRYPTODEV_NAME_CCP_PMD crypto_ccp +#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
@@ -1544,7 +1544,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
@@ -70,6 +70,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 ;
@@ -97,7 +99,8 @@ driver_id == openssl_pmd || driver_id == armv8_pmd || driver_id == mrvl_pmd || - driver_id == ccp_pmd) { /* Fall through */ + driver_id == ccp_pmd || + driver_id == virtio_pmd) { /* Fall through */ digest_len = tdata->digest.len; } else if (driver_id == aesni_mb_pmd || driver_id == scheduler_pmd) {
@@ -574,6 +577,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 :
@@ -638,6 +643,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
@@ -28,6 +28,7 @@#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_CCP 0x0040/* CCP flag */ +#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO 0x0200/* VIRTIO flag */ #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
PATCH v9 11/11 doc: add virtio crypto PMD guide
In reply to Jay ZhouThis patch adds the guide for virtio crypto PMD.
--- MAINTAINERS | 2 + 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 | 5 +- 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/guides/cryptodevs/features/virtio.ini create mode 100644 doc/guides/cryptodevs/virtio.rst
MAINTAINERS +2 -0
@@ -761,6 +761,8 @@ 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]>
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
@@ -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
@@ -23,4 +23,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
doc/guides/rel_notes/release_18_05.rst +4 -1
@@ -84,7 +84,10 @@ New Features * **Added the virtio crypto PMD.** - Added a new poll mode driver for virtio crypto devices. + Added a new poll mode driver for virtio crypto devices, which provides + AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. See the + :doc:`../cryptodevs/virtio` crypto driver guide for more details on + this new driver. API Changes
Signature · 1 line
1.8.3.1
v10 cover crypto: add virtio poll mode driver
In reply to Jay ZhouThis 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 merged into dpdk-next-virtio too.
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_idThe 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
+ 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 v10:
- squash the meson build files into the previous patches [Pablo]
Changes in v9:
- fix compilation error when CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO=y and CONFIG_RTE_BUILD_SHARED_LIB=y
Changes in v8:
- using the virtio_crypto.h in compat lib instead of the linux header file
- add meson build
Changes in v7:
- add detailed commit messages [Pablo]
Changes in v6:
- split the patches in a more functional way [Pablo]
Changes in v5:
- rebased on the newest dpdk-next-crypto
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 (10):
crypto/virtio: add virtio crypto PMD crypto/virtio: support virtio device init crypto/virtio: support basic PMD ops crypto/virtio: support session related ops crypto/virtio: support crypto enqueue/dequeue burst API crypto/virtio: support stats related ops crypto/virtio: support AES-CBC
crypto/virtio: support HMAC-SHA1
test/crypto: add function tests for virtio crypto PMD
doc: add virtio crypto PMD guide
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 | 7 + drivers/crypto/Makefile | 1 + drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/Makefile | 32 + drivers/crypto/virtio/meson.build | 12 + .../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 | 1504 ++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 62 + drivers/crypto/virtio/virtio_logs.h | 91 ++ drivers/crypto/virtio/virtio_pci.c | 462 ++++++ drivers/crypto/virtio/virtio_pci.h | 252 ++++ drivers/crypto/virtio/virtio_ring.h | 137 ++ drivers/crypto/virtio/virtio_rxtx.c | 515 +++++++ drivers/crypto/virtio/virtqueue.c | 43 + drivers/crypto/virtio/virtqueue.h | 171 +++ mk/rte.app.mk | 1 + test/test/test_cryptodev.c | 48 + 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 + 28 files changed, 3610 insertions(+), 10 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/meson.build 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
Signature · 1 line
1.8.3.1
PATCH v10 1/10 crypto/virtio: add virtio crypto PMD
The virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
--- MAINTAINERS | 4 +++ config/common_base | 14 +++++++++ doc/guides/rel_notes/release_18_05.rst | 4 +++ drivers/crypto/Makefile | 1 + drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/Makefile | 29 +++++++++++++++++ drivers/crypto/virtio/meson.build | 11 +++++++ .../virtio/rte_pmd_virtio_crypto_version.map | 3 ++ drivers/crypto/virtio/virtio_cryptodev.c | 36 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 10 ++++++ mk/rte.app.mk | 1 + 11 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/virtio/Makefile create mode 100644 drivers/crypto/virtio/meson.build create mode 100644 drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map create mode 100644 drivers/crypto/virtio/virtio_cryptodev.c create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
MAINTAINERS +4 -0
@@ -758,6 +758,10 @@ 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/ + ZUC M: Pablo de Lara <[email protected]> F: drivers/crypto/zuc/
config/common_base +14 -0
@@ -493,6 +493,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
@@ -82,6 +82,10 @@ New Features Linux uevent is supported as backend of this device event notification framework. +* **Added the virtio crypto PMD.** + + Added a new poll mode driver for virtio crypto devices. + API Changes -----------
drivers/crypto/Makefile +1 -0
@@ -21,5 +21,6 @@ ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec endif DIRS-$(CONFIG_RTE_LIBRTE_PMD_CCP) += ccp +DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/meson.build +1 -1
@@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = ['dpaa_sec', 'dpaa2_sec', - 'openssl', 'null', 'qat'] + 'openssl', 'null', 'qat', 'virtio'] std_deps = ['cryptodev'] # cryptodev pulls in all other needed deps config_flag_fmt = 'RTE_LIBRTE_@0@_PMD'
drivers/crypto/virtio/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +# 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) += virtio_cryptodev.c + +# this lib depends upon: +LDLIBS += -lcrypto +LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool +LDLIBS += -lrte_cryptodev +LDLIBS += -lrte_pci -lrte_bus_pci + +include $(RTE_SDK)/mk/rte.lib.mk
drivers/crypto/virtio/meson.build new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) +if not dep.found() + build = false +endif +deps += ['bus_pci'] +sources = files('virtio_cryptodev.c') +ext_deps += dep +pkgconfig_extra_libs += '-lcrypto'
drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map new file +3 -0
@@ -0,0 +1,3 @@ +DPDK_18.05 { + local: *; +};
drivers/crypto/virtio/virtio_cryptodev.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_cryptodev_pmd.h> +#include "virtio_cryptodev.h" + +uint8_t cryptodev_virtio_driver_id; + +static int +crypto_virtio_pci_probe ( + struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static int +crypto_virtio_pci_remove ( + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static struct rte_pci_driver rte_virtio_crypto_driver = { + .probe = crypto_virtio_pci_probe, + .remove = crypto_virtio_pci_remove +}; + +static struct cryptodev_driver virtio_crypto_drv; + +RTE_PMD_REGISTER_PCI (CRYPTODEV_NAME_VIRTIO_PMD , rte_virtio_crypto_driver); +RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, + rte_virtio_crypto_driver.driver, + cryptodev_virtio_driver_id);
drivers/crypto/virtio/virtio_cryptodev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ + +#ifndef _VIRTIO_CRYPTODEV_H_ +#define _VIRTIO_CRYPTODEV_H_ + +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio + +#endif /* _VIRTIO_CRYPTODEV_H_ */
mk/rte.app.mk +1 -0
@@ -208,6 +208,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM) += -lIPSec_MB _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
Re: [PATCH v10 01/10] crypto/virtio: add virtio crypto PMD
Hi Jay,
Quoted 19 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Monday, April 16, 2018 3:21 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v10 01/10]crypto/virtio: add virtio crypto PMDThe virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
Signed-off-by Jay Zhou <[email protected]>Reviewed-by Fan Zhang <[email protected]>Acked-by Fan Zhang <[email protected]>
...
drivers/crypto/virtio/meson.build line 6
Quoted 8 lines
+++ b/drivers/crypto/virtio/meson.build
drivers/crypto/virtio/meson.build new file +6
-0@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 HUAWEI +TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) if not dep.found() + build = false +endif
Does this PMD have a dependency on libcrypto?
Looking at the code, I don't think it does.
Therefore, you should remove this and also LDLIBS += -lcrypto in the Makefile. Once this is removed, and you add the path to the virtio_crypto.h file (as Ferruh suggested), I'd say this PMD can be enabled by default.
Re: [PATCH v10 01/10] crypto/virtio: add virtio crypto PMD
Hi Pablo,
Quoted 34 lines
-----Original Message-----
From: De Lara Guarch, Pablo [mailto:[email protected]]
Sent: Monday, April 16, 2018 10:16 PM
To: Zhoujian (jay) <[email protected]>; [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; Gonglei (Arei) <[email protected]>; Zeng, Xin <[email protected]>; Huangweidong (C) <[email protected]>; wangxin (U) <[email protected]>; longpeng <[email protected]>
Subject: RE: [PATCH v10 01/10]crypto/virtio: add virtio crypto PMDHi Jay,
Quoted 19 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Monday, April 16, 2018 3:21 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v10 01/10]crypto/virtio: add virtio crypto PMDThe virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
Signed-off-by Jay Zhou <[email protected]>Reviewed-by Fan Zhang <[email protected]>Acked-by Fan Zhang <[email protected]>...
Quoted 12 lines
drivers/crypto/virtio/meson.build line 6
Quoted 8 lines
+++ b/drivers/crypto/virtio/meson.build
drivers/crypto/virtio/meson.build new file +6
-0@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 HUAWEI +TECHNOLOGIES CO., LTD. + +dep = dependency('libcrypto', required: false) if not dep.found() + build = false +endifDoes this PMD have a dependency on libcrypto?
Looking at the code, I don't think it does.
Therefore, you should remove this and also LDLIBS += -lcrypto in theMakefile.
It's compiled successfully without the dependency, so you're right. I'll remove it.
Quoted 2 lines
Once this is removed, and you add the path to the
virtio_crypto.hfile (as Ferruh suggested), I'd say this PMD can be enabled by default.
I agree with you and Ferruh. If the other codes are fine for you, I'll send the next version tomorrow with this PMD enabled by default as well as the updated path to virtio_crypto.h file.
Regards,
Jay
PATCH v10 2/10 crypto/virtio: support virtio device init
In reply to Jay ZhouThis patch implements the initialization of the virtio crypto device. The virtio crypto device conforms to virtio-1.0, so this patch only supports modern mode operation.
The cryptodev is created at the virtio crypto pci device probing stage. The function of virtio_crypto_pkt_tx_burst() is used to burst transfer packets and virtio_crypto_pkt_rx_burst() is used to burst receive packets.
--- drivers/crypto/virtio/Makefile | 3 + drivers/crypto/virtio/meson.build | 3 +- drivers/crypto/virtio/virtio_cryptodev.c | 245 +++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 13 + drivers/crypto/virtio/virtio_logs.h | 91 ++++++ drivers/crypto/virtio/virtio_pci.c | 462 +++++++++++++++++++++++++++++++ drivers/crypto/virtio/virtio_pci.h | 252 +++++++++++++++++ drivers/crypto/virtio/virtio_ring.h | 137 +++++++++ drivers/crypto/virtio/virtio_rxtx.c | 26 ++ drivers/crypto/virtio/virtqueue.c | 43 +++ drivers/crypto/virtio/virtqueue.h | 171 ++++++++++++ 11 files changed, 1443 insertions(+), 3 deletions(-) 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
drivers/crypto/virtio/Makefile +3 -0
@@ -18,6 +18,9 @@ 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:
drivers/crypto/virtio/meson.build +2 -1
@@ -6,6 +6,7 @@ if not dep.found() build = false endif deps += ['bus_pci'] -sources = files('virtio_cryptodev.c') +sources = files('virtio_cryptodev.c', 'virtio_pci.c', + 'virtio_rxtx.c', 'virtqueue.c') ext_deps += dep pkgconfig_extra_libs += '-lcrypto'
drivers/crypto/virtio/virtio_cryptodev.c +243 -2
273 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +13 -0
@@ -5,6 +5,19 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ +#include <rte_cryptodev.h> + +/* Features desired/implemented by this driver. */ +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); + +uint16_t virtio_crypto_pkt_rx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); +#endif /* _VIRTIO_CRYPTODEV_H_ */
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 +462 -0
462 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h new file +252 -0
252 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/virtio_rxtx.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include "virtio_cryptodev.h" + +uint16_t +virtio_crypto_pkt_rx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_rx =0 ; + +return nb_rx; +} + +uint16_t +virtio_crypto_pkt_tx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_tx =0 ; + +return nb_tx; +}
drivers/crypto/virtio/virtqueue.c new file +43 -0
43 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v10 3/10 crypto/virtio: support basic PMD ops
In reply to Jay ZhouThis patch implements the basic operations of virtio crypto PMD, which includes start, stop, close, information getting, queue setup and release of the device.
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.
--- drivers/crypto/virtio/virtio_cryptodev.c | 437 ++++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 32 ++- drivers/crypto/virtio/virtio_rxtx.c | 68 +++++ 3 files changed, 528 insertions(+), 9 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +429 -8
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ +#include <rte_errno.h> #include <rte_pci.h> #include <rte_bus_pci.h> #include <rte_cryptodev.h>
@@ -15,6 +16,22 @@int virtio_crypto_logtype_tx;int virtio_crypto_logtype_driver; +static int virtio_crypto_dev_configure (struct rte_cryptodev *dev, +struct rte_cryptodev_config *config); +static int virtio_crypto_dev_start (struct rte_cryptodev *dev); +static void virtio_crypto_dev_stop (struct rte_cryptodev *dev); +static int virtio_crypto_dev_close (struct rte_cryptodev *dev); +static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *dev_info); +static int virtio_crypto_qp_setup (struct rte_cryptodev *dev, +uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, +struct rte_mempool *session_pool); +static int virtio_crypto_qp_release (struct rte_cryptodev *dev, +uint16_t queue_pair_id); +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev); +/* * The set of PCI devices this driver supports */
@@ -26,22 +43,251 @@uint8_t cryptodev_virtio_driver_id; +void +virtio_crypto_queue_release (struct virtqueue *vq) +{ +struct virtio_crypto_hw *hw; + +PMD_INIT_FUNC_TRACE (); + +if (vq) { + hw = vq->hw; +/* Select and deactivate the queue */ +VTPCI_OPS (hw)->del_queue (hw, vq); + +rte_memzone_free (vq->mz); +rte_mempool_free (vq->mpool); +rte_free (vq); + } +} + +#define MPOOL_MAX_NAME_SZ 32 + +int +virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq) +{ +char vq_name[VIRTQUEUE_MAX_NAME_SZ ]; +char mpool_name[MPOOL_MAX_NAME_SZ ]; +const struct rte_memzone *mz; +unsigned int vq_size, size; +struct virtio_crypto_hw *hw = dev->data->dev_private; +struct virtqueue *vq =NULL ; +uint32_t i =0 ; +uint32_t j; + +PMD_INIT_FUNC_TRACE (); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("setting up queue: %u" , vtpci_queue_idx); + +/* +* Read the virtqueue size from the Queue Size field +* Always power of 2 and if 0 virtqueue does not exist +*/ + vq_size =VTPCI_OPS (hw)->get_queue_num (hw, vtpci_queue_idx); +if (vq_size ==0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue does not exist" ); +return -EINVAL ; + } +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq_size: %u" , vq_size); + +if (!rte_is_power_of_2 (vq_size)) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue size is not powerof 2" ); +return -EINVAL ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_dataqueue%d" , + dev->data->dev_id, vtpci_queue_idx); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_dataqueue%d_mpool" , + dev->data->dev_id, vtpci_queue_idx); + }else if (queue_type ==VTCRYPTO_CTRLQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_controlqueue" , + dev->data->dev_id); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_controlqueue_mpool" , + dev->data->dev_id); + } + size =RTE_ALIGN_CEIL (sizeof (*vq) + + vq_size *sizeof (struct vq_desc_extra ), +RTE_CACHE_LINE_SIZE ); + vq =rte_zmalloc_socket (vq_name, size,RTE_CACHE_LINE_SIZE , + socket_id); +if (vq ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("Can not allocate virtqueue" ); +return -ENOMEM ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +/* pre-allocate a mempool and use it in the data plane to +* improve performance +*/ + vq->mpool =rte_mempool_lookup (mpool_name); +if (vq->mpool ==NULL ) + vq->mpool =rte_mempool_create (mpool_name, + vq_size, +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ,0 , +NULL ,NULL ,NULL ,NULL , socket_id, +0 ); +if (!vq->mpool) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Virtio Crypto PMD " +"Cannot create mempool" ); + goto mpool_create_err; + } +for (i =0 ; i < vq_size; i++) { + vq->vq_descx[i].cookie = +rte_zmalloc ("crypto PMD op cookie pointer" , +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ); +if (vq->vq_descx[i].cookie ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Failed to " +"alloc mem for cookie" ); + goto cookie_alloc_err; + } + } + } + + vq->hw = hw; + vq->dev_id = dev->data->dev_id; + vq->vq_queue_index = vtpci_queue_idx; + vq->vq_nentries = vq_size; + +/* +* Using part of the vring entries is permitted, but the maximum +* is vq_size +*/ +if (nb_desc ==0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; + +/* +* Reserve a memzone for vring elements +*/ + size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN ); +VIRTIO_CRYPTO_INIT_LOG_DBG ("%s vring_size: %d, rounded_vring_size: %d" , + (queue_type ==VTCRYPTO_DATAQ ) ?"dataq" :"ctrlq" , + size, vq->vq_ring_size); + + mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, + socket_id,0 ,VIRTIO_PCI_VRING_ALIGN ); +if (mz ==NULL ) { +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("not enough memory" ); + goto mz_reserve_err; + } + } + +/* +* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, +* and only accepts 32 bit page frame number. +* Check if the allocated physical memory exceeds 16TB. +*/ +if ((mz->phys_addr + vq->vq_ring_size -1 ) + >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT +32 )) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("vring address shouldn't be " +"above 16TB!" ); + goto vring_addr_err; + } + +memset (mz->addr,0 ,sizeof (mz->len)); + vq->mz = mz; + vq->vq_ring_mem = mz->phys_addr; + vq->vq_ring_virt_mem = mz->addr; +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_mem(physical): 0x%" PRIx64, + (uint64_t )mz->phys_addr); +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_virt_mem: 0x%" PRIx64, + (uint64_t )(uintptr_t )mz->addr); + + *pvq = vq; + +return 0 ; + +vring_addr_err: +rte_memzone_free (mz); +mz_reserve_err: +cookie_alloc_err: +rte_mempool_free (vq->mpool); +if (i !=0 ) { +for (j =0 ; j < i; j++) +rte_free (vq->vq_descx[j].cookie); + } +mpool_create_err: +rte_free (vq); +return -ENOMEM ; +} + +static int +virtio_crypto_ctrlq_setup (struct rte_cryptodev *dev,uint16_t queue_idx) +{ +int ret; +struct virtqueue *vq; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +/* if virtio device has started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + +PMD_INIT_FUNC_TRACE (); + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_CTRLQ , queue_idx, +0 ,SOCKET_ID_ANY , &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control vq initialization failed" ); +return ret; + } + + hw->cvq = vq; + +return 0 ; +} + +static void +virtio_crypto_free_queues (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +/* control queue release */ +virtio_crypto_queue_release (hw->cvq); + +/* data queue release */ +for (i =0 ; i < hw->max_dataqueues; i++) +virtio_crypto_queue_release (dev->data->queue_pairs[i]); +} + +static int +virtio_crypto_dev_close(struct rte_cryptodev *dev __rte_unused) +{ +return 0 ; +} +/* * dev_ops for virtio, bare necessities for basic operation */ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {/* Device related operations */ - .dev_configure =NULL , - .dev_start =NULL , - .dev_stop =NULL , - .dev_close =NULL , - .dev_infos_get =NULL , + .dev_configure = virtio_crypto_dev_configure, + .dev_start = virtio_crypto_dev_start, + .dev_stop = virtio_crypto_dev_stop, + .dev_close = virtio_crypto_dev_close, + .dev_infos_get = virtio_crypto_dev_info_get, .stats_get =NULL , .stats_reset =NULL , - .queue_pair_setup =NULL , - .queue_pair_release =NULL , + .queue_pair_setup = virtio_crypto_qp_setup, + .queue_pair_release = virtio_crypto_qp_release, .queue_pair_start =NULL , .queue_pair_stop =NULL , .queue_pair_count =NULL ,
@@ -55,6 +301,51 @@ };static int +virtio_crypto_qp_setup (struct rte_cryptodev *dev,uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, + struct rte_mempool *session_pool __rte_unused) +{ +int ret; +struct virtqueue *vq; + +PMD_INIT_FUNC_TRACE (); + +/* if virtio dev is started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_DATAQ , queue_pair_id, + qp_conf->nb_descriptors, socket_id, &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ( +"virtio crypto data queue initialization failed\n" ); +return ret; + } + + dev->data->queue_pairs[queue_pair_id] = vq; + +return 0 ; +} + +static int +virtio_crypto_qp_release (struct rte_cryptodev *dev,uint16_t queue_pair_id) +{ +struct virtqueue *vq + = (struct virtqueue *)dev->data->queue_pairs[queue_pair_id]; + +PMD_INIT_FUNC_TRACE (); + +if (vq ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_DBG ("vq already freed" ); +return 0 ; + } + +virtio_crypto_queue_release (vq); +return 0 ; +} + +static int virtio_negotiate_features (struct virtio_crypto_hw *hw,uint64_t req_features) {uint64_t host_features;
@@ -192,6 +483,136 @@ }static int +virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (cryptodev->data->dev_started) { +virtio_crypto_dev_stop (cryptodev); +virtio_crypto_dev_close (cryptodev); + } + + cryptodev->dev_ops =NULL ; + cryptodev->enqueue_burst =NULL ; + cryptodev->dequeue_burst =NULL ; + +/* release control queue */ +virtio_crypto_queue_release (hw->cvq); + +rte_free (cryptodev->data); + cryptodev->data =NULL ; + +VIRTIO_CRYPTO_DRV_LOG_INFO ("dev_uninit completed" ); + +return 0 ; +} + +static int +virtio_crypto_dev_configure (struct rte_cryptodev *cryptodev, + struct rte_cryptodev_config *config __rte_unused) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (virtio_crypto_init_device (cryptodev, +VIRTIO_CRYPTO_PMD_GUEST_FEATURES ) <0 ) +return -1 ; + +/* setup control queue +* [0, 1, ... ,(config->max_dataqueues - 1)] are data queues +* config->max_dataqueues is the control queue +*/ +if (virtio_crypto_ctrlq_setup (cryptodev, hw->max_dataqueues) <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control queue setup error" ); +return -1 ; + } +virtio_crypto_ctrlq_start (cryptodev); + +return 0 ; +} + +static void +virtio_crypto_dev_stop (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); +VIRTIO_CRYPTO_DRV_LOG_DBG ("virtio_dev_stop" ); + +vtpci_cryptodev_reset (hw); + +virtio_crypto_dev_free_mbufs (dev); +virtio_crypto_free_queues (dev); + + dev->data->dev_started =0 ; +} + +static int +virtio_crypto_dev_start (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +if (dev->data->dev_started) +return 0 ; + +/* Do final configuration before queue engine starts */ +virtio_crypto_dataq_start (dev); +vtpci_cryptodev_reinit_complete (hw); + + dev->data->dev_started =1 ; + +return 0 ; +} + +static void +virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev) +{ +uint32_t i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +for (i =0 ; i < hw->max_dataqueues; i++) { +VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " +"and unused buf" , i); +VIRTQUEUE_DUMP ((struct virtqueue *) + dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("queue_pairs[%d]=%p" , + i, dev->data->queue_pairs[i]); + +virtqueue_detatch_unused (dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("After freeing dataq[%d] used and " +"unused buf" , i); +VIRTQUEUE_DUMP ( + (struct virtqueue *)dev->data->queue_pairs[i]); + } +} + +static void +virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *info) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (info !=NULL ) { + info->driver_id = cryptodev_virtio_driver_id; + info->pci_dev =RTE_DEV_TO_PCI (dev->device); + info->feature_flags = dev->feature_flags; + info->max_nb_queue_pairs = hw->max_dataqueues; + info->sym.max_nb_sessions = +RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + } +} + +static int crypto_virtio_pci_probe ( struct rte_pci_driver *pci_drv __rte_unused,struct rte_pci_device *pci_dev)
@@ -231,7 +652,7 @@if (cryptodev ==NULL )return -ENODEV ; -return 0 ; +return virtio_crypto_dev_uninit (cryptodev); }static struct rte_pci_driver rte_virtio_crypto_driver = {
drivers/crypto/virtio/virtio_cryptodev.h +31 -1
@@ -5,13 +5,43 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ -#include <rte_cryptodev.h> +#include <virtio_crypto.h> + +#include "virtio_pci.h" +#include "virtio_ring.h" /* Features desired/implemented by this driver. */ #define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 + +struct virtio_crypto_op_cookie { +struct virtio_crypto_op_data_req data_req; +struct virtio_crypto_inhdr inhdr; +struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ]; +}; + +/* +* Control queue function prototype +*/ +void virtio_crypto_ctrlq_start (struct rte_cryptodev *dev); + +/* +* Data queue function prototype +*/ +void virtio_crypto_dataq_start (struct rte_cryptodev *dev); + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq); + +void virtio_crypto_queue_release (struct virtqueue *vq); +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue,struct rte_crypto_op **tx_pkts,uint16_t nb_pkts);
drivers/crypto/virtio/virtio_rxtx.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v10 4/10 crypto/virtio: support session related ops
In reply to Jay ZhouThis patch implements session related operations, which includes creating and destroying the session. For now, it only supports the session-oriented API implementation. The control queue used to create or destroy sessions for symmetric algorithms.
--- drivers/crypto/virtio/virtio_crypto_algs.h | 27 ++ drivers/crypto/virtio/virtio_cryptodev.c | 737 ++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 7 + 3 files changed, 768 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +27 -0
@@ -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 <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_ */
drivers/crypto/virtio/virtio_cryptodev.c +734 -3
775 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +7 -0
@@ -17,6 +17,13 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +enum virtio_crypto_cmd_id { +VIRTIO_CRYPTO_CMD_CIPHER =0 , +VIRTIO_CRYPTO_CMD_AUTH =1 , +VIRTIO_CRYPTO_CMD_CIPHER_HASH =2 , +VIRTIO_CRYPTO_CMD_HASH_CIPHER =3 +}; +struct virtio_crypto_op_cookie {struct virtio_crypto_op_data_req data_req;struct virtio_crypto_inhdr inhdr;
Signature · 1 line
1.8.3.1
PATCH v10 5/10 crypto/virtio: support crypto enqueue/dequeue burst API
In reply to Jay ZhouThis patch implements the functions of virtio_crypto_pkt_tx_burst() and virtio_crypto_pkt_rx_burst(). The encryption and decryption requests are placed in the data queue and are ultimately handled by the backend crypto accelerators.
--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 441 ++++++++++++++++++++++++++++++- 2 files changed, 433 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -17,6 +17,8 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +extern uint8_t cryptodev_virtio_driver_id; +enum virtio_crypto_cmd_id {VIRTIO_CRYPTO_CMD_CIPHER =0 ,VIRTIO_CRYPTO_CMD_AUTH =1 ,
drivers/crypto/virtio/virtio_rxtx.c +431 -10
463 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v10 6/10 crypto/virtio: support stats related ops
In reply to Jay ZhouThis patch implements the statistics of the packets.
--- drivers/crypto/virtio/virtio_cryptodev.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +64 -2
@@ -29,6 +29,9 @@ static int virtio_crypto_dev_configure(struct rte_cryptodev *dev,static int virtio_crypto_dev_close (struct rte_cryptodev *dev);static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev,struct rte_cryptodev_info *dev_info); +static void virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats); +static void virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev); static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
@@ -501,8 +504,8 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .dev_close = virtio_crypto_dev_close, .dev_infos_get = virtio_crypto_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = virtio_crypto_dev_stats_get, + .stats_reset = virtio_crypto_dev_stats_reset, .queue_pair_setup = virtio_crypto_qp_setup, .queue_pair_release = virtio_crypto_qp_release,
@@ -518,6 +521,65 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .qp_detach_session = NULL }; +static void +virtio_crypto_update_stats (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (stats ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("invalid pointer" ); +return ; + } + +for (i =0 ; i < hw->max_dataqueues; i++) { +const struct virtqueue *data_queue + = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + stats->enqueued_count += data_queue->packets_sent_total; + stats->enqueue_err_count += data_queue->packets_sent_failed; + + stats->dequeued_count += data_queue->packets_received_total; + stats->dequeue_err_count + += data_queue->packets_received_failed; + } +} + +static void +virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +PMD_INIT_FUNC_TRACE (); + +virtio_crypto_update_stats (dev, stats); +} + +static void +virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +for (i =0 ; i < hw->max_dataqueues; i++) { +struct virtqueue *data_queue = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + data_queue->packets_sent_total =0 ; + data_queue->packets_sent_failed =0 ; + + data_queue->packets_received_total =0 ; + data_queue->packets_received_failed =0 ; + } +} + static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
Signature · 1 line
1.8.3.1
PATCH v10 7/10 crypto/virtio: support AES-CBC
In reply to Jay ZhouThe AES-CBC cipher only algorithm has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 30 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 11 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 \ + { /* 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 +11 -0
@@ -15,6 +15,7 @@#include "virtio_cryptodev.h" #include "virtqueue.h" #include "virtio_crypto_algs.h" +#include "virtio_crypto_capabilities.h" int virtio_crypto_logtype_init;int virtio_crypto_logtype_session;
@@ -58,6 +59,11 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, { .vendor_id = 0, /* sentinel */ }, }; +static const struct rte_cryptodev_capabilities virtio_capabilities[] = { +VIRTIO_SYM_CAPABILITIES , +RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST () +}; +uint8_t cryptodev_virtio_driver_id;#define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -746,6 +752,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, hw = cryptodev->data->dev_private; hw->dev_id = cryptodev->data->dev_id; + hw->virtio_dev_capabilities = virtio_capabilities; VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x", cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1139,6 +1146,9 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_cipher_xform *cipher_xform) {switch (cipher_xform->algo) { +case RTE_CRYPTO_CIPHER_AES_CBC : + para->algo =VIRTIO_CRYPTO_CIPHER_AES_CBC ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Unsupported " "Cipher alg %u" , cipher_xform->algo);
@@ -1402,6 +1412,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, info->max_nb_queue_pairs = hw->max_dataqueues; info->sym.max_nb_sessions =RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + info->capabilities = hw->virtio_dev_capabilities; } }
Signature · 1 line
1.8.3.1
PATCH v10 8/10 crypto/virtio: support HMAC-SHA1
In reply to Jay ZhouThe AES-CBC with HMAC-SHA1 has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 21 +++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +21 -0
@@ -6,6 +6,27 @@#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 = { \
drivers/crypto/virtio/virtio_cryptodev.c +3 -1
@@ -1196,11 +1196,13 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, }switch (auth_xform->algo) { +case RTE_CRYPTO_AUTH_SHA1_HMAC : + *algo =VIRTIO_CRYPTO_MAC_HMAC_SHA1 ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Undefined Hash algo %u specified" , auth_xform->algo); - *algo =VIRTIO_CRYPTO_NO_MAC ;return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v10 9/10 test/crypto: add function tests for virtio crypto PMD
In reply to Jay ZhouOnly 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 | 48 +++++++++++++++++++++++++++++ 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, 74 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +48 -0
@@ -1820,6 +1820,25 @@ 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;
@@ -8879,6 +8898,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,
@@ -9808,6 +9839,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(
@@ -10040,3 +10087,4 @@ struct test_crypto_vector {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_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND (cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
@@ -63,6 +63,7 @@#define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler#define CRYPTODEV_NAME_MRVL_PMD crypto_mrvl#define CRYPTODEV_NAME_CCP_PMD crypto_ccp +#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
@@ -1544,7 +1544,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
@@ -70,6 +70,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 ;
@@ -97,7 +99,8 @@ driver_id == openssl_pmd || driver_id == armv8_pmd || driver_id == mrvl_pmd || - driver_id == ccp_pmd) { /* Fall through */ + driver_id == ccp_pmd || + driver_id == virtio_pmd) { /* Fall through */ digest_len = tdata->digest.len; } else if (driver_id == aesni_mb_pmd || driver_id == scheduler_pmd) {
@@ -574,6 +577,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 :
@@ -638,6 +643,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
@@ -28,6 +28,7 @@#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_CCP 0x0040/* CCP flag */ +#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO 0x0200/* VIRTIO flag */ #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
PATCH v10 10/10 doc: add virtio crypto PMD guide
In reply to Jay ZhouThis patch adds the guide for virtio crypto PMD.
--- MAINTAINERS | 2 + 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 | 5 +- 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/guides/cryptodevs/features/virtio.ini create mode 100644 doc/guides/cryptodevs/virtio.rst
MAINTAINERS +2 -0
@@ -761,6 +761,8 @@ 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]>
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
@@ -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
@@ -23,4 +23,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
doc/guides/rel_notes/release_18_05.rst +4 -1
@@ -84,7 +84,10 @@ New Features * **Added the virtio crypto PMD.** - Added a new poll mode driver for virtio crypto devices. + Added a new poll mode driver for virtio crypto devices, which provides + AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. See the + :doc:`../cryptodevs/virtio` crypto driver guide for more details on + this new driver. API Changes
Signature · 1 line
1.8.3.1
v11 cover crypto: add virtio poll mode driver
In reply to Jay ZhouThis 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 merged into dpdk-next-virtio too.
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_idThe 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
+ 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 v11:
- remove dependency on libcrypto [Pablo]
- enabled this PMD by default [Pablo]
- update path to the virtio_crypto.h file [Ferruh]
Changes in v10:
- squash the meson build files into the previous patches [Pablo]
Changes in v9:
- fix compilation error when CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO=y and CONFIG_RTE_BUILD_SHARED_LIB=y
Changes in v8:
- using the virtio_crypto.h in compat lib instead of the linux header file
- add meson build
Changes in v7:
- add detailed commit messages [Pablo]
Changes in v6:
- split the patches in a more functional way [Pablo]
Changes in v5:
- rebased on the newest dpdk-next-crypto
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 (10):
crypto/virtio: add virtio crypto PMD crypto/virtio: support virtio device init crypto/virtio: support basic PMD ops crypto/virtio: support session related ops crypto/virtio: support crypto enqueue/dequeue burst API crypto/virtio: support stats related ops crypto/virtio: support AES-CBC
crypto/virtio: support HMAC-SHA1
test/crypto: add function tests for virtio crypto PMD
doc: add virtio crypto PMD guide
MAINTAINERS | 6 + config/common_base | 14 + config/rte_config.h | 4 + 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 | 7 + drivers/crypto/Makefile | 1 + drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/Makefile | 35 + drivers/crypto/virtio/meson.build | 8 + .../virtio/rte_pmd_virtio_crypto_version.map | 3 + drivers/crypto/virtio/virtio_crypto_algs.h | 28 + drivers/crypto/virtio/virtio_crypto_capabilities.h | 51 + drivers/crypto/virtio/virtio_cryptodev.c | 1504 ++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 62 + drivers/crypto/virtio/virtio_logs.h | 91 ++ drivers/crypto/virtio/virtio_pci.c | 462 ++++++ drivers/crypto/virtio/virtio_pci.h | 253 ++++ drivers/crypto/virtio/virtio_ring.h | 137 ++ drivers/crypto/virtio/virtio_rxtx.c | 515 +++++++ drivers/crypto/virtio/virtqueue.c | 43 + drivers/crypto/virtio/virtqueue.h | 171 +++ mk/rte.app.mk | 1 + test/test/test_cryptodev.c | 48 + 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 + 29 files changed, 3615 insertions(+), 10 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/meson.build 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
Signature · 1 line
1.8.3.1
PATCH v11 1/10 crypto/virtio: add virtio crypto PMD
The virtio crypto device is a virtual cryptography device as well as a kind of virtual hardware accelerator for virtual machines. The linux kernel virtio-crypto driver has been merged, and this patch introduces virtio crypto PMD to achieve better performance.
--- MAINTAINERS | 4 +++ config/common_base | 14 +++++++++ config/rte_config.h | 4 +++ doc/guides/rel_notes/release_18_05.rst | 4 +++ drivers/crypto/Makefile | 1 + drivers/crypto/meson.build | 2 +- drivers/crypto/virtio/Makefile | 28 +++++++++++++++++ drivers/crypto/virtio/meson.build | 6 ++++ .../virtio/rte_pmd_virtio_crypto_version.map | 3 ++ drivers/crypto/virtio/virtio_cryptodev.c | 36 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.h | 10 ++++++ mk/rte.app.mk | 1 + 12 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/virtio/Makefile create mode 100644 drivers/crypto/virtio/meson.build create mode 100644 drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map create mode 100644 drivers/crypto/virtio/virtio_cryptodev.c create mode 100644 drivers/crypto/virtio/virtio_cryptodev.h
MAINTAINERS +4 -0
@@ -772,6 +772,10 @@ 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/ + ZUC M: Pablo de Lara <[email protected]> F: drivers/crypto/zuc/
config/common_base +14 -0
@@ -494,6 +494,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=y +# +# 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
config/rte_config.h +4 -0
@@ -84,6 +84,10 @@/* QuickAssist device */ #define RTE_QAT_PMD_MAX_NB_SESSIONS 2048 +/* virtio crypto defines */ +#define RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS 1024 +#define RTE_MAX_VIRTIO_CRYPTO 32 +/* DPAA2_SEC */ #define RTE_DPAA2_SEC_PMD_MAX_NB_SESSIONS 2048
doc/guides/rel_notes/release_18_05.rst +4 -0
@@ -127,6 +127,10 @@ New Features Linux uevent is supported as backend of this device event notification framework. +* **Added the virtio crypto PMD.** + + Added a new poll mode driver for virtio crypto devices. + API Changes -----------
drivers/crypto/Makefile +1 -0
@@ -21,5 +21,6 @@ ifeq ($(CONFIG_RTE_LIBRTE_DPAA_BUS),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA_SEC) += dpaa_sec endif DIRS-$(CONFIG_RTE_LIBRTE_PMD_CCP) += ccp +DIRS-$(CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO) += virtio include $(RTE_SDK)/mk/rte.subdir.mk
drivers/crypto/meson.build +1 -1
@@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = ['dpaa_sec', 'dpaa2_sec', - 'openssl', 'null', 'qat'] + 'openssl', 'null', 'qat', 'virtio'] std_deps = ['cryptodev'] # cryptodev pulls in all other needed deps config_flag_fmt = 'RTE_LIBRTE_@0@_PMD'
drivers/crypto/virtio/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# 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) += virtio_cryptodev.c + +# this lib depends upon: +LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool +LDLIBS += -lrte_cryptodev +LDLIBS += -lrte_pci -lrte_bus_pci + +include $(RTE_SDK)/mk/rte.lib.mk
drivers/crypto/virtio/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. + +deps += 'bus_pci' +name = 'virtio_crypto' +sources = files('virtio_cryptodev.c')
drivers/crypto/virtio/rte_pmd_virtio_crypto_version.map new file +3 -0
@@ -0,0 +1,3 @@ +DPDK_18.05 { + local: *; +};
drivers/crypto/virtio/virtio_cryptodev.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_cryptodev_pmd.h> +#include "virtio_cryptodev.h" + +uint8_t cryptodev_virtio_driver_id; + +static int +crypto_virtio_pci_probe ( + struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static int +crypto_virtio_pci_remove ( + struct rte_pci_device *pci_dev __rte_unused) +{ +return 0 ; +} + +static struct rte_pci_driver rte_virtio_crypto_driver = { + .probe = crypto_virtio_pci_probe, + .remove = crypto_virtio_pci_remove +}; + +static struct cryptodev_driver virtio_crypto_drv; + +RTE_PMD_REGISTER_PCI (CRYPTODEV_NAME_VIRTIO_PMD , rte_virtio_crypto_driver); +RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, + rte_virtio_crypto_driver.driver, + cryptodev_virtio_driver_id);
drivers/crypto/virtio/virtio_cryptodev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ + +#ifndef _VIRTIO_CRYPTODEV_H_ +#define _VIRTIO_CRYPTODEV_H_ + +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio + +#endif /* _VIRTIO_CRYPTODEV_H_ */
mk/rte.app.mk +1 -0
@@ -209,6 +209,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM) += -lIPSec_MB _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 _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
PATCH v11 2/10 crypto/virtio: support virtio device init
In reply to Jay ZhouThis patch implements the initialization of the virtio crypto device. The virtio crypto device conforms to virtio-1.0, so this patch only supports modern mode operation.
The cryptodev is created at the virtio crypto pci device probing stage. The function of virtio_crypto_pkt_tx_burst() is used to burst transfer packets and virtio_crypto_pkt_rx_burst() is used to burst receive packets.
--- drivers/crypto/virtio/Makefile | 7 + drivers/crypto/virtio/meson.build | 4 +- drivers/crypto/virtio/virtio_cryptodev.c | 245 +++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 13 + drivers/crypto/virtio/virtio_logs.h | 91 ++++++ drivers/crypto/virtio/virtio_pci.c | 462 +++++++++++++++++++++++++++++++ drivers/crypto/virtio/virtio_pci.h | 253 +++++++++++++++++ drivers/crypto/virtio/virtio_ring.h | 137 +++++++++ drivers/crypto/virtio/virtio_rxtx.c | 26 ++ drivers/crypto/virtio/virtqueue.c | 43 +++ drivers/crypto/virtio/virtqueue.h | 171 ++++++++++++ 11 files changed, 1449 insertions(+), 3 deletions(-) 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
drivers/crypto/virtio/Makefile +7 -0
@@ -8,6 +8,10 @@ include $(RTE_SDK)/mk/rte.vars.mk # LIB = librte_pmd_virtio_crypto.a +# +# include virtio_crypto.h +# +CFLAGS += -I$(RTE_SDK)/lib/librte_vhost CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS)
@@ -18,6 +22,9 @@ 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:
drivers/crypto/virtio/meson.build +3 -1
@@ -1,6 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +includes += include_directories('../../../lib/librte_vhost') deps += 'bus_pci' name = 'virtio_crypto' -sources = files('virtio_cryptodev.c') +sources = files('virtio_cryptodev.c', 'virtio_pci.c', + 'virtio_rxtx.c', 'virtqueue.c')
drivers/crypto/virtio/virtio_cryptodev.c +243 -2
273 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +13 -0
@@ -5,6 +5,19 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ +#include <rte_cryptodev.h> + +/* Features desired/implemented by this driver. */ +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); + +uint16_t virtio_crypto_pkt_rx_burst (void *tx_queue, +struct rte_crypto_op **tx_pkts, +uint16_t nb_pkts); +#endif /* _VIRTIO_CRYPTODEV_H_ */
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 +462 -0
462 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/virtio_rxtx.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. +*/ +#include "virtio_cryptodev.h" + +uint16_t +virtio_crypto_pkt_rx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_rx =0 ; + +return nb_rx; +} + +uint16_t +virtio_crypto_pkt_tx_burst ( + void *tx_queue __rte_unused, + struct rte_crypto_op **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +uint16_t nb_tx =0 ; + +return nb_tx; +}
drivers/crypto/virtio/virtqueue.c new file +43 -0
43 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v11 3/10 crypto/virtio: support basic PMD ops
In reply to Jay ZhouThis patch implements the basic operations of virtio crypto PMD, which includes start, stop, close, information getting, queue setup and release of the device.
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.
--- drivers/crypto/virtio/virtio_cryptodev.c | 437 ++++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 32 ++- drivers/crypto/virtio/virtio_rxtx.c | 68 +++++ 3 files changed, 528 insertions(+), 9 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +429 -8
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ +#include <rte_errno.h> #include <rte_pci.h> #include <rte_bus_pci.h> #include <rte_cryptodev.h>
@@ -15,6 +16,22 @@int virtio_crypto_logtype_tx;int virtio_crypto_logtype_driver; +static int virtio_crypto_dev_configure (struct rte_cryptodev *dev, +struct rte_cryptodev_config *config); +static int virtio_crypto_dev_start (struct rte_cryptodev *dev); +static void virtio_crypto_dev_stop (struct rte_cryptodev *dev); +static int virtio_crypto_dev_close (struct rte_cryptodev *dev); +static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *dev_info); +static int virtio_crypto_qp_setup (struct rte_cryptodev *dev, +uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, +struct rte_mempool *session_pool); +static int virtio_crypto_qp_release (struct rte_cryptodev *dev, +uint16_t queue_pair_id); +static void virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev); +/* * The set of PCI devices this driver supports */
@@ -26,22 +43,251 @@uint8_t cryptodev_virtio_driver_id; +void +virtio_crypto_queue_release (struct virtqueue *vq) +{ +struct virtio_crypto_hw *hw; + +PMD_INIT_FUNC_TRACE (); + +if (vq) { + hw = vq->hw; +/* Select and deactivate the queue */ +VTPCI_OPS (hw)->del_queue (hw, vq); + +rte_memzone_free (vq->mz); +rte_mempool_free (vq->mpool); +rte_free (vq); + } +} + +#define MPOOL_MAX_NAME_SZ 32 + +int +virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq) +{ +char vq_name[VIRTQUEUE_MAX_NAME_SZ ]; +char mpool_name[MPOOL_MAX_NAME_SZ ]; +const struct rte_memzone *mz; +unsigned int vq_size, size; +struct virtio_crypto_hw *hw = dev->data->dev_private; +struct virtqueue *vq =NULL ; +uint32_t i =0 ; +uint32_t j; + +PMD_INIT_FUNC_TRACE (); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("setting up queue: %u" , vtpci_queue_idx); + +/* +* Read the virtqueue size from the Queue Size field +* Always power of 2 and if 0 virtqueue does not exist +*/ + vq_size =VTPCI_OPS (hw)->get_queue_num (hw, vtpci_queue_idx); +if (vq_size ==0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue does not exist" ); +return -EINVAL ; + } +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq_size: %u" , vq_size); + +if (!rte_is_power_of_2 (vq_size)) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("virtqueue size is not powerof 2" ); +return -EINVAL ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_dataqueue%d" , + dev->data->dev_id, vtpci_queue_idx); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_dataqueue%d_mpool" , + dev->data->dev_id, vtpci_queue_idx); + }else if (queue_type ==VTCRYPTO_CTRLQ ) { +snprintf (vq_name,sizeof (vq_name),"dev%d_controlqueue" , + dev->data->dev_id); +snprintf (mpool_name,sizeof (mpool_name), +"dev%d_controlqueue_mpool" , + dev->data->dev_id); + } + size =RTE_ALIGN_CEIL (sizeof (*vq) + + vq_size *sizeof (struct vq_desc_extra ), +RTE_CACHE_LINE_SIZE ); + vq =rte_zmalloc_socket (vq_name, size,RTE_CACHE_LINE_SIZE , + socket_id); +if (vq ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("Can not allocate virtqueue" ); +return -ENOMEM ; + } + +if (queue_type ==VTCRYPTO_DATAQ ) { +/* pre-allocate a mempool and use it in the data plane to +* improve performance +*/ + vq->mpool =rte_mempool_lookup (mpool_name); +if (vq->mpool ==NULL ) + vq->mpool =rte_mempool_create (mpool_name, + vq_size, +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ,0 , +NULL ,NULL ,NULL ,NULL , socket_id, +0 ); +if (!vq->mpool) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Virtio Crypto PMD " +"Cannot create mempool" ); + goto mpool_create_err; + } +for (i =0 ; i < vq_size; i++) { + vq->vq_descx[i].cookie = +rte_zmalloc ("crypto PMD op cookie pointer" , +sizeof (struct virtio_crypto_op_cookie ), +RTE_CACHE_LINE_SIZE ); +if (vq->vq_descx[i].cookie ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("Failed to " +"alloc mem for cookie" ); + goto cookie_alloc_err; + } + } + } + + vq->hw = hw; + vq->dev_id = dev->data->dev_id; + vq->vq_queue_index = vtpci_queue_idx; + vq->vq_nentries = vq_size; + +/* +* Using part of the vring entries is permitted, but the maximum +* is vq_size +*/ +if (nb_desc ==0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; + +/* +* Reserve a memzone for vring elements +*/ + size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN ); +VIRTIO_CRYPTO_INIT_LOG_DBG ("%s vring_size: %d, rounded_vring_size: %d" , + (queue_type ==VTCRYPTO_DATAQ ) ?"dataq" :"ctrlq" , + size, vq->vq_ring_size); + + mz =rte_memzone_reserve_aligned (vq_name, vq->vq_ring_size, + socket_id,0 ,VIRTIO_PCI_VRING_ALIGN ); +if (mz ==NULL ) { +if (rte_errno ==EEXIST ) + mz =rte_memzone_lookup (vq_name); +if (mz ==NULL ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("not enough memory" ); + goto mz_reserve_err; + } + } + +/* +* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, +* and only accepts 32 bit page frame number. +* Check if the allocated physical memory exceeds 16TB. +*/ +if ((mz->phys_addr + vq->vq_ring_size -1 ) + >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT +32 )) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("vring address shouldn't be " +"above 16TB!" ); + goto vring_addr_err; + } + +memset (mz->addr,0 ,sizeof (mz->len)); + vq->mz = mz; + vq->vq_ring_mem = mz->phys_addr; + vq->vq_ring_virt_mem = mz->addr; +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_mem(physical): 0x%" PRIx64, + (uint64_t )mz->phys_addr); +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_ring_virt_mem: 0x%" PRIx64, + (uint64_t )(uintptr_t )mz->addr); + + *pvq = vq; + +return 0 ; + +vring_addr_err: +rte_memzone_free (mz); +mz_reserve_err: +cookie_alloc_err: +rte_mempool_free (vq->mpool); +if (i !=0 ) { +for (j =0 ; j < i; j++) +rte_free (vq->vq_descx[j].cookie); + } +mpool_create_err: +rte_free (vq); +return -ENOMEM ; +} + +static int +virtio_crypto_ctrlq_setup (struct rte_cryptodev *dev,uint16_t queue_idx) +{ +int ret; +struct virtqueue *vq; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +/* if virtio device has started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + +PMD_INIT_FUNC_TRACE (); + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_CTRLQ , queue_idx, +0 ,SOCKET_ID_ANY , &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control vq initialization failed" ); +return ret; + } + + hw->cvq = vq; + +return 0 ; +} + +static void +virtio_crypto_free_queues (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +/* control queue release */ +virtio_crypto_queue_release (hw->cvq); + +/* data queue release */ +for (i =0 ; i < hw->max_dataqueues; i++) +virtio_crypto_queue_release (dev->data->queue_pairs[i]); +} + +static int +virtio_crypto_dev_close(struct rte_cryptodev *dev __rte_unused) +{ +return 0 ; +} +/* * dev_ops for virtio, bare necessities for basic operation */ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {/* Device related operations */ - .dev_configure =NULL , - .dev_start =NULL , - .dev_stop =NULL , - .dev_close =NULL , - .dev_infos_get =NULL , + .dev_configure = virtio_crypto_dev_configure, + .dev_start = virtio_crypto_dev_start, + .dev_stop = virtio_crypto_dev_stop, + .dev_close = virtio_crypto_dev_close, + .dev_infos_get = virtio_crypto_dev_info_get, .stats_get =NULL , .stats_reset =NULL , - .queue_pair_setup =NULL , - .queue_pair_release =NULL , + .queue_pair_setup = virtio_crypto_qp_setup, + .queue_pair_release = virtio_crypto_qp_release, .queue_pair_start =NULL , .queue_pair_stop =NULL , .queue_pair_count =NULL ,
@@ -55,6 +301,51 @@ };static int +virtio_crypto_qp_setup (struct rte_cryptodev *dev,uint16_t queue_pair_id, +const struct rte_cryptodev_qp_conf *qp_conf, +int socket_id, + struct rte_mempool *session_pool __rte_unused) +{ +int ret; +struct virtqueue *vq; + +PMD_INIT_FUNC_TRACE (); + +/* if virtio dev is started, do not touch the virtqueues */ +if (dev->data->dev_started) +return 0 ; + + ret =virtio_crypto_queue_setup (dev,VTCRYPTO_DATAQ , queue_pair_id, + qp_conf->nb_descriptors, socket_id, &vq); +if (ret <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ( +"virtio crypto data queue initialization failed\n" ); +return ret; + } + + dev->data->queue_pairs[queue_pair_id] = vq; + +return 0 ; +} + +static int +virtio_crypto_qp_release (struct rte_cryptodev *dev,uint16_t queue_pair_id) +{ +struct virtqueue *vq + = (struct virtqueue *)dev->data->queue_pairs[queue_pair_id]; + +PMD_INIT_FUNC_TRACE (); + +if (vq ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_DBG ("vq already freed" ); +return 0 ; + } + +virtio_crypto_queue_release (vq); +return 0 ; +} + +static int virtio_negotiate_features (struct virtio_crypto_hw *hw,uint64_t req_features) {uint64_t host_features;
@@ -192,6 +483,136 @@ }static int +virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return -EPERM ; + +if (cryptodev->data->dev_started) { +virtio_crypto_dev_stop (cryptodev); +virtio_crypto_dev_close (cryptodev); + } + + cryptodev->dev_ops =NULL ; + cryptodev->enqueue_burst =NULL ; + cryptodev->dequeue_burst =NULL ; + +/* release control queue */ +virtio_crypto_queue_release (hw->cvq); + +rte_free (cryptodev->data); + cryptodev->data =NULL ; + +VIRTIO_CRYPTO_DRV_LOG_INFO ("dev_uninit completed" ); + +return 0 ; +} + +static int +virtio_crypto_dev_configure (struct rte_cryptodev *cryptodev, + struct rte_cryptodev_config *config __rte_unused) +{ +struct virtio_crypto_hw *hw = cryptodev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (virtio_crypto_init_device (cryptodev, +VIRTIO_CRYPTO_PMD_GUEST_FEATURES ) <0 ) +return -1 ; + +/* setup control queue +* [0, 1, ... ,(config->max_dataqueues - 1)] are data queues +* config->max_dataqueues is the control queue +*/ +if (virtio_crypto_ctrlq_setup (cryptodev, hw->max_dataqueues) <0 ) { +VIRTIO_CRYPTO_INIT_LOG_ERR ("control queue setup error" ); +return -1 ; + } +virtio_crypto_ctrlq_start (cryptodev); + +return 0 ; +} + +static void +virtio_crypto_dev_stop (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); +VIRTIO_CRYPTO_DRV_LOG_DBG ("virtio_dev_stop" ); + +vtpci_cryptodev_reset (hw); + +virtio_crypto_dev_free_mbufs (dev); +virtio_crypto_free_queues (dev); + + dev->data->dev_started =0 ; +} + +static int +virtio_crypto_dev_start (struct rte_cryptodev *dev) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +if (dev->data->dev_started) +return 0 ; + +/* Do final configuration before queue engine starts */ +virtio_crypto_dataq_start (dev); +vtpci_cryptodev_reinit_complete (hw); + + dev->data->dev_started =1 ; + +return 0 ; +} + +static void +virtio_crypto_dev_free_mbufs (struct rte_cryptodev *dev) +{ +uint32_t i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +for (i =0 ; i < hw->max_dataqueues; i++) { +VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " +"and unused buf" , i); +VIRTQUEUE_DUMP ((struct virtqueue *) + dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("queue_pairs[%d]=%p" , + i, dev->data->queue_pairs[i]); + +virtqueue_detatch_unused (dev->data->queue_pairs[i]); + +VIRTIO_CRYPTO_INIT_LOG_DBG ("After freeing dataq[%d] used and " +"unused buf" , i); +VIRTQUEUE_DUMP ( + (struct virtqueue *)dev->data->queue_pairs[i]); + } +} + +static void +virtio_crypto_dev_info_get (struct rte_cryptodev *dev, +struct rte_cryptodev_info *info) +{ +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (info !=NULL ) { + info->driver_id = cryptodev_virtio_driver_id; + info->pci_dev =RTE_DEV_TO_PCI (dev->device); + info->feature_flags = dev->feature_flags; + info->max_nb_queue_pairs = hw->max_dataqueues; + info->sym.max_nb_sessions = +RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + } +} + +static int crypto_virtio_pci_probe ( struct rte_pci_driver *pci_drv __rte_unused,struct rte_pci_device *pci_dev)
@@ -231,7 +652,7 @@if (cryptodev ==NULL )return -ENODEV ; -return 0 ; +return virtio_crypto_dev_uninit (cryptodev); }static struct rte_pci_driver rte_virtio_crypto_driver = {
drivers/crypto/virtio/virtio_cryptodev.h +31 -1
@@ -5,13 +5,43 @@#ifndef _VIRTIO_CRYPTODEV_H_#define _VIRTIO_CRYPTODEV_H_ -#include <rte_cryptodev.h> +#include "virtio_crypto.h" + +#include "virtio_pci.h" +#include "virtio_ring.h" /* Features desired/implemented by this driver. */ #define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 + +struct virtio_crypto_op_cookie { +struct virtio_crypto_op_data_req data_req; +struct virtio_crypto_inhdr inhdr; +struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ]; +}; + +/* +* Control queue function prototype +*/ +void virtio_crypto_ctrlq_start (struct rte_cryptodev *dev); + +/* +* Data queue function prototype +*/ +void virtio_crypto_dataq_start (struct rte_cryptodev *dev); + +int virtio_crypto_queue_setup (struct rte_cryptodev *dev, +int queue_type, +uint16_t vtpci_queue_idx, +uint16_t nb_desc, +int socket_id, +struct virtqueue **pvq); + +void virtio_crypto_queue_release (struct virtqueue *vq); +uint16_t virtio_crypto_pkt_tx_burst (void *tx_queue,struct rte_crypto_op **tx_pkts,uint16_t nb_pkts);
drivers/crypto/virtio/virtio_rxtx.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v11 4/10 crypto/virtio: support session related ops
In reply to Jay ZhouThis patch implements session related operations, which includes creating and destroying the session. For now, it only supports the session-oriented API implementation. The control queue used to create or destroy sessions for symmetric algorithms.
--- drivers/crypto/virtio/virtio_crypto_algs.h | 28 ++ drivers/crypto/virtio/virtio_cryptodev.c | 737 ++++++++++++++++++++++++++++- drivers/crypto/virtio/virtio_cryptodev.h | 7 + 3 files changed, 769 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_crypto_algs.h
drivers/crypto/virtio/virtio_crypto_algs.h new file +28 -0
@@ -0,0 +1,28 @@ +/* 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 "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_ */
drivers/crypto/virtio/virtio_cryptodev.c +734 -3
775 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +7 -0
@@ -17,6 +17,13 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +enum virtio_crypto_cmd_id { +VIRTIO_CRYPTO_CMD_CIPHER =0 , +VIRTIO_CRYPTO_CMD_AUTH =1 , +VIRTIO_CRYPTO_CMD_CIPHER_HASH =2 , +VIRTIO_CRYPTO_CMD_HASH_CIPHER =3 +}; +struct virtio_crypto_op_cookie {struct virtio_crypto_op_data_req data_req;struct virtio_crypto_inhdr inhdr;
Signature · 1 line
1.8.3.1
PATCH v11 5/10 crypto/virtio: support crypto enqueue/dequeue burst API
In reply to Jay ZhouThis patch implements the functions of virtio_crypto_pkt_tx_burst() and virtio_crypto_pkt_rx_burst(). The encryption and decryption requests are placed in the data queue and are ultimately handled by the backend crypto accelerators.
--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 441 ++++++++++++++++++++++++++++++- 2 files changed, 433 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -17,6 +17,8 @@#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +extern uint8_t cryptodev_virtio_driver_id; +enum virtio_crypto_cmd_id {VIRTIO_CRYPTO_CMD_CIPHER =0 ,VIRTIO_CRYPTO_CMD_AUTH =1 ,
drivers/crypto/virtio/virtio_rxtx.c +431 -10
463 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v11 6/10 crypto/virtio: support stats related ops
In reply to Jay ZhouThis patch implements the statistics of the packets.
--- drivers/crypto/virtio/virtio_cryptodev.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +64 -2
@@ -29,6 +29,9 @@ static int virtio_crypto_dev_configure(struct rte_cryptodev *dev,static int virtio_crypto_dev_close (struct rte_cryptodev *dev);static void virtio_crypto_dev_info_get (struct rte_cryptodev *dev,struct rte_cryptodev_info *dev_info); +static void virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats); +static void virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev); static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
@@ -501,8 +504,8 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .dev_close = virtio_crypto_dev_close, .dev_infos_get = virtio_crypto_dev_info_get, - .stats_get = NULL, - .stats_reset = NULL, + .stats_get = virtio_crypto_dev_stats_get, + .stats_reset = virtio_crypto_dev_stats_reset, .queue_pair_setup = virtio_crypto_qp_setup, .queue_pair_release = virtio_crypto_qp_release,
@@ -518,6 +521,65 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, .qp_detach_session = NULL }; +static void +virtio_crypto_update_stats (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +if (stats ==NULL ) { +VIRTIO_CRYPTO_DRV_LOG_ERR ("invalid pointer" ); +return ; + } + +for (i =0 ; i < hw->max_dataqueues; i++) { +const struct virtqueue *data_queue + = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + stats->enqueued_count += data_queue->packets_sent_total; + stats->enqueue_err_count += data_queue->packets_sent_failed; + + stats->dequeued_count += data_queue->packets_received_total; + stats->dequeue_err_count + += data_queue->packets_received_failed; + } +} + +static void +virtio_crypto_dev_stats_get (struct rte_cryptodev *dev, +struct rte_cryptodev_stats *stats) +{ +PMD_INIT_FUNC_TRACE (); + +virtio_crypto_update_stats (dev, stats); +} + +static void +virtio_crypto_dev_stats_reset (struct rte_cryptodev *dev) +{ +unsigned int i; +struct virtio_crypto_hw *hw = dev->data->dev_private; + +PMD_INIT_FUNC_TRACE (); + +for (i =0 ; i < hw->max_dataqueues; i++) { +struct virtqueue *data_queue = dev->data->queue_pairs[i]; +if (data_queue ==NULL ) +continue ; + + data_queue->packets_sent_total =0 ; + data_queue->packets_sent_failed =0 ; + + data_queue->packets_received_total =0 ; + data_queue->packets_received_failed =0 ; + } +} + static int virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf,
Signature · 1 line
1.8.3.1
PATCH v11 7/10 crypto/virtio: support AES-CBC
In reply to Jay ZhouThe AES-CBC cipher only algorithm has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 30 ++++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 11 ++++++++ 2 files changed, 41 insertions(+) create mode 100644 drivers/crypto/virtio/virtio_crypto_capabilities.h
drivers/crypto/virtio/virtio_crypto_capabilities.h new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 \ + { /* 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 +11 -0
@@ -15,6 +15,7 @@#include "virtio_cryptodev.h" #include "virtqueue.h" #include "virtio_crypto_algs.h" +#include "virtio_crypto_capabilities.h" int virtio_crypto_logtype_init;int virtio_crypto_logtype_session;
@@ -58,6 +59,11 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, { .vendor_id = 0, /* sentinel */ }, }; +static const struct rte_cryptodev_capabilities virtio_capabilities[] = { +VIRTIO_SYM_CAPABILITIES , +RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST () +}; +uint8_t cryptodev_virtio_driver_id;#define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -746,6 +752,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, hw = cryptodev->data->dev_private; hw->dev_id = cryptodev->data->dev_id; + hw->virtio_dev_capabilities = virtio_capabilities; VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x", cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1139,6 +1146,9 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_cipher_xform *cipher_xform) {switch (cipher_xform->algo) { +case RTE_CRYPTO_CIPHER_AES_CBC : + para->algo =VIRTIO_CRYPTO_CIPHER_AES_CBC ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Unsupported " "Cipher alg %u" , cipher_xform->algo);
@@ -1402,6 +1412,7 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, info->max_nb_queue_pairs = hw->max_dataqueues; info->sym.max_nb_sessions =RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS ; + info->capabilities = hw->virtio_dev_capabilities; } }
Signature · 1 line
1.8.3.1
PATCH v11 8/10 crypto/virtio: support HMAC-SHA1
In reply to Jay ZhouThe AES-CBC with HMAC-SHA1 has been supported now.
--- drivers/crypto/virtio/virtio_crypto_capabilities.h | 21 +++++++++++++++++++++ drivers/crypto/virtio/virtio_cryptodev.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +21 -0
@@ -6,6 +6,27 @@#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 = { \
drivers/crypto/virtio/virtio_cryptodev.c +3 -1
@@ -1196,11 +1196,13 @@ static int virtio_crypto_sym_configure_session(struct rte_cryptodev *dev, }switch (auth_xform->algo) { +case RTE_CRYPTO_AUTH_SHA1_HMAC : + *algo =VIRTIO_CRYPTO_MAC_HMAC_SHA1 ; +break ;default :VIRTIO_CRYPTO_SESSION_LOG_ERR ("Crypto: Undefined Hash algo %u specified" , auth_xform->algo); - *algo =VIRTIO_CRYPTO_NO_MAC ;return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v11 9/10 test/crypto: add function tests for virtio crypto PMD
In reply to Jay ZhouOnly 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 | 48 +++++++++++++++++++++++++++++ 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, 74 insertions(+), 9 deletions(-)
test/test/test_cryptodev.c +48 -0
@@ -1820,6 +1820,25 @@ 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;
@@ -8879,6 +8898,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,
@@ -9808,6 +9839,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(
@@ -10040,3 +10087,4 @@ struct test_crypto_vector {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_ccp_autotest, test_cryptodev_ccp); +REGISTER_TEST_COMMAND (cryptodev_virtio_autotest, test_cryptodev_virtio);
test/test/test_cryptodev.h +1 -0
@@ -63,6 +63,7 @@#define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler#define CRYPTODEV_NAME_MRVL_PMD crypto_mrvl#define CRYPTODEV_NAME_CCP_PMD crypto_ccp +#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
@@ -1544,7 +1544,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |BLOCKCIPHER_TEST_TARGET_PMD_MRVL | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@BLOCKCIPHER_TEST_TARGET_PMD_QAT |BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC | -BLOCKCIPHER_TEST_TARGET_PMD_CCP +BLOCKCIPHER_TEST_TARGET_PMD_CCP | +BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO }, { .test_descr = "AES-128-CTR Encryption",
test/test/test_cryptodev_blockcipher.c +8 -1
@@ -70,6 +70,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 ;
@@ -97,7 +99,8 @@ driver_id == openssl_pmd || driver_id == armv8_pmd || driver_id == mrvl_pmd || - driver_id == ccp_pmd) { /* Fall through */ + driver_id == ccp_pmd || + driver_id == virtio_pmd) { /* Fall through */ digest_len = tdata->digest.len; } else if (driver_id == aesni_mb_pmd || driver_id == scheduler_pmd) {
@@ -574,6 +577,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 :
@@ -638,6 +643,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
@@ -28,6 +28,7 @@#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_CCP 0x0040/* CCP flag */ +#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO 0x0200/* VIRTIO flag */ #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ BLOCKCIPHER_TEST_OP_DECRYPT)
Signature · 1 line
1.8.3.1
PATCH v11 10/10 doc: add virtio crypto PMD guide
In reply to Jay ZhouThis patch adds the guide for virtio crypto PMD.
--- MAINTAINERS | 2 + 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 | 5 +- 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/guides/cryptodevs/features/virtio.ini create mode 100644 doc/guides/cryptodevs/virtio.rst
MAINTAINERS +2 -0
@@ -775,6 +775,8 @@ 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]>
doc/guides/cryptodevs/features/virtio.ini new file +26 -0
@@ -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
@@ -23,4 +23,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
doc/guides/rel_notes/release_18_05.rst +4 -1
@@ -129,7 +129,10 @@ New Features * **Added the virtio crypto PMD.** - Added a new poll mode driver for virtio crypto devices. + Added a new poll mode driver for virtio crypto devices, which provides + AES-CBC ciphering and AES-CBC with HMAC-SHA1 algorithm-chaining. See the + :doc:`../cryptodevs/virtio` crypto driver guide for more details on + this new driver. API Changes
Signature · 1 line
1.8.3.1
Quoted 13 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 10:23 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v11 00/10] crypto: add virtio poll mode driver
Quoted 1 line
This patch series introduce virtio crypto poll mode driver.
Series applied to dpdk-next-crypto.
Thanks for the work!
Pablo
Quoted 25 lines
-----Original Message-----
From: De Lara Guarch, Pablo [mailto:[email protected]]
Sent: Wednesday, April 18, 2018 6:01 PM
To: Zhoujian (jay) <[email protected]>; [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; Gonglei (Arei) <[email protected]>; Zeng, Xin <[email protected]>; Huangweidong (C) <[email protected]>; wangxin (U) <[email protected]>; longpeng <[email protected]>
Subject: RE: [PATCH v11 00/10] crypto: add virtio poll mode driverQuoted 11 lines
-----Original Message-----
From: Jay Zhou [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 10:23 AM
To: [email protected]
Cc: De Lara Guarch, Pablo <[email protected]>; Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Zeng, Xin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v11 00/10] crypto: add virtio poll mode driver
Quoted 6 lines
Quoted 1 line
This patch series introduce virtio crypto poll mode driver.
Series applied to dpdk-next-crypto.
Thanks for the work!
Pablo
Thank for your help and review, Pablo!
Regards,
Jay