[PATCH 25/33] virtio: introduce .skip_vhost_migration_log() handler

Vladimir Sementsov-Ogievskiy posted 33 patches 3 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, Jason Wang <jasowang@redhat.com>, Fam Zheng <fam@euphon.net>, "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH 25/33] virtio: introduce .skip_vhost_migration_log() handler
Posted by Vladimir Sementsov-Ogievskiy 3 months ago
For vhost user backend migration we'll need to disable memory
logging on the device. Let's prepare a corresponding handler for
the device.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/virtio/vhost.c          | 10 ++++++++++
 include/hw/virtio/virtio.h |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index e7c809400b..0427fc29b2 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1134,6 +1134,16 @@ static int vhost_migration_log(MemoryListener *listener, bool enable)
     struct vhost_dev *dev = container_of(listener, struct vhost_dev,
                                          memory_listener);
     int r;
+
+    if (dev->vdev) {
+        VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
+
+        if (vdc->skip_vhost_migration_log &&
+            vdc->skip_vhost_migration_log(dev->vdev)) {
+            return 0;
+        }
+    }
+
     if (enable == dev->log_enabled) {
         return 0;
     }
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 8b9db08ddf..9a4a0a94aa 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -234,6 +234,8 @@ struct VirtioDeviceClass {
     /* May be called even when vdev->vhost_started is false */
     struct vhost_dev *(*get_vhost)(VirtIODevice *vdev);
     void (*toggle_device_iotlb)(VirtIODevice *vdev);
+
+    bool (*skip_vhost_migration_log)(VirtIODevice *vdev);
 };
 
 void virtio_instance_init_common(Object *proxy_obj, void *data,
-- 
2.48.1
Re: [PATCH 25/33] virtio: introduce .skip_vhost_migration_log() handler
Posted by Raphael Norwitz 1 month ago
Acked-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>

On Wed, Aug 13, 2025 at 1:00 PM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> For vhost user backend migration we'll need to disable memory
> logging on the device. Let's prepare a corresponding handler for
> the device.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/vhost.c          | 10 ++++++++++
>  include/hw/virtio/virtio.h |  2 ++
>  2 files changed, 12 insertions(+)
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index e7c809400b..0427fc29b2 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1134,6 +1134,16 @@ static int vhost_migration_log(MemoryListener *listener, bool enable)
>      struct vhost_dev *dev = container_of(listener, struct vhost_dev,
>                                           memory_listener);
>      int r;
> +
> +    if (dev->vdev) {
> +        VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
> +
> +        if (vdc->skip_vhost_migration_log &&
> +            vdc->skip_vhost_migration_log(dev->vdev)) {
> +            return 0;
> +        }
> +    }
> +
>      if (enable == dev->log_enabled) {
>          return 0;
>      }
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 8b9db08ddf..9a4a0a94aa 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -234,6 +234,8 @@ struct VirtioDeviceClass {
>      /* May be called even when vdev->vhost_started is false */
>      struct vhost_dev *(*get_vhost)(VirtIODevice *vdev);
>      void (*toggle_device_iotlb)(VirtIODevice *vdev);
> +
> +    bool (*skip_vhost_migration_log)(VirtIODevice *vdev);
>  };
>
>  void virtio_instance_init_common(Object *proxy_obj, void *data,
> --
> 2.48.1
>
>