All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [PATCH hci-8.2 v4 0/5] vhost-blk: support the werror/rerror policies
@ 2026-12-01  9:18 Alexander Ivanov
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:18 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.

v4:
- patch 2, 5: add Reviewed-by
- patch 3: add the Fixes tag
- no code changes

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] 10+ messages in thread

* [PATCH hci-8.2 v4 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175
  2026-12-01  9:18 [PATCH hci-8.2 v4 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
@ 2026-12-01  9:18 ` Alexander Ivanov
  2026-12-01  9:21   ` no-reply
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:18 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] 10+ messages in thread

* [PATCH hci-8.2 v4 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175
  2026-12-01  9:18 [PATCH hci-8.2 v4 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:18 ` Alexander Ivanov
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:18 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>
Reviewed-by: Sashiko <no-reply@sashiko.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] 10+ messages in thread

* [PATCH hci-8.2 v4 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175
  2026-12-01  9:18 [PATCH hci-8.2 v4 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 2/5] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:18 ` Alexander Ivanov
  2026-12-01  9:24   ` no-reply
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 5/5] vhost-blk: migrate the held requests #VSTOR-152175 Alexander Ivanov
  4 siblings, 1 reply; 10+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:18 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

Fixes: d31b67263a21 ("hw/block/vhost-blk: support migration #PSBM-152243")
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] 10+ messages in thread

* [PATCH hci-8.2 v4 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175
  2026-12-01  9:18 [PATCH hci-8.2 v4 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
                   ` (2 preceding siblings ...)
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:18 ` Alexander Ivanov
  2026-12-01  9:25   ` no-reply
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 5/5] vhost-blk: migrate the held requests #VSTOR-152175 Alexander Ivanov
  4 siblings, 1 reply; 10+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:18 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] 10+ messages in thread

* [PATCH hci-8.2 v4 5/5] vhost-blk: migrate the held requests #VSTOR-152175
  2026-12-01  9:18 [PATCH hci-8.2 v4 0/5] vhost-blk: support the werror/rerror policies Alexander Ivanov
                   ` (3 preceding siblings ...)
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:18 ` Alexander Ivanov
  4 siblings, 0 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-12-01  9:18 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>
Reviewed-by: Sashiko <no-reply@sashiko.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] 10+ messages in thread

* Re: [PATCH hci-8.2 v4 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 1/5] linux-headers: add the vhost-blk held request ioctls #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:21   ` no-reply
  0 siblings, 0 replies; 10+ messages in thread
From: no-reply @ 2026-12-01  9:21 UTC (permalink / raw)
  To: Alexander Ivanov, 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>

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/20261201091818.1894308-1-alexander.ivanov@virtuozzo.com?part=1


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

* Re: [PATCH hci-8.2 v4 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 3/5] vhost-blk: stop vhost on every VM stop #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:24   ` no-reply
  0 siblings, 0 replies; 10+ messages in thread
From: no-reply @ 2026-12-01  9:24 UTC (permalink / raw)
  To: Alexander Ivanov, 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
> 
> Fixes: d31b67263a21 ("hw/block/vhost-blk: support migration #PSBM-152243")
> 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/20261201091818.1894308-1-alexander.ivanov@virtuozzo.com?part=3


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

* Re: [PATCH hci-8.2 v4 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175
  2026-12-01  9:18 ` [PATCH hci-8.2 v4 4/5] vhost-blk: pause the VM on a request failed with ENOSPC #VSTOR-152175 Alexander Ivanov
@ 2026-12-01  9:25   ` no-reply
  2026-12-01  9:41     ` Alexander Ivanov
  0 siblings, 1 reply; 10+ messages in thread
From: no-reply @ 2026-12-01  9:25 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 with no
  progress check or bound
- [Low] vhost-blk: BLOCK_IO_ERROR reports wrong op type and fake
  offset/bytes
- [Low] vhost-blk: realize warns about unsupported hold even with
  default werror
--

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

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

This commit makes vhost-blk set a hold policy in the kernel from werror and rerror. The kernel then holds requests that fail with ENOSPC instead of completing them with an error. QEMU stops the VM and emits BLOCK_IO_ERROR when a request is held, saves the held list on stop, and resubmits it on the next start.

> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -32,6 +32,102 @@
[ ... ]
> +    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;
> +        }

[Severity: Medium]
Can this loop spin forever? If VHOST_BLK_RESUBMIT keeps failing with ENOMEM and reports reqs->nr == 0, then done does not advance and the identical ioctl is reissued. There is no retry limit, backoff or zero-progress check.

vhost_blk_resubmit_held() runs from vhost_blk_start() with the BQL held, so the whole VM and QMP would hang under persistent host memory pressure. Should the ENOMEM retry give up, or back off, when reqs->nr is 0?

[ ... ]
> @@ -274,6 +397,38 @@ static void vhost_blk_vm_state(void *opaque, bool running, RunState state)
[ ... ]
> +    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);

[Severity: Low]
Is the event content accurate here? Any held request whose type is not VIRTIO_BLK_T_IN, such as flush, discard or write-zeroes, is reported as a WRITE. The offset and bytes are always 0, 0. The commit message says the event is emitted "as the block layer does for other devices", but management software gets inaccurate operation, offset and bytes fields.

[ ... ]
> @@ -815,6 +978,14 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
[ ... ]
> +    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");
> +    }

[Severity: Low]
Will this warning fire for every device on an older kernel? Realize maps werror=AUTO to BLOCKDEV_ON_ERROR_ENOSPC, so vhost_blk_error_policy() is non-zero even when the user never set werror or rerror. The result is log noise on every vhost-blk device, while the commit message only says "warn and run as before".

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

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

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

>> +    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;
>> +        }
> [Severity: Medium]
> Can this loop spin forever? If VHOST_BLK_RESUBMIT keeps failing with ENOMEM and reports reqs->nr == 0, then done does not advance and the identical ioctl is reissued. There is no retry limit, backoff or zero-progress check.
>
> vhost_blk_resubmit_held() runs from vhost_blk_start() with the BQL held, so the whole VM and QMP would hang under persistent host memory pressure. Should the ENOMEM retry give up, or back off, when reqs->nr is 0?
Already answered on the previous revision: -ENOMEM here is transient, 
and bounding the retries would drop the held requests and hang the guest 
I/O for good.
>> +    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);
> [Severity: Low]
> Is the event content accurate here? Any held request whose type is not VIRTIO_BLK_T_IN, such as flush, discard or write-zeroes, is reported as a WRITE. The offset and bytes are always 0, 0. The commit message says the event is emitted "as the block layer does for other devices", but management software gets inaccurate operation, offset and bytes fields.
This is intended. virtio-blk reports flush, discard and write-zeroes
failures as "write" too, IoOperationType has nothing else. The kernel
does not pass the sector and the length of a held request, so offset
and bytes are 0; libvirt does not read them.
>> +    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");
>> +    }
> [Severity: Low]
> Will this warning fire for every device on an older kernel? Realize maps werror=AUTO to BLOCKDEV_ON_ERROR_ENOSPC, so vhost_blk_error_policy() is non-zero even when the user never set werror or rerror. The result is log noise on every vhost-blk device, while the commit message only says "warn and run as before".
Intended: werror=auto means enospc, which pauses the VM on every other
block device. On an older kernel it does not, and the user should know
even with the defaults. It is one line per device at realize.

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

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

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

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.