lib/librte_vhost: introduce new vhost_user crypto backend support
cover lib/librte_vhost: introduce new vhost_user crypto backend support
This RFC patchset adds crypto backend suppport to vhost_user library, including a proof-of-concept sample application. The implementation follows the virtio-crypto specification and have been tested with qemu 2.9.50 (with several patches applied, detailed later) with Fedora 24 running in the frontend.
The vhost_user library acts as a "bridge" method that translate the virtio-crypto crypto requests to DPDK crypto operations, so it is purely software implementation. However it does require the user to provide the DPDK Cryptodev ID so it knows how to handle the virtio-crypto session creation and deletion mesages.
Currently the implementation supports AES-CBC-128 and HMAC-SHA1 cipher only/chaining modes and does not support sessionless mode yet. The guest can use standard virtio-crypto driver to set up session and sends encryption/decryption requests to backend. The vhost-crypto sample application provided in this patchset will do the actual crypto work.
To make this patchset working, a few tweaks need to be done:
In the host:
1. Download the qemu source code, and apply the patches in:
list.nongnu.org/archive/html/qemu-devel/2017-07/msg04664.html. As the patches have been out for over 2 months, they cannot be cleanly applied to the latest code. I have reverted the commits back to 4c4414a to make the patches applied cleanly.
2. Recompile your qemu.
3. Apply this patchset to latest DPDK code and recompile DPDK.
4. Compile and run vhost-crypto sample application.
./examples/vhost_crypto/build/vhost-crypto -l 11,12,13 -w 0000:86:01.0 \
--socket-mem 2048,2048
Where 0000:86:01.0 is the QAT PCI address. You may use AES-NI-MB if it is not available. The sample application requires 3 lcores: 1 master, 1 worker, and 1 statistics displaying worker. The application will create a UNIX socket file /tmp/vhost_crypto1.socket.
5. Start your qemu application. Here is my command:
qemu/x86_64-softmmu/qemu-system-x86_64 -machine accel=kvm -cpu host \
-smp 2 -m 1G -hda ~/path-to-your/image.qcow \
-object memory-backend-file,id=mem,size=1G,mem-path=/dev/hugepages,share=on \
-mem-prealloc -numa node,memdev=mem -chardev \
socket,id=charcrypto0,path=/tmp/vhost_crypto1.socket \
-object cryptodev-vhost-user,id=cryptodev0,chardev=charcrypto0 \
-device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0
6. Once guest is booted. The Linux virtio_crypto kernel module is loaded by default. You shall see the following logs in your demsg:
[ 17.611044] virtio_crypto: loading out-of-tree module taints kernel. [ 17.611083] virtio_crypto: module verification failed: signature and/or ... [ 17.611723] virtio_crypto virtio0: max_queues: 1, max_cipher_key_len: ... [ 17.612156] virtio_crypto virtio0: will run requests pump with realtime ... [ 18.376100] virtio_crypto virtio0: Accelerator is ready
The virtio_crypto driver in the guest is now up and running.
7. The rest steps can be as same as the Testing section in
https://wiki.qemu.org/Features/VirtioCrypto
Fan Zhang (6):
lib/librte_vhost: add vhost_user private info structure lib/librte_vhost: add virtio-crypto spec support lib/librte_vhost: add vhost_user backend support config/common_base: add vhost_crypto configuration items lib/librte_vhost: update Makefile for vhost_crypto example/vhost_crypto: add vhost_crypto sample application
config/common_base | 1 + examples/vhost_crypto/Makefile | 59 ++ examples/vhost_crypto/main.c | 617 +++++++++++++++++ lib/librte_vhost/Makefile | 5 +- lib/librte_vhost/rte_vhost_crypto.h | 150 +++++ lib/librte_vhost/vhost_crypto.c | 1254 +++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.c | 13 +- lib/librte_vhost/vhost_user.h | 34 +- 8 files changed, 2128 insertions(+), 5 deletions(-) create mode 100644 examples/vhost_crypto/Makefile create mode 100644 examples/vhost_crypto/main.c create mode 100644 lib/librte_vhost/rte_vhost_crypto.h create mode 100644 lib/librte_vhost/vhost_crypto.c
Signature · 1 line
2.9.5
RFC PATCH 1/6 lib/librte_vhost: add vhost_user private info structure
This patch adds a vhost_user_dev_priv structure and a vhost_user message handler function prototype to vhost_user. This allows different types of devices to add private information and their device-specific vhost-user message function handlers to virtio_net structure. The change to vhost_user_msg_handler is also added to call the device-specific message handler.
--- lib/librte_vhost/vhost_user.c | 13 ++++++++++++- lib/librte_vhost/vhost_user.h | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost_user.c +12 -1
@@ -1324,7 +1324,18 @@ vhost_user_msg_handler(int vid, int fd)break ;default : - ret =-1 ; +if (!dev->private_data) + ret =-1 ; +else { +struct vhost_user_dev_priv *priv = dev->private_data; + +if (!priv->vhost_user_msg_handler) + ret =-1 ; +else { + ret = (*priv->vhost_user_msg_handler)(dev, + &msg, fd); + } + }break ; }
lib/librte_vhost/vhost_user.h +7 -0
@@ -137,6 +137,13 @@ typedef struct VhostUserMsg {/* The version of the protocol we support */ #define VHOST_USER_VERSION 0x1 +typedef int (*msg_handler )(struct virtio_net *dev,struct VhostUserMsg *msg, +int fd); + +struct vhost_user_dev_priv { +msg_handler vhost_user_msg_handler; +char data[0 ]; +};/* vhost_user.c */ int vhost_user_msg_handler (int vid,int fd);
Signature · 1 line
2.9.5
RFC PATCH 2/6 lib/librte_vhost: add virtio-crypto spec support
In reply to Fan ZhangThis patch adds virtio-crypto support to vhost_user.
--- lib/librte_vhost/vhost_user.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost_user.h +26 -1
@@ -81,7 +81,7 @@ typedef enum VhostUserRequest {VHOST_USER_NET_SET_MTU =20 ,VHOST_USER_SET_SLAVE_REQ_FD =21 ,VHOST_USER_IOTLB_MSG =22 , - VHOST_USER_MAX + VHOST_USER_MAX = 25 } VhostUserRequest; typedef enum VhostUserSlaveRequest {
@@ -108,6 +108,30 @@ typedef struct VhostUserLog {uint64_t mmap_offset; } VhostUserLog; +/* Comply with Cryptodev-Linux */ +#define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512 +#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 + +/* Same structure as vhost-user backend session info */ +typedef struct VhostUserCryptoSessionParam { +int64_t session_id; +uint32_t op_code; +uint32_t cipher_algo; +uint32_t cipher_key_len; +uint32_t hash_algo; +uint32_t digest_len; +uint32_t auth_key_len; +uint32_t aad_len; +uint8_t op_type; +uint8_t dir; +uint8_t hash_mode; +uint8_t chaining_dir; +uint8_t *ciphe_key; +uint8_t *auth_key; +uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ]; +uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +}VhostUserCryptoSessionParam ; + typedef struct VhostUserMsg { union { VhostUserRequest master;
@@ -128,6 +152,7 @@ typedef struct VhostUserMsg {VhostUserMemory memory;VhostUserLog log;struct vhost_iotlb_msg iotlb; +VhostUserCryptoSessionParam crypto_session; } payload;int fds[VHOST_MEMORY_MAX_NREGIONS ]; } __attribute((packed)) VhostUserMsg;
Signature · 1 line
2.9.5
RFC PATCH 3/6 lib/librte_vhost: add vhost_user backend support
In reply to Fan ZhangThis patch adds vhost_crypto device driver support to vhost_user. Several new APIs are introduced for user to create and delete vhost_crypto devices, fetch virtio queue descriptors and translate to DPDK crypto operations for enqueuing to target cryptodev in the backend. After dequeuing from the cryptodev, an API is introduced to finalizing the crypto operations back to the frontend.
--- lib/librte_vhost/rte_vhost_crypto.h | 150 +++++ lib/librte_vhost/vhost_crypto.c | 1254 +++++++++++++++++++++++++++++++++++ 2 files changed, 1404 insertions(+) create mode 100644 lib/librte_vhost/rte_vhost_crypto.h create mode 100644 lib/librte_vhost/vhost_crypto.c
lib/librte_vhost/rte_vhost_crypto.h new file +150 -0
@@ -0,0 +1,150 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2017 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _VHOST_CRYPTO_H_ +#define _VHOST_CRYPTO_H_ + +#include <linux/virtio_crypto.h> +#include <rte_cryptodev.h> +#include <rte_hash.h> +#include <rte_pause.h> +#include "rte_vhost.h" + +#ifndef MAX_DATA_QUEUES +#define MAX_DATA_QUEUES (1) +#endif + +#define VIRTIO_CRYPTO_CTRL_QUEUE (0) +#define VIRTIO_CRYPTO_MAX_NUM_DEVS (64) + +/** Feature bits */ +#define VIRTIO_CRYPTO_F_CIPHER_SESSION_MODE (1) +#define VIRTIO_CRYPTO_F_HASH_SESSION_MODE (2) +#define VIRTIO_CRYPTO_F_MAC_SESSION_MODE (3) +#define VIRTIO_CRYPTO_F_AEAD_SESSION_MODE (4) + +/** +* Create Vhost-crypto instance +* +* @param vid +* The identifier of the vhost device. +* @param cryptodev_id +* The identifier of DPDK Cryptodev, the same cryptodev_id can be assigned to +* multiple Vhost-crypto devices. +* @param sess_pool +* The pointer to the created cryptodev session pool with the private data size +* matches the target DPDK Cryptodev. +* @param socket_id +* NUMA Socket ID to allocate resources on. * +* @return +* 0 if the Vhost Crypto Instance is created successfully. +* Negative integer if otherwise +*/ +int +rte_vhost_crypto_create (int vid,uint8_t cryptodev_id, +struct rte_mempool *sess_pool,int socket_id); + +/** +* Free the Vhost-crypto instance +* +* @param vid +* The identifier of the vhost device. +* @return +* 0 if the Vhost Crypto Instance is created successfully. +* Negative integer if otherwise +*/ +int +rte_vhost_crypto_free (int vid); + +/** +* Creates a crypto operation pool +* +* @param name +* pool name +* @param type +* crypto operation type, use RTE_CRYPTO_OP_TYPE_UNDEFINED for a pool which +* supports all operation types +* @param nb_elts +* number of elements in pool +* @param cache_size +* Number of elements to cache on lcore, see *rte_mempool_create* for further +* details about cache size +* @param socket_id +* Socket to allocate memory on +* @return +* On success pointer to mempool +* On failure NULL +*/ +struct rte_mempool * +rte_vhost_crypto_create_cop_pool (const char *name,enum rte_crypto_op_type type, +unsigned nb_elts,unsigned cache_size,int socket_id); + +/** +* Fetch a number of vring descriptors from virt-queue and translate to DPDK +* crypto operations. After this function is executed, the user can enqueue +* the processed ops to the target cryptodev. +* +* @param vid +* The identifier of the vhost device. +* @param qid +* Virtio queue index. +* @param ops +* The address of an array of pointers to *rte_crypto_op* structures that must +* be large enough to store *nb_ops* pointers in it. +* @param nb_ops +* The maximum number of operations to be fetched and translated. +* @return +* The number of fetched and processed vhost crypto request operations. +*/ +uint16_t +rte_vhost_crypto_fetch_requests (int vid,uint32_t qid, +struct rte_crypto_op **ops,uint16_t nb_ops); +/** +* Finalize the dequeued crypto ops. After the translated crypto ops are +* dequeued from the cryptodev, this function shall be called to write the +* processed data back to the vring descriptor (if no-copy is turned off) and +* obtain the bit mask of the vhost devices contained in the crypto ops. +* +* @param ops +* The address of an array of *rte_crypto_op* structure that was dequeued +* from cryptodev. +* @param nb_ops +* The number of operations contained in the array. +* @return +* The bit-mask of the vhost devices contained in the ops. +*/ +uint64_t +rte_vhost_crypto_finalize_requests (struct rte_crypto_op **ops, +uint16_t nb_ops); + +#endif /**< _VHOST_CRYPTO_H_ */
lib/librte_vhost/vhost_crypto.c new file +1254 -0
1,254 lines not on this page · raw message
Signature · 1 line
2.9.5
RFC PATCH 4/6 config/common_base: add vhost_crypto configuration items
In reply to Fan ZhangThis patch adds the vhost_crypto related compile configuration items to config/common_base. A new item "CONFIG_RTE_LIBRTE_VHOST_CRYPTO_DATA_QUEUE_NO_COPY" is introduced to turn on/off data queue no copy feature to vhost_crypto. This feature is in experimental level so no gurantee it would work, especially when kernel crypto framework and virtio-crypto driver are used in the frontend.
--- config/common_base | 1 + 1 file changed, 1 insertion(+)
config/common_base +1 -0
@@ -764,6 +764,7 @@ CONFIG_RTE_LIBRTE_PDUMP=y # Compile vhost user library # CONFIG_RTE_LIBRTE_VHOST=n +CONFIG_RTE_LIBRTE_VHOST_CRYPTO_DATA_QUEUE_NO_COPY=n CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n
Signature · 1 line
2.9.5
RFC PATCH 5/6 lib/librte_vhost: update Makefile for vhost_crypto
In reply to Fan Zhang--- lib/librte_vhost/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
lib/librte_vhost/Makefile +2 -3
@@ -48,9 +48,8 @@ endif # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ - vhost_user.c virtio_net.c + vhost_user.c virtio_net.c vhost_crypto.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h - +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vhost_crypto.h include $(RTE_SDK)/mk/rte.lib.mk
Signature · 1 line
2.9.5
RFC PATCH 6/6 example/vhost_crypto: add vhost_crypto sample application
In reply to Fan ZhangThis patch adds vhost_crypto sample application to DPDK.
--- examples/vhost_crypto/Makefile | 59 ++++ examples/vhost_crypto/main.c | 617 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 676 insertions(+) create mode 100644 examples/vhost_crypto/Makefile create mode 100644 examples/vhost_crypto/main.c
examples/vhost_crypto/Makefile new file +59 -0
@@ -0,0 +1,59 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2017 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +ifneq ($(CONFIG_RTE_EXEC_ENV),"linuxapp") +$(info This application can only operate in a linuxapp environment, \ +please change the definition of the RTE_TARGET environment variable) +all: +else + +# binary name +APP = vhost-crypto + +# all source are stored in SRCS-y +SRCS-y := main.c + +CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 +CFLAGS += $(WERROR_FLAGS) +CFLAGS += -D_GNU_SOURCE + +include $(RTE_SDK)/mk/rte.extapp.mk + +endif
examples/vhost_crypto/main.c new file +617 -0
617 lines not on this page · raw message
Signature · 1 line
2.9.5
v2 cover lib/librte_vhost: introduce new vhost_user crypto backend support
In reply to Fan ZhangThis is a RFC patch, so please review. Thanks.
This RFC patchset adds crypto backend suppport to vhost_user library, including a proof-of-concept sample application. The implementation follows the virtio-crypto specification and have been tested with qemu 2.9.50 (with several patches applied, detailed later) with Fedora 24 running in the frontend.
The vhost_user library acts as a "bridge" method that translate the virtio-crypto crypto requests to DPDK crypto operations, so it is purely software implementation. However it does require the user to provide the DPDK Cryptodev ID so it knows how to handle the virtio-crypto session creation and deletion mesages.
Currently the implementation supports AES-CBC-128 and HMAC-SHA1 cipher only/chaining modes and does not support sessionless mode yet. The guest can use standard virtio-crypto driver to set up session and sends encryption/decryption requests to backend. The vhost-crypto sample application provided in this patchset will do the actual crypto work.
To make this patchset working, a few tweaks need to be done:
In the host:
1. Download the qemu source code, and apply the patches in:
list.nongnu.org/archive/html/qemu-devel/2017-07/msg04664.html. As the patches have been out for over 2 months, they cannot be cleanly applied to the latest code. I have reverted the commits back to 4c4414a to make the patches applied cleanly.
2. Recompile your qemu.
3. Apply this patchset to latest DPDK code and recompile DPDK.
4. Compile and run vhost-crypto sample application.
./examples/vhost_crypto/build/vhost-crypto -l 11,12,13 -w 0000:86:01.0 \
--socket-mem 2048,2048
Where 0000:86:01.0 is the QAT PCI address. You may use AES-NI-MB if it is not available. The sample application requires 3 lcores: 1 master, 1 worker, and 1 statistics displaying worker. The application will create a UNIX socket file /tmp/vhost_crypto1.socket.
5. Start your qemu application. Here is my command:
qemu/x86_64-softmmu/qemu-system-x86_64 -machine accel=kvm -cpu host \
-smp 2 -m 1G -hda ~/path-to-your/image.qcow \
-object memory-backend-file,id=mem,size=1G,mem-path=/dev/hugepages,share=on \
-mem-prealloc -numa node,memdev=mem -chardev \
socket,id=charcrypto0,path=/tmp/vhost_crypto1.socket \
-object cryptodev-vhost-user,id=cryptodev0,chardev=charcrypto0 \
-device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0
6. Once guest is booted. The Linux virtio_crypto kernel module is loaded by default. You shall see the following logs in your demsg:
[ 17.611044] virtio_crypto: loading out-of-tree module taints kernel. [ 17.611083] virtio_crypto: module verification failed: signature and/or ... [ 17.611723] virtio_crypto virtio0: max_queues: 1, max_cipher_key_len: ... [ 17.612156] virtio_crypto virtio0: will run requests pump with realtime ... [ 18.376100] virtio_crypto virtio0: Accelerator is ready
The virtio_crypto driver in the guest is now up and running.
7. The rest steps can be as same as the Testing section in
https://wiki.qemu.org/Features/VirtioCrypto
Fan Zhang (7):
v2:
Added the missed patch
lib/librte_vhost: add private data field lib/librte_vhost: add vhost_user private info structure lib/librte_vhost: add virtio-crypto spec support lib/librte_vhost: add vhost_user backend support config/common_base: add vhost_crypto configuration items lib/librte_vhost: update Makefile for vhost_crypto example/vhost_crypto: add vhost_crypto sample application
config/common_base | 1 + examples/vhost_crypto/Makefile | 59 ++ examples/vhost_crypto/main.c | 617 +++++++++++++++++ lib/librte_vhost/Makefile | 5 +- lib/librte_vhost/rte_vhost_crypto.h | 150 +++++ lib/librte_vhost/vhost.h | 4 +- lib/librte_vhost/vhost_crypto.c | 1254 +++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.c | 13 +- lib/librte_vhost/vhost_user.h | 34 +- 9 files changed, 2131 insertions(+), 6 deletions(-) create mode 100644 examples/vhost_crypto/Makefile create mode 100644 examples/vhost_crypto/main.c create mode 100644 lib/librte_vhost/rte_vhost_crypto.h create mode 100644 lib/librte_vhost/vhost_crypto.c
Signature · 1 line
2.9.5
RFC PATCH v2 1/7 lib/librte_vhost: add private data field
This patch adds a private data pointer to virtio_net structure, to allow more virtio device driver information.
--- lib/librte_vhost/vhost.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost.h +3 -1
@@ -253,8 +253,10 @@ struct virtio_net {struct guest_page *guest_pages;int slave_req_fd; -} __rte_cache_aligned; +/* Private data for different virtio device type */ +void *private_data; +} __rte_cache_aligned;#define VHOST_LOG_PAGE 4096
Signature · 1 line
2.9.5
RFC PATCH v2 2/7 lib/librte_vhost: add vhost_user private info structure
In reply to Fan ZhangThis patch adds a vhost_user_dev_priv structure and a vhost_user message handler function prototype to vhost_user. This allows different types of devices to add private information and their device-specific vhost-user message function handlers to virtio_net structure. The change to vhost_user_msg_handler is also added to call the device-specific message handler.
--- lib/librte_vhost/vhost_user.c | 13 ++++++++++++- lib/librte_vhost/vhost_user.h | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost_user.c +12 -1
@@ -1324,7 +1324,18 @@ vhost_user_msg_handler(int vid, int fd)break ;default : - ret =-1 ; +if (!dev->private_data) + ret =-1 ; +else { +struct vhost_user_dev_priv *priv = dev->private_data; + +if (!priv->vhost_user_msg_handler) + ret =-1 ; +else { + ret = (*priv->vhost_user_msg_handler)(dev, + &msg, fd); + } + }break ; }
lib/librte_vhost/vhost_user.h +7 -0
@@ -137,6 +137,13 @@ typedef struct VhostUserMsg {/* The version of the protocol we support */ #define VHOST_USER_VERSION 0x1 +typedef int (*msg_handler )(struct virtio_net *dev,struct VhostUserMsg *msg, +int fd); + +struct vhost_user_dev_priv { +msg_handler vhost_user_msg_handler; +char data[0 ]; +};/* vhost_user.c */ int vhost_user_msg_handler (int vid,int fd);
Signature · 1 line
2.9.5
RFC PATCH v2 3/7 lib/librte_vhost: add virtio-crypto spec support
In reply to Fan ZhangThis patch adds virtio-crypto support to vhost_user.
--- lib/librte_vhost/vhost_user.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost_user.h +26 -1
@@ -81,7 +81,7 @@ typedef enum VhostUserRequest {VHOST_USER_NET_SET_MTU =20 ,VHOST_USER_SET_SLAVE_REQ_FD =21 ,VHOST_USER_IOTLB_MSG =22 , - VHOST_USER_MAX + VHOST_USER_MAX = 25 } VhostUserRequest; typedef enum VhostUserSlaveRequest {
@@ -108,6 +108,30 @@ typedef struct VhostUserLog {uint64_t mmap_offset; } VhostUserLog; +/* Comply with Cryptodev-Linux */ +#define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512 +#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 + +/* Same structure as vhost-user backend session info */ +typedef struct VhostUserCryptoSessionParam { +int64_t session_id; +uint32_t op_code; +uint32_t cipher_algo; +uint32_t cipher_key_len; +uint32_t hash_algo; +uint32_t digest_len; +uint32_t auth_key_len; +uint32_t aad_len; +uint8_t op_type; +uint8_t dir; +uint8_t hash_mode; +uint8_t chaining_dir; +uint8_t *ciphe_key; +uint8_t *auth_key; +uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ]; +uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +}VhostUserCryptoSessionParam ; + typedef struct VhostUserMsg { union { VhostUserRequest master;
@@ -128,6 +152,7 @@ typedef struct VhostUserMsg {VhostUserMemory memory;VhostUserLog log;struct vhost_iotlb_msg iotlb; +VhostUserCryptoSessionParam crypto_session; } payload;int fds[VHOST_MEMORY_MAX_NREGIONS ]; } __attribute((packed)) VhostUserMsg;
Signature · 1 line
2.9.5
RFC PATCH v2 4/7 lib/librte_vhost: add vhost_user backend support
In reply to Fan ZhangThis patch adds vhost_crypto device driver support to vhost_user. Several new APIs are introduced for user to create and delete vhost_crypto devices, fetch virtio queue descriptors and translate to DPDK crypto operations for enqueuing to target cryptodev in the backend. After dequeuing from the cryptodev, an API is introduced to finalizing the crypto operations back to the frontend.
--- lib/librte_vhost/rte_vhost_crypto.h | 150 +++++ lib/librte_vhost/vhost_crypto.c | 1254 +++++++++++++++++++++++++++++++++++ 2 files changed, 1404 insertions(+) create mode 100644 lib/librte_vhost/rte_vhost_crypto.h create mode 100644 lib/librte_vhost/vhost_crypto.c
lib/librte_vhost/rte_vhost_crypto.h new file +150 -0
@@ -0,0 +1,150 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2017 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _VHOST_CRYPTO_H_ +#define _VHOST_CRYPTO_H_ + +#include <linux/virtio_crypto.h> +#include <rte_cryptodev.h> +#include <rte_hash.h> +#include <rte_pause.h> +#include "rte_vhost.h" + +#ifndef MAX_DATA_QUEUES +#define MAX_DATA_QUEUES (1) +#endif + +#define VIRTIO_CRYPTO_CTRL_QUEUE (0) +#define VIRTIO_CRYPTO_MAX_NUM_DEVS (64) + +/** Feature bits */ +#define VIRTIO_CRYPTO_F_CIPHER_SESSION_MODE (1) +#define VIRTIO_CRYPTO_F_HASH_SESSION_MODE (2) +#define VIRTIO_CRYPTO_F_MAC_SESSION_MODE (3) +#define VIRTIO_CRYPTO_F_AEAD_SESSION_MODE (4) + +/** +* Create Vhost-crypto instance +* +* @param vid +* The identifier of the vhost device. +* @param cryptodev_id +* The identifier of DPDK Cryptodev, the same cryptodev_id can be assigned to +* multiple Vhost-crypto devices. +* @param sess_pool +* The pointer to the created cryptodev session pool with the private data size +* matches the target DPDK Cryptodev. +* @param socket_id +* NUMA Socket ID to allocate resources on. * +* @return +* 0 if the Vhost Crypto Instance is created successfully. +* Negative integer if otherwise +*/ +int +rte_vhost_crypto_create (int vid,uint8_t cryptodev_id, +struct rte_mempool *sess_pool,int socket_id); + +/** +* Free the Vhost-crypto instance +* +* @param vid +* The identifier of the vhost device. +* @return +* 0 if the Vhost Crypto Instance is created successfully. +* Negative integer if otherwise +*/ +int +rte_vhost_crypto_free (int vid); + +/** +* Creates a crypto operation pool +* +* @param name +* pool name +* @param type +* crypto operation type, use RTE_CRYPTO_OP_TYPE_UNDEFINED for a pool which +* supports all operation types +* @param nb_elts +* number of elements in pool +* @param cache_size +* Number of elements to cache on lcore, see *rte_mempool_create* for further +* details about cache size +* @param socket_id +* Socket to allocate memory on +* @return +* On success pointer to mempool +* On failure NULL +*/ +struct rte_mempool * +rte_vhost_crypto_create_cop_pool (const char *name,enum rte_crypto_op_type type, +unsigned nb_elts,unsigned cache_size,int socket_id); + +/** +* Fetch a number of vring descriptors from virt-queue and translate to DPDK +* crypto operations. After this function is executed, the user can enqueue +* the processed ops to the target cryptodev. +* +* @param vid +* The identifier of the vhost device. +* @param qid +* Virtio queue index. +* @param ops +* The address of an array of pointers to *rte_crypto_op* structures that must +* be large enough to store *nb_ops* pointers in it. +* @param nb_ops +* The maximum number of operations to be fetched and translated. +* @return +* The number of fetched and processed vhost crypto request operations. +*/ +uint16_t +rte_vhost_crypto_fetch_requests (int vid,uint32_t qid, +struct rte_crypto_op **ops,uint16_t nb_ops); +/** +* Finalize the dequeued crypto ops. After the translated crypto ops are +* dequeued from the cryptodev, this function shall be called to write the +* processed data back to the vring descriptor (if no-copy is turned off) and +* obtain the bit mask of the vhost devices contained in the crypto ops. +* +* @param ops +* The address of an array of *rte_crypto_op* structure that was dequeued +* from cryptodev. +* @param nb_ops +* The number of operations contained in the array. +* @return +* The bit-mask of the vhost devices contained in the ops. +*/ +uint64_t +rte_vhost_crypto_finalize_requests (struct rte_crypto_op **ops, +uint16_t nb_ops); + +#endif /**< _VHOST_CRYPTO_H_ */
lib/librte_vhost/vhost_crypto.c new file +1254 -0
1,254 lines not on this page · raw message
Signature · 1 line
2.9.5
RFC PATCH v2 5/7 config/common_base: add vhost_crypto configuration items
In reply to Fan ZhangThis patch adds the vhost_crypto related compile configuration items to config/common_base. A new item "CONFIG_RTE_LIBRTE_VHOST_CRYPTO_DATA_QUEUE_NO_COPY" is introduced to turn on/off data queue no copy feature to vhost_crypto. This feature is in experimental level so no gurantee it would work, especially when kernel crypto framework and virtio-crypto driver are used in the frontend.
--- config/common_base | 1 + 1 file changed, 1 insertion(+)
config/common_base +1 -0
@@ -764,6 +764,7 @@ CONFIG_RTE_LIBRTE_PDUMP=y # Compile vhost user library # CONFIG_RTE_LIBRTE_VHOST=n +CONFIG_RTE_LIBRTE_VHOST_CRYPTO_DATA_QUEUE_NO_COPY=n CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n
Signature · 1 line
2.9.5
RFC PATCH v2 6/7 lib/librte_vhost: update Makefile for vhost_crypto
In reply to Fan Zhang--- lib/librte_vhost/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
lib/librte_vhost/Makefile +2 -3
@@ -48,9 +48,8 @@ endif # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ - vhost_user.c virtio_net.c + vhost_user.c virtio_net.c vhost_crypto.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h - +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vhost_crypto.h include $(RTE_SDK)/mk/rte.lib.mk
Signature · 1 line
2.9.5
RFC PATCH v2 7/7 example/vhost_crypto: add vhost_crypto sample application
In reply to Fan ZhangThis patch adds vhost_crypto sample application to DPDK.
--- examples/vhost_crypto/Makefile | 59 ++++ examples/vhost_crypto/main.c | 617 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 676 insertions(+) create mode 100644 examples/vhost_crypto/Makefile create mode 100644 examples/vhost_crypto/main.c
examples/vhost_crypto/Makefile new file +59 -0
@@ -0,0 +1,59 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2017 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +ifneq ($(CONFIG_RTE_EXEC_ENV),"linuxapp") +$(info This application can only operate in a linuxapp environment, \ +please change the definition of the RTE_TARGET environment variable) +all: +else + +# binary name +APP = vhost-crypto + +# all source are stored in SRCS-y +SRCS-y := main.c + +CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 +CFLAGS += $(WERROR_FLAGS) +CFLAGS += -D_GNU_SOURCE + +include $(RTE_SDK)/mk/rte.extapp.mk + +endif
examples/vhost_crypto/main.c new file +617 -0
617 lines not on this page · raw message
Signature · 1 line
2.9.5