From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
qemu-devel@nongnu.org, qemu-arm@nongnu.org,
peter.maydell@linaro.org, jean-philippe@linaro.org,
dgilbert@redhat.com, quintela@redhat.com, mst@redhat.com,
peterx@redhat.com
Cc: kevin.tian@intel.com, bharatb.linux@gmail.com, tnowicki@marvell.com
Subject: [PATCH v12 12/13] virtio-iommu: Support migration
Date: Thu, 9 Jan 2020 15:43:18 +0100 [thread overview]
Message-ID: <20200109144319.15912-13-eric.auger@redhat.com> (raw)
In-Reply-To: <20200109144319.15912-1-eric.auger@redhat.com>
Add Migration support. We rely on recently added gtree and qlist
migration. We only migrate the domain gtree. The endpoint gtree
is re-constructed in a post-load operation.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v11 -> v12:
- do not migrate the endpoint gtree but reconstruct it from the
domain gtree (Peter's suggestion)
- add MIG_PRI_IOMMU
---
hw/virtio/virtio-iommu.c | 109 +++++++++++++++++++++++++++++++++++----
1 file changed, 99 insertions(+), 10 deletions(-)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 09193970ee..b0fde3af6f 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -655,16 +655,6 @@ static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f,
return f;
}
-/*
- * Migration is not yet supported: most of the state consists
- * of balanced binary trees which are not yet ready for getting
- * migrated
- */
-static const VMStateDescription vmstate_virtio_iommu_device = {
- .name = "virtio-iommu-device",
- .unmigratable = 1,
-};
-
static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
{
guint ua = GPOINTER_TO_UINT(a);
@@ -748,9 +738,108 @@ static void virtio_iommu_instance_init(Object *obj)
{
}
+#define VMSTATE_INTERVAL \
+{ \
+ .name = "interval", \
+ .version_id = 1, \
+ .minimum_version_id = 1, \
+ .fields = (VMStateField[]) { \
+ VMSTATE_UINT64(low, VirtIOIOMMUInterval), \
+ VMSTATE_UINT64(high, VirtIOIOMMUInterval), \
+ VMSTATE_END_OF_LIST() \
+ } \
+}
+
+#define VMSTATE_MAPPING \
+{ \
+ .name = "mapping", \
+ .version_id = 1, \
+ .minimum_version_id = 1, \
+ .fields = (VMStateField[]) { \
+ VMSTATE_UINT64(phys_addr, VirtIOIOMMUMapping),\
+ VMSTATE_UINT32(flags, VirtIOIOMMUMapping), \
+ VMSTATE_END_OF_LIST() \
+ }, \
+}
+
+static const VMStateDescription vmstate_interval_mapping[2] = {
+ VMSTATE_MAPPING, /* value */
+ VMSTATE_INTERVAL /* key */
+};
+
+static int domain_preload(void *opaque)
+{
+ VirtIOIOMMUDomain *domain = opaque;
+
+ domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp,
+ NULL, g_free, g_free);
+ return 0;
+}
+
+static const VMStateDescription vmstate_endpoint = {
+ .name = "endpoint",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32(id, VirtIOIOMMUEndpoint),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static const VMStateDescription vmstate_domain = {
+ .name = "domain",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .pre_load = domain_preload,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32(id, VirtIOIOMMUDomain),
+ VMSTATE_GTREE_V(mappings, VirtIOIOMMUDomain, 1,
+ vmstate_interval_mapping,
+ VirtIOIOMMUInterval, VirtIOIOMMUMapping),
+ VMSTATE_QLIST_V(endpoint_list, VirtIOIOMMUDomain, 1,
+ vmstate_endpoint, VirtIOIOMMUEndpoint, next),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static gboolean reconstruct_endpoints(gpointer key, gpointer value,
+ gpointer data)
+{
+ VirtIOIOMMU *s = (VirtIOIOMMU *)data;
+ VirtIOIOMMUDomain *d = (VirtIOIOMMUDomain *)value;
+ VirtIOIOMMUEndpoint *iter;
+
+ QLIST_FOREACH(iter, &d->endpoint_list, next) {
+ iter->domain = d;
+ g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter);
+ }
+ return false; /* continue the domain traversal */
+}
+
+static int iommu_post_load(void *opaque, int version_id)
+{
+ VirtIOIOMMU *s = opaque;
+
+ g_tree_foreach(s->domains, reconstruct_endpoints, s);
+ return 0;
+}
+
+static const VMStateDescription vmstate_virtio_iommu_device = {
+ .name = "virtio-iommu-device",
+ .minimum_version_id = 1,
+ .version_id = 1,
+ .post_load = iommu_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_GTREE_DIRECT_KEY_V(domains, VirtIOIOMMU, 1,
+ &vmstate_domain, VirtIOIOMMUDomain),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
static const VMStateDescription vmstate_virtio_iommu = {
.name = "virtio-iommu",
.minimum_version_id = 1,
+ .priority = MIG_PRI_IOMMU,
.version_id = 1,
.fields = (VMStateField[]) {
VMSTATE_VIRTIO_DEVICE,
--
2.20.1
next prev parent reply other threads:[~2020-01-09 14:54 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 14:43 [PATCH v12 00/13] VIRTIO-IOMMU device Eric Auger
2020-01-09 14:43 ` [PATCH v12 01/13] migration: Support QLIST migration Eric Auger
2020-01-09 14:43 ` [PATCH v12 02/13] virtio-iommu: Add skeleton Eric Auger
2020-01-13 19:53 ` Peter Xu
2020-01-09 14:43 ` [PATCH v12 03/13] virtio-iommu: Decode the command payload Eric Auger
2020-01-09 14:43 ` [PATCH v12 04/13] virtio-iommu: Add the iommu regions Eric Auger
2020-01-13 19:53 ` Peter Xu
2020-01-14 8:37 ` Auger Eric
2020-01-14 18:49 ` Peter Xu
2020-01-13 20:06 ` Peter Xu
2020-01-14 8:48 ` Auger Eric
2020-01-09 14:43 ` [PATCH v12 05/13] virtio-iommu: Endpoint and domains structs and helpers Eric Auger
2020-01-13 20:23 ` Peter Xu
2020-01-14 8:51 ` Auger Eric
2020-01-14 18:07 ` Peter Xu
2020-01-15 13:00 ` Auger Eric
2020-01-15 14:59 ` Peter Xu
2020-01-15 16:55 ` Auger Eric
2020-01-15 13:15 ` Auger Eric
2020-01-09 14:43 ` [PATCH v12 06/13] virtio-iommu: Implement attach/detach command Eric Auger
2020-01-09 14:43 ` [PATCH v12 07/13] virtio-iommu: Implement map/unmap Eric Auger
2020-01-14 18:55 ` Peter Xu
2020-01-09 14:43 ` [PATCH v12 08/13] virtio-iommu: Implement translate Eric Auger
2020-01-09 14:43 ` [PATCH v12 09/13] virtio-iommu: Implement fault reporting Eric Auger
2020-01-14 19:04 ` Peter Xu
2020-01-15 13:12 ` Auger Eric
2020-01-15 15:04 ` Peter Xu
2020-01-15 16:36 ` Auger Eric
2020-01-09 14:43 ` [PATCH v12 10/13] virtio-iommu-pci: Add virtio iommu pci support Eric Auger
2020-01-09 14:43 ` [PATCH v12 11/13] hw/arm/virt: Add the virtio-iommu device tree mappings Eric Auger
2020-01-09 14:43 ` Eric Auger [this message]
2020-01-14 19:07 ` [PATCH v12 12/13] virtio-iommu: Support migration Peter Xu
2020-02-10 12:33 ` Juan Quintela
2020-02-10 13:09 ` Auger Eric
2020-02-10 13:36 ` Auger Eric
2020-02-10 16:44 ` Juan Quintela
2020-01-09 14:43 ` [PATCH v12 13/13] tests: Add virtio-iommu test Eric Auger
2020-01-09 15:12 ` [PATCH v12 00/13] VIRTIO-IOMMU device no-reply
2020-01-09 16:07 ` Auger Eric
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200109144319.15912-13-eric.auger@redhat.com \
--to=eric.auger@redhat.com \
--cc=bharatb.linux@gmail.com \
--cc=dgilbert@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=jean-philippe@linaro.org \
--cc=kevin.tian@intel.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=tnowicki@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).