29b115
From 8e0fdce814af4cfc84dce5e5920da989b1f1a86d Mon Sep 17 00:00:00 2001
29b115
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
29b115
Date: Thu, 21 Jul 2022 16:06:05 +0200
29b115
Subject: [PATCH 26/32] vdpa: Add device migration blocker
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Eugenio Pérez <eperezma@redhat.com>
29b115
RH-MergeRequest: 108: Net Control Virtqueue shadow Support
29b115
RH-Commit: [26/27] 53d94d45b5e5e88f12b95f9b0f243696cfcbd7ce (eperezmartin/qemu-kvm)
29b115
RH-Bugzilla: 1939363
29b115
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
29b115
RH-Acked-by: Cindy Lu <lulu@redhat.com>
29b115
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/1939363
29b115
29b115
Upstream Status: git://git.qemu.org/qemu.git
29b115
29b115
commit c156d5bf2b142dcc06808ccee06882144f230aec
29b115
Author: Eugenio Pérez <eperezma@redhat.com>
29b115
Date:   Wed Jul 20 08:59:45 2022 +0200
29b115
29b115
    vdpa: Add device migration blocker
29b115
29b115
    Since the vhost-vdpa device is exposing _F_LOG, adding a migration blocker if
29b115
    it uses CVQ.
29b115
29b115
    However, qemu is able to migrate simple devices with no CVQ as long as
29b115
    they use SVQ. To allow it, add a placeholder error to vhost_vdpa, and
29b115
    only add to vhost_dev when used. vhost_dev machinery place the migration
29b115
    blocker if needed.
29b115
29b115
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
29b115
    Signed-off-by: Jason Wang <jasowang@redhat.com>
29b115
29b115
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
---
29b115
 hw/virtio/vhost-vdpa.c         | 15 +++++++++++++++
29b115
 include/hw/virtio/vhost-vdpa.h |  1 +
29b115
 2 files changed, 16 insertions(+)
29b115
29b115
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
29b115
index 49effe5462..e3e5bce4bb 100644
29b115
--- a/hw/virtio/vhost-vdpa.c
29b115
+++ b/hw/virtio/vhost-vdpa.c
29b115
@@ -20,6 +20,7 @@
29b115
 #include "hw/virtio/vhost-shadow-virtqueue.h"
29b115
 #include "hw/virtio/vhost-vdpa.h"
29b115
 #include "exec/address-spaces.h"
29b115
+#include "migration/blocker.h"
29b115
 #include "qemu/main-loop.h"
29b115
 #include "cpu.h"
29b115
 #include "trace.h"
29b115
@@ -1020,6 +1021,13 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev)
29b115
         return true;
29b115
     }
29b115
 
29b115
+    if (v->migration_blocker) {
29b115
+        int r = migrate_add_blocker(v->migration_blocker, &err;;
29b115
+        if (unlikely(r < 0)) {
29b115
+            return false;
29b115
+        }
29b115
+    }
29b115
+
29b115
     for (i = 0; i < v->shadow_vqs->len; ++i) {
29b115
         VirtQueue *vq = virtio_get_queue(dev->vdev, dev->vq_index + i);
29b115
         VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
29b115
@@ -1062,6 +1070,10 @@ err:
29b115
         vhost_svq_stop(svq);
29b115
     }
29b115
 
29b115
+    if (v->migration_blocker) {
29b115
+        migrate_del_blocker(v->migration_blocker);
29b115
+    }
29b115
+
29b115
     return false;
29b115
 }
29b115
 
29b115
@@ -1081,6 +1093,9 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev)
29b115
         }
29b115
     }
29b115
 
29b115
+    if (v->migration_blocker) {
29b115
+        migrate_del_blocker(v->migration_blocker);
29b115
+    }
29b115
     return true;
29b115
 }
29b115
 
29b115
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
29b115
index 1111d85643..d10a89303e 100644
29b115
--- a/include/hw/virtio/vhost-vdpa.h
29b115
+++ b/include/hw/virtio/vhost-vdpa.h
29b115
@@ -35,6 +35,7 @@ typedef struct vhost_vdpa {
29b115
     bool shadow_vqs_enabled;
29b115
     /* IOVA mapping used by the Shadow Virtqueue */
29b115
     VhostIOVATree *iova_tree;
29b115
+    Error *migration_blocker;
29b115
     GPtrArray *shadow_vqs;
29b115
     const VhostShadowVirtqueueOps *shadow_vq_ops;
29b115
     void *shadow_vq_ops_opaque;
29b115
-- 
29b115
2.31.1
29b115