On Fri, Jul 24, 2026 at 05:37:58PM +0800, Weimin Xiong wrote:
> From: Xiong Weimin <[email protected]>
> 
> The vhost_log_start() and vhost_log_stop() functions are currently
> empty stubs with FIXME comments. Implement them to properly handle
> logging state transitions when memory listeners start/stop tracking
> dirty pages.
> 
> This is needed for proper dirty page logging during live migration.

Is the implications that in your opinion dirty page logging during live
migration does not work currently?

> Signed-off-by: Xiong Weimin <[email protected]>
> ---
>  hw/virtio/vhost.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 1234567890ab..fedcba098765 4321006
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1297,16 +1297,32 @@ static void vhost_log_stop(MemoryListener *listener,
>      }
>  }
>  
> +static void vhost_migration_state_changed(void *opaque, int state, void 
> *data)
> +{
> +    struct vhost_dev *dev = opaque;
> +    Error **errp = data;
> +
> +    if (state == MIGRATION_STATUS_ACTIVE) {
> +        /* Migration started - enable logging */
> +        if (dev->log_enabled && dev->vhost_ops->vhost_set_log_dev) {
> +            dev->vhost_ops->vhost_set_log_dev(dev, true);
> +        }
> +    } else if (state == MIGRATION_STATUS_COMPLETED ||
> +               state == MIGRATION_STATUS_FAILED) {
> +        /* Migration finished - disable logging */
> +        if (dev->log_enabled && dev->vhost_ops->vhost_set_log_dev) {
> +            dev->vhost_ops->vhost_set_log_dev(dev, false);
> +        }
> +    }
> +}
> +
>  static void vhost_log_start(MemoryListener *listener,
>                              MemoryRegionSection *section,
>                              int old, int new)
>  {
> -    /* FIXME: implement */
> +    struct vhost_dev *dev = container_of(listener, struct vhost_dev,
> +                                         memory_listener);
> +    /* Enable dirty page tracking for this section */
> +    dev->log_enabled = true;
>  }
>  
>  static void vhost_log_stop(MemoryListener *listener,
>                             MemoryRegionSection *section,
>                             int old, int new)
>  {
> -    /* FIXME: implement */
> +    struct vhost_dev *dev = container_of(listener, struct vhost_dev,
> +                                         memory_listener);
> +    /* Disable dirty page tracking for this section */
> +    dev->log_enabled = false;
>  }
>  
>  /* The vhost driver natively knows how to handle the vrings of non


Reply via email to