All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] vhost: support host notifier
@ 2018-06-08  3:22 Tiwei Bie
  2018-06-08  3:22 ` [PATCH v3 1/2] " Tiwei Bie
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Tiwei Bie @ 2018-06-08  3:22 UTC (permalink / raw)
  To: maxime.coquelin, dev

The host notifier support in vhost-user has been merged
into QEMU. This patch set enables the support for host
notifier in DPDK vhost-user and ifcvf driver.

The original subject is:
Extend vhost to support VFIO based accelerator

v3:
- Address the changes in QEMU
- Minor fixes and refinements

Tiwei Bie (2):
  vhost: support host notifier
  net/ifcvf: enable the host notifier support

 drivers/net/ifc/ifcvf_vdpa.c  |   3 +
 lib/librte_vhost/rte_vhost.h  |   8 ++
 lib/librte_vhost/vhost.c      |   3 +
 lib/librte_vhost/vhost.h      |   1 +
 lib/librte_vhost/vhost_user.c | 146 ++++++++++++++++++++++++++++++++++
 lib/librte_vhost/vhost_user.h |  13 ++-
 6 files changed, 173 insertions(+), 1 deletion(-)

-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/2] vhost: support host notifier
  2018-06-08  3:22 [PATCH v3 0/2] vhost: support host notifier Tiwei Bie
@ 2018-06-08  3:22 ` Tiwei Bie
  2018-06-08  3:22 ` [PATCH v3 2/2] net/ifcvf: enable the host notifier support Tiwei Bie
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Tiwei Bie @ 2018-06-08  3:22 UTC (permalink / raw)
  To: maxime.coquelin, dev

When a vDPA device is attached, vhost user will try to
register host notifiers to QEMU to allow notifications
to be delivered between the driver in the guest and the
vDPA device in the host directly.

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 lib/librte_vhost/rte_vhost.h  |   8 ++
 lib/librte_vhost/vhost.c      |   3 +
 lib/librte_vhost/vhost.h      |   1 +
 lib/librte_vhost/vhost_user.c | 146 ++++++++++++++++++++++++++++++++++
 lib/librte_vhost/vhost_user.h |  13 ++-
 5 files changed, 170 insertions(+), 1 deletion(-)

diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 7f0cb9bc8..b02673d4a 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -58,6 +58,14 @@ extern "C" {
 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
 #endif
 
+#ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD
+#define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10
+#endif
+
+#ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
+#define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
+#endif
+
 /** Indicate whether protocol features negotiation is supported. */
 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
 #define VHOST_USER_F_PROTOCOL_FEATURES	30
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index afded4952..6ca5beb13 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -291,6 +291,7 @@ vhost_new_device(void)
 	dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET;
 	dev->slave_req_fd = -1;
 	dev->vdpa_dev_id = -1;
+	rte_spinlock_init(&dev->slave_req_lock);
 
 	return i;
 }
@@ -346,6 +347,8 @@ vhost_detach_vdpa_device(int vid)
 	if (dev == NULL)
 		return;
 
+	vhost_user_host_notifier_ctrl(vid, false);
+
 	dev->vdpa_dev_id = -1;
 }
 
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 58c425a5c..b10ac124b 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -301,6 +301,7 @@ struct virtio_net {
 	struct guest_page       *guest_pages;
 
 	int			slave_req_fd;
+	rte_spinlock_t		slave_req_lock;
 
 	/*
 	 * Device id to identify a specific backend device.
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 947290fc3..a28fc3495 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -1384,6 +1384,22 @@ send_vhost_reply(int sockfd, struct VhostUserMsg *msg)
 	return send_vhost_message(sockfd, msg, NULL, 0);
 }
 
+static int
+send_vhost_slave_message(struct virtio_net *dev, struct VhostUserMsg *msg,
+			 int *fds, int fd_num)
+{
+	int ret;
+
+	if (msg->flags & VHOST_USER_NEED_REPLY)
+		rte_spinlock_lock(&dev->slave_req_lock);
+
+	ret = send_vhost_message(dev->slave_req_fd, msg, fds, fd_num);
+	if (ret < 0 && (msg->flags & VHOST_USER_NEED_REPLY))
+		rte_spinlock_unlock(&dev->slave_req_lock);
+
+	return ret;
+}
+
 /*
  * Allocate a queue pair if it hasn't been allocated yet
  */
@@ -1705,11 +1721,45 @@ vhost_user_msg_handler(int vid, int fd)
 		if (vdpa_dev->ops->dev_conf)
 			vdpa_dev->ops->dev_conf(dev->vid);
 		dev->flags |= VIRTIO_DEV_VDPA_CONFIGURED;
+		if (vhost_user_host_notifier_ctrl(dev->vid, true) != 0) {
+			RTE_LOG(INFO, VHOST_CONFIG,
+				"(%d) software relay is used for vDPA, performance may be low.\n",
+				dev->vid);
+		}
 	}
 
 	return 0;
 }
 
+static int process_slave_message_reply(struct virtio_net *dev,
+				       const VhostUserMsg *msg)
+{
+	VhostUserMsg msg_reply;
+	int ret;
+
+	if ((msg->flags & VHOST_USER_NEED_REPLY) == 0)
+		return 0;
+
+	if (read_vhost_message(dev->slave_req_fd, &msg_reply) < 0) {
+		ret = -1;
+		goto out;
+	}
+
+	if (msg_reply.request.slave != msg->request.slave) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"Received unexpected msg type (%u), expected %u\n",
+			msg_reply.request.slave, msg->request.slave);
+		ret = -1;
+		goto out;
+	}
+
+	ret = msg_reply.payload.u64 ? -1 : 0;
+
+out:
+	rte_spinlock_unlock(&dev->slave_req_lock);
+	return ret;
+}
+
 int
 vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
 {
@@ -1735,3 +1785,99 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
 
 	return 0;
 }
+
+static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,
+						    int index, int fd,
+						    uint64_t offset,
+						    uint64_t size)
+{
+	int *fdp = NULL;
+	size_t fd_num = 0;
+	int ret;
+	struct VhostUserMsg msg = {
+		.request.slave = VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG,
+		.flags = VHOST_USER_VERSION | VHOST_USER_NEED_REPLY,
+		.size = sizeof(msg.payload.area),
+		.payload.area = {
+			.u64 = index & VHOST_USER_VRING_IDX_MASK,
+			.size = size,
+			.offset = offset,
+		},
+	};
+
+	if (fd < 0)
+		msg.payload.area.u64 |= VHOST_USER_VRING_NOFD_MASK;
+	else {
+		fdp = &fd;
+		fd_num = 1;
+	}
+
+	ret = send_vhost_slave_message(dev, &msg, fdp, fd_num);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"Failed to set host notifier (%d)\n", ret);
+		return ret;
+	}
+
+	return process_slave_message_reply(dev, &msg);
+}
+
+int vhost_user_host_notifier_ctrl(int vid, bool enable)
+{
+	struct virtio_net *dev;
+	struct rte_vdpa_device *vdpa_dev;
+	int vfio_device_fd, did, ret = 0;
+	uint64_t offset, size;
+	unsigned int i;
+
+	dev = get_device(vid);
+	if (!dev)
+		return -ENODEV;
+
+	did = dev->vdpa_dev_id;
+	if (did < 0)
+		return -EINVAL;
+
+	if (!(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ||
+	    !(dev->features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) ||
+	    !(dev->protocol_features &
+			(1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ)) ||
+	    !(dev->protocol_features &
+			(1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)) ||
+	    !(dev->protocol_features &
+			(1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER)))
+		return -ENOTSUP;
+
+	vdpa_dev = rte_vdpa_get_device(did);
+
+	RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_vfio_device_fd, -ENOTSUP);
+	RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_notify_area, -ENOTSUP);
+
+	vfio_device_fd = vdpa_dev->ops->get_vfio_device_fd(vid);
+	if (vfio_device_fd < 0)
+		return -ENOTSUP;
+
+	if (enable) {
+		for (i = 0; i < dev->nr_vring; i++) {
+			if (vdpa_dev->ops->get_notify_area(vid, i, &offset,
+					&size) < 0) {
+				ret = -ENOTSUP;
+				goto disable;
+			}
+
+			if (vhost_user_slave_set_vring_host_notifier(dev, i,
+					vfio_device_fd, offset, size) < 0) {
+				ret = -EFAULT;
+				goto disable;
+			}
+		}
+	} else {
+disable:
+		for (i = 0; i < dev->nr_vring; i++) {
+			vhost_user_slave_set_vring_host_notifier(dev, i, -1,
+					0, 0);
+		}
+	}
+
+	return ret;
+}
diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h
index 1ad5cf467..42166adf2 100644
--- a/lib/librte_vhost/vhost_user.h
+++ b/lib/librte_vhost/vhost_user.h
@@ -20,7 +20,9 @@
 					 (1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
 					 (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU) | \
 					 (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
-					 (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION))
+					 (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION) | \
+					 (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \
+					 (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER))
 
 typedef enum VhostUserRequest {
 	VHOST_USER_NONE = 0,
@@ -54,6 +56,7 @@ typedef enum VhostUserRequest {
 typedef enum VhostUserSlaveRequest {
 	VHOST_USER_SLAVE_NONE = 0,
 	VHOST_USER_SLAVE_IOTLB_MSG = 1,
+	VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
 	VHOST_USER_SLAVE_MAX
 } VhostUserSlaveRequest;
 
@@ -99,6 +102,12 @@ typedef struct VhostUserCryptoSessionParam {
 	uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH];
 } VhostUserCryptoSessionParam;
 
+typedef struct VhostUserVringArea {
+	uint64_t u64;
+	uint64_t size;
+	uint64_t offset;
+} VhostUserVringArea;
+
 typedef struct VhostUserMsg {
 	union {
 		uint32_t master; /* a VhostUserRequest value */
@@ -120,6 +129,7 @@ typedef struct VhostUserMsg {
 		VhostUserLog    log;
 		struct vhost_iotlb_msg iotlb;
 		VhostUserCryptoSessionParam crypto_session;
+		VhostUserVringArea area;
 	} payload;
 	int fds[VHOST_MEMORY_MAX_NREGIONS];
 } __attribute((packed)) VhostUserMsg;
@@ -133,6 +143,7 @@ typedef struct VhostUserMsg {
 /* vhost_user.c */
 int vhost_user_msg_handler(int vid, int fd);
 int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
+int vhost_user_host_notifier_ctrl(int vid, bool enable);
 
 /* socket.c */
 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/2] net/ifcvf: enable the host notifier support
  2018-06-08  3:22 [PATCH v3 0/2] vhost: support host notifier Tiwei Bie
  2018-06-08  3:22 ` [PATCH v3 1/2] " Tiwei Bie
@ 2018-06-08  3:22 ` Tiwei Bie
  2018-06-13  6:43   ` Wang, Xiao W
  2018-06-15  7:35 ` [PATCH v3 0/2] vhost: support host notifier Maxime Coquelin
  2018-06-15  8:00 ` Maxime Coquelin
  3 siblings, 1 reply; 6+ messages in thread
From: Tiwei Bie @ 2018-06-08  3:22 UTC (permalink / raw)
  To: maxime.coquelin, dev; +Cc: xiao.w.wang

The necessary vDPA ops have already been implemented
in ifcvf driver. So just need to announce the necessary
protocol features to enable the host notifier support.

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 drivers/net/ifc/ifcvf_vdpa.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ifc/ifcvf_vdpa.c b/drivers/net/ifc/ifcvf_vdpa.c
index c6627c23a..b8e22daf3 100644
--- a/drivers/net/ifc/ifcvf_vdpa.c
+++ b/drivers/net/ifc/ifcvf_vdpa.c
@@ -646,6 +646,9 @@ ifcvf_get_vdpa_features(int did, uint64_t *features)
 
 #define VDPA_SUPPORTED_PROTOCOL_FEATURES \
 		(1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK | \
+		 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | \
+		 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD | \
+		 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \
 		 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD)
 static int
 ifcvf_get_protocol_features(int did __rte_unused, uint64_t *features)
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 2/2] net/ifcvf: enable the host notifier support
  2018-06-08  3:22 ` [PATCH v3 2/2] net/ifcvf: enable the host notifier support Tiwei Bie
@ 2018-06-13  6:43   ` Wang, Xiao W
  0 siblings, 0 replies; 6+ messages in thread
From: Wang, Xiao W @ 2018-06-13  6:43 UTC (permalink / raw)
  To: Bie, Tiwei, maxime.coquelin, dev

Hi,

> -----Original Message-----
> From: Bie, Tiwei
> Sent: Friday, June 8, 2018 11:22 AM
> To: maxime.coquelin@redhat.com; dev@dpdk.org
> Cc: Wang, Xiao W <xiao.w.wang@intel.com>
> Subject: [PATCH v3 2/2] net/ifcvf: enable the host notifier support
> 
> The necessary vDPA ops have already been implemented
> in ifcvf driver. So just need to announce the necessary
> protocol features to enable the host notifier support.
> 
> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> ---
>  drivers/net/ifc/ifcvf_vdpa.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ifc/ifcvf_vdpa.c b/drivers/net/ifc/ifcvf_vdpa.c
> index c6627c23a..b8e22daf3 100644
> --- a/drivers/net/ifc/ifcvf_vdpa.c
> +++ b/drivers/net/ifc/ifcvf_vdpa.c
> @@ -646,6 +646,9 @@ ifcvf_get_vdpa_features(int did, uint64_t *features)
> 
>  #define VDPA_SUPPORTED_PROTOCOL_FEATURES \
>  		(1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK | \
> +		 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | \
> +		 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD | \
> +		 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \
>  		 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD)
>  static int
>  ifcvf_get_protocol_features(int did __rte_unused, uint64_t *features)
> --
> 2.17.0

Acked-by: Xiao Wang <xiao.w.wang@intel.com>

BRs,
Xiao

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] vhost: support host notifier
  2018-06-08  3:22 [PATCH v3 0/2] vhost: support host notifier Tiwei Bie
  2018-06-08  3:22 ` [PATCH v3 1/2] " Tiwei Bie
  2018-06-08  3:22 ` [PATCH v3 2/2] net/ifcvf: enable the host notifier support Tiwei Bie
@ 2018-06-15  7:35 ` Maxime Coquelin
  2018-06-15  8:00 ` Maxime Coquelin
  3 siblings, 0 replies; 6+ messages in thread
From: Maxime Coquelin @ 2018-06-15  7:35 UTC (permalink / raw)
  To: Tiwei Bie, dev



On 06/08/2018 05:22 AM, Tiwei Bie wrote:
> The host notifier support in vhost-user has been merged
> into QEMU. This patch set enables the support for host
> notifier in DPDK vhost-user and ifcvf driver.
> 
> The original subject is:
> Extend vhost to support VFIO based accelerator
> 
> v3:
> - Address the changes in QEMU
> - Minor fixes and refinements
> 
> Tiwei Bie (2):
>    vhost: support host notifier
>    net/ifcvf: enable the host notifier support
> 
>   drivers/net/ifc/ifcvf_vdpa.c  |   3 +
>   lib/librte_vhost/rte_vhost.h  |   8 ++
>   lib/librte_vhost/vhost.c      |   3 +
>   lib/librte_vhost/vhost.h      |   1 +
>   lib/librte_vhost/vhost_user.c | 146 ++++++++++++++++++++++++++++++++++
>   lib/librte_vhost/vhost_user.h |  13 ++-
>   6 files changed, 173 insertions(+), 1 deletion(-)
> 

For the series:
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks!
Maxime

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] vhost: support host notifier
  2018-06-08  3:22 [PATCH v3 0/2] vhost: support host notifier Tiwei Bie
                   ` (2 preceding siblings ...)
  2018-06-15  7:35 ` [PATCH v3 0/2] vhost: support host notifier Maxime Coquelin
@ 2018-06-15  8:00 ` Maxime Coquelin
  3 siblings, 0 replies; 6+ messages in thread
From: Maxime Coquelin @ 2018-06-15  8:00 UTC (permalink / raw)
  To: Tiwei Bie, dev



On 06/08/2018 05:22 AM, Tiwei Bie wrote:
> The host notifier support in vhost-user has been merged
> into QEMU. This patch set enables the support for host
> notifier in DPDK vhost-user and ifcvf driver.
> 
> The original subject is:
> Extend vhost to support VFIO based accelerator
> 
> v3:
> - Address the changes in QEMU
> - Minor fixes and refinements
> 
> Tiwei Bie (2):
>    vhost: support host notifier
>    net/ifcvf: enable the host notifier support
> 
>   drivers/net/ifc/ifcvf_vdpa.c  |   3 +
>   lib/librte_vhost/rte_vhost.h  |   8 ++
>   lib/librte_vhost/vhost.c      |   3 +
>   lib/librte_vhost/vhost.h      |   1 +
>   lib/librte_vhost/vhost_user.c | 146 ++++++++++++++++++++++++++++++++++
>   lib/librte_vhost/vhost_user.h |  13 ++-
>   6 files changed, 173 insertions(+), 1 deletion(-)
> 

Applied to dpdk-next-virtio/master

Thanks,
Maxime

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-06-15  8:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08  3:22 [PATCH v3 0/2] vhost: support host notifier Tiwei Bie
2018-06-08  3:22 ` [PATCH v3 1/2] " Tiwei Bie
2018-06-08  3:22 ` [PATCH v3 2/2] net/ifcvf: enable the host notifier support Tiwei Bie
2018-06-13  6:43   ` Wang, Xiao W
2018-06-15  7:35 ` [PATCH v3 0/2] vhost: support host notifier Maxime Coquelin
2018-06-15  8:00 ` Maxime Coquelin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.