All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] system/memory: Convert MemoryRegion properties to class properties
@ 2026-12-04 10:47 Oscar Alejandro Sánchez Lucero
  2026-12-04 11:44 ` Philippe Mathieu-Daudé
  2026-12-04 11:55 ` Markus Armbruster
  0 siblings, 2 replies; 4+ messages in thread
From: Oscar Alejandro Sánchez Lucero @ 2026-12-04 10:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Peter Xu, Philippe Mathieu-Daudé,
	Oscar Alejandro Sánchez Lucero

Instance-level property registration via object_property_add*() is
deprecated in favor of class-level registration in class_init (see
include/qom/object.h).

Move the "container", "addr" (guarded with QEMU_BUILD_BUG_ON to
ensure hwaddr remains 64-bit), "priority", and "size" properties from
memory_region_initfn() to a new memory_region_class_init() callback.
Because MemoryRegion objects are instantiated dozens or hundreds of
times per machine (for example, 74 instances even on a minimal arm
'virt' board), registering these properties on the class eliminates
redundant per-instance heap allocations and hash table insertions while
allowing class-level QOM property introspection.

Verified with tests/unit/check-qom-proplist, recursive QMP qom-list
across all 74 MemoryRegion instances on arm 'virt', and live QMP
qom-get queries on both root and mapped MMIO regions.

Signed-off-by: Oscar Alejandro Sánchez Lucero <aleszlucero@gmail.com>
---
 system/memory.c | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/system/memory.c b/system/memory.c
index 56c5dd6c8a..3880e0ee27 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1285,23 +1285,6 @@ static void memory_region_initfn(Object *obj)
     mr->destructor = memory_region_destructor_none;
     QTAILQ_INIT(&mr->subregions);
     QTAILQ_INIT(&mr->coalesced);
-
-    object_property_add_link(obj, "container",
-                             TYPE_MEMORY_REGION,
-                             (Object **)&mr->container,
-                             NULL, /* read-only: no check means no setter */
-                             0);
-
-    object_property_add_uint64_ptr(OBJECT(mr), "addr",
-                                   &mr->addr, OBJ_PROP_FLAG_READ);
-    object_property_add(OBJECT(mr), "priority", "int32", &int32_type_info,
-                        memory_region_get_priority,
-                        NULL, /* memory_region_set_priority */
-                        NULL, NULL);
-    object_property_add(OBJECT(mr), "size", "uint64", &uint64_type_info,
-                        memory_region_get_size,
-                        NULL, /* memory_region_set_size, */
-                        NULL, NULL);
 }
 
 static void iommu_memory_region_initfn(Object *obj)
@@ -3650,11 +3633,34 @@ void __attribute__((weak)) fuzz_dma_read_cb(size_t addr,
 }
 #endif
 
+static void memory_region_class_init(ObjectClass *oc, const void *data)
+{
+    object_class_property_add_link(oc, "container",
+                                   TYPE_MEMORY_REGION,
+                                   offsetof(MemoryRegion, container),
+                                   NULL, /* read-only: no setter */
+                                   0);
+
+    QEMU_BUILD_BUG_ON(sizeof_field(MemoryRegion, addr) != sizeof(uint64_t));
+    object_class_property_add_uint64_ptr(oc, "addr",
+                                         offsetof(MemoryRegion, addr),
+                                         OBJ_PROP_FLAG_READ);
+    object_class_property_add(oc, "priority", "int32", &int32_type_info,
+                              memory_region_get_priority,
+                              NULL, /* memory_region_set_priority */
+                              NULL, NULL);
+    object_class_property_add(oc, "size", "uint64", &uint64_type_info,
+                              memory_region_get_size,
+                              NULL, /* memory_region_set_size, */
+                              NULL, NULL);
+}
+
 static const TypeInfo memory_region_info = {
     .parent             = TYPE_OBJECT,
     .name               = TYPE_MEMORY_REGION,
     .class_size         = sizeof(MemoryRegionClass),
     .instance_size      = sizeof(MemoryRegion),
+    .class_init         = memory_region_class_init,
     .instance_init      = memory_region_initfn,
     .instance_finalize  = memory_region_finalize,
 };

---
base-commit: f210851c088e477e9b79fa906b60c4f15a8bb011
change-id: 20261204-memory-class-props-6469c2a680c1

Best regards,
--  
Oscar Alejandro Sánchez Lucero <aleszlucero@gmail.com>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04 12:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 10:47 [PATCH] system/memory: Convert MemoryRegion properties to class properties Oscar Alejandro Sánchez Lucero
2026-12-04 11:44 ` Philippe Mathieu-Daudé
2026-12-04 11:55 ` Markus Armbruster
2026-12-04 12:16   ` Alejandro Lucero

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.