Skip to contentSkip to conversation

vhost/crypto: fix initialization.

dpdk-dev Applied Fan Zhang 3 participants 14 messages Oct 2, 2020 – Oct 10, 2020

lore
Share & tools
lore

Fan Zhang

author
#0 lore raw

This patch fixes the problem that vhost crypto cannot be initialized due to the different requirement between built-in virtio-net and virtio-crypto. The fix includes the following change:

- Added new internal enum type virtio_backend_type to distinguish virtio-net, virtio-crypto, and external device types.
- Added new API rte_vhost_crypto_driver_start to distinguish between virtio-net and virtio-crypto built-in drivers initialization.
- Added new internal function for the vhost library to use different feature flags when initializing virtio-crypto.

Fixes 2ab58f20db51 ("vhost: refactor virtio ready check")
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 +++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/socket.c              | 44 +++++++++++++++++++++-----
 lib/librte_vhost/vhost.h               |  1 -
 lib/librte_vhost/vhost_crypto.c        | 35 ++++++++++++--------
 lib/librte_vhost/vhost_user.h          | 12 +++++++
 7 files changed, 84 insertions(+), 24 deletions(-)
examples/vhost_crypto/main.c +2 -1
index 11b022e81..ef64e96de 100644
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo->socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start vhost.\n");
 				goto error_exit;
lib/librte_vhost/rte_vhost_crypto.h +12 -0
index b54d61db6..c809c46a2 100644
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
lib/librte_vhost/rte_vhost_version.map +1 -0
index 20b4abcb4..a454d5f41 100644
@@ -48,6 +48,7 @@ EXPERIMENTAL {
 	rte_vhost_get_vring_base;
 	rte_vhost_set_vring_base;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
lib/librte_vhost/socket.c +36 -8

88 lines not on this page · raw message

lib/librte_vhost/vhost.h +0 -1
index 73a1ed889..1da9ed871 100644
@@ -352,7 +352,6 @@ struct vring_packed_desc_event {
 				(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
 				(1ULL << VIRTIO_F_RING_PACKED))
 
-
 struct guest_page {
 	uint64_t guest_phys_addr;
 	uint64_t host_phys_addr;
lib/librte_vhost/vhost_crypto.c +21 -14
index e08f9c6d7..e9c6702c2 100644
@@ -35,13 +35,13 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |			\
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |			\
-		(1 << VIRTIO_NET_F_CTRL_VQ) |				\
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |			\
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |			\
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |				\
+		(1ULL << VHOST_USER_PROTOCOL_F_CONFIG) |		\
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1400,20 @@ vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,
 	return processed;
 }
 
+void
+vhost_crypto_set_feature_flags(uint64_t *feature_flags,
+		uint64_t *protocol_feature_flags)
+{
+	*feature_flags = VIRTIO_CRYPTO_FEATURES;
+	*protocol_feature_flags |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+}
+
+int
+rte_vhost_crypto_driver_start(const char *path)
+{
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1431,6 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
lib/librte_vhost/vhost_user.h +12 -0
index 16fe03f88..d28da17dd 100644
@@ -158,6 +158,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
+/* virtio backend types */
+enum virtio_backend_type {
+	VIRTIO_DEV_UNKNOWN = 0, /* Likely external */
+	VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */
+	VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */
+};
 
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
@@ -167,5 +173,11 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
 		int *fd_num);
 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
+int vhost_driver_start(const char *path,
+		enum virtio_backend_type backend_type);
+
+/* vhost_crypto.c */
+void vhost_crypto_set_feature_flags(uint64_t *feature_flags,
+		uint64_t *protocol_feature_flags);
 
 #endif
Signature · 1 line
2.20.1
#1 lore raw

Hi Fan,

Thanks for working on this.

The commit message should not contain dot, please remove it in v2.

Quoted 5 lines · Fan Zhang

This patch fixes the problem that vhost crypto cannot be initialized due to the different requirement between built-in virtio-net and virtio-crypto. The fix includes the following change:

Quoted 9 lines

- Added new internal enum type virtio_backend_type to distinguish virtio-net, virtio-crypto, and external device types.
- Added new API rte_vhost_crypto_driver_start to distinguish between virtio-net and virtio-crypto built-in drivers initialization.
- Added new internal function for the vhost library to use different feature flags when initializing virtio-crypto.

This last one should be part of a dedicated patch.

Quoted 1 line
Fixes 2ab58f20db51 ("vhost: refactor virtio ready check")

Please remove that Fixes tag.
Looking in this patch, we can see it worked by luck. Thanks to the v20.08 refactoring, we spotted that Vhost crypto was broken.

Quoted 77 lines
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 +++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/socket.c              | 44 +++++++++++++++++++++-----
 lib/librte_vhost/vhost.h               |  1 -
 lib/librte_vhost/vhost_crypto.c        | 35 ++++++++++++--------
 lib/librte_vhost/vhost_user.h          | 12 +++++++
 7 files changed, 84 insertions(+), 24 deletions(-)
examples/vhost_crypto/main.c +2 -1
index 11b022e81..ef64e96de 100644
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo->socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start vhost.\n");
 				goto error_exit;
lib/librte_vhost/rte_vhost_crypto.h +12 -0
index b54d61db6..c809c46a2 100644
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
lib/librte_vhost/rte_vhost_version.map +1 -0
index 20b4abcb4..a454d5f41 100644
@@ -48,6 +48,7 @@ EXPERIMENTAL {
 	rte_vhost_get_vring_base;
 	rte_vhost_set_vring_base;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
lib/librte_vhost/socket.c +1 -1
index 73e1dca95..3de2da836 100644
@@ -39,7 +39,7 @@ struct vhost_user_socket {
 	bool reconnect;
 	bool dequeue_zero_copy;
 	bool iommu_support;
-	bool use_builtin_virtio_net;
+	enum virtio_backend_type backend_type;
 	bool extbuf;
 	bool linearbuf;
 	bool async_copy;
@@ -225,7 +225,15 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	size = strnlen(vsocket->path, PATH_MAX);

lib/librte_vhost/socket.c vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) · line 234

Quoted 10 lines
lib/librte_vhost/socket.c +7 -1
 	vhost_set_ifname(vid, vsocket->path, size);
 
-	vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);
+	vhost_set_builtin_virtio_net(vid,
+			vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET ?
+					true : false);
+
+	if (vsocket->backend_type == VIRTIO_DEV_BUILTIN_CRYPTO) {
+		vhost_crypto_set_feature_flags(&vsocket->supported_features,
+				&vsocket->protocol_features);

It should not be done like that, we have API for that. We don't want to call vhost_crypto API in socket.c

Features supported by the application/backend have to be set between rte_vhost_driver_register() and rte_vhost_driver_start() calls.

It think it can be done in rte_vhost_crypto_driver_start() function, please see below.

Quoted 91 lines
lib/librte_vhost/socket.c +28 -6
+		vsocket->features = vsocket->supported_features;
+	}
 
 	vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
 
@@ -636,7 +644,7 @@ rte_vhost_driver_disable_features(const char *path, uint64_t features)
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 
-	/* Note that use_builtin_virtio_net is not affected by this function
+	/* Note that backend type is not affected by this function
 	 * since callers may want to selectively disable features of the
 	 * built-in vhost net device backend.
 	 */
@@ -685,7 +693,7 @@ rte_vhost_driver_set_features(const char *path, uint64_t features)
 		/* Anyone setting feature bits is implementing their own vhost
 		 * device backend.
 		 */
-		vsocket->use_builtin_virtio_net = false;
+		vsocket->backend_type = VIRTIO_DEV_UNKNOWN;
 	}
 	pthread_mutex_unlock(&vhost_user.mutex);
 
@@ -913,7 +921,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 	 * rte_vhost_driver_set_features(), which will overwrite following
 	 * two values.
 	 */
-	vsocket->use_builtin_virtio_net = true;
+	vsocket->backend_type = VIRTIO_DEV_BUILTIN_NET;
 	vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->protocol_features  = VHOST_USER_PROTOCOL_FEATURES;
@@ -1164,10 +1172,17 @@ vhost_driver_callback_get(const char *path)
 }
 
 int
-rte_vhost_driver_start(const char *path)
+vhost_driver_start(const char *path, enum virtio_backend_type backend_type)
 {
 	struct vhost_user_socket *vsocket;
 	static pthread_t fdset_tid;
+	int ret;
+
+	if (backend_type <= VIRTIO_DEV_UNKNOWN ||
+			backend_type > VIRTIO_DEV_BUILTIN_CRYPTO) {
+		VHOST_LOG_CONFIG(ERR, "Wrong backend type\n");
+		return -1;
+	}
 
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
@@ -1200,7 +1215,20 @@ rte_vhost_driver_start(const char *path)
 	}
 
 	if (vsocket->is_server)
-		return vhost_user_start_server(vsocket);
+		ret = vhost_user_start_server(vsocket);
 	else
-		return vhost_user_start_client(vsocket);
+		ret = vhost_user_start_client(vsocket);
+
+	if (ret < 0)
+		return ret;
+
+	vsocket->backend_type = backend_type;
+
+	return 0;
+}
+
+int
+rte_vhost_driver_start(const char *path)
+{
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_NET);
 }
lib/librte_vhost/vhost.h +0 -1
index 73a1ed889..1da9ed871 100644
@@ -352,7 +352,6 @@ struct vring_packed_desc_event {
 				(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
 				(1ULL << VIRTIO_F_RING_PACKED))
 
-
 struct guest_page {
 	uint64_t guest_phys_addr;
 	uint64_t host_phys_addr;
lib/librte_vhost/vhost_crypto.c +0 -0
index e08f9c6d7..e9c6702c2 100644

lib/librte_vhost/vhost_crypto.c line 42

Quoted 8 lines
lib/librte_vhost/vhost_crypto.c +0 -5
@@ -35,13 +35,13 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |			\
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |			\

The two above lines are not Virtio features, how can it have possibly work in the past?

lib/librte_vhost/vhost_crypto.c line 43

Quoted 8 lines
lib/librte_vhost/vhost_crypto.c +6 -2
-		(1 << VIRTIO_NET_F_CTRL_VQ) |				\
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |			\
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |			\
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |				\
+		(1ULL << VHOST_USER_PROTOCOL_F_CONFIG) |		\

Ouch, VHOST_USER_PROTOCOL_F_CONFIG is not a Virtio feature, but a Vhost- user protocol feature. Please remove that in a dedicated patch.

lib/librte_vhost/vhost_crypto.c line 44

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))

Why is this now necessary? I don't see the link with the purpose of the patch.

I think I understand now! I bet that it just means that previously, VHOST_USER_GET_FEATURES was sent before Vhost-crypto would call rte_vhost_driver_set_features(), which makes a lot of sense as I said when I was surprised .new_device() was called without features not being negotiated.

It was really working by luck.

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +0 -0
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1409

Quoted 10 lines
lib/librte_vhost/vhost_crypto.c +7 -0
@@ -1400,6 +1400,20 @@ vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,
 	return processed;
 }
 
+void
+vhost_crypto_set_feature_flags(uint64_t *feature_flags,
+		uint64_t *protocol_feature_flags)
+{
+	*feature_flags = VIRTIO_CRYPTO_FEATURES;
+	*protocol_feature_flags |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+}

So above function can be removed.

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1413

Quoted 3 lines
lib/librte_vhost/vhost_crypto.c +3 -0
+int
+rte_vhost_crypto_driver_start(const char *path)
+{

Here we set supported Virtio and Vhost-usuer protocol features:

	int ret;

	ret = rte_vhost_driver_set_features(path, VIRTIO_CRYPTO_FEATURES);
	if (ret)
		return -1;

	ret = rte_vhost_driver_get_protocol_features(path, &protocol_features);
	if (ret)
		return -1;
	protocol_features |= VHOST_USER_PROTOCOL_F_CONFIG;
	ret = rte_vhost_driver_set_protocol_features(path, protocol_features);
	if (ret)
		return -1;
Quoted 50 lines
lib/librte_vhost/vhost_crypto.c +3 -7
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1431,6 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
lib/librte_vhost/vhost_user.h +12 -0
index 16fe03f88..d28da17dd 100644
@@ -158,6 +158,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
+/* virtio backend types */
+enum virtio_backend_type {
+	VIRTIO_DEV_UNKNOWN = 0, /* Likely external */
+	VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */
+	VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */
+};
 
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
@@ -167,5 +173,11 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
 		int *fd_num);
 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
+int vhost_driver_start(const char *path,
+		enum virtio_backend_type backend_type);
+
+/* vhost_crypto.c */
+void vhost_crypto_set_feature_flags(uint64_t *feature_flags,
+		uint64_t *protocol_feature_flags);
 
 #endif
#2 lore raw

Hi Maxime,

Quoted 31 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, October 2, 2020 1:18 PM
To: Zhang, Roy Fan <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Liu, Changpeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] vhost/crypto: fix initialization.

Hi Fan,

Thanks for working on this.

The commit message should not contain dot, please remove it in v2.

Quoted 5 lines · Fan Zhang

This patch fixes the problem that vhost crypto cannot be initialized due to the different requirement between built-in virtio-net and virtio-crypto. The fix includes the following change:

Quoted 9 lines

- Added new internal enum type virtio_backend_type to distinguish virtio-net, virtio-crypto, and external device types.
- Added new API rte_vhost_crypto_driver_start to distinguish between virtio-net and virtio-crypto built-in drivers initialization.
- Added new internal function for the vhost library to use different feature flags when initializing virtio-crypto.

Quoted 1 line

This last one should be part of a dedicated patch.

Will do.

Quoted 106 lines
Quoted 3 lines
Fixes 2ab58f20db51 ("vhost: refactor virtio ready check")

Please remove that Fixes tag.
Looking in this patch, we can see it worked by luck. Thanks to the v20.08 refactoring, we spotted that Vhost crypto was broken.

Quoted 13 lines
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 +++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/socket.c              | 44 +++++++++++++++++++++-----
 lib/librte_vhost/vhost.h               |  1 -
 lib/librte_vhost/vhost_crypto.c        | 35 ++++++++++++--------
 lib/librte_vhost/vhost_user.h          | 12 +++++++
 7 files changed, 84 insertions(+), 24 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/examples/vhost_crypto/main.c

examples/vhost_crypto/main.c main(int argc, char *argv[]) · line 605

Quoted 13 lines

index 11b022e81..ef64e96de 100644

examples/vhost_crypto/main.c +2 -1
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo-
 socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start

vhost.\n");

Review

Quoted 2 lines
examples/vhost_crypto/main.c +0 -0
 				goto error_exit;
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_crypto.h

Review

Quoted 23 lines

index b54d61db6..c809c46a2 100644

lib/librte_vhost/rte_vhost_crypto.h +12 -0
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_version.map

lib/librte_vhost/socket.c vhost_user_add_connection(int fd, struct

Quoted 25 lines

index 20b4abcb4..a454d5f41 100644

lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -48,6 +48,7 @@ EXPERIMENTAL {
 	rte_vhost_get_vring_base;
 	rte_vhost_set_vring_base;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
lib/librte_vhost/socket.c +1 -1
index 73e1dca95..3de2da836 100644
@@ -39,7 +39,7 @@ struct vhost_user_socket {
 	bool reconnect;
 	bool dequeue_zero_copy;
 	bool iommu_support;
-	bool use_builtin_virtio_net;
+	enum virtio_backend_type backend_type;
 	bool extbuf;
 	bool linearbuf;
 	bool async_copy;
@@ -225,7 +225,15 @@ vhost_user_add_connection(int fd, struct

vhost_user_socket *vsocket)

lib/librte_vhost/socket.c vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)

Quoted 6 lines
lib/librte_vhost/socket.c +2 -1
 	size = strnlen(vsocket->path, PATH_MAX);
 	vhost_set_ifname(vid, vsocket->path, size);
 
-	vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);
+	vhost_set_builtin_virtio_net(vid,
+			vsocket->backend_type ==

VIRTIO_DEV_BUILTIN_NET ?

lib/librte_vhost/socket.c vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) · line 234

Quoted 6 lines
lib/librte_vhost/socket.c +5 -0
+					true : false);
+
+	if (vsocket->backend_type == VIRTIO_DEV_BUILTIN_CRYPTO) {
+		vhost_crypto_set_feature_flags(&vsocket-
 supported_features,
+				&vsocket->protocol_features);

It should not be done like that, we have API for that. We don't want to call vhost_crypto API in socket.c

Quoted 2 lines

Features supported by the application/backend have to be set between rte_vhost_driver_register() and rte_vhost_driver_start() calls.

I agree. This is actually the place I am not certain for the patch.

Quoted 111 lines

It think it can be done in rte_vhost_crypto_driver_start() function, please see below.

lib/librte_vhost/socket.c rte_vhost_driver_disable_features(const char

Quoted 6 lines
lib/librte_vhost/socket.c +2 -0
+		vsocket->features = vsocket->supported_features;
+	}
 
 	vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
@@ -636,7 +644,7 @@ rte_vhost_driver_disable_features(const char

*path, uint64_t features)

lib/librte_vhost/socket.c rte_vhost_driver_set_features(const char *path,

Quoted 9 lines
lib/librte_vhost/socket.c +1 -1
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 
-	/* Note that use_builtin_virtio_net is not affected by this function
+	/* Note that backend type is not affected by this function
 	 * since callers may want to selectively disable features of the
 	 * built-in vhost net device backend.
 	 */
@@ -685,7 +693,7 @@ rte_vhost_driver_set_features(const char *path,

uint64_t features)

lib/librte_vhost/socket.c rte_vhost_driver_set_features(const char *path, · line 693

Quoted 1 line
lib/librte_vhost/socket.c +0 -0
 		/* Anyone setting feature bits is implementing their own

vhost

lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path,

Quoted 8 lines
lib/librte_vhost/socket.c +1 -1
 		 * device backend.
 		 */
-		vsocket->use_builtin_virtio_net = false;
+		vsocket->backend_type = VIRTIO_DEV_UNKNOWN;
 	}
 	pthread_mutex_unlock(&vhost_user.mutex);
 
@@ -913,7 +921,7 @@ rte_vhost_driver_register(const char *path,

uint64_t flags)

lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path, uint64_t flags)

Quoted 6 lines
lib/librte_vhost/socket.c +1 -1
 	 * rte_vhost_driver_set_features(), which will overwrite following
 	 * two values.
 	 */
-	vsocket->use_builtin_virtio_net = true;
+	vsocket->backend_type = VIRTIO_DEV_BUILTIN_NET;
 	vsocket->supported_features =

VIRTIO_NET_SUPPORTED_FEATURES;

lib/librte_vhost/socket.c vhost_driver_callback_get(const char *path) · line 1175

Quoted 8 lines
lib/librte_vhost/socket.c +1 -1
 	vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->protocol_features  = VHOST_USER_PROTOCOL_FEATURES;
@@ -1164,10 +1172,17 @@ vhost_driver_callback_get(const char *path)
 }
 
 int
-rte_vhost_driver_start(const char *path)
+vhost_driver_start(const char *path, enum virtio_backend_type

backend_type)

Review

Quoted 49 lines
lib/librte_vhost/socket.c +22 -2
 {
 	struct vhost_user_socket *vsocket;
 	static pthread_t fdset_tid;
+	int ret;
+
+	if (backend_type <= VIRTIO_DEV_UNKNOWN ||
+			backend_type > VIRTIO_DEV_BUILTIN_CRYPTO) {
+		VHOST_LOG_CONFIG(ERR, "Wrong backend type\n");
+		return -1;
+	}
 
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
@@ -1200,7 +1215,20 @@ rte_vhost_driver_start(const char *path)
 	}
 
 	if (vsocket->is_server)
-		return vhost_user_start_server(vsocket);
+		ret = vhost_user_start_server(vsocket);
 	else
-		return vhost_user_start_client(vsocket);
+		ret = vhost_user_start_client(vsocket);
+
+	if (ret < 0)
+		return ret;
+
+	vsocket->backend_type = backend_type;
+
+	return 0;
+}
+
+int
+rte_vhost_driver_start(const char *path)
+{
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_NET);
 }
lib/librte_vhost/vhost.h +0 -1
index 73a1ed889..1da9ed871 100644
@@ -352,7 +352,6 @@ struct vring_packed_desc_event {
 				(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
 				(1ULL << VIRTIO_F_RING_PACKED))
 
-
 struct guest_page {
 	uint64_t guest_phys_addr;
 	uint64_t host_phys_addr;
(quoted diff) +0 -0

b/lib/librte_vhost/vhost_crypto.c

lib/librte_vhost/vhost_crypto.c line 38

Quoted 8 lines

index e08f9c6d7..e9c6702c2 100644

lib/librte_vhost/vhost_crypto.c +0 -1
@@ -35,13 +35,13 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY)

| \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |
	\
Quoted 8 lines

lib/librte_vhost/vhost_crypto.c line 41

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +0 -2
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |
	\

The two above lines are not Virtio features, how can it have possibly work in the past?

Not sure - amazingly it worked :-). Sorry for made the mistake in the first place. By then it was my first virtio task.

Quoted 16 lines

lib/librte_vhost/vhost_crypto.c line 43

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_NET_F_CTRL_VQ) |
	\

lib/librte_vhost/vhost_crypto.c line 38

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +1 -1
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL <<

VIRTIO_F_NOTIFY_ON_EMPTY) | \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
	\

lib/librte_vhost/vhost_crypto.c line 40

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |
	\

lib/librte_vhost/vhost_crypto.c line 43

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VHOST_USER_PROTOCOL_F_CONFIG) |
	\
Quoted 8 lines

Ouch, VHOST_USER_PROTOCOL_F_CONFIG is not a Virtio feature, but a Vhost-
user protocol feature. Please remove that in a dedicated patch.

lib/librte_vhost/vhost_crypto.c line 44

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))

Why is this now necessary? I don't see the link with the purpose of the patch.

Without this line 1 out of 2 times the feature negotiation will fail. I was using Qemu 3.0.1 for my test.

Quoted 8 lines

I think I understand now! I bet that it just means that previously, VHOST_USER_GET_FEATURES was sent before Vhost-crypto would call rte_vhost_driver_set_features(), which makes a lot of sense as I said when I was surprised .new_device() was called without features not being negotiated.

It was really working by luck.

You are right.

Quoted 43 lines

lib/librte_vhost/vhost_crypto.c

Quoted 5 lines
lib/librte_vhost/vhost_crypto.c +0 -0
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1400,20 @@

vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 9 lines
lib/librte_vhost/vhost_crypto.c +6 -0
 	return processed;
 }
 
+void
+vhost_crypto_set_feature_flags(uint64_t *feature_flags,
+		uint64_t *protocol_feature_flags)
+{
+	*feature_flags = VIRTIO_CRYPTO_FEATURES;
+	*protocol_feature_flags |= (1ULL <<

VHOST_USER_PROTOCOL_F_CONFIG);

lib/librte_vhost/vhost_crypto.c line 1409

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+}

So above function can be removed.

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1413

Quoted 3 lines
lib/librte_vhost/vhost_crypto.c +3 -0
+int
+rte_vhost_crypto_driver_start(const char *path)
+{

Here we set supported Virtio and Vhost-usuer protocol features:

	int ret;

	ret = rte_vhost_driver_set_features(path,
VIRTIO_CRYPTO_FEATURES);
	if (ret)
		return -1;

	ret = rte_vhost_driver_get_protocol_features(path,
&protocol_features);
	if (ret)
		return -1;
	protocol_features |= VHOST_USER_PROTOCOL_F_CONFIG;
	ret = rte_vhost_driver_set_protocol_features(path,
protocol_features);
	if (ret)
		return -1;
Quoted 1 line

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1414

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);

Thanks. I will prepare v2 right away with your change proposed.

Regards,
Fan

Quoted 53 lines

lib/librte_vhost/vhost_crypto.c rte_vhost_crypto_create(int vid, uint8_t

Quoted 6 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1431,6 @@ rte_vhost_crypto_create(int vid, uint8_t

cryptodev_id,

lib/librte_vhost/vhost_user.h int vhost_user_iotlb_miss(struct virtio_net *dev,

Quoted 31 lines
lib/librte_vhost/vhost_crypto.c +0 -7
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
lib/librte_vhost/vhost_user.h +6 -0
index 16fe03f88..d28da17dd 100644
@@ -158,6 +158,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
+/* virtio backend types */
+enum virtio_backend_type {
+	VIRTIO_DEV_UNKNOWN = 0, /* Likely external */
+	VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */
+	VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */
+};
 
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
@@ -167,5 +173,11 @@ int vhost_user_iotlb_miss(struct virtio_net *dev,

uint64_t iova, uint8_t perm);

lib/librte_vhost/vhost_user.h int vhost_user_iotlb_miss(struct virtio_net *dev, · line 173

Quoted 1 line
lib/librte_vhost/vhost_user.h +0 -0
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int

max_fds,

lib/librte_vhost/vhost_user.h int vhost_user_iotlb_miss(struct virtio_net *dev, · line 175

Quoted 2 lines
lib/librte_vhost/vhost_user.h +0 -0
 		int *fd_num);
 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int

fd_num);

Quoted 9 lines
lib/librte_vhost/vhost_user.h +6 -0
+int vhost_driver_start(const char *path,
+		enum virtio_backend_type backend_type);
+
+/* vhost_crypto.c */
+void vhost_crypto_set_feature_flags(uint64_t *feature_flags,
+		uint64_t *protocol_feature_flags);
 
 #endif
author
#3 lore raw

v2 cover vhost/crypto: fix initialization

In reply to Fan Zhang

This patch fixes the problem that vhost crypto cannot be initialized due to the different requirement between built-in virtio-net and virtio-crypto. The fix includes the following change:

- Added new internal enum type virtio_backend_type to distinguish virtio-net, virtio-crypto, and external device types.
- Added new API rte_vhost_crypto_driver_start to distinguish between virtio-net and virtio-crypto built-in drivers initialization.

v2:
- Removed socket.c setting vhost crypto features.
- Fixed incorrect feature flag.
- Rebased on top of latest master.

Fan Zhang (2):
vhost: add backend type in driver start
vhost/crypto: fix feature negotiation

 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/socket.c              | 39 +++++++++++++++++++-----
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 lib/librte_vhost/vhost_user.h          |  8 +++++
 6 files changed, 81 insertions(+), 23 deletions(-)
Signature · 1 line
2.20.1
author
#4 lore raw

PATCH v2 1/2 vhost: add backend type in driver start

This patch adds an internal driver start function with a newly added backend type identifier as parameter. With this way different built-in driver types (net, crypto) can be identified.

---
 lib/librte_vhost/socket.c     | 39 ++++++++++++++++++++++++++++-------
 lib/librte_vhost/vhost_user.h |  8 +++++++
 2 files changed, 39 insertions(+), 8 deletions(-)
lib/librte_vhost/socket.c +31 -8
index 0169d3648..a53e536ac 100644
@@ -38,7 +38,7 @@ struct vhost_user_socket {
 	bool is_server;
 	bool reconnect;
 	bool iommu_support;
-	bool use_builtin_virtio_net;
+	enum virtio_backend_type backend_type;
 	bool extbuf;
 	bool linearbuf;
 	bool async_copy;
@@ -224,7 +224,9 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	size = strnlen(vsocket->path, PATH_MAX);
 	vhost_set_ifname(vid, vsocket->path, size);
 
-	vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);
+	vhost_set_builtin_virtio_net(vid,
+			vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET ?
+					true : false);
 
 	vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
 
@@ -632,7 +634,7 @@ rte_vhost_driver_disable_features(const char *path, uint64_t features)
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 
-	/* Note that use_builtin_virtio_net is not affected by this function
+	/* Note that backend type is not affected by this function
 	 * since callers may want to selectively disable features of the
 	 * built-in vhost net device backend.
 	 */
@@ -681,7 +683,8 @@ rte_vhost_driver_set_features(const char *path, uint64_t features)
 		/* Anyone setting feature bits is implementing their own vhost
 		 * device backend.
 		 */
-		vsocket->use_builtin_virtio_net = false;
+		if (vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET)
+			vsocket->backend_type = VIRTIO_DEV_UNKNOWN;
 	}
 	pthread_mutex_unlock(&vhost_user.mutex);
 
@@ -899,7 +902,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 	 * rte_vhost_driver_set_features(), which will overwrite following
 	 * two values.
 	 */
-	vsocket->use_builtin_virtio_net = true;
+	vsocket->backend_type = VIRTIO_DEV_BUILTIN_NET;
 	vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->protocol_features  = VHOST_USER_PROTOCOL_FEATURES;
@@ -1117,10 +1120,17 @@ vhost_driver_callback_get(const char *path)
 }
 
 int
-rte_vhost_driver_start(const char *path)
+vhost_driver_start(const char *path, enum virtio_backend_type backend_type)
 {
 	struct vhost_user_socket *vsocket;
 	static pthread_t fdset_tid;
+	int ret;
+
+	if (backend_type <= VIRTIO_DEV_UNKNOWN ||
+			backend_type > VIRTIO_DEV_BUILTIN_CRYPTO) {
+		VHOST_LOG_CONFIG(ERR, "Wrong backend type\n");
+		return -1;
+	}
 
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
@@ -1153,7 +1163,20 @@ rte_vhost_driver_start(const char *path)
 	}
 
 	if (vsocket->is_server)
-		return vhost_user_start_server(vsocket);
+		ret = vhost_user_start_server(vsocket);
 	else
-		return vhost_user_start_client(vsocket);
+		ret = vhost_user_start_client(vsocket);
+
+	if (ret < 0)
+		return ret;
+
+	vsocket->backend_type = backend_type;
+
+	return 0;
+}
+
+int
+rte_vhost_driver_start(const char *path)
+{
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_NET);
 }
lib/librte_vhost/vhost_user.h +8 -0
index 16fe03f88..9f526e676 100644
@@ -158,6 +158,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
+/* virtio backend types */
+enum virtio_backend_type {
+	VIRTIO_DEV_UNKNOWN = 0, /* Likely external */
+	VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */
+	VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */
+};
 
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
@@ -167,5 +173,7 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
 		int *fd_num);
 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
+int vhost_driver_start(const char *path,
+		enum virtio_backend_type backend_type);
 
 #endif
Signature · 1 line
2.20.1
#5 lore raw

Re: [dpdk-dev] [dpdk-dev v2 1/2] vhost: add backend type in driver start

Hi Fan,

Quoted 87 lines · Fan Zhang

This patch adds an internal driver start function with a newly added backend type identifier as parameter. With this way different built-in driver types (net, crypto) can be identified.

---
 lib/librte_vhost/socket.c     | 39 ++++++++++++++++++++++++++++-------
 lib/librte_vhost/vhost_user.h |  8 +++++++
 2 files changed, 39 insertions(+), 8 deletions(-)
lib/librte_vhost/socket.c +17 -7
index 0169d3648..a53e536ac 100644
@@ -38,7 +38,7 @@ struct vhost_user_socket {
 	bool is_server;
 	bool reconnect;
 	bool iommu_support;
-	bool use_builtin_virtio_net;
+	enum virtio_backend_type backend_type;
 	bool extbuf;
 	bool linearbuf;
 	bool async_copy;
@@ -224,7 +224,9 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	size = strnlen(vsocket->path, PATH_MAX);
 	vhost_set_ifname(vid, vsocket->path, size);
 
-	vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);
+	vhost_set_builtin_virtio_net(vid,
+			vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET ?
+					true : false);
 
 	vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
 
@@ -632,7 +634,7 @@ rte_vhost_driver_disable_features(const char *path, uint64_t features)
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 
-	/* Note that use_builtin_virtio_net is not affected by this function
+	/* Note that backend type is not affected by this function
 	 * since callers may want to selectively disable features of the
 	 * built-in vhost net device backend.
 	 */
@@ -681,7 +683,8 @@ rte_vhost_driver_set_features(const char *path, uint64_t features)
 		/* Anyone setting feature bits is implementing their own vhost
 		 * device backend.
 		 */
-		vsocket->use_builtin_virtio_net = false;
+		if (vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET)
+			vsocket->backend_type = VIRTIO_DEV_UNKNOWN;
 	}
 	pthread_mutex_unlock(&vhost_user.mutex);
 
@@ -899,7 +902,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 	 * rte_vhost_driver_set_features(), which will overwrite following
 	 * two values.
 	 */
-	vsocket->use_builtin_virtio_net = true;
+	vsocket->backend_type = VIRTIO_DEV_BUILTIN_NET;
 	vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->protocol_features  = VHOST_USER_PROTOCOL_FEATURES;
@@ -1117,10 +1120,17 @@ vhost_driver_callback_get(const char *path)
 }
 
 int
-rte_vhost_driver_start(const char *path)
+vhost_driver_start(const char *path, enum virtio_backend_type backend_type)
 {
 	struct vhost_user_socket *vsocket;
 	static pthread_t fdset_tid;
+	int ret;
+
+	if (backend_type <= VIRTIO_DEV_UNKNOWN ||
+			backend_type > VIRTIO_DEV_BUILTIN_CRYPTO) {
+		VHOST_LOG_CONFIG(ERR, "Wrong backend type\n");
+		return -1;
+	}
 
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
@@ -1153,7 +1163,20 @@ rte_vhost_driver_start(const char *path)
 	}
 
 	if (vsocket->is_server)
-		return vhost_user_start_server(vsocket);
+		ret = vhost_user_start_server(vsocket);

lib/librte_vhost/socket.c rte_vhost_driver_start(const char *path) · line 1175

Quoted 10 lines
lib/librte_vhost/socket.c +8 -1
 	else
-		return vhost_user_start_client(vsocket);
+		ret = vhost_user_start_client(vsocket);
+
+	if (ret < 0)
+		return ret;
+
+	vsocket->backend_type = backend_type;
+
+	return 0;

Looking at it again, I think patch 1 is not necessary. Patch 2 should be enough and would be easier to backport.

What do you think?

Regards,
Maxime

Quoted 33 lines
lib/librte_vhost/socket.c +6 -0
+}
+
+int
+rte_vhost_driver_start(const char *path)
+{
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_NET);
 }
lib/librte_vhost/vhost_user.h +8 -0
index 16fe03f88..9f526e676 100644
@@ -158,6 +158,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
+/* virtio backend types */
+enum virtio_backend_type {
+	VIRTIO_DEV_UNKNOWN = 0, /* Likely external */
+	VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */
+	VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */
+};
 
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
@@ -167,5 +173,7 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
 		int *fd_num);
 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
+int vhost_driver_start(const char *path,
+		enum virtio_backend_type backend_type);
 
 #endif
#6 lore raw

Re: [dpdk-dev] [dpdk-dev v2 1/2] vhost: add backend type in driver start

Hi Maxime,

I think you are right :-)

Regards,
Fan

Quoted 162 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, October 6, 2020 8:54 AM
To: Zhang, Roy Fan <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Liu, Changpeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev v2 1/2] vhost: add backend type in driver start

Hi Fan,

lib/librte_vhost/socket.c vhost_user_add_connection(int fd, struct

Quoted 24 lines · Fan Zhang

This patch adds an internal driver start function with a newly added backend type identifier as parameter. With this way different built-in driver types (net, crypto) can be identified.

---
 lib/librte_vhost/socket.c     | 39 ++++++++++++++++++++++++++++-------
 lib/librte_vhost/vhost_user.h |  8 +++++++
 2 files changed, 39 insertions(+), 8 deletions(-)
lib/librte_vhost/socket.c +1 -1
index 0169d3648..a53e536ac 100644
@@ -38,7 +38,7 @@ struct vhost_user_socket {
 	bool is_server;
 	bool reconnect;
 	bool iommu_support;
-	bool use_builtin_virtio_net;
+	enum virtio_backend_type backend_type;
 	bool extbuf;
 	bool linearbuf;
 	bool async_copy;
@@ -224,7 +224,9 @@ vhost_user_add_connection(int fd, struct

vhost_user_socket *vsocket)

lib/librte_vhost/socket.c vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)

Quoted 6 lines
lib/librte_vhost/socket.c +2 -1
 	size = strnlen(vsocket->path, PATH_MAX);
 	vhost_set_ifname(vid, vsocket->path, size);
 
-	vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);
+	vhost_set_builtin_virtio_net(vid,
+			vsocket->backend_type ==

VIRTIO_DEV_BUILTIN_NET ?

lib/librte_vhost/socket.c rte_vhost_driver_disable_features(const char

Quoted 5 lines
lib/librte_vhost/socket.c +1 -0
+					true : false);
 
 	vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
 
@@ -632,7 +634,7 @@ rte_vhost_driver_disable_features(const char

*path, uint64_t features)

lib/librte_vhost/socket.c rte_vhost_driver_set_features(const char *path,

Quoted 9 lines
lib/librte_vhost/socket.c +1 -1
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 
-	/* Note that use_builtin_virtio_net is not affected by this function
+	/* Note that backend type is not affected by this function
 	 * since callers may want to selectively disable features of the
 	 * built-in vhost net device backend.
 	 */
@@ -681,7 +683,8 @@ rte_vhost_driver_set_features(const char *path,

uint64_t features)

lib/librte_vhost/socket.c rte_vhost_driver_set_features(const char *path, · line 683

Quoted 1 line
lib/librte_vhost/socket.c +0 -0
 		/* Anyone setting feature bits is implementing their own

vhost

lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path,

Quoted 9 lines
lib/librte_vhost/socket.c +2 -1
 		 * device backend.
 		 */
-		vsocket->use_builtin_virtio_net = false;
+		if (vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET)
+			vsocket->backend_type = VIRTIO_DEV_UNKNOWN;
 	}
 	pthread_mutex_unlock(&vhost_user.mutex);
 
@@ -899,7 +902,7 @@ rte_vhost_driver_register(const char *path,

uint64_t flags)

lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path, uint64_t flags)

Quoted 6 lines
lib/librte_vhost/socket.c +1 -1
 	 * rte_vhost_driver_set_features(), which will overwrite following
 	 * two values.
 	 */
-	vsocket->use_builtin_virtio_net = true;
+	vsocket->backend_type = VIRTIO_DEV_BUILTIN_NET;
 	vsocket->supported_features =

VIRTIO_NET_SUPPORTED_FEATURES;

lib/librte_vhost/socket.c vhost_driver_callback_get(const char *path) · line 1123

Quoted 8 lines
lib/librte_vhost/socket.c +1 -1
 	vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
 	vsocket->protocol_features  = VHOST_USER_PROTOCOL_FEATURES;
@@ -1117,10 +1120,17 @@ vhost_driver_callback_get(const char *path)
 }
 
 int
-rte_vhost_driver_start(const char *path)
+vhost_driver_start(const char *path, enum virtio_backend_type

backend_type)

Quoted 19 lines
lib/librte_vhost/socket.c +8 -1
 {
 	struct vhost_user_socket *vsocket;
 	static pthread_t fdset_tid;
+	int ret;
+
+	if (backend_type <= VIRTIO_DEV_UNKNOWN ||
+			backend_type > VIRTIO_DEV_BUILTIN_CRYPTO) {
+		VHOST_LOG_CONFIG(ERR, "Wrong backend type\n");
+		return -1;
+	}
 
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
@@ -1153,7 +1163,20 @@ rte_vhost_driver_start(const char *path)
 	}
 
 	if (vsocket->is_server)
-		return vhost_user_start_server(vsocket);
+		ret = vhost_user_start_server(vsocket);

lib/librte_vhost/socket.c rte_vhost_driver_start(const char *path) · line 1175

Quoted 10 lines
lib/librte_vhost/socket.c +8 -1
 	else
-		return vhost_user_start_client(vsocket);
+		ret = vhost_user_start_client(vsocket);
+
+	if (ret < 0)
+		return ret;
+
+	vsocket->backend_type = backend_type;
+
+	return 0;

Looking at it again, I think patch 1 is not necessary. Patch 2 should be enough and would be easier to backport.

What do you think?

Regards,
Maxime

lib/librte_vhost/vhost_user.h int vhost_user_iotlb_miss(struct virtio_net *dev,

Quoted 25 lines
lib/librte_vhost/socket.c +6 -0
+}
+
+int
+rte_vhost_driver_start(const char *path)
+{
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_NET);
 }
lib/librte_vhost/vhost_user.h +6 -0
index 16fe03f88..9f526e676 100644
@@ -158,6 +158,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
+/* virtio backend types */
+enum virtio_backend_type {
+	VIRTIO_DEV_UNKNOWN = 0, /* Likely external */
+	VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */
+	VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */
+};
 
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
@@ -167,5 +173,7 @@ int vhost_user_iotlb_miss(struct virtio_net *dev,

uint64_t iova, uint8_t perm);

lib/librte_vhost/vhost_user.h int vhost_user_iotlb_miss(struct virtio_net *dev, · line 173

Quoted 1 line
lib/librte_vhost/vhost_user.h +0 -0
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int

max_fds,

lib/librte_vhost/vhost_user.h int vhost_user_iotlb_miss(struct virtio_net *dev, · line 175

Quoted 2 lines
lib/librte_vhost/vhost_user.h +0 -0
 		int *fd_num);
 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int

fd_num);

Quoted 5 lines
lib/librte_vhost/vhost_user.h +2 -0
+int vhost_driver_start(const char *path,
+		enum virtio_backend_type backend_type);
 
 #endif
author
#7 lore raw

PATCH v2 2/2 vhost/crypto: fix feature negotiation

In reply to Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function implementation")
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)
examples/vhost_crypto/main.c +2 -1
index d78fd9b81..11ad49159 100644
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo->socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start vhost.\n");
 				goto error_exit;
lib/librte_vhost/rte_vhost_crypto.h +12 -0
index b54d61db6..c809c46a2 100644
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
lib/librte_vhost/rte_vhost_version.map +1 -0
index 55e98e557..9183d6f2f 100644
@@ -55,6 +55,7 @@ EXPERIMENTAL {
 	rte_vhost_driver_get_protocol_features;
 	rte_vhost_driver_get_queue_num;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
lib/librte_vhost/vhost_crypto.c +27 -14

59 lines not on this page · raw message

Signature · 1 line
2.20.1
#8 lore raw

Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Quoted 93 lines · Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function implementation")
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)
examples/vhost_crypto/main.c +2 -1
index d78fd9b81..11ad49159 100644
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo->socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start vhost.\n");
 				goto error_exit;
lib/librte_vhost/rte_vhost_crypto.h +12 -0
index b54d61db6..c809c46a2 100644
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
lib/librte_vhost/rte_vhost_version.map +1 -0
index 55e98e557..9183d6f2f 100644
@@ -55,6 +55,7 @@ EXPERIMENTAL {
 	rte_vhost_driver_get_protocol_features;
 	rte_vhost_driver_get_queue_num;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
lib/librte_vhost/vhost_crypto.c +6 -7
index e08f9c6d7..6195958d2 100644
@@ -35,13 +35,12 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |			\
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |			\
-		(1 << VIRTIO_NET_F_CTRL_VQ) |				\
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |			\
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |			\
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |				\
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1399,27 @@ vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,
 	return processed;
 }

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1410

Quoted 10 lines
lib/librte_vhost/vhost_crypto.c +9 -0
 
+int
+rte_vhost_crypto_driver_start(const char *path)
+{
+	uint64_t protocol_features;
+	int ret;
+
+	ret = rte_vhost_driver_set_features(path, VIRTIO_CRYPTO_FEATURES);
+	if (ret)
+		return -1;

As rte_vhost_driver_set_features is now called on time, use_builtin_virtio_net is set to false before the connection is established.

So it should be enough.

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1420

Quoted 9 lines
lib/librte_vhost/vhost_crypto.c +9 -0
+	ret = rte_vhost_driver_get_protocol_features(path, &protocol_features);
+	if (ret)
+		return -1;
+	protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+	ret = rte_vhost_driver_set_protocol_features(path, protocol_features);
+	if (ret)
+		return -1;
+
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);

We just have to remove the extra param.

I will to the change and apply it today so that you can test.

Thanks,
Maxime

Quoted 20 lines
lib/librte_vhost/vhost_crypto.c +2 -7
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1437,6 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
#9 lore raw

Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Hi Maxime,

Thanks I will verify it after you applied the patch.

Regards,
Fan

Quoted 179 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, October 6, 2020 9:10 AM
To: Zhang, Roy Fan <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Liu, Changpeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Quoted 10 lines · Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function implementation")

Review

Quoted 8 lines
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/examples/vhost_crypto/main.c

examples/vhost_crypto/main.c main(int argc, char *argv[]) · line 605

Quoted 13 lines

index d78fd9b81..11ad49159 100644

examples/vhost_crypto/main.c +2 -1
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo-
 socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start

vhost.\n");

Review

Quoted 2 lines
examples/vhost_crypto/main.c +0 -0
 				goto error_exit;
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_crypto.h

Review

Quoted 23 lines

index b54d61db6..c809c46a2 100644

lib/librte_vhost/rte_vhost_crypto.h +12 -0
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_version.map

Review

Quoted 12 lines

index 55e98e557..9183d6f2f 100644

lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -55,6 +55,7 @@ EXPERIMENTAL {
 	rte_vhost_driver_get_protocol_features;
 	rte_vhost_driver_get_queue_num;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
(quoted diff) +0 -0

b/lib/librte_vhost/vhost_crypto.c

lib/librte_vhost/vhost_crypto.c line 38

Quoted 8 lines

index e08f9c6d7..6195958d2 100644

lib/librte_vhost/vhost_crypto.c +0 -1
@@ -35,13 +35,12 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY)

| \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |
	\

lib/librte_vhost/vhost_crypto.c line 41

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +0 -2
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |
	\

lib/librte_vhost/vhost_crypto.c line 43

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_NET_F_CTRL_VQ) |
	\

lib/librte_vhost/vhost_crypto.c line 38

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +1 -1
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL <<

VIRTIO_F_NOTIFY_ON_EMPTY) | \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
	\

lib/librte_vhost/vhost_crypto.c line 40

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |
	\

lib/librte_vhost/vhost_crypto.c

Quoted 5 lines
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1399,27 @@

vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 10 lines
lib/librte_vhost/vhost_crypto.c +7 -0
 	return processed;
 }
 
+int
+rte_vhost_crypto_driver_start(const char *path)
+{
+	uint64_t protocol_features;
+	int ret;
+
+	ret = rte_vhost_driver_set_features(path,

VIRTIO_CRYPTO_FEATURES);

lib/librte_vhost/vhost_crypto.c line 1410

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+	if (ret)
+		return -1;

As rte_vhost_driver_set_features is now called on time, use_builtin_virtio_net is set to false before the connection is established.

So it should be enough.

lib/librte_vhost/vhost_crypto.c line 1411

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+	ret = rte_vhost_driver_get_protocol_features(path,

&protocol_features);

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +4 -0
+	if (ret)
+		return -1;
+	protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+	ret = rte_vhost_driver_set_protocol_features(path,

protocol_features);

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1420

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +4 -0
+	if (ret)
+		return -1;
+
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);

We just have to remove the extra param.

I will to the change and apply it today so that you can test.

Thanks,
Maxime

lib/librte_vhost/vhost_crypto.c rte_vhost_crypto_create(int vid, uint8_t

Quoted 6 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1437,6 @@ rte_vhost_crypto_create(int vid, uint8_t

cryptodev_id,

Quoted 14 lines
lib/librte_vhost/vhost_crypto.c +0 -7
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
#10 lore raw

Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Quoted 3 lines · Roy Fan

Hi Maxime,

Thanks I will verify it after you applied the patch.

Thanks,
Your patch is now on dpdk-next-virtio/main.
I would be glad if you could test it before Ferruh merges it.

Thanks,
Maxime

Quoted 183 lines

Regards,
Fan

Quoted 179 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, October 6, 2020 9:10 AM
To: Zhang, Roy Fan <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Liu, Changpeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Quoted 10 lines · Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function implementation")

Review

Quoted 8 lines
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/examples/vhost_crypto/main.c

examples/vhost_crypto/main.c main(int argc, char *argv[]) · line 605

Quoted 13 lines

index d78fd9b81..11ad49159 100644

examples/vhost_crypto/main.c +2 -1
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo-
 socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start

vhost.\n");

Review

Quoted 2 lines
examples/vhost_crypto/main.c +0 -0
 				goto error_exit;
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_crypto.h

Review

Quoted 23 lines

index b54d61db6..c809c46a2 100644

lib/librte_vhost/rte_vhost_crypto.h +12 -0
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_version.map

Review

Quoted 12 lines

index 55e98e557..9183d6f2f 100644

lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -55,6 +55,7 @@ EXPERIMENTAL {
 	rte_vhost_driver_get_protocol_features;
 	rte_vhost_driver_get_queue_num;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
(quoted diff) +0 -0

b/lib/librte_vhost/vhost_crypto.c

lib/librte_vhost/vhost_crypto.c line 38

Quoted 8 lines

index e08f9c6d7..6195958d2 100644

lib/librte_vhost/vhost_crypto.c +0 -1
@@ -35,13 +35,12 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY)

| \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |
	\

lib/librte_vhost/vhost_crypto.c line 41

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +0 -2
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |
	\

lib/librte_vhost/vhost_crypto.c line 43

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_NET_F_CTRL_VQ) |
	\

lib/librte_vhost/vhost_crypto.c line 38

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +1 -1
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL <<

VIRTIO_F_NOTIFY_ON_EMPTY) | \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
	\

lib/librte_vhost/vhost_crypto.c line 40

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |
	\

lib/librte_vhost/vhost_crypto.c

Quoted 5 lines
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1399,27 @@

vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 10 lines
lib/librte_vhost/vhost_crypto.c +7 -0
 	return processed;
 }
 
+int
+rte_vhost_crypto_driver_start(const char *path)
+{
+	uint64_t protocol_features;
+	int ret;
+
+	ret = rte_vhost_driver_set_features(path,

VIRTIO_CRYPTO_FEATURES);

lib/librte_vhost/vhost_crypto.c line 1410

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+	if (ret)
+		return -1;

As rte_vhost_driver_set_features is now called on time, use_builtin_virtio_net is set to false before the connection is established.

So it should be enough.

lib/librte_vhost/vhost_crypto.c line 1411

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+	ret = rte_vhost_driver_get_protocol_features(path,

&protocol_features);

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +4 -0
+	if (ret)
+		return -1;
+	protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+	ret = rte_vhost_driver_set_protocol_features(path,

protocol_features);

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1420

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +4 -0
+	if (ret)
+		return -1;
+
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);

We just have to remove the extra param.

I will to the change and apply it today so that you can test.

Thanks,
Maxime

lib/librte_vhost/vhost_crypto.c rte_vhost_crypto_create(int vid, uint8_t

Quoted 6 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1437,6 @@ rte_vhost_crypto_create(int vid, uint8_t

cryptodev_id,

Quoted 14 lines
lib/librte_vhost/vhost_crypto.c +0 -7
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
Tested-by
#11 lore raw

Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Best Regards
Jiang yu

Quoted 209 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Maxime Coquelin
Sent: Friday, October 9, 2020 3:36 PM
To: Zhang, Roy Fan <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Liu, Changpeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Quoted 3 lines · Roy Fan

Hi Maxime,

Thanks I will verify it after you applied the patch.

Thanks,
Your patch is now on dpdk-next-virtio/main.
I would be glad if you could test it before Ferruh merges it.

Thanks,
Maxime

Quoted 89 lines

Regards,
Fan

Quoted 86 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, October 6, 2020 9:10 AM
To: Zhang, Roy Fan <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Liu, Changpeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

Quoted 11 lines · Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function

implementation")
Cc: [email protected]

Review

Quoted 8 lines
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/examples/vhost_crypto/main.c

examples/vhost_crypto/main.c main(int argc, char *argv[]) · line 605

Quoted 13 lines

index d78fd9b81..11ad49159 100644

examples/vhost_crypto/main.c +2 -1
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo-
 socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start

vhost.\n");

Review

Quoted 2 lines
examples/vhost_crypto/main.c +0 -0
 				goto error_exit;
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_crypto.h

Review

Quoted 23 lines

index b54d61db6..c809c46a2 100644

lib/librte_vhost/rte_vhost_crypto.h +12 -0
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
(quoted diff) +0 -0

b/lib/librte_vhost/rte_vhost_version.map

Review

Quoted 12 lines

index 55e98e557..9183d6f2f 100644

lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -55,6 +55,7 @@ EXPERIMENTAL {
 	rte_vhost_driver_get_protocol_features;
 	rte_vhost_driver_get_queue_num;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
(quoted diff) +0 -0

b/lib/librte_vhost/vhost_crypto.c

Quoted 8 lines
Quoted 8 lines

lib/librte_vhost/vhost_crypto.c line 38

Quoted 8 lines

index e08f9c6d7..6195958d2 100644

lib/librte_vhost/vhost_crypto.c +0 -1
@@ -35,13 +35,12 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 <<

VIRTIO_F_NOTIFY_ON_EMPTY)

Quoted 15 lines
Quoted 15 lines

| \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |
	\

lib/librte_vhost/vhost_crypto.c line 41

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +0 -2
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |
	\

lib/librte_vhost/vhost_crypto.c line 43

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +0 -1
-		(1 << VIRTIO_NET_F_CTRL_VQ) |
	\

lib/librte_vhost/vhost_crypto.c line 38

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +1 -1
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL <<

VIRTIO_F_NOTIFY_ON_EMPTY) | \

lib/librte_vhost/vhost_crypto.c line 39

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
	\
Quoted 8 lines
Quoted 8 lines

lib/librte_vhost/vhost_crypto.c line 40

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |
	\

lib/librte_vhost/vhost_crypto.c line 42

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |
	\

lib/librte_vhost/vhost_crypto.c

Quoted 3 lines
lib/librte_vhost/vhost_crypto.c +1 -0
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)
	\
Quoted 63 lines
Quoted 62 lines

lib/librte_vhost/vhost_crypto.c

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +0 -1
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p)) @@
-1400,6 +1399,27 @@

vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 9 lines
lib/librte_vhost/vhost_crypto.c +6 -0
 	return processed;
 }
 
+int
+rte_vhost_crypto_driver_start(const char *path) {
+	uint64_t protocol_features;
+	int ret;
+
+	ret = rte_vhost_driver_set_features(path,

VIRTIO_CRYPTO_FEATURES);

lib/librte_vhost/vhost_crypto.c

Quoted 2 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+	if (ret)
+		return -1;

As rte_vhost_driver_set_features is now called on time, use_builtin_virtio_net is set to false before the connection is established.

So it should be enough.

lib/librte_vhost/vhost_crypto.c

Quoted 1 line
lib/librte_vhost/vhost_crypto.c +1 -0
+	ret = rte_vhost_driver_get_protocol_features(path,

&protocol_features);

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +4 -0
+	if (ret)
+		return -1;
+	protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+	ret = rte_vhost_driver_set_protocol_features(path,

protocol_features);

lib/librte_vhost/vhost_crypto.c vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops, · line 1420

Quoted 4 lines
lib/librte_vhost/vhost_crypto.c +4 -0
+	if (ret)
+		return -1;
+
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);

We just have to remove the extra param.

I will to the change and apply it today so that you can test.

Thanks,
Maxime

lib/librte_vhost/vhost_crypto.c rte_vhost_crypto_create(int vid, uint8_t

Quoted 6 lines
lib/librte_vhost/vhost_crypto.c +2 -0
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1437,6 @@ rte_vhost_crypto_create(int vid, uint8_t

cryptodev_id,

Quoted 14 lines
lib/librte_vhost/vhost_crypto.c +0 -7
 		return -EINVAL;
 	}
 
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {
Reviewed-by on v2 2/2
#12 lore raw

Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

In reply to Fan Zhang
Quoted 123 lines · Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function implementation")
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)
examples/vhost_crypto/main.c +2 -1
index d78fd9b81..11ad49159 100644
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
 			rte_vhost_driver_callback_register(lo->socket_files[j],
 				&virtio_crypto_device_ops);
 
-			ret = rte_vhost_driver_start(lo->socket_files[j]);
+			ret = rte_vhost_crypto_driver_start(
+					lo->socket_files[j]);
 			if (ret < 0)  {
 				RTE_LOG(ERR, USER1, "failed to start vhost.\n");
 				goto error_exit;
lib/librte_vhost/rte_vhost_crypto.h +12 -0
index b54d61db6..c809c46a2 100644
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
lib/librte_vhost/rte_vhost_version.map +1 -0
index 55e98e557..9183d6f2f 100644
@@ -55,6 +55,7 @@ EXPERIMENTAL {
 	rte_vhost_driver_get_protocol_features;
 	rte_vhost_driver_get_queue_num;
 	rte_vhost_crypto_create;
+	rte_vhost_crypto_driver_start;
 	rte_vhost_crypto_free;
 	rte_vhost_crypto_fetch_requests;
 	rte_vhost_crypto_finalize_requests;
lib/librte_vhost/vhost_crypto.c +27 -7
index e08f9c6d7..6195958d2 100644
@@ -35,13 +35,12 @@
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
-		(1 << VIRTIO_RING_F_INDIRECT_DESC) |			\
-		(1 << VIRTIO_RING_F_EVENT_IDX) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |			\
-		(1 << VIRTIO_CRYPTO_SERVICE_MAC) |			\
-		(1 << VIRTIO_NET_F_CTRL_VQ) |				\
-		(1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |	\
+		(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |			\
+		(1ULL << VIRTIO_RING_F_EVENT_IDX) |			\
+		(1ULL << VIRTIO_NET_F_CTRL_VQ) |			\
+		(1ULL << VIRTIO_F_VERSION_1) |				\
+		(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)					\
 	((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1399,27 @@ vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,
 	return processed;
 }
 
+int
+rte_vhost_crypto_driver_start(const char *path)
+{
+	uint64_t protocol_features;
+	int ret;
+
+	ret = rte_vhost_driver_set_features(path, VIRTIO_CRYPTO_FEATURES);
+	if (ret)
+		return -1;
+
+	ret = rte_vhost_driver_get_protocol_features(path, &protocol_features);
+	if (ret)
+		return -1;
+	protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+	ret = rte_vhost_driver_set_protocol_features(path, protocol_features);
+	if (ret)
+		return -1;
+
+	return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO);
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		struct rte_mempool *sess_pool,
@@ -1417,13 +1437,6 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 		return -EINVAL;
 	}
 

lib/librte_vhost/vhost_crypto.c rte_vhost_crypto_create(int vid, uint8_t cryptodev_id, · line 1442

Quoted 10 lines
lib/librte_vhost/vhost_crypto.c +0 -7
-	ret = rte_vhost_driver_set_features(dev->ifname,
-			VIRTIO_CRYPTO_FEATURES);
-	if (ret < 0) {
-		VC_LOG_ERR("Error setting features");
-		return -1;
-	}
-
 	vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (!vcrypto) {

Only for this patch:

Thanks,
Maxime

#13 lore raw

Re: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation

In reply to Fan Zhang
Quoted 9 lines · Fan Zhang

This patch fixes the feature negotiation for vhost crypto during initialization. The patch uses the newly created driver start function to inform the driver type with the fixed vhost features. In addtion the patch provides a new API specifically used by the application to start a vhost-crypto driver.

Fixes 939066d96563 ("vhost/crypto: add public function implementation")
Quoted 7 lines
---
 examples/vhost_crypto/main.c           |  3 +-
 lib/librte_vhost/rte_vhost_crypto.h    | 12 ++++++++
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/vhost_crypto.c        | 41 +++++++++++++++++---------
 4 files changed, 42 insertions(+), 15 deletions(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime