qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v1 05/11] memory: Parent Memory Regions to their


From: Peter Crosthwaite
Subject: [Qemu-devel] [RFC PATCH v1 05/11] memory: Parent Memory Regions to their registered owners
Date: Mon, 2 Jun 2014 19:09:18 -0700

As the QOM child. This gives Memory regions a canon path without
machines having to do it manually.

Unfortunately, there are no assurances against multiple memory
regions having the same name even when parented to the same owner.

We could munge names, but the canon paths will then get messy
and far less usable.

So we forbid naming ambiguity when initing mmio. We cant do this
forcefully, so we just ignore the error when subsequent inits
come along with the same name.

The consequences of a memory_region not getting parent will be an
assertion later when someone tries to link with it. This will only
happen with super modern Memory QOMified code. All legacy Memory
API users are unaffected until they are converted to QOM.

To aid with that conversion there's a macro you can define to
force an assertion on naming ambiguity. I'm hoping that make check
with this turned on will find the bulk of the violators.

Signed-off-by: Peter Crosthwaite <address@hidden>
---

 memory.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/memory.c b/memory.c
index 9e030ad..9192941 100644
--- a/memory.c
+++ b/memory.c
@@ -846,6 +846,21 @@ static void memory_region_readd_subregion(MemoryRegion *mr)
     }
 }
 
+/* It's going to take some time and patience to weed out tree-wide user's
+ * where a single owner of multiple memory regions adds them with the
+ * same name. This is not supported when using QOM APIs with memory
+ * regions due to canonical path ambiguity. But things will continue to
+ * work for non QOMified Memory API users when the error is simply
+ * ignored. So we ignore it by default for the moment.
+ *
+ * When QOMifying Memomy API users, switch this on to trap this failure
+ * rather than get an obscure segfault later than the point of error.
+ */
+
+#ifndef TRAP_DUP_MR_NAME
+#define TRAP_DUP_MR_NAME 0
+#endif
+
 void memory_region_init(MemoryRegion *mr,
                         Object *owner,
                         const char *name,
@@ -854,6 +869,10 @@ void memory_region_init(MemoryRegion *mr,
     object_initialize(mr, sizeof(*mr), TYPE_MEMORY_REGION);
 
     mr->owner = owner;
+    if (owner) {
+        object_property_add_child(owner, name, OBJECT(mr),
+                                  TRAP_DUP_MR_NAME ? &error_abort : NULL);
+    }
     mr->size = int128_make64(size);
     if (size == UINT64_MAX) {
         mr->size = int128_2_64();
-- 
2.0.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]