From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLAJK-0003nc-BY for qemu-devel@nongnu.org; Tue, 10 Feb 2015 07:53:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLAJF-0000Z7-Cc for qemu-devel@nongnu.org; Tue, 10 Feb 2015 07:53:02 -0500 Received: from mail-we0-x235.google.com ([2a00:1450:400c:c03::235]:38051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLAJF-0000Yk-6q for qemu-devel@nongnu.org; Tue, 10 Feb 2015 07:52:57 -0500 Received: by mail-we0-f181.google.com with SMTP id w62so15947681wes.12 for ; Tue, 10 Feb 2015 04:52:55 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 10 Feb 2015 13:52:49 +0100 Message-Id: <1423572769-4238-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] memory: unregister AddressSpace MemoryListener within BQL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com 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 Fixes: 374f2981d1f10bc4307f250f24b2a7ddb9b14be0 Signed-off-by: Paolo Bonzini --- exec.c | 6 +++++- include/exec/memory-internal.h | 1 + memory.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 6b79ad1..6dff7bc 100644 --- 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; } diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 25c43c0..fb467ac 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -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; diff --git a/memory.c b/memory.c index 9b91243..130152c 100644 --- 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 -- 1.8.3.1