vhost: implement VHOST_SET_VRING_ERR
v2 cover vhost: implement VHOST_SET_VRING_ERR
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(+)
Signature · 1 line
2.25.1
PATCH v2 1/2 vhost: add method vhost_set_vring_err
From: Konstantin Khlebnikov <[email protected]>
Kernel and user vhost may report virtqueue errors via eventfd. This is only reliable way to get notification about protocol error.
--- hw/virtio/vhost-backend.c | 7 +++++++ hw/virtio/vhost-user.c | 6 ++++++ include/hw/virtio/vhost-backend.h | 3 +++ 3 files changed, 16 insertions(+)
hw/virtio/vhost-backend.c +7 -0
@@ -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,
hw/virtio/vhost-user.c +6 -0
@@ -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,
include/hw/virtio/vhost-backend.h +3 -0
@@ -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;
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] vhost: add method vhost_set_vring_err
Quoted 4 lines · Vladimir Sementsov-Ogievskiy
From: Konstantin Khlebnikov <[email protected]>
Kernel and user vhost may report virtqueue errors via eventfd. This is only reliable way to get notification about protocol error.
^^^ the
Quoted 2 lines
Signed-off-by Konstantin Khlebnikov <[email protected]>
As long as you pick this series over from Konstantin you need to append your s-o-b.
Other than that,
PATCH v2 2/2 vhost: setup error eventfd and dump errors
In reply to Vladimir Sementsov-OgievskiyFrom: Konstantin Khlebnikov <[email protected]>
Vhost has error notifications, let's log them like other errors. For each virt-queue setup eventfd for vring error notifications.
[vsementsov: rename patch, change commit message and dump error like
other errors in the file]
--- hw/virtio/vhost.c | 37 +++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost.h | 1 + 2 files changed, 38 insertions(+)
hw/virtio/vhost.c +37 -0
@@ -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,
include/hw/virtio/vhost.h +1 -0
@@ -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; };
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] vhost: setup error eventfd and dump errors
Quoted 5 lines · Vladimir Sementsov-Ogievskiy
From: Konstantin Khlebnikov <[email protected]>
Vhost has error notifications, let's log them like other errors. For each virt-queue setup eventfd for vring error notifications.
Quoted 8 lines
Signed-off-by Konstantin Khlebnikov <[email protected]>[vsementsov: rename patch, change commit message and dump error like
other errors in the file]Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- hw/virtio/vhost.c | 37 +++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost.h | 1 + 2 files changed, 38 insertions(+)