[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 8/9] memory: Do not create circular reference with subregion
From: |
Akihiko Odaki |
Subject: |
[PATCH v3 8/9] memory: Do not create circular reference with subregion |
Date: |
Mon, 08 Jul 2024 15:55:19 +0900 |
memory_region_update_container_subregions() calls memory_region_ref()
on behalf of the owner of the container. memory_region_ref() must not
be called if the owner of the container also owns the subregion.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
system/memory.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/system/memory.c b/system/memory.c
index 2d6952136066..09c98042e443 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2625,7 +2625,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);
@@ -2683,7 +2686,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 v3 0/9] Fix check-qtest-ppc64 sanitizer errors, Akihiko Odaki, 2024/07/08
- [PATCH v3 1/9] spapr: Free stdout path, Akihiko Odaki, 2024/07/08
- [PATCH v3 2/9] ppc/vof: Fix unaligned FDT property access, Akihiko Odaki, 2024/07/08
- [PATCH v3 3/9] migration: Free removed SaveStateEntry, Akihiko Odaki, 2024/07/08
- [PATCH v3 4/9] memory: Do not refer to "memory region's reference count", Akihiko Odaki, 2024/07/08
- [PATCH v3 5/9] memory: Refer to docs/devel/memory.rst for "owner", Akihiko Odaki, 2024/07/08
- [PATCH v3 6/9] memory: Clarify that owner may be missing, Akihiko Odaki, 2024/07/08
- [PATCH v3 8/9] memory: Do not create circular reference with subregion,
Akihiko Odaki <=
- [PATCH v3 7/9] memory: Clarify owner must not call memory_region_ref(), Akihiko Odaki, 2024/07/08
- [PATCH v3 9/9] tests/qtest: Delete previous boot file, Akihiko Odaki, 2024/07/08