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

* Re: [PATCH] system/memory: Convert MemoryRegion properties to class properties
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-12-04 11:44 UTC (permalink / raw)
  To: Oscar Alejandro Sánchez Lucero, qemu-devel
  Cc: Paolo Bonzini, Peter Xu, Mark Cave-Ayland

Hi Oscar,

On 4/12/26 11:47, Oscar Alejandro Sánchez Lucero wrote:
> 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.

Just curious, is it done with LLM?

> 
> 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));

The assert out of nowhere is surprising when reading the code.
Maybe move the commit comment in the code instead? But I doubt
we need to check. Cc'ing Mark who did previous conversions of
this API. LGTM otherwise.

> +    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	[flat|nested] 4+ messages in thread

* Re: [PATCH] system/memory: Convert MemoryRegion properties to class properties
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2026-12-04 11:55 UTC (permalink / raw)
  To: Oscar Alejandro Sánchez Lucero
  Cc: qemu-devel, Paolo Bonzini, Peter Xu, Philippe Mathieu-Daudé

Does this clash with

    From: Markus Armbruster <armbru@redhat.com>
    Subject: [PATCH 0/7] backends/hostmem: Make QOM types and properties unconditional
    To: qemu-devel@nongnu.org
    Date: Wed, 11 Nov 2026 13:23:35 +0100
    Message-ID: <20261111122342.634370-1-armbru@redhat.com>

?


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

* Re: [PATCH] system/memory: Convert MemoryRegion properties to class properties
  2026-12-04 11:55 ` Markus Armbruster
@ 2026-12-04 12:16   ` Alejandro Lucero
  0 siblings, 0 replies; 4+ messages in thread
From: Alejandro Lucero @ 2026-12-04 12:16 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, Paolo Bonzini, Peter Xu, Philippe Mathieu-Daudé

Hi Philippe,

On 4/12/26 12:xx, Philippe Mathieu-Daudé wrote:
> Just curious, is it done with LLM?
> The assert out of nowhere is surprising when reading the code.
> Maybe move the commit comment in the code instead? But I doubt
> we need to check. Cc'ing Mark who did previous conversions of
> this API. LGTM otherwise.

Yes, I use scripts and LLM assistance to help audit the tree and draft the
boilerplate, then review each diff manually and verify it with the QOM
unit tests and live QMP queries.

Fair point on the QEMU_BUILD_BUG_ON(), it does look abrupt without
context. I can send a v2 with a short inline comment above it (or drop
it if you and Mark think it is unnecessary since hwaddr is always
64-bit).

> Does this clash with
>
>     From: Markus Armbruster <armbru@redhat.com>
>     Subject: [PATCH 0/7] backends/hostmem: Make QOM types and properties unconditional
>     To: qemu-devel@nongnu.org
>     Date: Wed, 11 Nov 2026 13:23:35 +0100
>     Message-ID: <20261111122342.634370-1-armbru@redhat.com>
>
> ?

No clash: Markus's series only touches backends/hostmem*.c (including
making the existing "hugetlb" and "hugetlbsize" class properties
unconditional in hostmem-memfd.c) and util/memfd.c. My patch only
modifies TYPE_MEMORY_REGION in system/memory.c.

Thanks for taking a look :)

Best regards,
Alejandro

El vie, 4 dic 2026 a la(s) 5:55 a.m., Markus Armbruster
(armbru@pond.sub.org) escribió:
>
> Does this clash with
>
>     From: Markus Armbruster <armbru@redhat.com>
>     Subject: [PATCH 0/7] backends/hostmem: Make QOM types and properties unconditional
>     To: qemu-devel@nongnu.org
>     Date: Wed, 11 Nov 2026 13:23:35 +0100
>     Message-ID: <20261111122342.634370-1-armbru@redhat.com>
>
> ?


^ permalink raw reply	[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.