diff mbox

[RFC,v2,6/6] qemu: numa

Message ID 1458292438-13909-7-git-send-email-b.reynal@virtualopensystems.com
State New
Headers show

Commit Message

Baptiste Reynal March 18, 2016, 9:13 a.m. UTC
From: Christian Pinto <c.pinto@virtualopensystems.com>

This patch modifies the behavior of
memory_region_allocate_system_memory, when the new shared memory backend
is used from a slave qemu instance.
In such case there is not yet a valid pointer for the memory region pointed
by the backend (it will be innitilized later when received from the master.)
and vmstate_register would fail.

The patch skips the call to vmstate_register in case of slave shared memory
backend, that will be performed later after the actual memory pointer is
available.

Signed-off-by: Christian Pinto <c.pinto@virtualopensystems.com>
---
 numa.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/numa.c b/numa.c
index e9b18f5..b39a892 100644
--- a/numa.c
+++ b/numa.c
@@ -33,6 +33,7 @@ 
 #include "qapi/dealloc-visitor.h"
 #include "hw/boards.h"
 #include "sysemu/hostmem.h"
+#include "sysemu/hostmem-shared.h"
 #include "qmp-commands.h"
 #include "hw/mem/pc-dimm.h"
 #include "qemu/option.h"
@@ -442,6 +443,7 @@  void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
 {
     uint64_t addr = 0;
     int i;
+    bool vmstate_register = true;
 
     if (nb_numa_nodes == 0 || !have_memdevs) {
         allocate_system_memory_nonnuma(mr, owner, name, ram_size);
@@ -453,9 +455,18 @@  void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
         Error *local_err = NULL;
         uint64_t size = numa_info[i].node_mem;
         HostMemoryBackend *backend = numa_info[i].node_memdev;
+
         if (!backend) {
             continue;
         }
+
+        if (IS_MEMORY_BACKEND_SHARED(backend)) {
+            HostMemoryBackendShared *shm = MEMORY_BACKEND_SHARED(backend);
+            if (!shm->master) {
+                vmstate_register = false;
+            }
+        }
+
         MemoryRegion *seg = host_memory_backend_get_memory(backend, &local_err);
         if (local_err) {
             error_report_err(local_err);
@@ -471,7 +482,11 @@  void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
         }
 
         memory_region_add_subregion(mr, addr, seg);
-        vmstate_register_ram_global(seg);
+
+        if (vmstate_register) {
+            vmstate_register_ram_global(seg);
+        }
+
         addr += size;
     }
 }