From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: "Eduardo Habkost" <eduardo@habkost.net>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"John Snow" <jsnow@redhat.com>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Alexey Kardashevskiy" <aik@ozlabs.ru>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
qemu-ppc@nongnu.org, Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH 08/14] memory: Do not create circular reference with subregion
Date: Wed, 26 Jun 2024 20:06:31 +0900 [thread overview]
Message-ID: <20240626-san-v1-8-f3cc42302189@daynix.com> (raw)
In-Reply-To: <20240626-san-v1-0-f3cc42302189@daynix.com>
A memory region does not use their own reference counters, but instead
piggybacks on another QOM object, "owner" (unless the owner is not the
memory region itself). When creating a subregion, a new reference to the
owner of the container must be created. However, if the subregion is
owned by the same QOM object, this result in a self-reference, and make
the owner immortal. Avoid such a self-reference.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
system/memory.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/system/memory.c b/system/memory.c
index 9540caa8a1f4..6645da02c658 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2638,7 +2638,10 @@ static void memory_region_update_container_subregions(MemoryRegion *subregion)
memory_region_transaction_begin();
- memory_region_ref(subregion);
+ if (mr->owner != subregion->owner) {
+ memory_region_ref(subregion);
+ }
+
QTAILQ_FOREACH(other, &mr->subregions, subregions_link) {
if (subregion->priority >= other->priority) {
QTAILQ_INSERT_BEFORE(other, subregion, subregions_link);
@@ -2696,7 +2699,11 @@ void memory_region_del_subregion(MemoryRegion *mr,
assert(alias->mapped_via_alias >= 0);
}
QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link);
- memory_region_unref(subregion);
+
+ if (mr->owner != subregion->owner) {
+ memory_region_unref(subregion);
+ }
+
memory_region_update_pending |= mr->enabled && subregion->enabled;
memory_region_transaction_commit();
}
--
2.45.2
next prev parent reply other threads:[~2024-06-26 11:09 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-26 11:06 [PATCH 00/14] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
2024-06-26 11:06 ` [PATCH 01/14] hw/core: Free CPUState allocations Akihiko Odaki
2024-06-26 12:04 ` Philippe Mathieu-Daudé
2024-06-26 11:06 ` [PATCH 02/14] hw/ide: Free macio-ide IRQs Akihiko Odaki
2024-06-26 12:59 ` Peter Maydell
2024-06-28 7:16 ` Mark Cave-Ayland
2024-06-26 11:06 ` [PATCH 03/14] hw/isa/vt82c686: Free irqs Akihiko Odaki
2024-06-26 12:57 ` Peter Maydell
2024-06-26 11:06 ` [PATCH 04/14] spapr: Free stdout path Akihiko Odaki
2024-06-26 12:02 ` Philippe Mathieu-Daudé
2024-06-26 11:06 ` [PATCH 05/14] ppc/vof: Fix unaligned FDT property access Akihiko Odaki
2024-06-26 12:03 ` Philippe Mathieu-Daudé
2024-06-27 13:12 ` Akihiko Odaki
2024-06-27 14:02 ` Philippe Mathieu-Daudé
2024-06-27 14:06 ` Akihiko Odaki
2024-06-26 11:06 ` [PATCH 06/14] hw/virtio: Free vqs before vhost_dev_cleanup() Akihiko Odaki
2024-06-26 11:21 ` Michael S. Tsirkin
2024-06-26 11:06 ` [PATCH 07/14] migration: Free removed SaveStateEntry Akihiko Odaki
2024-06-26 13:32 ` Peter Xu
2024-06-26 11:06 ` Akihiko Odaki [this message]
2024-06-26 11:06 ` [PATCH 09/14] tests/qtest: Use qtest_add_data_func_full() Akihiko Odaki
2024-06-26 11:06 ` [PATCH 10/14] tests/qtest: Free unused QMP response Akihiko Odaki
2024-06-26 11:06 ` [PATCH 11/14] tests/qtest: Free old machine variable name Akihiko Odaki
2024-06-26 11:06 ` [PATCH 12/14] tests/qtest: Delete previous boot file Akihiko Odaki
2024-06-26 11:06 ` [PATCH 13/14] tests/qtest: Free paths Akihiko Odaki
2024-06-26 11:06 ` [PATCH 14/14] tests/qtest: Free GThread Akihiko Odaki
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=20240626-san-v1-8-f3cc42302189@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=aik@ozlabs.ru \
--cc=alex.bennee@linaro.org \
--cc=balaton@eik.bme.hu \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=harshpb@linux.ibm.com \
--cc=jiaxun.yang@flygoat.com \
--cc=jsnow@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.com \
--cc=wangyanan55@huawei.com \
/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).