qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL v3 03/12] memory: allow destroying a non-empty MemoryRegion
Date: Fri,  9 Oct 2015 16:36:38 +0200	[thread overview]
Message-ID: <1444401407-7849-4-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1444401407-7849-1-git-send-email-armbru@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

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>
---
 memory.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index 1b03d22..2eb1597 100644
--- a/memory.c
+++ b/memory.c
@@ -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);
-- 
2.4.3

  parent reply	other threads:[~2015-10-09 14:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-09 14:36 [Qemu-devel] [PULL v3 00/12] Fix device introspection regressions Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 01/12] update-linux-headers: Rename SW_MAX to SW_MAX_ Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 02/12] virtio-input: Fix device introspection on non-Linux hosts Markus Armbruster
2015-10-09 14:36 ` Markus Armbruster [this message]
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 04/12] hw: do not pass NULL to memory_region_init from instance_init Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 05/12] macio: move DBDMA_init from instance_init to realize Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 06/12] tests: Fix how qom-test is run Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 07/12] libqtest: Clean up unused QTestState member sigact_old Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 08/12] libqtest: New hmp() & friends Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 09/12] device-introspect-test: New, covering device introspection Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 10/12] qmp: Fix device-list-properties not to crash for abstract device Markus Armbruster
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 11/12] qdev: Protect device-list-properties against broken devices Markus Armbruster
2015-10-09 15:32   ` Andreas Färber
2015-10-09 14:36 ` [Qemu-devel] [PULL v3 12/12] Revert "qdev: Use qdev_get_device_class() for -device <type>, help" Markus Armbruster
2015-10-12 12:13 ` [Qemu-devel] [PULL v3 00/12] Fix device introspection regressions Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444401407-7849-4-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).