Skip to content

Commit

Permalink
memory: allow destroying a non-empty MemoryRegion
Browse files Browse the repository at this point in the history
This is legal; the MemoryRegion will simply unreference all the
existing subregions and possibly bring them down with it as well.
However, it requires a bit of care to avoid an infinite loop.
Finalizing a memory region cannot trigger an address space update,
but memory_region_del_subregion errs on the side of caution and
might trigger a spurious update: avoid that by resetting mr->enabled
first.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1443689999-12182-2-git-send-email-armbru@redhat.com>
  • Loading branch information
bonzini authored and Markus Armbruster committed Oct 9, 2015
1 parent c6047e9 commit 2e2b8eb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion memory.c
Expand Up @@ -1304,7 +1304,22 @@ static void memory_region_finalize(Object *obj)
{
MemoryRegion *mr = MEMORY_REGION(obj);

assert(QTAILQ_EMPTY(&mr->subregions));
assert(!mr->container);

/* We know the region is not visible in any address space (it
* does not have a container and cannot be a root either because
* it has no references, so we can blindly clear mr->enabled.
* memory_region_set_enabled instead could trigger a transaction
* and cause an infinite loop.
*/
mr->enabled = false;
memory_region_transaction_begin();
while (!QTAILQ_EMPTY(&mr->subregions)) {
MemoryRegion *subregion = QTAILQ_FIRST(&mr->subregions);
memory_region_del_subregion(mr, subregion);
}
memory_region_transaction_commit();

mr->destructor(mr);
memory_region_clear_coalescing(mr);
g_free((char *)mr->name);
Expand Down

0 comments on commit 2e2b8eb

Please sign in to comment.