All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies
@ 2026-11-30  9:42 Alexander Ivanov
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-30  9:42 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

A vhost-blk disk completes requests to the guest from the kernel, so
QEMU never sees an I/O error and the werror/rerror policies cannot
work the usual way. vhost-blk in the Virtuozzo kernel can hold a
request failed with ENOSPC instead of completing it and signal an
eventfd. This series makes QEMU accept the policies, pause the VM on
a held request and resubmit it on resume or after a migration.

Patch 1 adds the UAPI of the held requests.

Patch 2 adds the werror and rerror properties, which libvirt passes
when the disk has error_policy or rerror_policy set. Without them
QEMU refuses to start such a VM.

Patch 3 stops vhost on every VM stop, not only on pause and at the
end of a migration. Otherwise the device state saved in the other
stopped states is stale, and so is the list of held requests.

Patch 4 sets the hold policy in the kernel, stops the VM with the
io-error reason and a BLOCK_IO_ERROR event on a held request, and
resubmits the held requests on the next start.

Patch 5 migrates the vq and head of each held request, so the
destination resubmits them.

v3:
- hold the requests in vhost-blk instead of dm-qcow2: the IO_ERROR
  uevent is replaced with an eventfd, and the held requests are
  resubmitted with an ioctl
- new patch 1: the UAPI of the held requests
- new patch 3: stop vhost on every VM stop
- patch 4 replaces "pause the VM on an IO_ERROR uevent from dm-qcow2"
- new patch 5: migrate the held requests instead of blocking
  migration and savevm
- patch 2: update the commit message, the code is unchanged

v2:
- patch 1: accept enospc as rerror, add Reviewed-by
- patch 2: stop the VM even if the event does not match the policy of
  the device, with a warning, as nobody resubmits the held request
  otherwise
- patch 2: ignore repeated events once the held request is reported,
  as the run state stays running until the main loop handles the stop
- patch 2: if the VM is already stopped, block migration and emit
  BLOCK_IO_ERROR without requesting a stop
- patch 2: ignore the event while vhost is stopped and in the
  suspended state
- patch 2: accept enospc without ueventfd, as it is the default

The series applies on top of "vhost-blk: support discard". On a
kernel without the held request ioctls QEMU warns and runs as before.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Alexander Ivanov (5):
  linux-headers: add the vhost-blk held request ioctls #VSTOR-152175
  vhost-blk: add the werror and rerror properties #VSTOR-152175
  vhost-blk: stop vhost on every VM stop #VSTOR-152175
  vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175
  vhost-blk: migrate the held requests #VSTOR-152175

 hw/block/vhost-blk.c                         | 275 ++++++++++++++++++-
 include/hw/virtio/vhost-blk.h                |   9 +
 include/standard-headers/linux/vhost_types.h |  18 ++
 linux-headers/linux/vhost.h                  |  31 +++
 4 files changed, 329 insertions(+), 4 deletions(-)

-- 
2.53.0


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

* [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175
  2026-11-30  9:42 [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
@ 2026-11-30  9:42 ` Alexander Ivanov
  2026-12-01  0:53   ` no-reply
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-30  9:42 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

vhost-blk in the Virtuozzo kernel can hold a request failed with ENOSPC
instead of completing it to the guest. Add its UAPI:
VHOST_BLK_SET_ERROR_POLICY, VHOST_BLK_SET_ERROR_FD,
VHOST_BLK_GET_HELD_REQS and VHOST_BLK_RESUBMIT.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 include/standard-headers/linux/vhost_types.h | 18 ++++++++++++
 linux-headers/linux/vhost.h                  | 31 ++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/include/standard-headers/linux/vhost_types.h b/include/standard-headers/linux/vhost_types.h
index 79b53a931a8..b11a2bc07f0 100644
--- a/include/standard-headers/linux/vhost_types.h
+++ b/include/standard-headers/linux/vhost_types.h
@@ -198,4 +198,22 @@ struct vhost_vdpa_iova_range {
 /* IOTLB don't flush memory mapping across device reset */
 #define VHOST_BACKEND_F_IOTLB_PERSIST  0x8
 
+/* VHOST_BLK_SET_ERROR_POLICY flags */
+#define VHOST_BLK_HOLD_ENOSPC_WRITE	(1ULL << 0)
+#define VHOST_BLK_HOLD_ENOSPC_READ	(1ULL << 1)
+
+struct vhost_blk_held_req {
+	uint16_t vq;
+	uint16_t head;
+	int32_t error;		/* positive errno */
+	uint32_t type;		/* VIRTIO_BLK_T_* */
+	uint32_t reserved;
+};
+
+struct vhost_blk_held_reqs {
+	uint32_t nr;
+	uint32_t reserved;
+	struct vhost_blk_held_req reqs[];
+};
+
 #endif
diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h
index b6eb628d973..4b585a1ceff 100644
--- a/linux-headers/linux/vhost.h
+++ b/linux-headers/linux/vhost.h
@@ -277,4 +277,35 @@
 #define VHOST_BLK_SET_BACKEND		_IOW(VHOST_VIRTIO, 0xFF, \
 					     struct vhost_vring_file)
 
+/*
+ * Hold a request failing with an error selected by VHOST_BLK_HOLD_* flags
+ * instead of completing it. The guest gets its head back only through
+ * VHOST_BLK_RESUBMIT.
+ */
+#define VHOST_BLK_SET_ERROR_POLICY	_IOW(VHOST_VIRTIO, 0xFD, __u64)
+
+/* An eventfd signalled on every held request, -1 to unset */
+#define VHOST_BLK_SET_ERROR_FD		_IOW(VHOST_VIRTIO, 0xFC, int)
+
+/*
+ * nr is the capacity of reqs on input and the number of held requests on
+ * output; -E2BIG if they do not fit. reserved must be 0. The list is final
+ * once the backend is unset, and is emptied by VHOST_RESET_OWNER and by a
+ * successful VHOST_BLK_SET_BACKEND with fd >= 0. A failing one may empty it
+ * too.
+ */
+#define VHOST_BLK_GET_HELD_REQS		_IOWR(VHOST_VIRTIO, 0xFB, \
+					      struct vhost_blk_held_reqs)
+
+/*
+ * Resubmit requests by vq and head, as if they were just taken from the avail
+ * ring. Only heads read with VHOST_BLK_GET_HELD_REQS after the last stop may be
+ * passed: the kernel does not track them, and a head passed again after its
+ * request completed, or still owned by the guest, is completed twice. A head
+ * still in flight fails with -EBUSY. error and type are ignored, reserved
+ * must be 0. On error, nr is set to the number of requests resubmitted.
+ */
+#define VHOST_BLK_RESUBMIT		_IOWR(VHOST_VIRTIO, 0xFA, \
+					      struct vhost_blk_held_reqs)
+
 #endif
-- 
2.53.0


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

* [PATCH hci-8.2 v3 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175
  2026-11-30  9:42 [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
@ 2026-11-30  9:42 ` Alexander Ivanov
  2026-12-01  0:54   ` no-reply
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-30  9:42 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

libvirt passes werror and rerror to the device when the disk has
error_policy or rerror_policy set, and QEMU refuses to start such a VM
with vhost-blk.

Accept them with the defaults of other block devices: enospc for
writes and report for reads. vhost-blk completes requests in the
kernel, which cannot ignore an error, so reject the ignore policy. The
other policies take effect with the next patch.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
 hw/block/vhost-blk.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 0e17b949726..164423f782c 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -752,6 +752,19 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (conf->conf.werror == BLOCKDEV_ON_ERROR_AUTO) {
+        conf->conf.werror = BLOCKDEV_ON_ERROR_ENOSPC;
+    }
+    if (conf->conf.rerror == BLOCKDEV_ON_ERROR_AUTO) {
+        conf->conf.rerror = BLOCKDEV_ON_ERROR_REPORT;
+    }
+
+    if (conf->conf.werror == BLOCKDEV_ON_ERROR_IGNORE ||
+        conf->conf.rerror == BLOCKDEV_ON_ERROR_IGNORE) {
+        error_setg(errp, "vhost-blk: 'ignore' error policy is not supported");
+        return;
+    }
+
     if (!vhost_blk_open_backend(s, errp)) {
         return;
     }
@@ -960,6 +973,7 @@ static const Property vhost_blk_properties[] = {
     DEFINE_PROP_BIT64("write-zeroes", VHostBlk, host_features,
                       VIRTIO_BLK_F_WRITE_ZEROES, false),
     DEFINE_PROP_STRING("serial", VHostBlk, conf.serial),
+    DEFINE_BLOCK_ERROR_PROPERTIES(VHostBlk, conf.conf),
 };
 
 static const VMStateDescription vmstate_vhost_blk = {
-- 
2.53.0


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

* [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175
  2026-11-30  9:42 [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
@ 2026-11-30  9:42 ` Alexander Ivanov
  2026-12-01  0:58   ` no-reply
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 5/5] vhost-blk: migrate the held requests #VSTOR-152175 Alexander Ivanov
  4 siblings, 1 reply; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-30  9:42 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

vhost is stopped only on pause and at the end of a migration. In any
other stopped state it keeps running in the kernel, so the device
state saved there is stale: vhost_dev_stop(), which fetches the vring
indexes from the kernel, has not run.

This affects savevm, which stops the VM with the save-vm reason, and
a migration of a VM stopped for debug, shutdown, a guest panic or a
watchdog: the VM is not live, so the migration does not run the state
handlers again. The destination then processes anew the requests the
source completed after the indexes were last fetched.

Stop vhost whenever the VM stops and start it whenever the VM runs.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 hw/block/vhost-blk.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 164423f782c..124885a2b30 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -267,10 +267,10 @@ static void vhost_blk_vm_state(void *opaque, bool running, RunState state)
 {
     VirtIODevice *vdev = opaque;
 
-    if (state == RUN_STATE_FINISH_MIGRATE || state == RUN_STATE_PAUSED) {
-        vhost_blk_reset(vdev);
-    } else if (state == RUN_STATE_RUNNING) {
+    if (running) {
         vhost_blk_start(vdev);
+    } else {
+        vhost_blk_reset(vdev);
     }
 }
 
-- 
2.53.0


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

* [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175
  2026-11-30  9:42 [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
                   ` (2 preceding siblings ...)
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
@ 2026-11-30  9:42 ` Alexander Ivanov
  2026-12-01  1:07   ` no-reply
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 5/5] vhost-blk: migrate the held requests #VSTOR-152175 Alexander Ivanov
  4 siblings, 1 reply; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-30  9:42 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

vhost-blk completes requests in the kernel, so werror and rerror have
no effect: dm-qcow2 mounted with report_enospc fails a write to a full
image at once, and the guest gets the error.

The kernel can hold such a request instead of completing it. Set the
hold policy from werror and rerror on every start, and pass an eventfd
the kernel signals on a held request. On the event stop the VM with the
io-error reason and emit BLOCK_IO_ERROR, as the block layer does for
other devices. The device field is the id of the proxy, which is the
disk alias libvirt looks the disk up by.

The kernel holds only ENOSPC, so the stop policy holds it too and
still reports other errors to the guest.

The kernel resubmits a held request by its vq and head, and only after
the backend is set anew. So read the list of held requests when vhost
stops, once the backend is unset and the list is final, and resubmit
them on the next start. VHOST_RESET_OWNER empties the list in the
kernel, and a device reset drops the saved one, as the guest rings are
gone.

A request may also be held while the VM is not running, when the stop
drains the requests in flight. Do not report it then: it is resubmitted
when the VM runs again, and pauses the VM if it fails again. A request
held while the guest is suspended is not reported either: a wakeup
resets the device, which drops it along with the rings.

Probe the ioctls at realize. On a kernel without them warn and run as
before.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 hw/block/vhost-blk.c          | 177 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/vhost-blk.h |   9 ++
 2 files changed, 185 insertions(+), 1 deletion(-)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 124885a2b30..19003def393 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -32,6 +32,102 @@
 #include "migration/blocker.h"
 #include "migration/cpr.h"
 #include "system/runstate.h"
+#include "qapi/qapi-events-block-core.h"
+
+static uint64_t vhost_blk_error_policy(VHostBlk *s)
+{
+    uint64_t policy = 0;
+
+    if (s->conf.conf.werror != BLOCKDEV_ON_ERROR_REPORT) {
+        policy |= VHOST_BLK_HOLD_ENOSPC_WRITE;
+    }
+    if (s->conf.conf.rerror != BLOCKDEV_ON_ERROR_REPORT) {
+        policy |= VHOST_BLK_HOLD_ENOSPC_READ;
+    }
+    return policy;
+}
+
+static struct vhost_blk_held_reqs *vhost_blk_get_held(VHostBlk *s)
+{
+    uint32_t nr = s->conf.num_queues * s->conf.queue_size;
+    struct vhost_blk_held_reqs *reqs;
+
+    if (!s->hold_supported) {
+        return NULL;
+    }
+
+    reqs = g_malloc0(sizeof(*reqs) + nr * sizeof(reqs->reqs[0]));
+    reqs->nr = nr;
+    if (ioctl(s->vhostfd, VHOST_BLK_GET_HELD_REQS, reqs)) {
+        error_report("vhost-blk: unable to get held requests: %s",
+                     strerror(errno));
+        g_free(reqs);
+        return NULL;
+    }
+    return reqs;
+}
+
+static void vhost_blk_save_held(VHostBlk *s)
+{
+    g_autofree struct vhost_blk_held_reqs *reqs = vhost_blk_get_held(s);
+    int i;
+
+    g_free(s->held);
+    s->held = NULL;
+    s->nr_held = reqs ? reqs->nr : 0;
+    if (!s->nr_held) {
+        return;
+    }
+
+    s->held = g_new(VHostBlkHeldReq, s->nr_held);
+    for (i = 0; i < s->nr_held; i++) {
+        s->held[i].vq = reqs->reqs[i].vq;
+        s->held[i].head = reqs->reqs[i].head;
+    }
+}
+
+static void vhost_blk_resubmit_held(VHostBlk *s)
+{
+    g_autofree struct vhost_blk_held_reqs *reqs = NULL;
+    uint32_t i, nr, done = 0;
+
+    if (!s->nr_held) {
+        return;
+    }
+
+    reqs = g_malloc0(sizeof(*reqs) + s->nr_held * sizeof(reqs->reqs[0]));
+
+    while (done < s->nr_held) {
+        nr = s->nr_held - done;
+        reqs->nr = nr;
+        for (i = 0; i < nr; i++) {
+            reqs->reqs[i].vq = s->held[done + i].vq;
+            reqs->reqs[i].head = s->held[done + i].head;
+        }
+
+        if (!ioctl(s->vhostfd, VHOST_BLK_RESUBMIT, reqs)) {
+            break;
+        }
+        if (reqs->nr >= nr) {
+            error_report("vhost-blk: unable to resubmit held requests: %s",
+                         strerror(errno));
+            break;
+        }
+
+        done += reqs->nr;
+        if (errno == ENOMEM) {
+            continue;
+        }
+        error_report("vhost-blk: unable to resubmit held request "
+                     "vq %u head %u: %s", s->held[done].vq,
+                     s->held[done].head, strerror(errno));
+        done++;
+    }
+
+    g_free(s->held);
+    s->held = NULL;
+    s->nr_held = 0;
+}
 
 /*
  * Spread the virtqueues round-robin over nworkers kernel threads. Thread 0 is
@@ -115,6 +211,19 @@ static int vhost_blk_start(VirtIODevice *vdev)
         return -ENOSYS;
     }
 
+    if (s->hold_supported) {
+        uint64_t policy = vhost_blk_error_policy(s);
+        int fd = event_notifier_get_fd(&s->error_notifier);
+
+        /* VHOST_RESET_OWNER drops both */
+        if (ioctl(s->vhostfd, VHOST_BLK_SET_ERROR_POLICY, &policy) ||
+            ioctl(s->vhostfd, VHOST_BLK_SET_ERROR_FD, &fd)) {
+            error_report("vhost-blk: unable to set error policy");
+            ret = -EINVAL;
+            goto err_reset_owner;
+        }
+    }
+
     if (nworkers > 1) {
         ret = vhost_blk_set_workers(hdev, nworkers);
         if (ret < 0) {
@@ -170,6 +279,8 @@ static int vhost_blk_start(VirtIODevice *vdev)
         event_notifier_set(virtio_queue_get_host_notifier(virtio_get_queue(vdev, i)));
     }
 
+    vhost_blk_resubmit_held(s);
+
     s->vhost_started = true;
 
     return 0;
@@ -216,6 +327,8 @@ static void vhost_blk_stop(VirtIODevice *vdev)
     ret = ioctl(s->vhostfd, VHOST_BLK_SET_BACKEND, &backend);
     assert(ret == 0);
 
+    vhost_blk_save_held(s);
+
     vhost_dev_stop(hdev, vdev, false);
 
     ret = k->set_guest_notifiers(qbus->parent, hdev->nvqs, false);
@@ -239,6 +352,16 @@ static void vhost_blk_reset(VirtIODevice *vdev)
     }
 }
 
+static void vhost_blk_device_reset(VirtIODevice *vdev)
+{
+    VHostBlk *s = VHOST_BLK(vdev);
+
+    vhost_blk_reset(vdev);
+    g_free(s->held);
+    s->held = NULL;
+    s->nr_held = 0;
+}
+
 static int vhost_blk_set_status(VirtIODevice *vdev, uint8_t status)
 {
     int ret;
@@ -274,6 +397,38 @@ static void vhost_blk_vm_state(void *opaque, bool running, RunState state)
     }
 }
 
+static void vhost_blk_error_event(EventNotifier *n)
+{
+    VHostBlk *s = container_of(n, VHostBlk, error_notifier);
+    DeviceState *dev = DEVICE(s);
+    DeviceState *proxy = qdev_get_parent_bus(dev)->parent;
+    g_autofree struct vhost_blk_held_reqs *reqs = NULL;
+    g_autofree char *path = NULL;
+    struct vhost_blk_held_req *req;
+
+    if (!event_notifier_test_and_clear(n) || !s->vhost_started ||
+        !runstate_is_running()) {
+        return;
+    }
+
+    reqs = vhost_blk_get_held(s);
+    if (!reqs || !reqs->nr) {
+        return;
+    }
+    req = &reqs->reqs[reqs->nr - 1];
+    path = object_get_canonical_path(OBJECT(dev));
+
+    qemu_system_vmstop_request_prepare();
+    qapi_event_send_block_io_error(path, proxy->id ?: "", NULL,
+                                   req->type == VIRTIO_BLK_T_IN ?
+                                   IO_OPERATION_TYPE_READ :
+                                   IO_OPERATION_TYPE_WRITE,
+                                   BLOCK_ERROR_ACTION_STOP, true,
+                                   req->error == ENOSPC, strerror(req->error),
+                                   0, 0);
+    qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
+}
+
 static bool vhost_blk_update_size(VHostBlk *s, Error **errp)
 {
     BlockConf *conf = &s->conf.conf;
@@ -720,6 +875,7 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
     VHostBlk *s = VHOST_BLK(vdev);
     VhostBlkConf *conf = &s->conf;
     struct vhost_virtqueue *vqs;
+    uint64_t policy = 0;
     int i, ret;
 
     if (!conf->devpath) {
@@ -796,6 +952,13 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
 
     s->mighand = qemu_add_vm_change_state_handler(vhost_blk_vm_state, vdev);
 
+    ret = event_notifier_init(&s->error_notifier, 0);
+    if (ret < 0) {
+        error_setg_errno(errp, -ret,
+                         "vhost-blk: unable to create the error eventfd");
+        goto cleanup;
+    }
+
     ret = vhost_dev_init(&s->dev, (void *)((size_t)s->vhostfd),
                          VHOST_BACKEND_TYPE_KERNEL, 0, NULL);
     if (ret < 0) {
@@ -815,6 +978,14 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
         goto cleanup;
     }
 
+    event_notifier_set_handler(&s->error_notifier, vhost_blk_error_event);
+    s->hold_supported = !ioctl(s->vhostfd, VHOST_BLK_SET_ERROR_POLICY,
+                               &policy);
+    if (!s->hold_supported && vhost_blk_error_policy(s)) {
+        warn_report("vhost-blk: the kernel cannot hold failed requests, "
+                    "werror and rerror have no effect");
+    }
+
     return;
 
 cleanup:
@@ -831,6 +1002,7 @@ cleanup:
         s->backend_fd = -1;
     }
     vhost_blk_uevent_detach(s);
+    event_notifier_cleanup(&s->error_notifier);
     for (i = 0; i < conf->num_queues; i++) {
         virtio_del_queue(vdev, i);
     }
@@ -848,6 +1020,9 @@ static void vhost_blk_device_unrealize(DeviceState *dev)
     qemu_del_vm_change_state_handler(s->mighand);
     vhost_blk_stop(vdev);
     vhost_dev_cleanup(&s->dev);
+    event_notifier_set_handler(&s->error_notifier, NULL);
+    event_notifier_cleanup(&s->error_notifier);
+    g_free(s->held);
     if (s->backend_fd >= 0) {
         qemu_close(s->backend_fd);
         s->backend_fd = -1;
@@ -999,7 +1174,7 @@ static void vhost_blk_class_init(ObjectClass *klass, const void *data)
     vdc->get_config = vhost_blk_update_config;
     vdc->get_features = vhost_blk_get_features;
     vdc->set_status = vhost_blk_set_status;
-    vdc->reset = vhost_blk_reset;
+    vdc->reset = vhost_blk_device_reset;
     vdc->get_vhost = vhost_blk_get_vhost;
 }
 
diff --git a/include/hw/virtio/vhost-blk.h b/include/hw/virtio/vhost-blk.h
index 9110462109f..dd6dd53c1c7 100644
--- a/include/hw/virtio/vhost-blk.h
+++ b/include/hw/virtio/vhost-blk.h
@@ -35,6 +35,11 @@ typedef struct VhostBlkConf {
     char *serial;
 } VhostBlkConf;
 
+typedef struct VHostBlkHeldReq {
+    uint16_t vq;
+    uint16_t head;
+} VHostBlkHeldReq;
+
 typedef struct VHostBlk {
     VirtIODevice parent_obj;
     VhostBlkConf conf;
@@ -52,6 +57,10 @@ typedef struct VHostBlk {
     bool discard;
     QEMUBH *resize_bh;
     Error *cpr_blocker;
+    EventNotifier error_notifier;
+    bool hold_supported;
+    VHostBlkHeldReq *held;
+    int32_t nr_held;
 } VHostBlk;
 
 #endif
-- 
2.53.0


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

* [PATCH hci-8.2 v3 5/5] vhost-blk: migrate the held requests #VSTOR-152175
  2026-11-30  9:42 [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
                   ` (3 preceding siblings ...)
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
@ 2026-11-30  9:42 ` Alexander Ivanov
  2026-12-01  1:10   ` no-reply
  4 siblings, 1 reply; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-30  9:42 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

Requests held by vhost-blk after ENOSPC are in neither the avail nor
the used ring, so a migration loses them and the guest waits for them
forever.

The request data stays in guest memory, so send only the vq and head
of each request, in a subsection present when there are held requests.
The destination resubmits them when it starts vhost, as after a pause.

Fail the load if the destination kernel cannot resubmit.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 hw/block/vhost-blk.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 19003def393..125fb32dcdf 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -1151,14 +1151,92 @@ static const Property vhost_blk_properties[] = {
     DEFINE_BLOCK_ERROR_PROPERTIES(VHostBlk, conf.conf),
 };
 
+static bool vhost_blk_held_needed(void *opaque)
+{
+    VHostBlk *s = opaque;
+
+    return s->nr_held > 0;
+}
+
+static int vhost_blk_pre_load(void *opaque)
+{
+    VHostBlk *s = opaque;
+
+    g_free(s->held);
+    s->held = NULL;
+    s->nr_held = 0;
+    return 0;
+}
+
+static bool vhost_blk_nr_held_valid(void *opaque, int version_id)
+{
+    VHostBlk *s = opaque;
+
+    return s->nr_held >= 0 &&
+           s->nr_held <= (uint32_t)s->conf.num_queues * s->conf.queue_size;
+}
+
+static int vhost_blk_held_post_load(void *opaque, int version_id)
+{
+    VHostBlk *s = opaque;
+    int i;
+
+    if (!s->hold_supported) {
+        error_report("vhost-blk: the kernel cannot resubmit held requests");
+        return -ENOTSUP;
+    }
+
+    for (i = 0; i < s->nr_held; i++) {
+        if (s->held[i].vq >= s->conf.num_queues ||
+            s->held[i].head >= s->conf.queue_size) {
+            error_report("vhost-blk: invalid held request: vq %u head %u",
+                         s->held[i].vq, s->held[i].head);
+            return -EINVAL;
+        }
+    }
+    return 0;
+}
+
+static const VMStateDescription vmstate_vhost_blk_held_req = {
+    .name = "vhost-blk/held-req",
+    .minimum_version_id = 1,
+    .version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT16(vq, VHostBlkHeldReq),
+        VMSTATE_UINT16(head, VHostBlkHeldReq),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+static const VMStateDescription vmstate_vhost_blk_held = {
+    .name = "vhost-blk/held",
+    .minimum_version_id = 1,
+    .version_id = 1,
+    .needed = vhost_blk_held_needed,
+    .post_load = vhost_blk_held_post_load,
+    .fields = (const VMStateField[]) {
+        VMSTATE_INT32(nr_held, VHostBlk),
+        VMSTATE_VALIDATE("nr_held in range", vhost_blk_nr_held_valid),
+        VMSTATE_STRUCT_VARRAY_ALLOC(held, VHostBlk, nr_held, 1,
+                                    vmstate_vhost_blk_held_req,
+                                    VHostBlkHeldReq),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
 static const VMStateDescription vmstate_vhost_blk = {
     .name = "vhost-blk",
     .minimum_version_id = 1,
     .version_id = 1,
+    .pre_load = vhost_blk_pre_load,
     .fields = (VMStateField[]) {
         VMSTATE_VIRTIO_DEVICE,
         VMSTATE_END_OF_LIST()
     },
+    .subsections = (const VMStateDescription * const []) {
+        &vmstate_vhost_blk_held,
+        NULL
+    },
 };
 
 static void vhost_blk_class_init(ObjectClass *klass, const void *data)
-- 
2.53.0


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

* Re: [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  0:53   ` no-reply
  2026-12-01  9:03     ` Alexander Ivanov
  0 siblings, 1 reply; 14+ messages in thread
From: no-reply @ 2026-12-01  0:53 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] linux-headers: ambiguous 'reserved must be 0' in held-request
  ioctl docs
--

commit 611e7f67446f06e405b70a31daff650440389848
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

linux-headers: add the vhost-blk held request ioctls #VSTOR-152175

This adds the UAPI for holding vhost-blk requests that fail with ENOSPC. It defines the error policy flags, the held request structures and the four ioctls VHOST_BLK_SET_ERROR_POLICY, VHOST_BLK_SET_ERROR_FD, VHOST_BLK_GET_HELD_REQS and VHOST_BLK_RESUBMIT.

> diff --git a/include/standard-headers/linux/vhost_types.h b/include/standard-headers/linux/vhost_types.h
> --- a/include/standard-headers/linux/vhost_types.h
> +++ b/include/standard-headers/linux/vhost_types.h

[ ... ]

> +struct vhost_blk_held_req {
> +	uint16_t vq;
> +	uint16_t head;
> +	int32_t error;		/* positive errno */
> +	uint32_t type;		/* VIRTIO_BLK_T_* */
> +	uint32_t reserved;
> +};
> +
> +struct vhost_blk_held_reqs {
> +	uint32_t nr;
> +	uint32_t reserved;
> +	struct vhost_blk_held_req reqs[];
> +};
> diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h
> --- a/linux-headers/linux/vhost.h
> +++ b/linux-headers/linux/vhost.h

[ ... ]

> +/*
> + * Resubmit requests by vq and head, as if they were just taken from the avail
> + * ring. Only heads read with VHOST_BLK_GET_HELD_REQS after the last stop may be
> + * passed: the kernel does not track them, and a head passed again after its
> + * request completed, or still owned by the guest, is completed twice. A head
> + * still in flight fails with -EBUSY. error and type are ignored, reserved
> + * must be 0. On error, nr is set to the number of requests resubmitted.
> + */
> +#define VHOST_BLK_RESUBMIT		_IOWR(VHOST_VIRTIO, 0xFA, \
> +					      struct vhost_blk_held_reqs)

[Severity: Low]
This isn't a bug, but is "reserved must be 0" clear enough here and in the VHOST_BLK_GET_HELD_REQS comment? Both struct vhost_blk_held_reqs and struct vhost_blk_held_req have a field named reserved. The comments do not say whether only the outer field, or also the reserved field of every element in reqs[], must be zero on input.

The VHOST_BLK_RESUBMIT comment also says error and type are ignored, but never says that vq and head are the fields read from each element. It does not say that nr is the number of entries to resubmit, whereas for GET it is the capacity of reqs[]. Since this header is the only ABI specification, could these be spelled out?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261130094210.1686802-1-alexander.ivanov@virtuozzo.com?part=1

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

* Re: [PATCH hci-8.2 v3 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  0:54   ` no-reply
  0 siblings, 0 replies; 14+ messages in thread
From: no-reply @ 2026-12-01  0:54 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

> libvirt passes werror and rerror to the device when the disk has
> error_policy or rerror_policy set, and QEMU refuses to start such a VM
> with vhost-blk.
> 
> Accept them with the defaults of other block devices: enospc for
> writes and report for reads. vhost-blk completes requests in the
> kernel, which cannot ignore an error, so reject the ignore policy. The
> other policies take effect with the next patch.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261130094210.1686802-1-alexander.ivanov@virtuozzo.com?part=2


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

* Re: [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  0:58   ` no-reply
  2026-12-01  9:07     ` Alexander Ivanov
  0 siblings, 1 reply; 14+ messages in thread
From: no-reply @ 2026-12-01  0:58 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] vhost-blk: bug-fix commit lacks a Fixes: trailer
--

commit e71551fedc73f702d64432e0da34c0e1ff494f27
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

> vhost-blk: stop vhost on every VM stop #VSTOR-152175
>
> vhost is stopped only on pause and at the end of a migration. In any
> other stopped state it keeps running in the kernel, so the device
> state saved there is stale: vhost_dev_stop(), which fetches the vring
> indexes from the kernel, has not run.
>
> This affects savevm, which stops the VM with the save-vm reason, and
> a migration of a VM stopped for debug, shutdown, a guest panic or a
> watchdog: the VM is not live, so the migration does not run the state
> handlers again. The destination then processes anew the requests the
> source completed after the indexes were last fetched.
>
> Stop vhost whenever the VM stops and start it whenever the VM runs.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

[Severity: Low]
This looks like a bug fix for the state-based start/stop filtering in
vhost_blk_vm_state(). Should this include:

  Fixes: c08e1fb19635 ("vhost_blk: support state saving #VSTOR-90838")

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261130094210.1686802-1-alexander.ivanov@virtuozzo.com?part=3

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

* Re: [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  1:07   ` no-reply
  2026-12-01  9:14     ` Alexander Ivanov
  0 siblings, 1 reply; 14+ messages in thread
From: no-reply @ 2026-12-01  1:07 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] vhost-blk: vhost_blk_resubmit_held() retries ENOMEM forever
  without progress
- [Medium] vhost-blk: vhost_blk_save_held() drops held requests when
  GET_HELD_REQS fails
- [Low] vhost-blk: vhost_blk_resubmit_held() drops a head on resubmit
  error
--

commit 81d26424eb761f296b39790b51894a86c271e60a
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

vhost-blk: pause the VM on a request failed with ENOSPC

vhost-blk completes requests in the kernel, so werror and rerror have no effect. This commit sets a hold policy in the kernel from werror and rerror, and passes an eventfd that is signalled on a held request. QEMU then stops the VM with the io-error reason, saves the held requests when vhost stops, and resubmits them on the next start.

> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 124885a2b3005..19003def39335 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c

[ ... ]

> +static void vhost_blk_save_held(VHostBlk *s)
> +{
> +    g_autofree struct vhost_blk_held_reqs *reqs = vhost_blk_get_held(s);
> +    int i;
> +
> +    g_free(s->held);
> +    s->held = NULL;
> +    s->nr_held = reqs ? reqs->nr : 0;

[Severity: Medium]
Does this lose held requests when VHOST_BLK_GET_HELD_REQS fails?
vhost_blk_get_held() returns NULL on any ioctl failure, and this line
treats that the same as an empty list.

The held heads are already consumed from the avail ring, and the kernel
list is dropped by the following VHOST_RESET_OWNER or the next
SET_BACKEND. Nothing is saved on the QEMU side, so these requests are
never resubmitted or completed, and the guest hangs on those descriptors.
Before this patch such requests were completed with an error. Should the
failure be distinguished from an empty list?

[ ... ]

> +static void vhost_blk_resubmit_held(VHostBlk *s)
> +{

[ ... ]

> +        if (!ioctl(s->vhostfd, VHOST_BLK_RESUBMIT, reqs)) {
> +            break;
> +        }
> +        if (reqs->nr >= nr) {
> +            error_report("vhost-blk: unable to resubmit held requests: %s",
> +                         strerror(errno));
> +            break;
> +        }
> +
> +        done += reqs->nr;
> +        if (errno == ENOMEM) {
> +            continue;
> +        }

[Severity: Medium]
Can this loop spin forever? If VHOST_BLK_RESUBMIT keeps failing with
ENOMEM and reports reqs->nr == 0, then "reqs->nr >= nr" is false,
"done += reqs->nr" adds nothing, and "continue" reissues the identical
request.

This runs from vhost_blk_start() on the main loop thread with the BQL
held (vm-state handler or set_status on DRIVER_OK), so the whole VM and
QMP would hang under host memory pressure. Would a no-progress check or
a retry bound help here?

> +        error_report("vhost-blk: unable to resubmit held request "
> +                     "vq %u head %u: %s", s->held[done].vq,
> +                     s->held[done].head, strerror(errno));
> +        done++;
> +    }
> +
> +    g_free(s->held);
> +    s->held = NULL;
> +    s->nr_held = 0;

[Severity: Low]
Is the guest request for a skipped head ever completed? When
VHOST_BLK_RESUBMIT fails for one head with an error other than ENOMEM,
the head is logged and skipped with done++, and s->held is freed after
the loop.

The linux-headers comment for VHOST_BLK_RESUBMIT says the kernel does not
track heads once they have been read out, so no later start can retry
this one. That guest I/O stays outstanding until the guest times out or
resets the device.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261130094210.1686802-1-alexander.ivanov@virtuozzo.com?part=4

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

* Re: [PATCH hci-8.2 v3 5/5] vhost-blk: migrate the held requests #VSTOR-152175
  2026-11-30  9:42 ` [PATCH hci-8.2 v3 5/5] vhost-blk: migrate the held requests #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  1:10   ` no-reply
  0 siblings, 0 replies; 14+ messages in thread
From: no-reply @ 2026-12-01  1:10 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

> Requests held by vhost-blk after ENOSPC are in neither the avail nor
> the used ring, so a migration loses them and the guest waits for them
> forever.
> 
> The request data stays in guest memory, so send only the vq and head
> of each request, in a subsection present when there are held requests.
> The destination resubmits them when it starts vhost, as after a pause.
> 
> Fail the load if the destination kernel cannot resubmit.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261130094210.1686802-1-alexander.ivanov@virtuozzo.com?part=5


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

* Re: [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175
  2026-12-01  0:53   ` no-reply
@ 2026-12-01  9:03     ` Alexander Ivanov
  0 siblings, 0 replies; 14+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:03 UTC (permalink / raw)
  To: no-reply, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

>> +/*
>> + * Resubmit requests by vq and head, as if they were just taken from the avail
>> + * ring. Only heads read with VHOST_BLK_GET_HELD_REQS after the last stop may be
>> + * passed: the kernel does not track them, and a head passed again after its
>> + * request completed, or still owned by the guest, is completed twice. A head
>> + * still in flight fails with -EBUSY. error and type are ignored, reserved
>> + * must be 0. On error, nr is set to the number of requests resubmitted.
>> + */
>> +#define VHOST_BLK_RESUBMIT		_IOWR(VHOST_VIRTIO, 0xFA, \
>> +					      struct vhost_blk_held_reqs)
> [Severity: Low]
> This isn't a bug, but is "reserved must be 0" clear enough here and in the VHOST_BLK_GET_HELD_REQS comment? Both struct vhost_blk_held_reqs and struct vhost_blk_held_req have a field named reserved. The comments do not say whether only the outer field, or also the reserved field of every element in reqs[], must be zero on input.
>
> The VHOST_BLK_RESUBMIT comment also says error and type are ignored, but never says that vq and head are the fields read from each element. It does not say that nr is the number of entries to resubmit, whereas for GET it is the capacity of reqs[]. Since this header is the only ABI specification, could these be spelled out?
Not changing this. This header is a copy of the kernel uapi one, so the
wording is not for this series to fix. The comment already names vq and
head as the fields read, and zeroing every reserved field is the usual
uapi convention, which QEMU follows.

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

* Re: [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175
  2026-12-01  0:58   ` no-reply
@ 2026-12-01  9:07     ` Alexander Ivanov
  0 siblings, 0 replies; 14+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:07 UTC (permalink / raw)
  To: no-reply, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

> [Severity: Low]
> This looks like a bug fix for the state-based start/stop filtering in
> vhost_blk_vm_state(). Should this include:
>
>    Fixes: c08e1fb19635 ("vhost_blk: support state saving #VSTOR-90838")
>
Added a Fixes tag, but pointing at d31b67263a21 ("hw/block/vhost-blk:
support migration #PSBM-152243"). That commit introduced the state-based
filtering, stopping vhost on RUN_STATE_FINISH_MIGRATE only. c08e1fb19635
just extended the condition with RUN_STATE_PAUSED, so it narrowed the
bug rather than introduced it.

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

* Re: [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175
  2026-12-01  1:07   ` no-reply
@ 2026-12-01  9:14     ` Alexander Ivanov
  0 siblings, 0 replies; 14+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:14 UTC (permalink / raw)
  To: no-reply, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

>> +static void vhost_blk_save_held(VHostBlk *s)
>> +{
>> +    g_autofree struct vhost_blk_held_reqs *reqs = vhost_blk_get_held(s);
>> +    int i;
>> +
>> +    g_free(s->held);
>> +    s->held = NULL;
>> +    s->nr_held = reqs ? reqs->nr : 0;
> [Severity: Medium]
> Does this lose held requests when VHOST_BLK_GET_HELD_REQS fails?
> vhost_blk_get_held() returns NULL on any ioctl failure, and this line
> treats that the same as an empty list.
>
> The held heads are already consumed from the avail ring, and the kernel
> list is dropped by the following VHOST_RESET_OWNER or the next
> SET_BACKEND. Nothing is saved on the QEMU side, so these requests are
> never resubmitted or completed, and the guest hangs on those descriptors.
> Before this patch such requests were completed with an error. Should the
> failure be distinguished from an empty list?
The ioctl cannot fail here: the buffer is valid, zeroed and sized for
the maximum, and the owner is set. If it did fail, QEMU would know
neither vq nor head, so there would be nothing to recover with.
>> +        if (!ioctl(s->vhostfd, VHOST_BLK_RESUBMIT, reqs)) {
>> +            break;
>> +        }
>> +        if (reqs->nr >= nr) {
>> +            error_report("vhost-blk: unable to resubmit held requests: %s",
>> +                         strerror(errno));
>> +            break;
>> +        }
>> +
>> +        done += reqs->nr;
>> +        if (errno == ENOMEM) {
>> +            continue;
>> +        }
> [Severity: Medium]
> Can this loop spin forever? If VHOST_BLK_RESUBMIT keeps failing with
> ENOMEM and reports reqs->nr == 0, then "reqs->nr >= nr" is false,
> "done += reqs->nr" adds nothing, and "continue" reissues the identical
> request.
>
> This runs from vhost_blk_start() on the main loop thread with the BQL
> held (vm-state handler or set_status on DRIVER_OK), so the whole VM and
> QMP would hang under host memory pressure. Would a no-progress check or
> a retry bound help here?
-ENOMEM here comes only from GFP_KERNEL allocations, so it is
transient: each retry sleeps in reclaim and stays killable. Bounding
the retries would drop the held requests and hang the guest I/O for
good, so I'd keep the loop as is.
>> +        error_report("vhost-blk: unable to resubmit held request "
>> +                     "vq %u head %u: %s", s->held[done].vq,
>> +                     s->held[done].head, strerror(errno));
>> +        done++;
>> +    }
>> +
>> +    g_free(s->held);
>> +    s->held = NULL;
>> +    s->nr_held = 0;
> [Severity: Low]
> Is the guest request for a skipped head ever completed? When
> VHOST_BLK_RESUBMIT fails for one head with an error other than ENOMEM,
> the head is logged and skipped with done++, and s->held is freed after
> the loop.
>
> The linux-headers comment for VHOST_BLK_RESUBMIT says the kernel does not
> track heads once they have been read out, so no later start can retry
> this one. That guest I/O stays outstanding until the guest times out or
> resets the device.
Right, but only on errors the guest causes itself: a descriptor chain
changed or a head reused while the request was held. The regular kick
path leaves such a head uncompleted too, and -ENOMEM is retried.

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

end of thread, other threads:[~2026-12-01  9:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  9:42 [PATCH hci-8.2 v3 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
2026-11-30  9:42 ` [PATCH hci-8.2 v3 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
2026-12-01  0:53   ` no-reply
2026-12-01  9:03     ` Alexander Ivanov
2026-11-30  9:42 ` [PATCH hci-8.2 v3 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
2026-12-01  0:54   ` no-reply
2026-11-30  9:42 ` [PATCH hci-8.2 v3 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
2026-12-01  0:58   ` no-reply
2026-12-01  9:07     ` Alexander Ivanov
2026-11-30  9:42 ` [PATCH hci-8.2 v3 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
2026-12-01  1:07   ` no-reply
2026-12-01  9:14     ` Alexander Ivanov
2026-11-30  9:42 ` [PATCH hci-8.2 v3 5/5] vhost-blk: migrate the held requests #VSTOR-152175 Alexander Ivanov
2026-12-01  1:10   ` no-reply

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.