[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 09/15] memory: Do not create circular reference with subregion
From: |
Akihiko Odaki |
Subject: |
[PATCH v2 09/15] memory: Do not create circular reference with subregion |
Date: |
Thu, 27 Jun 2024 22:37:52 +0900 |
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 74cd73ebc78b..949f5016a68d 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
[PATCH v2 05/15] spapr: Free stdout path, Akihiko Odaki, 2024/06/27
[PATCH v2 06/15] ppc/vof: Fix unaligned FDT property access, Akihiko Odaki, 2024/06/27
[PATCH v2 07/15] hw/virtio: Free vqs after vhost_dev_cleanup(), Akihiko Odaki, 2024/06/27
[PATCH v2 08/15] migration: Free removed SaveStateEntry, Akihiko Odaki, 2024/06/27
[PATCH v2 09/15] memory: Do not create circular reference with subregion,
Akihiko Odaki <=
[PATCH v2 10/15] tests/qtest: Use qtest_add_data_func_full(), Akihiko Odaki, 2024/06/27
[PATCH v2 11/15] tests/qtest: Free unused QMP response, Akihiko Odaki, 2024/06/27
[PATCH v2 12/15] tests/qtest: Free old machine variable name, Akihiko Odaki, 2024/06/27
[PATCH v2 13/15] tests/qtest: Delete previous boot file, Akihiko Odaki, 2024/06/27
[PATCH v2 15/15] tests/qtest: Free GThread, Akihiko Odaki, 2024/06/27
[PATCH v2 14/15] tests/qtest: Free paths, Akihiko Odaki, 2024/06/27