DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com,
	mkp@redhat.com, fbl@redhat.com, jasowang@redhat.com,
	cunming.liang@intel.com, xieyongji@bytedance.com,
	echaudro@redhat.com, eperezma@redhat.com, amorenoz@redhat.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [RFC 14/27] vhost: add helper for interrupt injection
Date: Fri, 31 Mar 2023 17:42:46 +0200	[thread overview]
Message-ID: <20230331154259.1447831-15-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20230331154259.1447831-1-maxime.coquelin@redhat.com>

Vhost-user uses eventfd to inject IRQs, but VDUSE uses
an ioctl.

This patch prepares vhost_vring_call_split() and
vhost_vring_call_packed() to support VDUSE by introducing
a new helper.

It also adds a new counter to for guest notification
failures, which could happen in case of uninitialized call
file descriptor for example.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/vhost.c      |  6 +++++
 lib/vhost/vhost.h      | 54 +++++++++++++++++++++++-------------------
 lib/vhost/vhost_user.c | 10 ++++++++
 3 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 790eb06b28..c07028f2b3 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -44,6 +44,7 @@ static const struct vhost_vq_stats_name_off vhost_vq_stat_strings[] = {
 	{"size_1024_1518_packets", offsetof(struct vhost_virtqueue, stats.size_bins[6])},
 	{"size_1519_max_packets",  offsetof(struct vhost_virtqueue, stats.size_bins[7])},
 	{"guest_notifications",    offsetof(struct vhost_virtqueue, stats.guest_notifications)},
+	{"guest_notifications_error",    offsetof(struct vhost_virtqueue, stats.guest_notifications_error)},
 	{"iotlb_hits",             offsetof(struct vhost_virtqueue, stats.iotlb_hits)},
 	{"iotlb_misses",           offsetof(struct vhost_virtqueue, stats.iotlb_misses)},
 	{"inflight_submitted",     offsetof(struct vhost_virtqueue, stats.inflight_submitted)},
@@ -697,6 +698,11 @@ vhost_new_device(struct vhost_backend_ops *ops)
 		return -1;
 	}
 
+	if (ops->inject_irq == NULL) {
+		VHOST_LOG_CONFIG("device", ERR, "missing IRQ injection backend op.\n");
+		return -1;
+	}
+
 	pthread_mutex_lock(&vhost_dev_lock);
 	for (i = 0; i < RTE_MAX_VHOST_DEVICE; i++) {
 		if (vhost_devices[i] == NULL)
diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
index ee7640e901..8f0875b4e2 100644
--- a/lib/vhost/vhost.h
+++ b/lib/vhost/vhost.h
@@ -90,16 +90,20 @@
 #endif
 
 struct virtio_net;
+struct vhost_virtqueue;
+
 typedef void (*vhost_iotlb_remove_notify)(uint64_t addr, uint64_t off, uint64_t size);
 
 typedef int (*vhost_iotlb_miss_cb)(struct virtio_net *dev, uint64_t iova, uint8_t perm);
 
+typedef int (*vhost_vring_inject_irq_cb)(struct virtio_net *dev, struct vhost_virtqueue *vq);
 /**
  * Structure that contains backend-specific ops.
  */
 struct vhost_backend_ops {
 	vhost_iotlb_remove_notify iotlb_remove_notify;
 	vhost_iotlb_miss_cb iotlb_miss;
+	vhost_vring_inject_irq_cb inject_irq;
 };
 
 /**
@@ -149,6 +153,7 @@ struct virtqueue_stats {
 	/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */
 	uint64_t size_bins[8];
 	uint64_t guest_notifications;
+	uint64_t guest_notifications_error;
 	uint64_t iotlb_hits;
 	uint64_t iotlb_misses;
 	uint64_t inflight_submitted;
@@ -900,6 +905,24 @@ vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
 	return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
 }
 
+static __rte_always_inline void
+vhost_vring_inject_irq(struct virtio_net *dev, struct vhost_virtqueue *vq)
+{
+	int ret;
+
+	ret = dev->backend_ops->inject_irq(dev, vq);
+	if (ret) {
+		if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
+			vq->stats.guest_notifications_error++;
+		return;
+	}
+
+	if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
+		vq->stats.guest_notifications++;
+	if (dev->notify_ops->guest_notified)
+		dev->notify_ops->guest_notified(dev->vid);
+}
+
 static __rte_always_inline void
 vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 {
@@ -919,25 +942,13 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 			"%s: used_event_idx=%d, old=%d, new=%d\n",
 			__func__, vhost_used_event(vq), old, new);
 
-		if ((vhost_need_event(vhost_used_event(vq), new, old) ||
-					unlikely(!signalled_used_valid)) &&
-				vq->callfd >= 0) {
-			eventfd_write(vq->callfd, (eventfd_t) 1);
-			if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
-				vq->stats.guest_notifications++;
-			if (dev->notify_ops->guest_notified)
-				dev->notify_ops->guest_notified(dev->vid);
-		}
+		if (vhost_need_event(vhost_used_event(vq), new, old) ||
+					unlikely(!signalled_used_valid))
+			vhost_vring_inject_irq(dev, vq);
 	} else {
 		/* Kick the guest if necessary. */
-		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
-				&& (vq->callfd >= 0)) {
-			eventfd_write(vq->callfd, (eventfd_t)1);
-			if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
-				vq->stats.guest_notifications++;
-			if (dev->notify_ops->guest_notified)
-				dev->notify_ops->guest_notified(dev->vid);
-		}
+		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
+			vhost_vring_inject_irq(dev, vq);
 	}
 }
 
@@ -988,13 +999,8 @@ vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
 	if (vhost_need_event(off, new, old))
 		kick = true;
 kick:
-	if (kick && vq->callfd >= 0) {
-		eventfd_write(vq->callfd, (eventfd_t)1);
-		if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
-			vq->stats.guest_notifications++;
-		if (dev->notify_ops->guest_notified)
-			dev->notify_ops->guest_notified(dev->vid);
-	}
+	if (kick)
+		vhost_vring_inject_irq(dev, vq);
 }
 
 static __rte_always_inline void
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 6a9f32972a..2e4a9fdea4 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -3465,8 +3465,18 @@ int rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable)
 	return ret;
 }
 
+static int
+vhost_user_inject_irq(struct virtio_net *dev __rte_unused, struct vhost_virtqueue *vq)
+{
+	if (vq->callfd < 0)
+		return -1;
+
+	return eventfd_write(vq->callfd, (eventfd_t)1);
+}
+
 static struct vhost_backend_ops vhost_user_backend_ops = {
 	.iotlb_miss = vhost_user_iotlb_miss,
+	.inject_irq = vhost_user_inject_irq,
 };
 
 int
-- 
2.39.2


  parent reply	other threads:[~2023-03-31 15:44 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 15:42 [RFC 00/27] Add VDUSE support to Vhost library Maxime Coquelin
2023-03-31 15:42 ` [RFC 01/27] vhost: fix missing guest notif stat increment Maxime Coquelin
2023-04-24  2:57   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 02/27] vhost: fix invalid call FD handling Maxime Coquelin
2023-04-24  2:58   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 03/27] vhost: fix IOTLB entries overlap check with previous entry Maxime Coquelin
2023-04-17 19:15   ` Mike Pattrick
2023-04-24  2:58   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 04/27] vhost: add helper of IOTLB entries coredump Maxime Coquelin
2023-04-24  2:59   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 05/27] vhost: add helper for IOTLB entries shared page check Maxime Coquelin
2023-04-17 19:39   ` Mike Pattrick
2023-04-19  9:35     ` Maxime Coquelin
2023-04-19 14:52       ` Mike Pattrick
2023-04-24  2:59   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 06/27] vhost: don't dump unneeded pages with IOTLB Maxime Coquelin
2023-04-20 17:11   ` Mike Pattrick
2023-04-24  3:00   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 07/27] vhost: change to single IOTLB cache per device Maxime Coquelin
2023-04-25  6:19   ` Xia, Chenbo
2023-05-03 13:47     ` Maxime Coquelin
2023-03-31 15:42 ` [RFC 08/27] vhost: add offset field to IOTLB entries Maxime Coquelin
2023-04-25  6:20   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 09/27] vhost: add page size info to IOTLB entry Maxime Coquelin
2023-04-25  6:20   ` Xia, Chenbo
2023-05-03 13:57     ` Maxime Coquelin
2023-03-31 15:42 ` [RFC 10/27] vhost: retry translating IOVA after IOTLB miss Maxime Coquelin
2023-05-05  5:07   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 11/27] vhost: introduce backend ops Maxime Coquelin
2023-05-05  5:07   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 12/27] vhost: add IOTLB cache entry removal callback Maxime Coquelin
2023-05-05  5:07   ` Xia, Chenbo
2023-05-25 11:20     ` Maxime Coquelin
2023-03-31 15:42 ` [RFC 13/27] vhost: add helper for IOTLB misses Maxime Coquelin
2023-03-31 15:42 ` Maxime Coquelin [this message]
2023-05-05  5:07   ` [RFC 14/27] vhost: add helper for interrupt injection Xia, Chenbo
2023-03-31 15:42 ` [RFC 15/27] vhost: add API to set max queue pairs Maxime Coquelin
2023-05-05  5:07   ` Xia, Chenbo
2023-05-25 11:23     ` Maxime Coquelin
2023-03-31 15:42 ` [RFC 16/27] net/vhost: use " Maxime Coquelin
2023-05-05  5:07   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 17/27] vhost: add control virtqueue support Maxime Coquelin
2023-05-09  5:29   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 18/27] vhost: add VDUSE device creation and destruction Maxime Coquelin
2023-05-09  5:31   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 19/27] vhost: add VDUSE callback for IOTLB miss Maxime Coquelin
2023-05-09  5:31   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 20/27] vhost: add VDUSE callback for IOTLB entry removal Maxime Coquelin
2023-05-09  5:32   ` Xia, Chenbo
2023-05-25 11:35     ` Maxime Coquelin
2023-03-31 15:42 ` [RFC 21/27] vhost: add VDUSE callback for IRQ injection Maxime Coquelin
2023-05-09  5:33   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 22/27] vhost: add VDUSE events handler Maxime Coquelin
2023-05-09  5:34   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 23/27] vhost: add support for virtqueue state get event Maxime Coquelin
2023-05-09  5:34   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 24/27] vhost: add support for VDUSE status set event Maxime Coquelin
2023-05-09  5:34   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 25/27] vhost: add support for VDUSE IOTLB update event Maxime Coquelin
2023-05-09  5:35   ` Xia, Chenbo
2023-05-25 11:43     ` Maxime Coquelin
2023-03-31 15:42 ` [RFC 26/27] vhost: add VDUSE device startup Maxime Coquelin
2023-05-09  5:35   ` Xia, Chenbo
2023-03-31 15:42 ` [RFC 27/27] vhost: add multiqueue support to VDUSE Maxime Coquelin
2023-05-09  5:35   ` Xia, Chenbo
2023-04-06  3:44 ` [RFC 00/27] Add VDUSE support to Vhost library Yongji Xie
2023-04-06  8:16   ` Maxime Coquelin
2023-04-06 11:04     ` Yongji Xie
2023-04-12 11:33 ` Ferruh Yigit
2023-04-12 15:28   ` Maxime Coquelin
2023-04-12 19:40     ` Morten Brørup
2023-04-13  7:08       ` Xia, Chenbo
2023-04-13  7:58         ` Morten Brørup
2023-04-13  7:59         ` Maxime Coquelin
2023-04-14 10:48           ` Ferruh Yigit
2023-04-14 12:06             ` Maxime Coquelin
2023-04-14 14:25               ` Ferruh Yigit
2023-04-17  3:10                 ` Jason Wang
2023-05-05  5:53 ` Xia, Chenbo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230331154259.1447831-15-maxime.coquelin@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=amorenoz@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=cunming.liang@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=echaudro@redhat.com \
    --cc=eperezma@redhat.com \
    --cc=fbl@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mkp@redhat.com \
    --cc=xieyongji@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).