memory: unregister AddressSpace MemoryListener within BQL
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 10 Feb 2015 17:25:44 +0000 (10:25 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 10 Feb 2015 17:25:44 +0000 (10:25 -0700)
address_space_destroy_dispatch is called from an RCU callback and hence
outside the iothread mutex (BQL).  However, after address_space_destroy
no new accesses can hit the destroyed AddressSpace so it is not necessary
to observe changes to the memory map.  Move the memory_listener_unregister
call earlier, to make it thread-safe again.

Reported-by: Alex Williamson <alex.williamson@redhat.com>
Fixes: 374f2981d1f10bc4307f250f24b2a7ddb9b14be0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
exec.c
include/exec/memory-internal.h
memory.c

diff --git a/exec.c b/exec.c
index 6b79ad1d111ae6206c6145bcaa1d3eba582d0768..6dff7bc43a67b836b58fe18136a954310e65bdee 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -2059,11 +2059,15 @@ void address_space_init_dispatch(AddressSpace *as)
     memory_listener_register(&as->dispatch_listener, as);
 }
 
+void address_space_unregister(AddressSpace *as)
+{
+    memory_listener_unregister(&as->dispatch_listener);
+}
+
 void address_space_destroy_dispatch(AddressSpace *as)
 {
     AddressSpaceDispatch *d = as->dispatch;
 
-    memory_listener_unregister(&as->dispatch_listener);
     g_free(d);
     as->dispatch = NULL;
 }
index 25c43c06e9129babc212876fdb3d47f6cd16dc1d..fb467acdbad6cb54e4ed2a37949bf2578fc558e8 100644 (file)
@@ -23,6 +23,7 @@
 typedef struct AddressSpaceDispatch AddressSpaceDispatch;
 
 void address_space_init_dispatch(AddressSpace *as);
+void address_space_unregister(AddressSpace *as);
 void address_space_destroy_dispatch(AddressSpace *as);
 
 extern const MemoryRegionOps unassigned_mem_ops;
index 9b91243978523619f9168e4f0f364d76ae01d036..130152cf1d4515fceb11bec514715f49e6a4d7c8 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -1978,6 +1978,7 @@ void address_space_destroy(AddressSpace *as)
     as->root = NULL;
     memory_region_transaction_commit();
     QTAILQ_REMOVE(&address_spaces, as, address_spaces_link);
+    address_space_unregister(as);
 
     /* At this point, as->dispatch and as->current_map are dummy
      * entries that the guest should never use.  Wait for the old