From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, chenbo.xia@intel.com, david.marchand@redhat.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,
lulu@redhat.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [PATCH v4 12/26] vhost: add helper for interrupt injection
Date: Thu, 1 Jun 2023 22:07:58 +0200 [thread overview]
Message-ID: <20230601200812.672233-13-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20230601200812.672233-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 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>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
---
lib/vhost/vhost.c | 25 +++++++++++++------------
lib/vhost/vhost.h | 19 +++++++++----------
lib/vhost/vhost_user.c | 10 ++++++++++
3 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index f77f30d674..eb6309b681 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -701,6 +701,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)
@@ -1511,20 +1516,16 @@ rte_vhost_notify_guest(int vid, uint16_t queue_id)
rte_rwlock_read_lock(&vq->access_lock);
- if (vq->callfd >= 0) {
- int ret = eventfd_write(vq->callfd, (eventfd_t)1);
-
- if (ret) {
- if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
- __atomic_fetch_add(&vq->stats.guest_notifications_error,
+ if (dev->backend_ops->inject_irq(dev, vq)) {
+ if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
+ __atomic_fetch_add(&vq->stats.guest_notifications_error,
1, __ATOMIC_RELAXED);
- } else {
- if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
- __atomic_fetch_add(&vq->stats.guest_notifications,
+ } else {
+ if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
+ __atomic_fetch_add(&vq->stats.guest_notifications,
1, __ATOMIC_RELAXED);
- if (dev->notify_ops->guest_notified)
- dev->notify_ops->guest_notified(dev->vid);
- }
+ if (dev->notify_ops->guest_notified)
+ dev->notify_ops->guest_notified(dev->vid);
}
rte_rwlock_read_unlock(&vq->access_lock);
diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
index 25255aaea8..ea2798b0bf 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;
};
/**
@@ -906,8 +910,6 @@ vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
static __rte_always_inline void
vhost_vring_inject_irq(struct virtio_net *dev, struct vhost_virtqueue *vq)
{
- int ret;
-
if (dev->notify_ops->guest_notify &&
dev->notify_ops->guest_notify(dev->vid, vq->index)) {
if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
@@ -916,8 +918,7 @@ vhost_vring_inject_irq(struct virtio_net *dev, struct vhost_virtqueue *vq)
return;
}
- ret = eventfd_write(vq->callfd, (eventfd_t) 1);
- if (ret) {
+ if (dev->backend_ops->inject_irq(dev, vq)) {
if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
__atomic_fetch_add(&vq->stats.guest_notifications_error,
1, __ATOMIC_RELAXED);
@@ -950,14 +951,12 @@ 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)
+ 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))
+ if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
vhost_vring_inject_irq(dev, vq);
}
}
@@ -1009,7 +1008,7 @@ 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)
+ if (kick)
vhost_vring_inject_irq(dev, vq);
}
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 30ad63aba0..901a80bbaa 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.40.1
next prev parent reply other threads:[~2023-06-01 20:09 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-01 20:07 [PATCH v4 00/26] Add VDUSE support to Vhost library Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 01/26] vhost: fix IOTLB entries overlap check with previous entry Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 02/26] vhost: add helper of IOTLB entries coredump Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 03/26] vhost: add helper for IOTLB entries shared page check Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 04/26] vhost: don't dump unneeded pages with IOTLB Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 05/26] vhost: change to single IOTLB cache per device Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 06/26] vhost: add offset field to IOTLB entries Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 07/26] vhost: add page size info to IOTLB entry Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 08/26] vhost: retry translating IOVA after IOTLB miss Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 09/26] vhost: introduce backend ops Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 10/26] vhost: add IOTLB cache entry removal callback Maxime Coquelin
2023-06-01 20:07 ` [PATCH v4 11/26] vhost: add helper for IOTLB misses Maxime Coquelin
2023-06-01 20:07 ` Maxime Coquelin [this message]
2023-06-01 20:07 ` [PATCH v4 13/26] vhost: add API to set max queue pairs Maxime Coquelin
2023-06-05 7:56 ` Xia, Chenbo
2023-06-01 20:08 ` [PATCH v4 14/26] net/vhost: use " Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 15/26] vhost: add control virtqueue support Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 16/26] vhost: add VDUSE device creation and destruction Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 17/26] vhost: add VDUSE callback for IOTLB miss Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 18/26] vhost: add VDUSE callback for IOTLB entry removal Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 19/26] vhost: add VDUSE callback for IRQ injection Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 20/26] vhost: add VDUSE events handler Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 21/26] vhost: add support for virtqueue state get event Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 22/26] vhost: add support for VDUSE status set event Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 23/26] vhost: add support for VDUSE IOTLB update event Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 24/26] vhost: add VDUSE device startup Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 25/26] vhost: add multiqueue support to VDUSE Maxime Coquelin
2023-06-01 20:08 ` [PATCH v4 26/26] vhost: add VDUSE device stop Maxime Coquelin
2023-06-05 7:56 ` Xia, Chenbo
2023-06-06 8:14 ` Maxime Coquelin
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=20230601200812.672233-13-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=lulu@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).