From: "Oscar Alejandro Sánchez Lucero" <aleszlucero@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Oscar Alejandro Sánchez Lucero" <aleszlucero@gmail.com>
Subject: [PATCH] system/memory: Convert MemoryRegion properties to class properties
Date: Fri, 04 Dec 2026 10:47:41 +0000 [thread overview]
Message-ID: <20261204-memory-class-props-v1-1-a58840aa9cd6@gmail.com> (raw)
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>
next reply other threads:[~2026-12-04 10:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:47 Oscar Alejandro Sánchez Lucero [this message]
2026-12-04 11:44 ` [PATCH] system/memory: Convert MemoryRegion properties to class properties Philippe Mathieu-Daudé
2026-12-04 11:55 ` Markus Armbruster
2026-12-04 12:16 ` Alejandro Lucero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204-memory-class-props-v1-1-a58840aa9cd6@gmail.com \
--to=aleszlucero@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.