cryptodev: add vhost support
v2 cover cryptodev: add vhost support
From: Gonglei <[email protected]>
I posted the RFC verion five months ago for DPDK vhost-crypto implmention, and now it's time to send the formal version. Because we need an user space scheme for better performance.
The vhost user crypto server side patches had been sent to DPDK community, pls see
[RFC PATCH 0/6] lib/librte_vhost: introduce new vhost_user crypto backend support
http://dpdk.org/ml/archives/dev/2017-November/081048.html
You also can get virtio-crypto polling mode driver from:
[PATCH] virtio: add new driver for crypto devices
http://dpdk.org/ml/archives/dev/2017-November/081985.html
Gonglei (4):
cryptodev: add vhost-user as a new cryptodev backend
cryptodev: add vhost support
cryptodev-vhost-user: add crypto session handler
cryptodev-vhost-user: set the key length
backends/Makefile.objs | 4 + backends/cryptodev-builtin.c | 1 + backends/cryptodev-vhost-user.c | 381 ++++++++++++++++++++++++++++++++++ backends/cryptodev-vhost.c | 297 ++++++++++++++++++++++++++ docs/interop/vhost-user.txt | 19 ++ hw/virtio/Makefile.objs | 2 +- hw/virtio/vhost-user.c | 89 ++++++++ hw/virtio/virtio-crypto.c | 70 +++++++ include/hw/virtio/vhost-backend.h | 8 + include/hw/virtio/virtio-crypto.h | 1 + include/sysemu/cryptodev-vhost-user.h | 47 +++++ include/sysemu/cryptodev-vhost.h | 154 ++++++++++++++ include/sysemu/cryptodev.h | 8 + qemu-options.hx | 21 ++ vl.c | 4 + 15 files changed, 1105 insertions(+), 1 deletion(-) create mode 100644 backends/cryptodev-vhost-user.c create mode 100644 backends/cryptodev-vhost.c create mode 100644 include/sysemu/cryptodev-vhost-user.h create mode 100644 include/sysemu/cryptodev-vhost.h
--
1.8.3.1
PATCH v2 1/4 cryptodev: add vhost-user as a new cryptodev backend
From: Gonglei <[email protected]>
Usage:
-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
--- backends/Makefile.objs | 4 + backends/cryptodev-vhost-user.c | 333 +++++++++++++++++++++++++++++++++++++++ backends/cryptodev-vhost.c | 73 +++++++++ include/sysemu/cryptodev-vhost.h | 154 ++++++++++++++++++ qemu-options.hx | 21 +++ vl.c | 4 + 6 files changed, 589 insertions(+) create mode 100644 backends/cryptodev-vhost-user.c create mode 100644 backends/cryptodev-vhost.c create mode 100644 include/sysemu/cryptodev-vhost.h
backends/Makefile.objs +4 -0
@@ -8,3 +8,7 @@ common-obj-$(CONFIG_LINUX) += hostmem-file.o common-obj-y += cryptodev.o common-obj-y += cryptodev-builtin.o + +ifeq ($(CONFIG_VIRTIO),y) +common-obj-$(CONFIG_LINUX) += cryptodev-vhost.o cryptodev-vhost-user.o +endif
backends/cryptodev-vhost-user.c new file +333 -0
333 lines not on this page · raw message
backends/cryptodev-vhost.c new file +73 -0
73 lines not on this page · raw message
include/sysemu/cryptodev-vhost.h new file +154 -0
154 lines not on this page · raw message
qemu-options.hx +21 -0
@@ -4387,6 +4387,27 @@ which specify the queue number of cryptodev backend, the default of [...] @end example +@item -object cryptodev-vhost-user,id=@var{id},chardev=@var{chardevid}[,queues=@var{queues}] + +Creates a vhost-user cryptodev backend, backed by a chardev @var{chardevid}. +The @var{id} parameter is a unique ID that will be used to reference this +cryptodev backend from the @option{virtio-crypto} device. +The chardev should be a unix domain socket backed one. The vhost-user uses +a specifically defined protocol to pass vhost ioctl replacement messages +to an application on the other end of the socket. +The @var{queues} parameter is optional, which specify the queue number +of cryptodev backend for multiqueue vhost-user, the default of @var{queues} is 1. + +@example + + # qemu-system-x86_64 \ + [...] \ + -chardev socket,id=chardev0,path=/path/to/socket \ + -object cryptodev-vhost-user,id=cryptodev0,chardev=chardev0 \ + -device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0 \ + [...] +@end example + @item -object secret,id=@var{id},data=@var{string},format=@var{raw|base64}[,keyid=@var{secretid},iv=@var{string}] @item -object secret,id=@var{id},file=@var{filename},format=@var{raw|base64}[,keyid=@var{secretid},iv=@var{string}]
vl.c +4 -0
@@ -2912,6 +2912,10 @@ static bool object_create_initial(const char *type)return false; } +if (g_str_equal (type,"cryptodev-vhost-user" )) { +return false; + } +/* * return false for concrete netfilters since * they depend on netdevs already existing
Signature · 1 line
1.8.3.1
PATCH v2 2/4 cryptodev: add vhost support
In reply to Jay ZhouFrom: Gonglei <[email protected]>
Impliment the vhost-crypto's funtions, such as startup, stop and notification etc. Introduce an enum QCryptoCryptoDevBackendOptionsType in order to identify the cryptodev vhost backend is vhost-user or vhost-kernel-module (If exist).
At this point, the cryptdoev-vhost-user works.
--- backends/cryptodev-builtin.c | 1 + backends/cryptodev-vhost-user.c | 16 +++ backends/cryptodev-vhost.c | 224 ++++++++++++++++++++++++++++++++++ hw/virtio/Makefile.objs | 2 +- hw/virtio/virtio-crypto.c | 70 +++++++++++ include/hw/virtio/virtio-crypto.h | 1 + include/sysemu/cryptodev-vhost-user.h | 44 +++++++ include/sysemu/cryptodev.h | 8 ++ 8 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 include/sysemu/cryptodev-vhost-user.h
backends/cryptodev-builtin.c +1 -0
@@ -78,6 +78,7 @@ static void cryptodev_builtin_init( "cryptodev-builtin", NULL); cc->info_str =g_strdup_printf ("cryptodev-builtin0" ); cc->queue_index =0 ; + cc->type =CRYPTODEV_BACKEND_TYPE_BUILTIN ; backend->conf.peers.ccs[0 ] = cc; backend->conf.crypto_services =
backends/cryptodev-vhost-user.c +16 -0
@@ -29,6 +29,7 @@#include "standard-headers/linux/virtio_crypto.h" #include "sysemu/cryptodev-vhost.h" #include "chardev/char-fe.h" +#include "sysemu/cryptodev-vhost-user.h" /**
@@ -58,6 +59,20 @@ cryptodev_vhost_user_running(return crypto ?1 :0 ; } +CryptoDevBackendVhost * +cryptodev_vhost_user_get_vhost ( +CryptoDevBackendClient *cc, +CryptoDevBackend *b, +uint16_t queue) +{ +CryptoDevBackendVhostUser *s = +CRYPTODEV_BACKEND_VHOST_USER (b); +assert (cc->type ==CRYPTODEV_BACKEND_TYPE_VHOST_USER ); +assert (queue <MAX_CRYPTO_QUEUE_NUM ); + +return s->vhost_crypto[queue]; +} +static void cryptodev_vhost_user_stop (int queues,CryptoDevBackendVhostUser *s) {
@@ -190,6 +205,7 @@ static void cryptodev_vhost_user_init( cc->info_str =g_strdup_printf ("cryptodev-vhost-user%lu to %s " , i, chr->label); cc->queue_index = i; + cc->type =CRYPTODEV_BACKEND_TYPE_VHOST_USER ; backend->conf.peers.ccs[i] = cc;
backends/cryptodev-vhost.c +224 -0
234 lines not on this page · raw message
hw/virtio/Makefile.objs +1 -1
@@ -7,7 +7,7 @@ common-obj-y += virtio-mmio.o obj-y += virtio.o virtio-balloon.o obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o -obj-y += virtio-crypto.o +obj-$(CONFIG_LINUX) += virtio-crypto.o obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o endif
hw/virtio/virtio-crypto.c +70 -0
88 lines not on this page · raw message
include/hw/virtio/virtio-crypto.h +1 -0
@@ -96,6 +96,7 @@ typedef struct VirtIOCrypto {int multiqueue;uint32_t curr_queues;size_t config_size; + uint8_t vhost_started; } VirtIOCrypto;#endif /* _QEMU_VIRTIO_CRYPTO_H */
include/sysemu/cryptodev-vhost-user.h new file +44 -0
44 lines not on this page · raw message
include/sysemu/cryptodev.h +8 -0
@@ -163,12 +163,20 @@ typedef struct CryptoDevBackendClass { uint32_t queue_index, Error **errp); } CryptoDevBackendClass; +typedef enum CryptoDevBackendOptionsType { +CRYPTODEV_BACKEND_TYPE_NONE =0 , +CRYPTODEV_BACKEND_TYPE_BUILTIN =1 , +CRYPTODEV_BACKEND_TYPE_VHOST_USER =2 , +CRYPTODEV_BACKEND_TYPE__MAX , +}CryptoDevBackendOptionsType ;struct CryptoDevBackendClient { +CryptoDevBackendOptionsType type;char *model;char *name;char *info_str;unsigned int queue_index; +int vring_enable;QTAILQ_ENTRY (CryptoDevBackendClient) next; };
Signature · 1 line
1.8.3.1
PATCH v2 3/4 cryptodev-vhost-user: add crypto session handler
In reply to Jay ZhouFrom: Gonglei <[email protected]>
Introduce two vhost-user meassges: VHOST_USER_CREATE_CRYPTO_SESSION and VHOST_USER_CLOSE_CRYPTO_SESSION. At this point, the QEMU side support crypto operation in cryptodev host-user backend.
--- backends/cryptodev-vhost-user.c | 50 +++++++++++++++++----- docs/interop/vhost-user.txt | 19 +++++++++ hw/virtio/vhost-user.c | 89 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 8 ++++ 4 files changed, 155 insertions(+), 11 deletions(-)
backends/cryptodev-vhost-user.c +39 -11
@@ -233,7 +233,26 @@ static int64_t cryptodev_vhost_user_sym_create_session(CryptoDevBackendSymSessionInfo *sess_info, uint32_t queue_index, Error **errp) { - return 0; + CryptoDevBackendClient *cc = + backend->conf.peers.ccs[queue_index]; +CryptoDevBackendVhost *vhost_crypto; +uint64_t session_id =0 ; +int ret; + + vhost_crypto =cryptodev_vhost_user_get_vhost (cc, + backend, queue_index); +if (vhost_crypto) { +struct vhost_dev *dev = &(vhost_crypto->dev); + ret = dev->vhost_ops->vhost_crypto_create_session (dev, + sess_info, + &session_id); +if (ret <0 ) { +return -1 ; + }else { +return session_id; + } + } +return -1 ; } static int cryptodev_vhost_user_sym_close_session(
@@ -241,15 +260,24 @@ static int cryptodev_vhost_user_sym_close_session(uint64_t session_id, uint32_t queue_index, Error **errp) { - return 0; -} - -static int cryptodev_vhost_user_sym_operation ( -CryptoDevBackend *backend, -CryptoDevBackendSymOpInfo *op_info, -uint32_t queue_index,Error **errp) -{ -return VIRTIO_CRYPTO_OK ; + CryptoDevBackendClient *cc = + backend->conf.peers.ccs[queue_index]; +CryptoDevBackendVhost *vhost_crypto; +int ret; + + vhost_crypto =cryptodev_vhost_user_get_vhost (cc, + backend, queue_index); +if (vhost_crypto) { +struct vhost_dev *dev = &(vhost_crypto->dev); + ret = dev->vhost_ops->vhost_crypto_close_session (dev, + session_id); +if (ret <0 ) { +return -1 ; + }else { +return 0 ; + } + } +return -1 ; } static void cryptodev_vhost_user_cleanup(
@@ -328,7 +356,7 @@ cryptodev_vhost_user_class_init(ObjectClass *oc, void *data) bc->cleanup = cryptodev_vhost_user_cleanup; bc->create_session = cryptodev_vhost_user_sym_create_session; bc->close_session = cryptodev_vhost_user_sym_close_session; - bc->do_sym_op = cryptodev_vhost_user_sym_operation; + bc->do_sym_op =NULL ; }static const TypeInfo cryptodev_vhost_user_info = {
docs/interop/vhost-user.txt +19 -0
@@ -596,6 +596,25 @@ Master message types and expect this message once (per VQ) during device configuration (ie. before the master starts the VQ). + * VHOST_USER_CREATE_CRYPTO_SESSION + + Id: 23 + Equivalent ioctl: N/A + Master payload: crypto session description + Slave payload: crypto session description + + Create a session for crypto operation. The server side must return the + session id, 0 or positive for success, negative for failure. + + * VHOST_USER_CLOSE_CRYPTO_SESSION + + Id: 24 + Equivalent ioctl: N/A + Master payload: u64 + + Close a session for crypto operation which was previously + created by VHOST_USER_CREATE_CRYPTO_SESSION. + Slave message types -------------------
hw/virtio/vhost-user.c +89 -0
123 lines not on this page · raw message
include/hw/virtio/vhost-backend.h +8 -0
@@ -85,6 +85,12 @@ typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,typedef int (*vhost_send_device_iotlb_msg_op )(struct vhost_dev *dev,struct vhost_iotlb_msg *imsg); +typedef int (*vhost_crypto_create_session_op )(struct vhost_dev *dev, +void *session_info, +uint64_t *session_id); +typedef int (*vhost_crypto_close_session_op )(struct vhost_dev *dev, +uint64_t session_id); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init;
@@ -118,6 +124,8 @@ typedef struct VhostOps {vhost_vsock_set_running_op vhost_vsock_set_running;vhost_set_iotlb_callback_op vhost_set_iotlb_callback;vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg; +vhost_crypto_create_session_op vhost_crypto_create_session; +vhost_crypto_close_session_op vhost_crypto_close_session; } VhostOps;extern const VhostOps user_ops;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 3/4] cryptodev-vhost-user: add crypto session handler
Quoted 20 lines · Jay Zhou
docs/interop/vhost-user.txt +12
-0@@ -596,6 +596,25 @@ Master message types and expect this message once (per VQ) during device configuration (ie. before the master starts the VQ). + * VHOST_USER_CREATE_CRYPTO_SESSION + + Id: 23 + Equivalent ioctl: N/A + Master payload: crypto session description + Slave payload: crypto session description + + Create a session for crypto operation. The server side must return the + session id, 0 or positive for success, negative for failure. + + * VHOST_USER_CLOSE_CRYPTO_SESSION +
docs/interop/vhost-user.txt Master message types · line 620
Quoted 10 lines
docs/interop/vhost-user.txt +7
-0+ Id: 24 + Equivalent ioctl: N/A + Master payload: u64 + + Close a session for crypto operation which was previously + created by VHOST_USER_CREATE_CRYPTO_SESSION. + Slave message types -------------------
Sorry about a delayed response.
So an issue with this patchset is that you are adding new messages unconditionally.
You must add a protocol bit whenever you add new messages. If appropriate, you can document that it's a required feature for crypto devices.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v2 3/4] cryptodev-vhost-user: add crypto session handler
Quoted 48 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 16, 2018 12:24 PM
To: Zhoujian (jay) <[email protected]>
Cc: [email protected]; [email protected]; Huangweidong (C) <[email protected]>; [email protected]; [email protected]; longpeng <[email protected]>; [email protected]; [email protected]; Gonglei (Arei) <[email protected]>
Subject: Re: [PATCH v2 3/4] cryptodev-vhost-user: add crypto session handlerQuoted 6 lines · Jay Zhou
docs/interop/vhost-user.txt +0
-0@@ -596,6 +596,25 @@ Master message types and expect this message once (per VQ) during device configurationdocs/interop/vhost-user.txt Master message types · line 606
Quoted 10 lines
docs/interop/vhost-user.txt +8
-0(ie. before the master starts the VQ). + * VHOST_USER_CREATE_CRYPTO_SESSION + + Id: 23 + Equivalent ioctl: N/A + Master payload: crypto session description + Slave payload: crypto session description + + Create a session for crypto operation. The server side must returnthe
Quoted 4 lines
docs/interop/vhost-user.txt +4
-0+ session id, 0 or positive for success, negative for failure. + + * VHOST_USER_CLOSE_CRYPTO_SESSION +docs/interop/vhost-user.txt Master message types · line 620
Quoted 10 lines
docs/interop/vhost-user.txt +7
-0+ Id: 24 + Equivalent ioctl: N/A + Master payload: u64 + + Close a session for crypto operation which was previously + created by VHOST_USER_CREATE_CRYPTO_SESSION. + Slave message types -------------------Sorry about a delayed response.
So an issue with this patchset is that you are adding new messages unconditionally.
Quoted 3 lines
You must add a protocol bit whenever you add new messages. If appropriate, you can document that it's a required feature for crypto devices.
OK, will do.
Regards,
Jay
Quoted 4 lines
--
MST
PATCH v2 4/4 cryptodev-vhost-user: set the key length
In reply to Jay ZhouFrom: Gonglei <[email protected]>
--- backends/cryptodev-vhost-user.c | 4 ++++ include/sysemu/cryptodev-vhost-user.h | 3 +++ 2 files changed, 7 insertions(+)
backends/cryptodev-vhost-user.c +4 -0
@@ -226,6 +226,10 @@ static void cryptodev_vhost_user_init(1u <<VIRTIO_CRYPTO_SERVICE_MAC ; backend->conf.cipher_algo_l =1u <<VIRTIO_CRYPTO_CIPHER_AES_CBC ; backend->conf.hash_algo =1u <<VIRTIO_CRYPTO_HASH_SHA1 ; + + backend->conf.max_size =UINT64_MAX ; + backend->conf.max_cipher_key_len =VHOST_USER_MAX_AUTH_KEY_LEN ; + backend->conf.max_auth_key_len =VHOST_USER_MAX_AUTH_KEY_LEN ; } static int64_t cryptodev_vhost_user_sym_create_session(
include/sysemu/cryptodev-vhost-user.h +3 -0
@@ -23,6 +23,9 @@#ifndef CRYPTODEV_VHOST_USER_H #define CRYPTODEV_VHOST_USER_H +#define VHOST_USER_MAX_AUTH_KEY_LEN 512 +#define VHOST_USER_MAX_CIPHER_KEY_LEN 64 +/** * cryptodev_vhost_user_get_vhost:
Signature · 1 line
1.8.3.1