All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"John Snow" <jsnow@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Fam Zheng" <fam@euphon.net>, "Thomas Huth" <thuth@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
	qemu-s390x@nongnu.org,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Coiby Xu" <Coiby.Xu@gmail.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Peter Xu" <peterx@redhat.com>
Subject: [PULL 18/30] virtio-mem: Migrate immutable properties early
Date: Tue,  7 Feb 2023 01:56:38 +0100	[thread overview]
Message-ID: <20230207005650.1810-19-quintela@redhat.com> (raw)
In-Reply-To: <20230207005650.1810-1-quintela@redhat.com>

From: David Hildenbrand <david@redhat.com>

The bitmap and the size are immutable while migration is active: see
virtio_mem_is_busy(). We can migrate this information early, before
migrating any actual RAM content. Further, all information we need for
sanity checks is immutable as well.

Having this information in place early will, for example, allow for
properly preallocating memory before touching these memory locations
during RAM migration: this way, we can make sure that all memory was
actually preallocated and that any user errors (e.g., insufficient
hugetlb pages) can be handled gracefully.

In contrast, usable_region_size and requested_size can theoretically
still be modified on the source while the VM is running. Keep migrating
these properties the usual, late, way.

Use a new device property to keep behavior of compat machines
unmodified.

Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>S
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 include/hw/virtio/virtio-mem.h |  8 ++++++
 hw/core/machine.c              |  4 ++-
 hw/virtio/virtio-mem.c         | 51 ++++++++++++++++++++++++++++++++--
 3 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h
index 7745cfc1a3..f15e561785 100644
--- a/include/hw/virtio/virtio-mem.h
+++ b/include/hw/virtio/virtio-mem.h
@@ -31,6 +31,7 @@ OBJECT_DECLARE_TYPE(VirtIOMEM, VirtIOMEMClass,
 #define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size"
 #define VIRTIO_MEM_ADDR_PROP "memaddr"
 #define VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP "unplugged-inaccessible"
+#define VIRTIO_MEM_EARLY_MIGRATION_PROP "x-early-migration"
 #define VIRTIO_MEM_PREALLOC_PROP "prealloc"
 
 struct VirtIOMEM {
@@ -74,6 +75,13 @@ struct VirtIOMEM {
     /* whether to prealloc memory when plugging new blocks */
     bool prealloc;
 
+    /*
+     * Whether we migrate properties that are immutable while migration is
+     * active early, before state of other devices and especially, before
+     * migrating any RAM content.
+     */
+    bool early_migration;
+
     /* notifiers to notify when "size" changes */
     NotifierList size_change_notifiers;
 
diff --git a/hw/core/machine.c b/hw/core/machine.c
index f7761baab5..b5cd42cd8c 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -41,7 +41,9 @@
 #include "hw/virtio/virtio-pci.h"
 #include "qom/object_interfaces.h"
 
-GlobalProperty hw_compat_7_2[] = {};
+GlobalProperty hw_compat_7_2[] = {
+    { "virtio-mem", "x-early-migration", "false" },
+};
 const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
 
 GlobalProperty hw_compat_7_1[] = {
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 02f7b5469a..ca37949df8 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -31,6 +31,8 @@
 #include CONFIG_DEVICES
 #include "trace.h"
 
+static const VMStateDescription vmstate_virtio_mem_device_early;
+
 /*
  * We only had legacy x86 guests that did not support
  * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have legacy guests.
@@ -878,6 +880,10 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
 
     host_memory_backend_set_mapped(vmem->memdev, true);
     vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem));
+    if (vmem->early_migration) {
+        vmstate_register(VMSTATE_IF(vmem), VMSTATE_INSTANCE_ID_ANY,
+                         &vmstate_virtio_mem_device_early, vmem);
+    }
     qemu_register_reset(virtio_mem_system_reset, vmem);
 
     /*
@@ -899,6 +905,10 @@ static void virtio_mem_device_unrealize(DeviceState *dev)
      */
     memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
     qemu_unregister_reset(virtio_mem_system_reset, vmem);
+    if (vmem->early_migration) {
+        vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_early,
+                           vmem);
+    }
     vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem));
     host_memory_backend_set_mapped(vmem->memdev, false);
     virtio_del_queue(vdev, 0);
@@ -1015,18 +1025,53 @@ static const VMStateDescription vmstate_virtio_mem_sanity_checks = {
     },
 };
 
+static bool virtio_mem_vmstate_field_exists(void *opaque, int version_id)
+{
+    const VirtIOMEM *vmem = VIRTIO_MEM(opaque);
+
+    /* With early migration, these fields were already migrated. */
+    return !vmem->early_migration;
+}
+
 static const VMStateDescription vmstate_virtio_mem_device = {
     .name = "virtio-mem-device",
     .minimum_version_id = 1,
     .version_id = 1,
     .priority = MIG_PRI_VIRTIO_MEM,
     .post_load = virtio_mem_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_WITH_TMP_TEST(VirtIOMEM, virtio_mem_vmstate_field_exists,
+                              VirtIOMEMMigSanityChecks,
+                              vmstate_virtio_mem_sanity_checks),
+        VMSTATE_UINT64(usable_region_size, VirtIOMEM),
+        VMSTATE_UINT64_TEST(size, VirtIOMEM, virtio_mem_vmstate_field_exists),
+        VMSTATE_UINT64(requested_size, VirtIOMEM),
+        VMSTATE_BITMAP_TEST(bitmap, VirtIOMEM, virtio_mem_vmstate_field_exists,
+                            0, bitmap_size),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+/*
+ * Transfer properties that are immutable while migration is active early,
+ * such that we have have this information around before migrating any RAM
+ * content.
+ *
+ * Note that virtio_mem_is_busy() makes sure these properties can no longer
+ * change on the migration source until migration completed.
+ *
+ * With QEMU compat machines, we transmit these properties later, via
+ * vmstate_virtio_mem_device instead -- see virtio_mem_vmstate_field_exists().
+ */
+static const VMStateDescription vmstate_virtio_mem_device_early = {
+    .name = "virtio-mem-device-early",
+    .minimum_version_id = 1,
+    .version_id = 1,
+    .early_setup = true,
     .fields = (VMStateField[]) {
         VMSTATE_WITH_TMP(VirtIOMEM, VirtIOMEMMigSanityChecks,
                          vmstate_virtio_mem_sanity_checks),
-        VMSTATE_UINT64(usable_region_size, VirtIOMEM),
         VMSTATE_UINT64(size, VirtIOMEM),
-        VMSTATE_UINT64(requested_size, VirtIOMEM),
         VMSTATE_BITMAP(bitmap, VirtIOMEM, 0, bitmap_size),
         VMSTATE_END_OF_LIST()
     },
@@ -1211,6 +1256,8 @@ static Property virtio_mem_properties[] = {
     DEFINE_PROP_ON_OFF_AUTO(VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP, VirtIOMEM,
                             unplugged_inaccessible, ON_OFF_AUTO_AUTO),
 #endif
+    DEFINE_PROP_BOOL(VIRTIO_MEM_EARLY_MIGRATION_PROP, VirtIOMEM,
+                     early_migration, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
2.39.1



  parent reply	other threads:[~2023-02-07  1:04 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  0:56 [PULL 00/30] Migration 20230206 patches Juan Quintela
2023-02-07  0:56 ` [PULL 01/30] migration: Fix migration crash when target psize larger than host Juan Quintela
2023-02-10  9:32   ` Michael Tokarev
2023-02-10 12:11     ` Juan Quintela
2023-02-10 15:01       ` Peter Xu
2023-02-10 15:15         ` Juan Quintela
2023-02-10 15:28         ` Michael Tokarev
2023-02-10 15:48           ` Peter Xu
2023-02-07  0:56 ` [PULL 02/30] migration: No save_live_pending() method uses the QEMUFile parameter Juan Quintela
2023-02-07  0:56 ` [PULL 03/30] migration: Split save_live_pending() into state_pending_* Juan Quintela
2023-02-09  7:48   ` Avihai Horon
2023-02-09 15:24     ` Juan Quintela
2023-03-24 18:41   ` s390x TCG migration failure Nina Schoetterl-Glausch
2023-03-28 13:01     ` Thomas Huth
2023-03-28 22:21       ` Nina Schoetterl-Glausch
2023-03-29  6:36         ` Thomas Huth
2023-04-04 15:18           ` Thomas Huth
2023-04-12 20:31     ` Juan Quintela
2023-04-12 20:46     ` Juan Quintela
2023-04-12 21:01     ` Juan Quintela
2023-04-13 11:42       ` Nina Schoetterl-Glausch
2023-02-07  0:56 ` [PULL 04/30] migration: Remove unused threshold_size parameter Juan Quintela
2023-02-07  0:56 ` [PULL 05/30] migration: simplify migration_iteration_run() Juan Quintela
2023-02-07  0:56 ` [PULL 06/30] util/userfaultfd: Add uffd_open() Juan Quintela
2023-02-07  0:56 ` [PULL 07/30] migration/ram: Fix populate_read_range() Juan Quintela
2023-02-07  0:56 ` [PULL 08/30] migration/ram: Fix error handling in ram_write_tracking_start() Juan Quintela
2023-02-07  0:56 ` [PULL 09/30] migration/ram: Don't explicitly unprotect when unregistering uffd-wp Juan Quintela
2023-02-07  0:56 ` [PULL 10/30] migration/ram: Rely on used_length for uffd_change_protection() Juan Quintela
2023-02-07  0:56 ` [PULL 11/30] migration/ram: Optimize ram_write_tracking_start() for RamDiscardManager Juan Quintela
2023-02-07  0:56 ` [PULL 12/30] migration/savevm: Move more savevm handling into vmstate_save() Juan Quintela
2023-02-07  0:56 ` [PULL 13/30] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup() Juan Quintela
2023-02-07  0:56 ` [PULL 14/30] migration/savevm: Allow immutable device state to be migrated early (i.e., before RAM) Juan Quintela
2023-02-07  0:56 ` [PULL 15/30] migration/vmstate: Introduce VMSTATE_WITH_TMP_TEST() and VMSTATE_BITMAP_TEST() Juan Quintela
2023-02-07  0:56 ` [PULL 16/30] migration/ram: Factor out check for advised postcopy Juan Quintela
2023-02-07  0:56 ` [PULL 17/30] virtio-mem: Fail if a memory backend with "prealloc=on" is specified Juan Quintela
2023-02-07  0:56 ` Juan Quintela [this message]
2023-02-07  0:56 ` [PULL 19/30] virtio-mem: Proper support for preallocation with migration Juan Quintela
2023-02-07  0:56 ` [PULL 20/30] migration: Show downtime during postcopy phase Juan Quintela
2023-02-07  0:56 ` [PULL 21/30] migration/rdma: fix return value for qio_channel_rdma_{readv, writev} Juan Quintela
2023-02-07  0:56 ` [PULL 22/30] migration: Add canary to VMSTATE_END_OF_LIST Juan Quintela
2023-02-07  0:56 ` [PULL 23/30] migration: Perform vmsd structure check during tests Juan Quintela
2023-02-07  0:56 ` [PULL 24/30] migration/dirtyrate: Show sample pages only in page-sampling mode Juan Quintela
2023-02-07  0:56 ` [PULL 25/30] io: Add support for MSG_PEEK for socket channel Juan Quintela
2023-02-07  0:56 ` [PULL 26/30] migration: check magic value for deciding the mapping of channels Juan Quintela
2023-02-07  0:56 ` [PULL 27/30] multifd: Fix a race on reading MultiFDPages_t.block Juan Quintela
2023-02-07  0:56 ` [PULL 28/30] multifd: Fix flush of zero copy page send request Juan Quintela
2023-02-09  1:27   ` Duan, Zhenzhong
2023-02-09 12:29     ` Juan Quintela
2023-02-07  0:56 ` [PULL 29/30] migration: Introduce interface query-migrationthreads Juan Quintela
2023-02-07  0:56 ` [PULL 30/30] migration: save/delete migration thread info Juan Quintela
2023-02-07 16:52 ` [PULL 00/30] Migration 20230206 patches Peter Maydell

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=20230207005650.1810-19-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=fam@euphon.net \
    --cc=farman@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=jsnow@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    --cc=wangyanan55@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.