Commit 6e48e8f9 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Alex Williamson
Browse files

memory: unregister AddressSpace MemoryListener within BQL



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: default avatarAlex Williamson <alex.williamson@redhat.com>
Fixes: 374f2981
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent a2f2d288
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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;
}
+1 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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