Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH 2/3] hw/virtio: Implement vhost_log_start and vhost_log_stop
@ 2026-07-24  9:37 Weimin Xiong
  2026-07-24  9:37 ` [PATCH 3/3] hw/virtio: Add error handling for vhost_virtqueue_mask failure Weimin Xiong
  2026-07-24  9:48 ` [PATCH 2/3] hw/virtio: Implement vhost_log_start and vhost_log_stop Michael S. Tsirkin
  0 siblings, 2 replies; 4+ messages in thread
From: Weimin Xiong @ 2026-07-24  9:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: jasowang, mst, virtualization, Xiong Weimin

From: Xiong Weimin <xiongweimin@kylinos.cn>

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.

Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
---
 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


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

end of thread, other threads:[~2026-07-24  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24  9:37 [PATCH 2/3] hw/virtio: Implement vhost_log_start and vhost_log_stop Weimin Xiong
2026-07-24  9:37 ` [PATCH 3/3] hw/virtio: Add error handling for vhost_virtqueue_mask failure Weimin Xiong
2026-07-24  9:51   ` Michael S. Tsirkin
2026-07-24  9:48 ` [PATCH 2/3] hw/virtio: Implement vhost_log_start and vhost_log_stop Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox