Commit 3a80ff0721 for qemu.org
commit 3a80ff0721b641f9c70af0d416c5c9e171c29aa3
Author: Alexandr Moshkov <dtalexundeer@yandex-team.ru>
Date: Thu Jan 15 13:11:07 2026 +0500
vhost: add vmstate for inflight region with inner buffer
Prepare for future inflight region migration for vhost-user-blk.
We need to migrate size, queue_size, and inner buffer.
So firstly it migrate size and queue_size fields, then allocate memory
for buffer with
migrated size, then migrate inner buffer itself.
Signed-off-by: Alexandr Moshkov <dtalexundeer@yandex-team.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20260115081103.655749-5-dtalexundeer@yandex-team.ru>
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index c6a5928cb1..52801c1796 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1918,6 +1918,62 @@ void vhost_get_features_ex(struct vhost_dev *hdev,
}
}
+static bool vhost_inflight_buffer_pre_load(void *opaque, Error **errp)
+{
+ struct vhost_inflight *inflight = opaque;
+
+ int fd = -1;
+ void *addr = qemu_memfd_alloc("vhost-inflight", inflight->size,
+ F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL,
+ &fd, errp);
+ if (*errp) {
+ return -ENOMEM;
+ }
+
+ inflight->offset = 0;
+ inflight->addr = addr;
+ inflight->fd = fd;
+
+ return true;
+}
+
+const VMStateDescription vmstate_vhost_inflight_region_buffer = {
+ .name = "vhost-inflight-region/buffer",
+ .pre_load_errp = vhost_inflight_buffer_pre_load,
+ .fields = (const VMStateField[]) {
+ VMSTATE_VBUFFER_UINT64(addr, struct vhost_inflight, 0, NULL, size),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static bool vhost_inflight_region_post_load(void *opaque,
+ int version_id,
+ Error **errp)
+{
+ struct vhost_inflight *inflight = opaque;
+
+ if (inflight->addr == NULL) {
+ error_setg(errp, "inflight buffer subsection has not been loaded");
+ return false;
+ }
+
+ return true;
+}
+
+const VMStateDescription vmstate_vhost_inflight_region = {
+ .name = "vhost-inflight-region",
+ .post_load_errp = vhost_inflight_region_post_load,
+ .fields = (const VMStateField[]) {
+ VMSTATE_UINT64(size, struct vhost_inflight),
+ VMSTATE_UINT16(queue_size, struct vhost_inflight),
+ VMSTATE_END_OF_LIST()
+ },
+ .subsections = (const VMStateDescription * const []) {
+ &vmstate_vhost_inflight_region_buffer,
+ NULL
+ }
+};
+
void vhost_ack_features_ex(struct vhost_dev *hdev, const int *feature_bits,
const uint64_t *features)
{