[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 6/7] memory: Do not create circular reference with subregion
From: |
Akihiko Odaki |
Subject: |
[PATCH v4 6/7] memory: Do not create circular reference with subregion |
Date: |
Fri, 23 Aug 2024 15:13:11 +0900 |
memory_region_update_container_subregions() used to call
memory_region_ref(), which creates a reference to the owner of the
subregion, on behalf of the owner of the container. This results in a
circular reference if the subregion and container have the same owner.
memory_region_ref() creates a reference to the owner instead of the
memory region to match the lifetime of the owner and memory region. We
do not need such a hack if the subregion and container have the same
owner because the owner will be alive as long as the container is.
Therefore, create a reference to the subregion itself instead ot its
owner in such a case; the reference to the subregion is still necessary
to ensure that the subregion gets finalized after the container.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
system/memory.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/system/memory.c b/system/memory.c
index 5e6eb459d5de..e4d3e9d1f427 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2612,7 +2612,9 @@ static void
memory_region_update_container_subregions(MemoryRegion *subregion)
memory_region_transaction_begin();
- memory_region_ref(subregion);
+ object_ref(mr->owner == subregion->owner ?
+ OBJECT(subregion) : subregion->owner);
+
QTAILQ_FOREACH(other, &mr->subregions, subregions_link) {
if (subregion->priority >= other->priority) {
QTAILQ_INSERT_BEFORE(other, subregion, subregions_link);
@@ -2670,7 +2672,9 @@ void memory_region_del_subregion(MemoryRegion *mr,
assert(alias->mapped_via_alias >= 0);
}
QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link);
- memory_region_unref(subregion);
+ object_unref(mr->owner == subregion->owner ?
+ OBJECT(subregion) : subregion->owner);
+
memory_region_update_pending |= mr->enabled && subregion->enabled;
memory_region_transaction_commit();
}
--
2.46.0
- [PATCH v4 0/7] Fix check-qtest-ppc64 sanitizer errors, Akihiko Odaki, 2024/08/23
- [PATCH v4 1/7] migration: Free removed SaveStateEntry, Akihiko Odaki, 2024/08/23
- [PATCH v4 2/7] memory: Do not refer to "memory region's reference count", Akihiko Odaki, 2024/08/23
- [PATCH v4 4/7] memory: Clarify that owner may be missing, Akihiko Odaki, 2024/08/23
- [PATCH v4 3/7] memory: Refer to docs/devel/memory.rst for "owner", Akihiko Odaki, 2024/08/23
- [PATCH v4 5/7] memory: Clarify owner must not call memory_region_ref(), Akihiko Odaki, 2024/08/23
- [PATCH v4 6/7] memory: Do not create circular reference with subregion,
Akihiko Odaki <=
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Peter Xu, 2024/08/26
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Peter Maydell, 2024/08/26
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Peter Xu, 2024/08/26
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Akihiko Odaki, 2024/08/27
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Peter Xu, 2024/08/27
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Akihiko Odaki, 2024/08/28
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Peter Xu, 2024/08/28
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Akihiko Odaki, 2024/08/28
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Peter Xu, 2024/08/28
- Re: [PATCH v4 6/7] memory: Do not create circular reference with subregion, Akihiko Odaki, 2024/08/29