cryptodev: add vhost support
v8 cover cryptodev: add vhost support
From: Gonglei <[email protected]>
I posted the RFC verion a few 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 v2 0/7] crypto: add virtio poll mode driver
http://dpdk.org/ml/archives/dev/2018-February/091410.html
v8:
- make cryptodev-vhost.c complied linux independently
v7:
- make virtio crypto enabled on non-Linux
- fix format-string issues
- fix error reported by clang
- fix a typo when setting length of cipher key
- rebased on the master
v6:
- Fix compile error about backends/cryptodev-vhost-user.o and rebase on the master
v5:
- squash [PATCH v4 5/5] into previous patches [Michael]
v4:
- "[PATCH v4 5/5] cryptodev-vhost-user: depend on CONFIG_VHOST_CRYPTO and CONFIG_VHOST_USER" newly added to fix compilation dependency [Michael]
v3:
- New added vhost user messages should be sent only when feature has been successfully negotiated [Michael]
v2:
- Fix compile error on mingw32
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 | 6 + backends/cryptodev-builtin.c | 1 + backends/cryptodev-vhost-user.c | 377 ++++++++++++++++++++++++++++++++++ backends/cryptodev-vhost.c | 347 +++++++++++++++++++++++++++++++ configure | 15 ++ docs/interop/vhost-user.txt | 26 +++ hw/virtio/vhost-user.c | 104 ++++++++++ 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 | 6 + 15 files changed, 1191 insertions(+) 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 v8 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 | 6 + backends/cryptodev-vhost-user.c | 331 +++++++++++++++++++++++++++++++++++++++ backends/cryptodev-vhost.c | 89 +++++++++++ configure | 15 ++ include/sysemu/cryptodev-vhost.h | 154 ++++++++++++++++++ qemu-options.hx | 21 +++ vl.c | 6 + 7 files changed, 622 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 +6 -0
@@ -9,4 +9,10 @@ common-obj-$(CONFIG_LINUX) += hostmem-file.o common-obj-y += cryptodev.o common-obj-y += cryptodev-builtin.o +ifeq ($(CONFIG_VIRTIO),y) +common-obj-y += cryptodev-vhost.o +common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) += \ + cryptodev-vhost-user.o +endif + common-obj-$(CONFIG_LINUX) += hostmem-memfd.o
backends/cryptodev-vhost-user.c new file +331 -0
331 lines not on this page · raw message
backends/cryptodev-vhost.c new file +89 -0
89 lines not on this page · raw message
configure +15 -0
@@ -344,6 +344,7 @@ xfs="" tcg="yes" vhost_net="no" +vhost_crypto="no" vhost_scsi="no" vhost_vsock="no" vhost_user=""
@@ -813,6 +814,7 @@ Linux) linux_user="yes" kvm="yes" vhost_net="yes" + vhost_crypto="yes" vhost_scsi="yes" vhost_vsock="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
@@ -1183,6 +1185,14 @@ for opt do ;; --enable-vhost-net) vhost_net="yes" ;; + --disable-vhost-crypto) vhost_crypto="no" + ;; + --enable-vhost-crypto) + vhost_crypto="yes" + if test "$mingw32" = "yes"; then + error_exit "vhost-crypto isn't available on win32" + fi + ;; --disable-vhost-scsi) vhost_scsi="no" ;; --enable-vhost-scsi) vhost_scsi="yes"
@@ -1580,6 +1590,7 @@ disabled with --disable-FEATURE, default is enabled if available: cap-ng libcap-ng support attr attr and xattr support vhost-net vhost-net acceleration support + vhost-crypto vhost-crypto acceleration support spice spice rbd rados block device (rbd) libiscsi iscsi support
@@ -5771,6 +5782,7 @@ echo "posix_madvise $posix_madvise" echo "posix_memalign $posix_memalign" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" +echo "vhost-crypto support $vhost_crypto" echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user"
@@ -6855,6 +6867,9 @@ if supported_kvm_target $target; then echo "CONFIG_VHOST_USER_NET_TEST_$target_name=y" >> $config_host_mak fi fi + if test "$vhost_crypto" = "yes" ; then + echo "CONFIG_VHOST_CRYPTO=y" >> $config_target_mak + fi fi if supported_hax_target $target; then echo "CONFIG_HAX=y" >> $config_target_mak
include/sysemu/cryptodev-vhost.h new file +154 -0
154 lines not on this page · raw message
qemu-options.hx +21 -0
@@ -4233,6 +4233,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 +6 -0
@@ -2838,6 +2838,12 @@ static bool object_create_initial(const char *type)return false; } +#if defined(CONFIG_VHOST_USER ) && defined(CONFIG_LINUX ) +if (g_str_equal (type,"cryptodev-vhost-user" )) { +return false; + } +#endif +/* * return false for concrete netfilters since * they depend on netdevs already existing
Signature · 1 line
1.8.3.1
PATCH v8 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 | 258 ++++++++++++++++++++++++++++++++++ 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 ++ 7 files changed, 398 insertions(+) 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) {
@@ -188,6 +203,7 @@ static void cryptodev_vhost_user_init( cc->info_str =g_strdup_printf ("cryptodev-vhost-user%zu 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 +258 -0
277 lines not on this page · raw message
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 v8 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 | 48 ++++++++++++++---- docs/interop/vhost-user.txt | 26 ++++++++++ hw/virtio/vhost-user.c | 104 ++++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 8 +++ 4 files changed, 175 insertions(+), 11 deletions(-)
backends/cryptodev-vhost-user.c +37 -11
@@ -231,7 +231,25 @@ 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(
@@ -239,15 +257,23 @@ 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(
@@ -326,7 +352,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 +26 -0
@@ -368,6 +368,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_MTU 4 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 +#define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7 Master message types --------------------
@@ -663,6 +664,31 @@ Master message types field, and slaves MUST NOT accept SET_CONFIG for read-only configuration space fields unless the live migration bit is set. +* VHOST_USER_CREATE_CRYPTO_SESSION + + Id: 26 + 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. + This request should be sent only when VHOST_USER_PROTOCOL_F_CRYPTO_SESSION + feature has been successfully negotiated. + It's a required feature for crypto devices. + +* VHOST_USER_CLOSE_CRYPTO_SESSION + + Id: 27 + Equivalent ioctl: N/A + Master payload: u64 + + Close a session for crypto operation which was previously + created by VHOST_USER_CREATE_CRYPTO_SESSION. + This request should be sent only when VHOST_USER_PROTOCOL_F_CRYPTO_SESSION + feature has been successfully negotiated. + It's a required feature for crypto devices. + Slave message types -------------------
hw/virtio/vhost-user.c +104 -0
144 lines not on this page · raw message
include/hw/virtio/vhost-backend.h +8 -0
@@ -95,6 +95,12 @@ typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *data,typedef int (*vhost_get_config_op )(struct vhost_dev *dev,uint8_t *config,uint32_t config_len); +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;
@@ -130,6 +136,8 @@ typedef struct VhostOps {vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg;vhost_get_config_op vhost_get_config;vhost_set_config_op vhost_set_config; +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
PATCH v8 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
@@ -224,6 +224,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_CIPHER_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
The Intel guy Fan Zhang(CCed) reported a config issue when enabling and testing vhost_crypto, so I resend this version, thanks!
Regards,
Jay
Quoted 81 lines
-----Original Message-----
From: Zhoujian (jay)
Sent: Tuesday, February 27, 2018 2:33 PM
To: [email protected]
Cc: [email protected]; [email protected]; Huangweidong (C) <[email protected]>; [email protected]; Zhoujian (jay) <[email protected]>; [email protected]; longpeng <[email protected]>; [email protected]; [email protected]; Gonglei (Arei) <[email protected]>; wangxin (U) <[email protected]>
Subject: [PATCH v8 0/4] cryptodev: add vhost supportFrom: Gonglei <[email protected]>
I posted the RFC verion a few 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 newvhost_usercrypto backend support http://dpdk.org/ml/archives/dev/2017-November/081048.htmlYou also can get virtio-crypto polling mode driver from:
[PATCH v2 0/7] crypto: add virtio poll mode driver
http://dpdk.org/ml/archives/dev/2018-February/091410.htmlv8:
- makecryptodev-vhost.ccomplied linux independently
v7:
- make virtio crypto enabled on non-Linux
- fix format-string issues
- fix error reported by clang
- fix a typo when setting length of cipher key
- rebased on the master
v6:
- Fix compile error aboutbackends/cryptodev-vhost-user.oand rebase on the master
v5:
- squash [PATCH v4 5/5] into previous patches [Michael]
v4:
- "[PATCH v4 5/5] cryptodev-vhost-user: depend onCONFIG_VHOST_CRYPTOandCONFIG_VHOST_USER" newly added to fix compilation dependency [Michael]
v3:
- New added vhost user messages should be sent only when feature has been successfully negotiated [Michael]
v2:
- Fix compile error on mingw32Gonglei (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 lengthbackends/Makefile.objs | 6 + backends/cryptodev-builtin.c | 1 + backends/cryptodev-vhost-user.c | 377 ++++++++++++++++++++++++++++++++++ backends/cryptodev-vhost.c | 347 +++++++++++++++++++++++++++++++ configure | 15 ++ docs/interop/vhost-user.txt | 26 +++ hw/virtio/vhost-user.c | 104 ++++++++++ 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 | 6 + 15 files changed, 1191 insertions(+) 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