qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org,
	"Steve Sistare" <steven.sistare@oracle.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 17/17] exec/memory: Introduce RAM_NAMED_FILE flag
Date: Tue, 13 Jun 2023 11:38:22 +0200	[thread overview]
Message-ID: <20230613093822.63750-18-philmd@linaro.org> (raw)
In-Reply-To: <20230613093822.63750-1-philmd@linaro.org>

From: Steve Sistare <steven.sistare@oracle.com>

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>
---
 qapi/migration.json       | 4 ++--
 include/exec/cpu-common.h | 1 +
 include/exec/memory.h     | 3 +++
 backends/hostmem-file.c   | 1 +
 migration/ram.c           | 3 ++-
 softmmu/physmem.c         | 7 ++++++-
 6 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/qapi/migration.json b/qapi/migration.json
index 179af0c4d8..5bb5ab82a0 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -465,8 +465,8 @@
 #     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)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index e5a55ede5f..87dc9a752c 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -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);
diff --git a/include/exec/memory.h b/include/exec/memory.h
index c3661b2276..47c2e0221c 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -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,
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 38ea65bec5..b4335a80e6 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -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,
diff --git a/migration/ram.c b/migration/ram.c
index 88a6c82e63..5283a75f02 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -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
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 588d0d166b..6bdd944fe8 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -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");
-- 
2.38.1



  parent reply	other threads:[~2023-06-13 11:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13  9:38 [PULL 00/17] Misc patches for 2023-06-13 Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 01/17] linux-user, bsd-user: Preserve incoming order of environment variables in the target Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 02/17] cocoa: Fix warnings about invalid prototype declarations Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 03/17] util/cacheflush: Use declarations from <OSCacheControl.h> on Darwin Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 04/17] util/cacheflush: Avoid possible redundant dcache flush " Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 05/17] accel/hvf: Report HV_DENIED error Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 06/17] target/hppa/meson: Only build int_helper.o with system emulation Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 07/17] target/i386/helper: Remove do_cpu_sipi() stub for user-mode emulation Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 08/17] target/i386/helper: Shuffle do_cpu_init() Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 09/17] target/i386: Rename helper template headers as '.h.inc' Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 10/17] hw/i2c: Enable an id for the pca954x devices Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 11/17] hw/ide/ahci: Remove stray backslash Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 12/17] hw/scsi/megasas: Silent GCC duplicated-cond warning Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 13/17] hw/char/parallel: Export struct ParallelState Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 14/17] hw/char/parallel-isa: Export struct ISAParallelState Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 15/17] exec/ram_addr: Return number of dirty pages in cpu_physical_memory_set_dirty_lebitmap() Philippe Mathieu-Daudé
2023-06-13  9:38 ` [PULL 16/17] hw/vfio: Add number of dirty pages to vfio_get_dirty_bitmap tracepoint Philippe Mathieu-Daudé
2023-06-13  9:38 ` Philippe Mathieu-Daudé [this message]
2023-06-14  4:39 ` [PULL 00/17] Misc patches for 2023-06-13 Richard Henderson

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=20230613093822.63750-18-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=steven.sistare@oracle.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).