diff mbox

[PULL,09/14] memory: call begin, log_start and commit when registering a new listener

Message ID 1446653912-116150-10-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Nov. 4, 2015, 4:18 p.m. UTC
This ensures that cpu_reload_memory_map() is called as soon as
tcg_cpu_address_space_init() is called, and before cpu->memory_dispatch
is used.  qemu-system-s390x never changes the address spaces after
tcg_cpu_address_space_init() is called, and thus tcg_commit() is never
called.  This causes a SIGSEGV.

Because memory_map_init() will now call mem_commit(), we have to
initialize io_mem_* before address_space_memory and friends.

Reported-by: Philipp Kern <pkern@debian.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: 0a1c71cec63e95f9b8d0dc96d049d2daa00c5210
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 exec.c   | 2 +-
 memory.c | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 7431f2f..819ecc3 100644
--- a/exec.c
+++ b/exec.c
@@ -2694,8 +2694,8 @@  void cpu_register_map_client(QEMUBH *bh)
 void cpu_exec_init_all(void)
 {
     qemu_mutex_init(&ram_list.mutex);
-    memory_map_init();
     io_mem_init();
+    memory_map_init();
     qemu_mutex_init(&map_client_list_lock);
 }
 
diff --git a/memory.c b/memory.c
index 2eb1597..c435c88 100644
--- a/memory.c
+++ b/memory.c
@@ -2036,6 +2036,9 @@  static void listener_add_address_space(MemoryListener *listener,
         return;
     }
 
+    if (listener->begin) {
+        listener->begin(listener);
+    }
     if (global_dirty_log) {
         if (listener->log_global_start) {
             listener->log_global_start(listener);
@@ -2052,10 +2055,16 @@  static void listener_add_address_space(MemoryListener *listener,
             .offset_within_address_space = int128_get64(fr->addr.start),
             .readonly = fr->readonly,
         };
+        if (fr->dirty_log_mask && listener->log_start) {
+            listener->log_start(listener, &section, 0, fr->dirty_log_mask);
+        }
         if (listener->region_add) {
             listener->region_add(listener, &section);
         }
     }
+    if (listener->commit) {
+        listener->commit(listener);
+    }
     flatview_unref(view);
 }