]> git.proxmox.com Git - mirror_qemu.git/commitdiff
exec/memory: Introduce RAM_NAMED_FILE flag
authorSteve Sistare <steven.sistare@oracle.com>
Wed, 7 Jun 2023 15:18:36 +0000 (08:18 -0700)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Tue, 13 Jun 2023 09:28:58 +0000 (11:28 +0200)
migrate_ignore_shared() is an optimization that avoids copying memory
that is visible and can be mapped on the target.  However, a
memory-backend-ram or a memory-backend-memfd block with the RAM_SHARED
flag set is not migrated when migrate_ignore_shared() is true.  This is
wrong, because the block has no named backing store, and its contents will
be lost.  To fix, ignore shared memory iff it is a named file.  Define a
new flag RAM_NAMED_FILE to distinguish this case.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Message-Id: <1686151116-253260-1-git-send-email-steven.sistare@oracle.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
backends/hostmem-file.c
include/exec/cpu-common.h
include/exec/memory.h
migration/ram.c
qapi/migration.json
softmmu/physmem.c

index 38ea65bec584285517b6de65677baea1bde1611f..b4335a80e6da7d9c654f2935916fc191cae1436d 100644 (file)
@@ -57,6 +57,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
     ram_flags = backend->share ? RAM_SHARED : 0;
     ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
     ram_flags |= fb->is_pmem ? RAM_PMEM : 0;
+    ram_flags |= RAM_NAMED_FILE;
     memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name,
                                      backend->size, fb->align, ram_flags,
                                      fb->mem_path, fb->offset, fb->readonly,
index e5a55ede5f4817c17aebacba1df1235b57f29a0a..87dc9a752c9a209f82fdc4452b1eb9f2ae67a494 100644 (file)
@@ -93,6 +93,7 @@ void qemu_ram_set_uf_zeroable(RAMBlock *rb);
 bool qemu_ram_is_migratable(RAMBlock *rb);
 void qemu_ram_set_migratable(RAMBlock *rb);
 void qemu_ram_unset_migratable(RAMBlock *rb);
+bool qemu_ram_is_named_file(RAMBlock *rb);
 int qemu_ram_get_fd(RAMBlock *rb);
 
 size_t qemu_ram_pagesize(RAMBlock *block);
index c3661b2276c73d917b560750609bbae314e1e0ea..47c2e0221c35d757253c2dc86eb2df9acadfbb74 100644 (file)
@@ -232,6 +232,9 @@ typedef struct IOMMUTLBEvent {
 /* RAM that isn't accessible through normal means. */
 #define RAM_PROTECTED (1 << 8)
 
+/* RAM is an mmap-ed named file */
+#define RAM_NAMED_FILE (1 << 9)
+
 static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn,
                                        IOMMUNotifierFlag flags,
                                        hwaddr start, hwaddr end,
index 88a6c82e63e638816abb1bbbf9e025334848efeb..5283a75f02f7e0d9ad48389b2303f2568d3ecfb3 100644 (file)
@@ -197,7 +197,8 @@ static bool postcopy_preempt_active(void)
 bool ramblock_is_ignored(RAMBlock *block)
 {
     return !qemu_ram_is_migratable(block) ||
-           (migrate_ignore_shared() && qemu_ram_is_shared(block));
+           (migrate_ignore_shared() && qemu_ram_is_shared(block)
+                                    && qemu_ram_is_named_file(block));
 }
 
 #undef RAMBLOCK_FOREACH
index 179af0c4d8617e31aa298ad5e52cbfa6ea59524b..5bb5ab82a0cfebf06d27315dcdccbb61490f46e0 100644 (file)
 #     block devices (and thus take locks) immediately at the end of
 #     migration.  (since 3.0)
 #
-# @x-ignore-shared: If enabled, QEMU will not migrate shared memory
-#     (since 4.0)
+# @x-ignore-shared: If enabled, QEMU will not migrate shared memory that is
+#     accessible on the destination machine. (since 4.0)
 #
 # @validate-uuid: Send the UUID of the source to allow the destination
 #     to ensure it is the same.  (since 4.2)
index 588d0d166b91259ef974e9b4e88768589761d876..6bdd944fe8806cd00d340f0b66a5bee788dc6fcc 100644 (file)
@@ -1570,6 +1570,11 @@ void qemu_ram_unset_migratable(RAMBlock *rb)
     rb->flags &= ~RAM_MIGRATABLE;
 }
 
+bool qemu_ram_is_named_file(RAMBlock *rb)
+{
+    return rb->flags & RAM_NAMED_FILE;
+}
+
 int qemu_ram_get_fd(RAMBlock *rb)
 {
     return rb->fd;
@@ -1880,7 +1885,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
 
     /* Just support these ram flags by now. */
     assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE |
-                          RAM_PROTECTED)) == 0);
+                          RAM_PROTECTED | RAM_NAMED_FILE)) == 0);
 
     if (xen_enabled()) {
         error_setg(errp, "-mem-path not supported with Xen");