Skip to contentSkip to conversation

unset RAMBlock idstr when unregistering

PATCH New Hu Tao 1 participant 3 messages Apr 2, 2014

lore
Share & tools
lore

Hu Tao

author
#0 lore raw

cover unset RAMBlock idstr when unregistering

When hotplug an memdev that was previously plugged and unplugged, RAMBlock idstr is not cleared and triggers an assert error in qemu_ram_set_idstr(). This series fixes it.

Hu Tao (2):
exec: introduce qemu_ram_unset_idstr() to unset RAMBlock idstr unset RAMBlock idstr when unregister MemoryRegion

 exec.c                    | 26 +++++++++++++++++++++-----
 include/exec/cpu-common.h |  1 +
 savevm.c                  |  2 +-
 3 files changed, 23 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.5.2.229.g4448466
author
#1 lore raw

PATCH 1/2 exec: introduce qemu_ram_unset_idstr() to unset RAMBlock idstr

---
 exec.c                    | 26 +++++++++++++++++++++-----
 include/exec/cpu-common.h |  1 +
 2 files changed, 22 insertions(+), 5 deletions(-)
exec.c +21 -5
index 91513c6..cbf7923 100644
@@ -1202,17 +1202,24 @@ static void qemu_ram_setup_dump(void *addr, ram_addr_t size)
     }
 }
 
-void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
+static RAMBlock *find_ram_block(ram_addr_t addr)
 {
-    RAMBlock *new_block, *block;
+    RAMBlock *block;
 
-    new_block = NULL;
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
         if (block->offset == addr) {
-            new_block = block;
-            break;
+            return block;
         }
     }
+
+    return NULL;
+}
+
+void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
+{
+    RAMBlock *new_block = find_ram_block(addr);
+    RAMBlock *block;
+
     assert(new_block);
     assert(!new_block->idstr[0]);
 
@@ -1237,6 +1244,15 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
     qemu_mutex_unlock_ramlist();
 }
 
+void qemu_ram_unset_idstr(ram_addr_t addr)
+{
+    RAMBlock *block = find_ram_block(addr);
+
+    if (block) {
+        memset(block->idstr, 0, sizeof(block->idstr));
+    }
+}
+
 static int memory_try_enable_merging(void *addr, size_t len)
 {
     if (!qemu_opt_get_bool(qemu_get_machine_opts(), "mem-merge", true)) {
include/exec/cpu-common.h +1 -0
index a21b65a..89ec640 100644
@@ -54,6 +54,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
 /* This should not be used by devices.  */
 MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
 void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev);
+void qemu_ram_unset_idstr(ram_addr_t addr);
 
 void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
                             int len, int is_write);
Signature · 1 line
1.8.5.2.229.g4448466
author
#2 lore raw

PATCH 2/2 unset RAMBlock idstr when unregister MemoryRegion

In reply to Hu Tao
---
 savevm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
savevm.c +1 -1
index 22123be..6f4b1a5 100644
@@ -1208,7 +1208,7 @@ void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
 
 void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev)
 {
-    /* Nothing do to while the implementation is in RAMBlock */
+    qemu_ram_unset_idstr(memory_region_get_ram_addr(mr) & TARGET_PAGE_MASK);
 }
 
 void vmstate_register_ram_global(MemoryRegion *mr)
Signature · 1 line
1.8.5.2.229.g4448466