From: Paolo Bonzini Date: Thu, 1 Oct 2015 08:59:50 +0000 (+0200) Subject: memory: allow destroying a non-empty MemoryRegion X-Git-Tag: TizenStudio_2.0_p2.3.2~174^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91232d98da2bfe042d4c5744076b488880de3040;p=sdk%2Femulator%2Fqemu.git memory: allow destroying a non-empty MemoryRegion 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 Signed-off-by: Markus Armbruster Message-Id: <1443689999-12182-2-git-send-email-armbru@redhat.com> (cherry picked from commit 2e2b8eb70fdb7dfbec39f3a19b20f9a73f2f813e) Signed-off-by: Michael Roth --- diff --git a/memory.c b/memory.c index 4eb138a..10c1df5 100644 --- a/memory.c +++ b/memory.c @@ -1312,7 +1312,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);