thebeanogamer / rpms / qemu-kvm

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