All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] vhost: implement VHOST_SET_VRING_ERR
@ 2022-06-23 16:13 Vladimir Sementsov-Ogievskiy
  2022-06-23 16:13 ` [PATCH v2 1/2] vhost: add method vhost_set_vring_err Vladimir Sementsov-Ogievskiy
  2022-06-23 16:13 ` [PATCH v2 2/2] vhost: setup error eventfd and dump errors Vladimir Sementsov-Ogievskiy
  0 siblings, 2 replies; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2022-06-23 16:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, vsementsov, yc-core, rvkagan, armbru

Both vhost-user and kernel vhost can inform Qemu about virt-queue error
through separate eventfd. Let's use this possibility.

For now just dump a message on error like elsewhere in vhost.c.

Further plan is implement QAPI event for this and may be some other
vhost/virtio errors to make it possible to instantly notify user about
problems in vm. That would be a separate patch or patchset.

v2: don't add QAPI event for now. Let's first realize the vhost
interface.

Yandex-ST: CLOUD-101375

Konstantin Khlebnikov (2):
  vhost: add method vhost_set_vring_err
  vhost: setup error eventfd and dump errors

 hw/virtio/vhost-backend.c         |  7 ++++++
 hw/virtio/vhost-user.c            |  6 +++++
 hw/virtio/vhost.c                 | 37 +++++++++++++++++++++++++++++++
 include/hw/virtio/vhost-backend.h |  3 +++
 include/hw/virtio/vhost.h         |  1 +
 5 files changed, 54 insertions(+)

-- 
2.25.1



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

* [PATCH v2 1/2] vhost: add method vhost_set_vring_err
  2022-06-23 16:13 [PATCH v2 0/2] vhost: implement VHOST_SET_VRING_ERR Vladimir Sementsov-Ogievskiy
@ 2022-06-23 16:13 ` Vladimir Sementsov-Ogievskiy
  2022-06-24 11:47   ` Roman Kagan
  2022-06-23 16:13 ` [PATCH v2 2/2] vhost: setup error eventfd and dump errors Vladimir Sementsov-Ogievskiy
  1 sibling, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2022-06-23 16:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, vsementsov, yc-core, rvkagan, armbru, Konstantin Khlebnikov

From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>

Kernel and user vhost may report virtqueue errors via eventfd.
This is only reliable way to get notification about protocol error.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
 hw/virtio/vhost-backend.c         | 7 +++++++
 hw/virtio/vhost-user.c            | 6 ++++++
 include/hw/virtio/vhost-backend.h | 3 +++
 3 files changed, 16 insertions(+)

diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 4de8b6b3b0..8e581575c9 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -146,6 +146,12 @@ static int vhost_kernel_set_vring_call(struct vhost_dev *dev,
     return vhost_kernel_call(dev, VHOST_SET_VRING_CALL, file);
 }
 
+static int vhost_kernel_set_vring_err(struct vhost_dev *dev,
+                                      struct vhost_vring_file *file)
+{
+    return vhost_kernel_call(dev, VHOST_SET_VRING_ERR, file);
+}
+
 static int vhost_kernel_set_vring_busyloop_timeout(struct vhost_dev *dev,
                                                    struct vhost_vring_state *s)
 {
@@ -309,6 +315,7 @@ const VhostOps kernel_ops = {
         .vhost_get_vring_base = vhost_kernel_get_vring_base,
         .vhost_set_vring_kick = vhost_kernel_set_vring_kick,
         .vhost_set_vring_call = vhost_kernel_set_vring_call,
+        .vhost_set_vring_err = vhost_kernel_set_vring_err,
         .vhost_set_vring_busyloop_timeout =
                                 vhost_kernel_set_vring_busyloop_timeout,
         .vhost_set_features = vhost_kernel_set_features,
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 4b9be26e84..75b8df21a4 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1313,6 +1313,11 @@ static int vhost_user_set_vring_call(struct vhost_dev *dev,
     return vhost_set_vring_file(dev, VHOST_USER_SET_VRING_CALL, file);
 }
 
+static int vhost_user_set_vring_err(struct vhost_dev *dev,
+                                    struct vhost_vring_file *file)
+{
+    return vhost_set_vring_file(dev, VHOST_USER_SET_VRING_ERR, file);
+}
 
 static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t *u64)
 {
@@ -2616,6 +2621,7 @@ const VhostOps user_ops = {
         .vhost_get_vring_base = vhost_user_get_vring_base,
         .vhost_set_vring_kick = vhost_user_set_vring_kick,
         .vhost_set_vring_call = vhost_user_set_vring_call,
+        .vhost_set_vring_err = vhost_user_set_vring_err,
         .vhost_set_features = vhost_user_set_features,
         .vhost_get_features = vhost_user_get_features,
         .vhost_set_owner = vhost_user_set_owner,
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index 81bf3109f8..eab46d7f0b 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -69,6 +69,8 @@ typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
                                        struct vhost_vring_file *file);
 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
                                        struct vhost_vring_file *file);
+typedef int (*vhost_set_vring_err_op)(struct vhost_dev *dev,
+                                      struct vhost_vring_file *file);
 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
                                                    struct vhost_vring_state *r);
 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
@@ -145,6 +147,7 @@ typedef struct VhostOps {
     vhost_get_vring_base_op vhost_get_vring_base;
     vhost_set_vring_kick_op vhost_set_vring_kick;
     vhost_set_vring_call_op vhost_set_vring_call;
+    vhost_set_vring_err_op vhost_set_vring_err;
     vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
     vhost_set_features_op vhost_set_features;
     vhost_get_features_op vhost_get_features;
-- 
2.25.1



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

* [PATCH v2 2/2] vhost: setup error eventfd and dump errors
  2022-06-23 16:13 [PATCH v2 0/2] vhost: implement VHOST_SET_VRING_ERR Vladimir Sementsov-Ogievskiy
  2022-06-23 16:13 ` [PATCH v2 1/2] vhost: add method vhost_set_vring_err Vladimir Sementsov-Ogievskiy
@ 2022-06-23 16:13 ` Vladimir Sementsov-Ogievskiy
  2022-06-24 13:11   ` Roman Kagan
  1 sibling, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2022-06-23 16:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, vsementsov, yc-core, rvkagan, armbru, Konstantin Khlebnikov

From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>

Vhost has error notifications, let's log them like other errors.
For each virt-queue setup eventfd for vring error notifications.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
[vsementsov: rename patch, change commit message  and dump error like
             other errors in the file]
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/virtio/vhost.c         | 37 +++++++++++++++++++++++++++++++++++++
 include/hw/virtio/vhost.h |  1 +
 2 files changed, 38 insertions(+)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 6c41fa13e3..0827d631c0 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1278,6 +1278,19 @@ static int vhost_virtqueue_set_busyloop_timeout(struct vhost_dev *dev,
     return 0;
 }
 
+static void vhost_virtqueue_error_notifier(EventNotifier *n)
+{
+    struct vhost_virtqueue *vq = container_of(n, struct vhost_virtqueue,
+                                              error_notifier);
+    struct vhost_dev *dev = vq->dev;
+    int index = vq - dev->vqs;
+
+    if (event_notifier_test_and_clear(n) && dev->vdev) {
+        VHOST_OPS_DEBUG(-EINVAL,  "vhost vring error in virtqueue %d",
+                        dev->vq_index + index);
+    }
+}
+
 static int vhost_virtqueue_init(struct vhost_dev *dev,
                                 struct vhost_virtqueue *vq, int n)
 {
@@ -1299,7 +1312,27 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
 
     vq->dev = dev;
 
+    if (dev->vhost_ops->vhost_set_vring_err) {
+        r = event_notifier_init(&vq->error_notifier, 0);
+        if (r < 0) {
+            goto fail_call;
+        }
+
+        file.fd = event_notifier_get_fd(&vq->error_notifier);
+        r = dev->vhost_ops->vhost_set_vring_err(dev, &file);
+        if (r) {
+            VHOST_OPS_DEBUG(r, "vhost_set_vring_err failed");
+            goto fail_err;
+        }
+
+        event_notifier_set_handler(&vq->error_notifier,
+                                   vhost_virtqueue_error_notifier);
+    }
+
     return 0;
+
+fail_err:
+    event_notifier_cleanup(&vq->error_notifier);
 fail_call:
     event_notifier_cleanup(&vq->masked_notifier);
     return r;
@@ -1308,6 +1341,10 @@ fail_call:
 static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq)
 {
     event_notifier_cleanup(&vq->masked_notifier);
+    if (vq->dev->vhost_ops->vhost_set_vring_err) {
+        event_notifier_set_handler(&vq->error_notifier, NULL);
+        event_notifier_cleanup(&vq->error_notifier);
+    }
 }
 
 int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index b291fe4e24..1e7cbd9a10 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -29,6 +29,7 @@ struct vhost_virtqueue {
     unsigned long long used_phys;
     unsigned used_size;
     EventNotifier masked_notifier;
+    EventNotifier error_notifier;
     struct vhost_dev *dev;
 };
 
-- 
2.25.1



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

* Re: [PATCH v2 1/2] vhost: add method vhost_set_vring_err
  2022-06-23 16:13 ` [PATCH v2 1/2] vhost: add method vhost_set_vring_err Vladimir Sementsov-Ogievskiy
@ 2022-06-24 11:47   ` Roman Kagan
  0 siblings, 0 replies; 5+ messages in thread
From: Roman Kagan @ 2022-06-24 11:47 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy
  Cc: qemu-devel, mst, yc-core, armbru, Konstantin Khlebnikov

On Thu, Jun 23, 2022 at 07:13:24PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> 
> Kernel and user vhost may report virtqueue errors via eventfd.
> This is only reliable way to get notification about protocol error.
        ^^^
	the

> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>

As long as you pick this series over from Konstantin you need to append
your s-o-b.

Other than that,

Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>


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

* Re: [PATCH v2 2/2] vhost: setup error eventfd and dump errors
  2022-06-23 16:13 ` [PATCH v2 2/2] vhost: setup error eventfd and dump errors Vladimir Sementsov-Ogievskiy
@ 2022-06-24 13:11   ` Roman Kagan
  0 siblings, 0 replies; 5+ messages in thread
From: Roman Kagan @ 2022-06-24 13:11 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy
  Cc: qemu-devel, mst, yc-core, armbru, Konstantin Khlebnikov

On Thu, Jun 23, 2022 at 07:13:25PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> 
> Vhost has error notifications, let's log them like other errors.
> For each virt-queue setup eventfd for vring error notifications.
> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> [vsementsov: rename patch, change commit message  and dump error like
>              other errors in the file]
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/vhost.c         | 37 +++++++++++++++++++++++++++++++++++++
>  include/hw/virtio/vhost.h |  1 +
>  2 files changed, 38 insertions(+)

Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>


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

end of thread, other threads:[~2022-06-24 13:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 16:13 [PATCH v2 0/2] vhost: implement VHOST_SET_VRING_ERR Vladimir Sementsov-Ogievskiy
2022-06-23 16:13 ` [PATCH v2 1/2] vhost: add method vhost_set_vring_err Vladimir Sementsov-Ogievskiy
2022-06-24 11:47   ` Roman Kagan
2022-06-23 16:13 ` [PATCH v2 2/2] vhost: setup error eventfd and dump errors Vladimir Sementsov-Ogievskiy
2022-06-24 13:11   ` Roman Kagan

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.