All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, svt-core@virtuozzo.com
Subject: [PATCH hci-8.2 v4 5/5] vhost-blk: migrate the held requests #VSTOR-152175
Date: Tue,  1 Dec 2026 10:18:18 +0100	[thread overview]
Message-ID: <20261201091818.1894308-6-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261201091818.1894308-1-alexander.ivanov@virtuozzo.com>

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


      parent reply	other threads:[~2026-12-01  9:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Alexander Ivanov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201091818.1894308-6-alexander.ivanov@virtuozzo.com \
    --to=alexander.ivanov@virtuozzo.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.