qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, mst@redhat.com, qemu-stable@nongnu.org,
	dgilbert@redhat.com, pbonzini@redhat.com, lersek@redhat.com
Subject: [Qemu-devel] [PATCH for-2.1 1/2] migration: load smaller RAMBlock to a bigger one if permitted
Date: Fri, 25 Jul 2014 15:48:57 +0000	[thread overview]
Message-ID: <1406303338-13212-2-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1406303338-13212-1-git-send-email-imammedo@redhat.com>

Add API to mark memory region as extend-able on migration,
to allow migration code to load smaller RAMBlock into
a bigger one on destination QEMU instance.

This will allow to fix broken migration from QEMU 1.7/2.0 to
QEMU 2.1 due to  ACPI tables size changes across 1.7/2.0/2.1
versions by marking ACPI tables ROM blob as extend-able.
So that smaller tables from previos version could be always
migrated to a bigger rom blob on new version.

Credits-for-idea: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 arch_init.c             | 19 ++++++++++++++-----
 exec.c                  | 15 +++++++++------
 include/exec/cpu-all.h  | 15 ++++++++++++++-
 include/exec/memory.h   | 10 ++++++++++
 include/exec/ram_addr.h |  1 +
 memory.c                |  5 +++++
 6 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 8ddaf35..812f8b5 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1071,11 +1071,20 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 
                 QTAILQ_FOREACH(block, &ram_list.blocks, next) {
                     if (!strncmp(id, block->idstr, sizeof(id))) {
-                        if (block->length != length) {
-                            error_report("Length mismatch: %s: " RAM_ADDR_FMT
-                                         " in != " RAM_ADDR_FMT, id, length,
-                                         block->length);
-                            ret =  -EINVAL;
+                        if (block->flags & RAM_EXTENDABLE_ON_MIGRATE) {
+                            if (block->length < length) {
+                                error_report("Length too big: %s: "RAM_ADDR_FMT
+                                             " > " RAM_ADDR_FMT, id, length,
+                                             block->length);
+                                ret =  -EINVAL;
+                            }
+                        } else {
+                            if (block->length != length) {
+                                error_report("Length mismatch: %s: "RAM_ADDR_FMT
+                                             " in != " RAM_ADDR_FMT, id, length,
+                                             block->length);
+                                ret =  -EINVAL;
+                            }
                         }
                         break;
                     }
diff --git a/exec.c b/exec.c
index 765bd94..755b1d3 100644
--- a/exec.c
+++ b/exec.c
@@ -69,12 +69,6 @@ AddressSpace address_space_memory;
 MemoryRegion io_mem_rom, io_mem_notdirty;
 static MemoryRegion io_mem_unassigned;
 
-/* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */
-#define RAM_PREALLOC   (1 << 0)
-
-/* RAM is mmap-ed with MAP_SHARED */
-#define RAM_SHARED     (1 << 1)
-
 #endif
 
 struct CPUTailQ cpus = QTAILQ_HEAD_INITIALIZER(cpus);
@@ -1214,6 +1208,15 @@ void qemu_ram_unset_idstr(ram_addr_t addr)
     }
 }
 
+void qemu_ram_set_extendable_on_migration(ram_addr_t addr)
+{
+    RAMBlock *block = find_ram_block(addr);
+
+    if (block) {
+        block->flags |= RAM_EXTENDABLE_ON_MIGRATE;
+    }
+}
+
 static int memory_try_enable_merging(void *addr, size_t len)
 {
     if (!qemu_opt_get_bool(qemu_get_machine_opts(), "mem-merge", true)) {
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index f91581f..2b9aea3 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -296,13 +296,26 @@ CPUArchState *cpu_copy(CPUArchState *env);
 #if !defined(CONFIG_USER_ONLY)
 
 /* memory API */
+typedef enum {
+    /* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */
+    RAM_PREALLOC = 1 << 0,
+    /* RAM is mmap-ed with MAP_SHARED */
+    RAM_SHARED = 1 << 1,
+    /*
+     * Allow at migration time to load RAMBlock of smaller size than
+     * destination RAMBlock is
+     */
+    RAM_EXTENDABLE_ON_MIGRATE = 1 << 2,
+    RAM_FLAGS_END = 1 << 31
+} RAMBlockFlags;
+
 
 typedef struct RAMBlock {
     struct MemoryRegion *mr;
     uint8_t *host;
     ram_addr_t offset;
     ram_addr_t length;
-    uint32_t flags;
+    RAMBlockFlags flags;
     char idstr[256];
     /* Reads can take either the iothread or the ramlist lock.
      * Writes must take both locks.
diff --git a/include/exec/memory.h b/include/exec/memory.h
index e2c8e3e..6c03f70 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -894,6 +894,16 @@ bool memory_region_present(MemoryRegion *container, hwaddr addr);
 bool memory_region_is_mapped(MemoryRegion *mr);
 
 /**
+ * memory_region_permit_extendable_migration: allows to mark
+ * #MemoryRegion as extendable on migrartion, which permits to
+ * load source memory block of smaller size than destination memory block
+ * at migration time
+ *
+ * @mr: a #MemoryRegion which should be marked as extendable on migration
+ */
+void memory_region_permit_extendable_migration(MemoryRegion *mr);
+
+/**
  * memory_region_find: translate an address/size relative to a
  * MemoryRegion into a #MemoryRegionSection.
  *
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 6593be1..248c075 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -33,6 +33,7 @@ void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
 void *qemu_get_ram_ptr(ram_addr_t addr);
 void qemu_ram_free(ram_addr_t addr);
 void qemu_ram_free_from_ptr(ram_addr_t addr);
+void qemu_ram_set_extendable_on_migration(ram_addr_t addr);
 
 static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
                                                  ram_addr_t length,
diff --git a/memory.c b/memory.c
index 64d7176..744c746 100644
--- a/memory.c
+++ b/memory.c
@@ -1791,6 +1791,11 @@ bool memory_region_is_mapped(MemoryRegion *mr)
     return mr->container ? true : false;
 }
 
+void memory_region_permit_extendable_migration(MemoryRegion *mr)
+{
+    qemu_ram_set_extendable_on_migration(mr->ram_addr);
+}
+
 MemoryRegionSection memory_region_find(MemoryRegion *mr,
                                        hwaddr addr, uint64_t size)
 {
-- 
1.8.3.1

  reply	other threads:[~2014-07-25 15:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-25 15:48 [Qemu-devel] [PATCH for-2.1 0/2] Fix migration failure due to ACPI tables size changes Igor Mammedov
2014-07-25 15:48 ` Igor Mammedov [this message]
2014-07-25 17:56   ` [Qemu-devel] [PATCH for-2.1 1/2] migration: load smaller RAMBlock to a bigger one if permitted Laszlo Ersek
2014-07-28  7:40     ` Igor Mammedov
2014-07-28  8:11       ` Laszlo Ersek
2014-07-25 15:48 ` [Qemu-devel] [PATCH for-2.1 2/2] acpi: mark ACPI tables ROM blob as extend-able on migration Igor Mammedov
2014-07-25 17:37   ` Paolo Bonzini
2014-07-28  7:56     ` Igor Mammedov
2014-07-28  8:16       ` Paolo Bonzini
2014-07-25 17:58   ` Laszlo Ersek
2014-11-03 17:36   ` Dr. David Alan Gilbert
2014-11-04 16:30     ` Paolo Bonzini
2014-11-04 16:46       ` Michael S. Tsirkin
2014-11-04 16:54         ` Paolo Bonzini
2014-11-04 17:25           ` Michael S. Tsirkin
2014-11-04 17:35             ` Paolo Bonzini
2014-11-04 17:42               ` Michael S. Tsirkin
2014-07-25 16:17 ` [Qemu-devel] [PATCH for-2.1 0/2] Fix migration failure due to ACPI tables size changes Laszlo Ersek
2014-07-26  7:03   ` Paolo Bonzini

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=1406303338-13212-2-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /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).