All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/8] memory: Remove most _nomigrate variants
@ 2026-03-01 21:03 BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate() BALATON Zoltan
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

v5:
- convert Sun machines and their display devices from global vmstate

v4:
- separate patch converting Sun machines from memory_region_init_ram_nomigrate
- split helper to init ram into two functions: setup and error_propagate
- also use memory_region_init_io in memory_region_init_ram_device_ptr

v3:
- rebased on master after some patches were merged
- drop some more line from memory-region-housekeeping.cocci
- added comment to explain what factored out helper does
- some more clean ups included

BALATON Zoltan (8):
  hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
  memory: Remove memory_region_init_rom_nomigrate()
  sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate()
  memory: Remove memory_region_init_ram_nomigrate()
  memory: Factor out common ram region initialization
  memory: Add internal memory_region_register_ram function
  memory: Shorten memory_region_init_ram_device_ptr and
    memory_region_init_rom_device
  memory: Factor out more common ram region initialization

 docs/devel/memory.rst                         |   9 +-
 hw/display/cg3.c                              |   5 +-
 hw/display/tcx.c                              |   8 +-
 hw/display/vga.c                              |   4 +-
 hw/sparc/sun4m.c                              |  19 +-
 hw/sparc64/sun4u.c                            |  10 +-
 hw/xtensa/xtfpga.c                            |   4 +-
 include/system/memory.h                       |  49 ----
 .../memory-region-housekeeping.cocci          |  47 ---
 system/memory.c                               | 269 ++++++------------
 10 files changed, 108 insertions(+), 316 deletions(-)

-- 
2.41.3



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

* [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-03  9:51   ` Peter Maydell
  2026-03-01 21:03 ` [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate() BALATON Zoltan
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

Use memory_region_init_rom() instead which is what other devices do.
This is breaks migration but these devices are only used on sparc Sun
machines which have no migration compatibility guarantee.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 hw/display/cg3.c | 5 ++---
 hw/display/tcx.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/display/cg3.c b/hw/display/cg3.c
index 568d6048a6..61bdb0552e 100644
--- a/hw/display/cg3.c
+++ b/hw/display/cg3.c
@@ -282,8 +282,8 @@ static void cg3_initfn(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     CG3State *s = CG3(obj);
 
-    memory_region_init_rom_nomigrate(&s->rom, obj, "cg3.prom",
-                                     FCODE_MAX_ROM_SIZE, &error_fatal);
+    memory_region_init_rom(&s->rom, obj, "cg3.prom", FCODE_MAX_ROM_SIZE,
+                           &error_fatal);
     sysbus_init_mmio(sbd, &s->rom);
 
     memory_region_init_io(&s->reg, obj, &cg3_reg_ops, s, "cg3.reg",
@@ -299,7 +299,6 @@ static void cg3_realizefn(DeviceState *dev, Error **errp)
     char *fcode_filename;
 
     /* FCode ROM */
-    vmstate_register_ram_global(&s->rom);
     fcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, CG3_ROM_FILE);
     if (fcode_filename) {
         ret = load_image_mr(fcode_filename, &s->rom);
diff --git a/hw/display/tcx.c b/hw/display/tcx.c
index 36cad82abd..16114b9bb8 100644
--- a/hw/display/tcx.c
+++ b/hw/display/tcx.c
@@ -756,8 +756,8 @@ static void tcx_initfn(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     TCXState *s = TCX(obj);
 
-    memory_region_init_rom_nomigrate(&s->rom, obj, "tcx.prom",
-                                     FCODE_MAX_ROM_SIZE, &error_fatal);
+    memory_region_init_rom(&s->rom, obj, "tcx.prom", FCODE_MAX_ROM_SIZE,
+                           &error_fatal);
     sysbus_init_mmio(sbd, &s->rom);
 
     /* 2/STIP : Stippler */
@@ -822,7 +822,6 @@ static void tcx_realizefn(DeviceState *dev, Error **errp)
     vram_base = memory_region_get_ram_ptr(&s->vram_mem);
 
     /* 10/ROM : FCode ROM */
-    vmstate_register_ram_global(&s->rom);
     fcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, TCX_ROM_FILE);
     if (fcode_filename) {
         ret = load_image_mr(fcode_filename, &s->rom);
-- 
2.41.3



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

* [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate()
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate() BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-03  9:52   ` Peter Maydell
  2026-03-01 21:03 ` [PATCH v5 3/8] sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate() BALATON Zoltan
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

All users were converted so no longer needed.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 docs/devel/memory.rst                         |  1 -
 include/system/memory.h                       | 26 -----------------
 .../memory-region-housekeeping.cocci          | 28 -------------------
 system/memory.c                               | 19 ++-----------
 4 files changed, 3 insertions(+), 71 deletions(-)

diff --git a/docs/devel/memory.rst b/docs/devel/memory.rst
index 8558f70a42..0bb5acab21 100644
--- a/docs/devel/memory.rst
+++ b/docs/devel/memory.rst
@@ -113,7 +113,6 @@ have a special case where you need to manage the migration of
 the backing memory yourself, you can call the functions:
 
 - memory_region_init_ram_nomigrate()
-- memory_region_init_rom_nomigrate()
 
 which only initialize the MemoryRegion and leave handling
 migration to the caller.
diff --git a/include/system/memory.h b/include/system/memory.h
index 0562af3136..7117699b10 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -1588,32 +1588,6 @@ void memory_region_init_alias(MemoryRegion *mr,
                               hwaddr offset,
                               uint64_t size);
 
-/**
- * memory_region_init_rom_nomigrate: Initialize a ROM memory region.
- *
- * This has the same effect as calling memory_region_init_ram_nomigrate()
- * and then marking the resulting region read-only with
- * memory_region_set_readonly().
- *
- * Note that this function does not do anything to cause the data in the
- * RAM side of the memory region to be migrated; that is the responsibility
- * of the caller.
- *
- * @mr: the #MemoryRegion to be initialized.
- * @owner: the object that tracks the region's reference count
- * @name: Region name, becomes part of RAMBlock name used in migration stream
- *        must be unique within any device
- * @size: size of the region.
- * @errp: pointer to Error*, to store an error if it happens.
- *
- * Return: true on success, else false setting @errp with error.
- */
-bool memory_region_init_rom_nomigrate(MemoryRegion *mr,
-                                      Object *owner,
-                                      const char *name,
-                                      uint64_t size,
-                                      Error **errp);
-
 /**
  * memory_region_init_iommu: Initialize a memory region of a custom type
  * that translates addresses
diff --git a/scripts/coccinelle/memory-region-housekeeping.cocci b/scripts/coccinelle/memory-region-housekeeping.cocci
index 7f89e9712e..e45703141a 100644
--- a/scripts/coccinelle/memory-region-housekeeping.cocci
+++ b/scripts/coccinelle/memory-region-housekeeping.cocci
@@ -16,17 +16,10 @@
 expression E1, E2, E3, E4, E5;
 symbol true;
 @@
-(
 - memory_region_init_ram(E1, E2, E3, E4, E5);
 + memory_region_init_rom(E1, E2, E3, E4, E5);
   ... WHEN != E1
 - memory_region_set_readonly(E1, true);
-|
-- memory_region_init_ram_nomigrate(E1, E2, E3, E4, E5);
-+ memory_region_init_rom_nomigrate(E1, E2, E3, E4, E5);
-  ... WHEN != E1
-- memory_region_set_readonly(E1, true);
-)
 
 
 @possible_memory_region_init_rom@
@@ -53,11 +46,7 @@ cocci.print_main("potential use of memory_region_init_rom*() in ", p)
 expression ROM, E1, E2, E3, E4;
 expression ALIAS, E5, E6, E7, E8;
 @@
-(
   memory_region_init_rom(ROM, E1, E2, E3, E4);
-|
-  memory_region_init_rom_nomigrate(ROM, E1, E2, E3, E4);
-)
   ...
    memory_region_init_alias(ALIAS, E5, E6, ROM, E7, E8);
 -  memory_region_set_readonly(ALIAS, true);
@@ -80,23 +69,6 @@ expression ERRP;
  ...
 -vmstate_register_ram_global(MR);
 @@
-expression MR;
-expression NAME;
-expression SIZE;
-expression ERRP;
-@@
--memory_region_init_rom_nomigrate(MR, NULL, NAME, SIZE, ERRP);
-+memory_region_init_rom(MR, NULL, NAME, SIZE, ERRP);
- ...
--vmstate_register_ram_global(MR);
-@@
-expression MR;
-expression OPS;
-expression OPAQUE;
-expression NAME;
-expression SIZE;
-expression ERRP;
-@@
 typedef DeviceState;
 identifier device_fn, dev, obj;
 expression E1, E2, E3, E4, E5;
diff --git a/system/memory.c b/system/memory.c
index c51d0798a8..65042bd9fa 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1738,21 +1738,6 @@ void memory_region_init_alias(MemoryRegion *mr,
     mr->alias_offset = offset;
 }
 
-bool memory_region_init_rom_nomigrate(MemoryRegion *mr,
-                                      Object *owner,
-                                      const char *name,
-                                      uint64_t size,
-                                      Error **errp)
-{
-    if (!memory_region_init_ram_flags_nomigrate(mr, owner, name,
-                                                size, 0, errp)) {
-         return false;
-    }
-    mr->readonly = true;
-
-    return true;
-}
-
 void memory_region_init_iommu(void *_iommu_mr,
                               size_t instance_size,
                               const char *mrtypename,
@@ -3757,9 +3742,11 @@ bool memory_region_init_rom(MemoryRegion *mr,
 {
     DeviceState *owner_dev;
 
-    if (!memory_region_init_rom_nomigrate(mr, owner, name, size, errp)) {
+    if (!memory_region_init_ram_flags_nomigrate(mr, owner, name,
+                                                size, 0, errp)) {
         return false;
     }
+    mr->readonly = true;
     /* This will assert if owner is neither NULL nor a DeviceState.
      * We only want the owner here for the purposes of defining a
      * unique name for migration. TODO: Ideally we should implement
-- 
2.41.3



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

* [PATCH v5 3/8] sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate()
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate() BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate() BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-03  9:53   ` [PATCH v5 3/8] sun4m, sun4u, tcx: " Peter Maydell
  2026-03-01 21:03 ` [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate() BALATON Zoltan
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

Convert to use memory_region_init_{ram,rom} instead. This breaks
migration but these machines have no migration compatibility guarantee
and this removes most remaining usages of this nomigrate variant.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 hw/display/tcx.c   |  3 +--
 hw/sparc/sun4m.c   | 19 +++++--------------
 hw/sparc64/sun4u.c | 10 +++-------
 3 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/hw/display/tcx.c b/hw/display/tcx.c
index 16114b9bb8..c8a4ac21ca 100644
--- a/hw/display/tcx.c
+++ b/hw/display/tcx.c
@@ -815,9 +815,8 @@ static void tcx_realizefn(DeviceState *dev, Error **errp)
     uint8_t *vram_base;
     char *fcode_filename;
 
-    memory_region_init_ram_nomigrate(&s->vram_mem, OBJECT(s), "tcx.vram",
+    memory_region_init_ram(&s->vram_mem, OBJECT(s), "tcx.vram",
                            s->vram_size * (1 + 4 + 4), &error_fatal);
-    vmstate_register_ram_global(&s->vram_mem);
     memory_region_set_log(&s->vram_mem, true, DIRTY_MEMORY_VGA);
     vram_base = memory_region_get_ram_ptr(&s->vram_mem);
 
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index a17bdb3692..47853e3f76 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -587,13 +587,10 @@ static void idreg_realize(DeviceState *ds, Error **errp)
     IDRegState *s = MACIO_ID_REGISTER(ds);
     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
 
-    if (!memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.idreg",
-                                          sizeof(idreg_data), errp)) {
+    if (!memory_region_init_rom(&s->mem, OBJECT(ds), "sun4m.idreg",
+                                sizeof(idreg_data), errp)) {
         return;
     }
-
-    vmstate_register_ram_global(&s->mem);
-    memory_region_set_readonly(&s->mem, true);
     sysbus_init_mmio(dev, &s->mem);
 }
 
@@ -638,12 +635,9 @@ static void afx_realize(DeviceState *ds, Error **errp)
     AFXState *s = TCX_AFX(ds);
     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
 
-    if (!memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.afx",
-                                          4, errp)) {
+    if (!memory_region_init_ram(&s->mem, OBJECT(ds), "sun4m.afx", 4, errp)) {
         return;
     }
-
-    vmstate_register_ram_global(&s->mem);
     sysbus_init_mmio(dev, &s->mem);
 }
 
@@ -719,13 +713,10 @@ static void prom_realize(DeviceState *ds, Error **errp)
     PROMState *s = OPENPROM(ds);
     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
 
-    if (!memory_region_init_ram_nomigrate(&s->prom, OBJECT(ds), "sun4m.prom",
-                                          PROM_SIZE_MAX, errp)) {
+    if (!memory_region_init_rom(&s->prom, OBJECT(ds), "sun4m.prom",
+                                PROM_SIZE_MAX, errp)) {
         return;
     }
-
-    vmstate_register_ram_global(&s->prom);
-    memory_region_set_readonly(&s->prom, true);
     sysbus_init_mmio(dev, &s->prom);
 }
 
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index b8bda1eb81..2e41785b78 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -455,13 +455,10 @@ static void prom_realize(DeviceState *ds, Error **errp)
     PROMState *s = OPENPROM(ds);
     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
 
-    if (!memory_region_init_ram_nomigrate(&s->prom, OBJECT(ds), "sun4u.prom",
-                                          PROM_SIZE_MAX, errp)) {
+    if (!memory_region_init_rom(&s->prom, OBJECT(ds), "sun4u.prom",
+                                PROM_SIZE_MAX, errp)) {
         return;
     }
-
-    vmstate_register_ram_global(&s->prom);
-    memory_region_set_readonly(&s->prom, true);
     sysbus_init_mmio(dev, &s->prom);
 }
 
@@ -498,9 +495,8 @@ static void ram_realize(DeviceState *dev, Error **errp)
     RamDevice *d = SUN4U_RAM(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
-    memory_region_init_ram_nomigrate(&d->ram, OBJECT(d), "sun4u.ram", d->size,
+    memory_region_init_ram(&d->ram, OBJECT(d), "sun4u.ram", d->size,
                            &error_fatal);
-    vmstate_register_ram_global(&d->ram);
     sysbus_init_mmio(sbd, &d->ram);
 }
 
-- 
2.41.3



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

* [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate()
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
                   ` (2 preceding siblings ...)
  2026-03-01 21:03 ` [PATCH v5 3/8] sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate() BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-03  9:55   ` Peter Maydell
  2026-03-01 21:03 ` [PATCH v5 5/8] memory: Factor out common ram region initialization BALATON Zoltan
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

This is rarely needed and we can use
memory_region_init_ram_flags_nomigrate() instead which is now the only
nomigrate variant left.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 docs/devel/memory.rst                         |  8 +++----
 hw/display/vga.c                              |  4 ++--
 hw/xtensa/xtfpga.c                            |  4 ++--
 include/system/memory.h                       | 23 -------------------
 .../memory-region-housekeeping.cocci          | 19 ---------------
 system/memory.c                               | 13 ++---------
 6 files changed, 9 insertions(+), 62 deletions(-)

diff --git a/docs/devel/memory.rst b/docs/devel/memory.rst
index 0bb5acab21..9083b18f08 100644
--- a/docs/devel/memory.rst
+++ b/docs/devel/memory.rst
@@ -110,11 +110,9 @@ migrated:
 
 For most devices and boards this is the correct thing. If you
 have a special case where you need to manage the migration of
-the backing memory yourself, you can call the functions:
-
-- memory_region_init_ram_nomigrate()
-
-which only initialize the MemoryRegion and leave handling
+the backing memory yourself, you can call the function
+memory_region_init_ram_flags_nomigrate()
+which only initializes the MemoryRegion and leaves handling
 migration to the caller.
 
 The functions:
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 59a65cbbff..ee7d97b5c2 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -2235,8 +2235,8 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
         return false;
     }
 
-    memory_region_init_ram_nomigrate(&s->vram, obj, "vga.vram", s->vram_size,
-                                     &local_err);
+    memory_region_init_ram_flags_nomigrate(&s->vram, obj, "vga.vram",
+                                           s->vram_size, 0, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return false;
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index d427d68e50..b025cc53a8 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -163,8 +163,8 @@ static void xtfpga_net_init(MemoryRegion *address_space,
             sysbus_mmio_get_region(s, 1));
 
     ram = g_malloc(sizeof(*ram));
-    memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * KiB,
-                           &error_fatal);
+    memory_region_init_ram_flags_nomigrate(ram, OBJECT(s), "open_eth.ram",
+                                           16 * KiB, 0, &error_fatal);
     vmstate_register_ram_global(ram);
     memory_region_add_subregion(address_space, buffers, ram);
 }
diff --git a/include/system/memory.h b/include/system/memory.h
index 7117699b10..d4793a08a7 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -1374,29 +1374,6 @@ void memory_region_init_io(MemoryRegion *mr,
                            const char *name,
                            uint64_t size);
 
-/**
- * memory_region_init_ram_nomigrate:  Initialize RAM memory region.  Accesses
- *                                    into the region will modify memory
- *                                    directly.
- *
- * @mr: the #MemoryRegion to be initialized.
- * @owner: the object that tracks the region's reference count
- * @name: Region name, becomes part of RAMBlock name used in migration stream
- *        must be unique within any device
- * @size: size of the region.
- * @errp: pointer to Error*, to store an error if it happens.
- *
- * Note that this function does not do anything to cause the data in the
- * RAM memory region to be migrated; that is the responsibility of the caller.
- *
- * Return: true on success, else false setting @errp with error.
- */
-bool memory_region_init_ram_nomigrate(MemoryRegion *mr,
-                                      Object *owner,
-                                      const char *name,
-                                      uint64_t size,
-                                      Error **errp);
-
 /**
  * memory_region_init_ram_flags_nomigrate:  Initialize RAM memory region.
  *                                          Accesses into the region will
diff --git a/scripts/coccinelle/memory-region-housekeeping.cocci b/scripts/coccinelle/memory-region-housekeeping.cocci
index e45703141a..b23647a3d8 100644
--- a/scripts/coccinelle/memory-region-housekeeping.cocci
+++ b/scripts/coccinelle/memory-region-housekeeping.cocci
@@ -26,15 +26,9 @@ symbol true;
 expression E1, E2, E3, E4, E5;
 position p;
 @@
-(
   memory_region_init_ram@p(E1, E2, E3, E4, E5);
   ...
   memory_region_set_readonly(E1, true);
-|
-  memory_region_init_ram_nomigrate@p(E1, E2, E3, E4, E5);
-  ...
-  memory_region_set_readonly(E1, true);
-)
 @script:python@
 p << possible_memory_region_init_rom.p;
 @@
@@ -52,23 +46,10 @@ expression ALIAS, E5, E6, E7, E8;
 -  memory_region_set_readonly(ALIAS, true);
 
 
-// Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
-// code sequences with use of the new memory_region_init_ram function.
-// Similarly for the _rom and _rom_device functions.
 // We don't try to replace sequences with a non-NULL owner, because
 // there are none in the tree that can be automatically converted
 // (and only a handful that can be manually converted).
 @@
-expression MR;
-expression NAME;
-expression SIZE;
-expression ERRP;
-@@
--memory_region_init_ram_nomigrate(MR, NULL, NAME, SIZE, ERRP);
-+memory_region_init_ram(MR, NULL, NAME, SIZE, ERRP);
- ...
--vmstate_register_ram_global(MR);
-@@
 typedef DeviceState;
 identifier device_fn, dev, obj;
 expression E1, E2, E3, E4, E5;
diff --git a/system/memory.c b/system/memory.c
index 65042bd9fa..e15f931a8a 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1579,16 +1579,6 @@ void memory_region_init_io(MemoryRegion *mr,
     memory_region_set_ops(mr, ops, opaque);
 }
 
-bool memory_region_init_ram_nomigrate(MemoryRegion *mr,
-                                      Object *owner,
-                                      const char *name,
-                                      uint64_t size,
-                                      Error **errp)
-{
-    return memory_region_init_ram_flags_nomigrate(mr, owner, name,
-                                                  size, 0, errp);
-}
-
 bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr,
                                             Object *owner,
                                             const char *name,
@@ -3695,7 +3685,8 @@ bool memory_region_init_ram(MemoryRegion *mr,
 {
     DeviceState *owner_dev;
 
-    if (!memory_region_init_ram_nomigrate(mr, owner, name, size, errp)) {
+    if (!memory_region_init_ram_flags_nomigrate(mr, owner, name,
+                                                size, 0, errp)) {
         return false;
     }
     /* This will assert if owner is neither NULL nor a DeviceState.
-- 
2.41.3



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

* [PATCH v5 5/8] memory: Factor out common ram region initialization
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
                   ` (3 preceding siblings ...)
  2026-03-01 21:03 ` [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate() BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 6/8] memory: Add internal memory_region_register_ram function BALATON Zoltan
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

Introduce internal helper functions to remove duplicated code from
different memory_region_init_*ram functions.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 system/memory.c | 132 ++++++++++++++++++------------------------------
 1 file changed, 50 insertions(+), 82 deletions(-)

diff --git a/system/memory.c b/system/memory.c
index e15f931a8a..e1f073e1be 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1579,19 +1579,16 @@ void memory_region_init_io(MemoryRegion *mr,
     memory_region_set_ops(mr, ops, opaque);
 }
 
-bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr,
-                                            Object *owner,
-                                            const char *name,
-                                            uint64_t size,
-                                            uint32_t ram_flags,
-                                            Error **errp)
+static void memory_region_setup_ram(MemoryRegion *mr)
 {
-    Error *err = NULL;
-    memory_region_init(mr, owner, name, size);
     mr->ram = true;
     mr->terminates = true;
     mr->destructor = memory_region_destructor_ram;
-    mr->ram_block = qemu_ram_alloc(size, ram_flags, mr, &err);
+}
+
+static bool memory_region_error_propagate(MemoryRegion *mr,
+                                          Error *err, Error **errp)
+{
     if (err) {
         mr->size = int128_zero();
         object_unparent(OBJECT(mr));
@@ -1601,6 +1598,18 @@ bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr,
     return true;
 }
 
+bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, Object *owner,
+                                            const char *name, uint64_t size,
+                                            uint32_t ram_flags, Error **errp)
+{
+    Error *err = NULL;
+
+    memory_region_init(mr, owner, name, size);
+    memory_region_setup_ram(mr);
+    mr->ram_block = qemu_ram_alloc(size, ram_flags, mr, &err);
+    return memory_region_error_propagate(mr, err, errp);
+}
+
 bool memory_region_init_resizeable_ram(MemoryRegion *mr,
                                        Object *owner,
                                        const char *name,
@@ -1612,108 +1621,69 @@ bool memory_region_init_resizeable_ram(MemoryRegion *mr,
                                        Error **errp)
 {
     Error *err = NULL;
+
     memory_region_init(mr, owner, name, size);
-    mr->ram = true;
-    mr->terminates = true;
-    mr->destructor = memory_region_destructor_ram;
-    mr->ram_block = qemu_ram_alloc_resizeable(size, max_size, resized,
-                                              mr, &err);
-    if (err) {
-        mr->size = int128_zero();
-        object_unparent(OBJECT(mr));
-        error_propagate(errp, err);
-        return false;
-    }
-    return true;
+    memory_region_setup_ram(mr);
+    mr->ram_block = qemu_ram_alloc_resizeable(size, max_size, resized, mr,
+                                              &err);
+    return memory_region_error_propagate(mr, err, errp);
 }
 
 #if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
-bool memory_region_init_ram_from_file(MemoryRegion *mr,
-                                      Object *owner,
-                                      const char *name,
-                                      uint64_t size,
-                                      uint64_t align,
-                                      uint32_t ram_flags,
-                                      const char *path,
-                                      ram_addr_t offset,
+bool memory_region_init_ram_from_file(MemoryRegion *mr, Object *owner,
+                                      const char *name, uint64_t size,
+                                      uint64_t align, uint32_t ram_flags,
+                                      const char *path, ram_addr_t offset,
                                       Error **errp)
 {
     Error *err = NULL;
+
     memory_region_init(mr, owner, name, size);
-    mr->ram = true;
+    memory_region_setup_ram(mr);
     mr->readonly = !!(ram_flags & RAM_READONLY);
-    mr->terminates = true;
-    mr->destructor = memory_region_destructor_ram;
     mr->align = align;
-    mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path,
-                                             offset, &err);
-    if (err) {
-        mr->size = int128_zero();
-        object_unparent(OBJECT(mr));
-        error_propagate(errp, err);
-        return false;
-    }
-    return true;
+    mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path, offset,
+                                             &err);
+    return memory_region_error_propagate(mr, err, errp);
 }
 
-bool memory_region_init_ram_from_fd(MemoryRegion *mr,
-                                    Object *owner,
-                                    const char *name,
-                                    uint64_t size,
-                                    uint32_t ram_flags,
-                                    int fd,
-                                    ram_addr_t offset,
-                                    Error **errp)
+bool memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner,
+                                    const char *name, uint64_t size,
+                                    uint32_t ram_flags, int fd,
+                                    ram_addr_t offset, Error **errp)
 {
     Error *err = NULL;
+
     memory_region_init(mr, owner, name, size);
-    mr->ram = true;
+    memory_region_setup_ram(mr);
     mr->readonly = !!(ram_flags & RAM_READONLY);
-    mr->terminates = true;
-    mr->destructor = memory_region_destructor_ram;
     mr->ram_block = qemu_ram_alloc_from_fd(size, size, NULL, mr, ram_flags, fd,
                                            offset, false, &err);
-    if (err) {
-        mr->size = int128_zero();
-        object_unparent(OBJECT(mr));
-        error_propagate(errp, err);
-        return false;
-    }
-    return true;
+    return memory_region_error_propagate(mr, err, errp);
 }
 #endif
 
-void memory_region_init_ram_ptr(MemoryRegion *mr,
-                                Object *owner,
-                                const char *name,
-                                uint64_t size,
-                                void *ptr)
+void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner,
+                                const char *name, uint64_t size, void *ptr)
 {
     memory_region_init(mr, owner, name, size);
-    mr->ram = true;
-    mr->terminates = true;
-    mr->destructor = memory_region_destructor_ram;
-
+    memory_region_setup_ram(mr);
     /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL.  */
     assert(ptr != NULL);
     mr->ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort);
 }
 
-void memory_region_init_ram_device_ptr(MemoryRegion *mr,
-                                       Object *owner,
-                                       const char *name,
-                                       uint64_t size,
+void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner,
+                                       const char *name, uint64_t size,
                                        void *ptr)
 {
     memory_region_init(mr, owner, name, size);
-    mr->ram = true;
-    mr->ram_device = true;
     memory_region_set_ops(mr, &ram_device_mem_ops, mr);
-    mr->destructor = memory_region_destructor_ram;
-
+    memory_region_setup_ram(mr);
     /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL.  */
     assert(ptr != NULL);
     mr->ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort);
+    mr->ram_device = true;
 }
 
 void memory_region_init_alias(MemoryRegion *mr,
@@ -3764,15 +3734,13 @@ bool memory_region_init_rom_device(MemoryRegion *mr,
     assert(ops);
     memory_region_init(mr, owner, name, size);
     memory_region_set_ops(mr, ops, opaque);
-    mr->rom_device = true;
-    mr->destructor = memory_region_destructor_ram;
+    memory_region_setup_ram(mr);
     mr->ram_block = qemu_ram_alloc(size, 0, mr, &err);
-    if (err) {
-        mr->size = int128_zero();
-        object_unparent(OBJECT(mr));
-        error_propagate(errp, err);
+    if (!memory_region_error_propagate(mr, err, errp)) {
         return false;
     }
+    mr->ram = false;
+    mr->rom_device = true;
     /* This will assert if owner is neither NULL nor a DeviceState.
      * We only want the owner here for the purposes of defining a
      * unique name for migration. TODO: Ideally we should implement
-- 
2.41.3



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

* [PATCH v5 6/8] memory: Add internal memory_region_register_ram function
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
                   ` (4 preceding siblings ...)
  2026-03-01 21:03 ` [PATCH v5 5/8] memory: Factor out common ram region initialization BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 7/8] memory: Shorten memory_region_init_ram_device_ptr and memory_region_init_rom_device BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 8/8] memory: Factor out more common ram region initialization BALATON Zoltan
  7 siblings, 0 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

Factor out common operation from memory_region_init_{ram,rom}
functions to register the region for migration. This avoids
duplicating the long comment in several functions.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 system/memory.c | 76 ++++++++++++++-----------------------------------
 1 file changed, 21 insertions(+), 55 deletions(-)

diff --git a/system/memory.c b/system/memory.c
index e1f073e1be..198d1d0b92 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -3647,18 +3647,10 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled)
     }
 }
 
-bool memory_region_init_ram(MemoryRegion *mr,
-                            Object *owner,
-                            const char *name,
-                            uint64_t size,
-                            Error **errp)
+static void memory_region_register_ram(MemoryRegion *mr, Object *owner)
 {
     DeviceState *owner_dev;
 
-    if (!memory_region_init_ram_flags_nomigrate(mr, owner, name,
-                                                size, 0, errp)) {
-        return false;
-    }
     /* This will assert if owner is neither NULL nor a DeviceState.
      * We only want the owner here for the purposes of defining a
      * unique name for migration. TODO: Ideally we should implement
@@ -3667,68 +3659,50 @@ bool memory_region_init_ram(MemoryRegion *mr,
      */
     owner_dev = DEVICE(owner);
     vmstate_register_ram(mr, owner_dev);
+}
 
+bool memory_region_init_ram(MemoryRegion *mr, Object *owner,
+                            const char *name, uint64_t size,
+                            Error **errp)
+{
+    if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, size,
+                                                0, errp)) {
+        return false;
+    }
+    memory_region_register_ram(mr, owner);
     return true;
 }
 
-bool memory_region_init_ram_guest_memfd(MemoryRegion *mr,
-                                        Object *owner,
-                                        const char *name,
-                                        uint64_t size,
+bool memory_region_init_ram_guest_memfd(MemoryRegion *mr, Object *owner,
+                                        const char *name, uint64_t size,
                                         Error **errp)
 {
-    DeviceState *owner_dev;
-
     if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, size,
                                                 RAM_GUEST_MEMFD, errp)) {
         return false;
     }
-    /* This will assert if owner is neither NULL nor a DeviceState.
-     * We only want the owner here for the purposes of defining a
-     * unique name for migration. TODO: Ideally we should implement
-     * a naming scheme for Objects which are not DeviceStates, in
-     * which case we can relax this restriction.
-     */
-    owner_dev = DEVICE(owner);
-    vmstate_register_ram(mr, owner_dev);
-
+    memory_region_register_ram(mr, owner);
     return true;
 }
 
-bool memory_region_init_rom(MemoryRegion *mr,
-                            Object *owner,
-                            const char *name,
-                            uint64_t size,
+bool memory_region_init_rom(MemoryRegion *mr, Object *owner,
+                            const char *name, uint64_t size,
                             Error **errp)
 {
-    DeviceState *owner_dev;
-
     if (!memory_region_init_ram_flags_nomigrate(mr, owner, name,
                                                 size, 0, errp)) {
         return false;
     }
     mr->readonly = true;
-    /* This will assert if owner is neither NULL nor a DeviceState.
-     * We only want the owner here for the purposes of defining a
-     * unique name for migration. TODO: Ideally we should implement
-     * a naming scheme for Objects which are not DeviceStates, in
-     * which case we can relax this restriction.
-     */
-    owner_dev = DEVICE(owner);
-    vmstate_register_ram(mr, owner_dev);
-
+    memory_region_register_ram(mr, owner);
     return true;
 }
 
-bool memory_region_init_rom_device(MemoryRegion *mr,
-                                   Object *owner,
-                                   const MemoryRegionOps *ops,
-                                   void *opaque,
-                                   const char *name,
-                                   uint64_t size,
+bool memory_region_init_rom_device(MemoryRegion *mr, Object *owner,
+                                   const MemoryRegionOps *ops, void *opaque,
+                                   const char *name, uint64_t size,
                                    Error **errp)
 {
-    DeviceState *owner_dev;
     Error *err = NULL;
 
     assert(ops);
@@ -3741,15 +3715,7 @@ bool memory_region_init_rom_device(MemoryRegion *mr,
     }
     mr->ram = false;
     mr->rom_device = true;
-    /* This will assert if owner is neither NULL nor a DeviceState.
-     * We only want the owner here for the purposes of defining a
-     * unique name for migration. TODO: Ideally we should implement
-     * a naming scheme for Objects which are not DeviceStates, in
-     * which case we can relax this restriction.
-     */
-    owner_dev = DEVICE(owner);
-    vmstate_register_ram(mr, owner_dev);
-
+    memory_region_register_ram(mr, owner);
     return true;
 }
 
-- 
2.41.3



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

* [PATCH v5 7/8] memory: Shorten memory_region_init_ram_device_ptr and memory_region_init_rom_device
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
                   ` (5 preceding siblings ...)
  2026-03-01 21:03 ` [PATCH v5 6/8] memory: Add internal memory_region_register_ram function BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  2026-03-01 21:03 ` [PATCH v5 8/8] memory: Factor out more common ram region initialization BALATON Zoltan
  7 siblings, 0 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

We can reuse memory_region_init_io in these functions. Also shorten
some other function prototypes.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 system/memory.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/system/memory.c b/system/memory.c
index 198d1d0b92..492bf51f48 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1568,12 +1568,9 @@ static void memory_region_set_ops(MemoryRegion *mr,
     mr->terminates = true;
 }
 
-void memory_region_init_io(MemoryRegion *mr,
-                           Object *owner,
-                           const MemoryRegionOps *ops,
-                           void *opaque,
-                           const char *name,
-                           uint64_t size)
+void memory_region_init_io(MemoryRegion *mr, Object *owner,
+                           const MemoryRegionOps *ops, void *opaque,
+                           const char *name, uint64_t size)
 {
     memory_region_init(mr, owner, name, size);
     memory_region_set_ops(mr, ops, opaque);
@@ -1677,8 +1674,7 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner,
                                        const char *name, uint64_t size,
                                        void *ptr)
 {
-    memory_region_init(mr, owner, name, size);
-    memory_region_set_ops(mr, &ram_device_mem_ops, mr);
+    memory_region_init_io(mr, owner, &ram_device_mem_ops, mr, name, size);
     memory_region_setup_ram(mr);
     /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL.  */
     assert(ptr != NULL);
@@ -1686,12 +1682,9 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner,
     mr->ram_device = true;
 }
 
-void memory_region_init_alias(MemoryRegion *mr,
-                              Object *owner,
-                              const char *name,
-                              MemoryRegion *orig,
-                              hwaddr offset,
-                              uint64_t size)
+void memory_region_init_alias(MemoryRegion *mr, Object *owner,
+                              const char *name, MemoryRegion *orig,
+                              hwaddr offset, uint64_t size)
 {
     memory_region_init(mr, owner, name, size);
     mr->alias = orig;
@@ -3706,8 +3699,7 @@ bool memory_region_init_rom_device(MemoryRegion *mr, Object *owner,
     Error *err = NULL;
 
     assert(ops);
-    memory_region_init(mr, owner, name, size);
-    memory_region_set_ops(mr, ops, opaque);
+    memory_region_init_io(mr, owner, ops, opaque, name, size);
     memory_region_setup_ram(mr);
     mr->ram_block = qemu_ram_alloc(size, 0, mr, &err);
     if (!memory_region_error_propagate(mr, err, errp)) {
-- 
2.41.3



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

* [PATCH v5 8/8] memory: Factor out more common ram region initialization
  2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
                   ` (6 preceding siblings ...)
  2026-03-01 21:03 ` [PATCH v5 7/8] memory: Shorten memory_region_init_ram_device_ptr and memory_region_init_rom_device BALATON Zoltan
@ 2026-03-01 21:03 ` BALATON Zoltan
  7 siblings, 0 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-01 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Akihiko Odaki, Paolo Bonzini, Mark Cave-Ayland,
	Gerd Hoffmann, Max Filippov, Peter Maydell,
	Philippe Mathieu-Daudé

Introduce internal memory_region_setup_ram_ptr() function to remove
duplicated code from different memory_region_init_ram_*ptr functions.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 system/memory.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/system/memory.c b/system/memory.c
index 492bf51f48..fa3e19e1fd 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1660,25 +1660,28 @@ bool memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner,
 }
 #endif
 
-void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner,
-                                const char *name, uint64_t size, void *ptr)
+static void memory_region_setup_ram_ptr(MemoryRegion *mr, uint64_t size,
+                                        void *ptr)
 {
-    memory_region_init(mr, owner, name, size);
     memory_region_setup_ram(mr);
     /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL.  */
     assert(ptr != NULL);
     mr->ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort);
 }
 
+void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner,
+                                const char *name, uint64_t size, void *ptr)
+{
+    memory_region_init(mr, owner, name, size);
+    memory_region_setup_ram_ptr(mr, size, ptr);
+}
+
 void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner,
                                        const char *name, uint64_t size,
                                        void *ptr)
 {
     memory_region_init_io(mr, owner, &ram_device_mem_ops, mr, name, size);
-    memory_region_setup_ram(mr);
-    /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL.  */
-    assert(ptr != NULL);
-    mr->ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort);
+    memory_region_setup_ram_ptr(mr, size, ptr);
     mr->ram_device = true;
 }
 
-- 
2.41.3



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

* Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
  2026-03-01 21:03 ` [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate() BALATON Zoltan
@ 2026-03-03  9:51   ` Peter Maydell
  2026-03-05 11:15     ` Mark Cave-Ayland
  0 siblings, 1 reply; 17+ messages in thread
From: Peter Maydell @ 2026-03-03  9:51 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: qemu-devel, Peter Xu, Akihiko Odaki, Paolo Bonzini,
	Mark Cave-Ayland, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>
> Use memory_region_init_rom() instead which is what other devices do.
> This is breaks migration but these devices are only used on sparc Sun
> machines which have no migration compatibility guarantee.
>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  hw/display/cg3.c | 5 ++---
>  hw/display/tcx.c | 5 ++---
>  2 files changed, 4 insertions(+), 6 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

I think the compat break on these machines is worth it
to make progress on the cleanup of these functions.


thanks
-- PMM


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

* Re: [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate()
  2026-03-01 21:03 ` [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate() BALATON Zoltan
@ 2026-03-03  9:52   ` Peter Maydell
  0 siblings, 0 replies; 17+ messages in thread
From: Peter Maydell @ 2026-03-03  9:52 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: qemu-devel, Peter Xu, Akihiko Odaki, Paolo Bonzini,
	Mark Cave-Ayland, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>
> All users were converted so no longer needed.
>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  docs/devel/memory.rst                         |  1 -
>  include/system/memory.h                       | 26 -----------------
>  .../memory-region-housekeeping.cocci          | 28 -------------------
>  system/memory.c                               | 19 ++-----------
>  4 files changed, 3 insertions(+), 71 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


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

* Re: [PATCH v5 3/8] sun4m, sun4u, tcx: Do not use memory_region_init_ram_nomigrate()
  2026-03-01 21:03 ` [PATCH v5 3/8] sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate() BALATON Zoltan
@ 2026-03-03  9:53   ` Peter Maydell
  0 siblings, 0 replies; 17+ messages in thread
From: Peter Maydell @ 2026-03-03  9:53 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: qemu-devel, Peter Xu, Akihiko Odaki, Paolo Bonzini,
	Mark Cave-Ayland, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>
> Convert to use memory_region_init_{ram,rom} instead. This breaks
> migration but these machines have no migration compatibility guarantee
> and this removes most remaining usages of this nomigrate variant.
>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  hw/display/tcx.c   |  3 +--
>  hw/sparc/sun4m.c   | 19 +++++--------------
>  hw/sparc64/sun4u.c | 10 +++-------
>  3 files changed, 9 insertions(+), 23 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


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

* Re: [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate()
  2026-03-01 21:03 ` [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate() BALATON Zoltan
@ 2026-03-03  9:55   ` Peter Maydell
  2026-03-03 13:10     ` BALATON Zoltan
  0 siblings, 1 reply; 17+ messages in thread
From: Peter Maydell @ 2026-03-03  9:55 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: qemu-devel, Peter Xu, Akihiko Odaki, Paolo Bonzini,
	Mark Cave-Ayland, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>
> This is rarely needed and we can use
> memory_region_init_ram_flags_nomigrate() instead which is now the only
> nomigrate variant left.
>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>

I don't think this one is worth doing. We might as well
wait until we can get rid of the VGA case.

> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index d427d68e50..b025cc53a8 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -163,8 +163,8 @@ static void xtfpga_net_init(MemoryRegion *address_space,
>              sysbus_mmio_get_region(s, 1));
>
>      ram = g_malloc(sizeof(*ram));
> -    memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * KiB,
> -                           &error_fatal);
> +    memory_region_init_ram_flags_nomigrate(ram, OBJECT(s), "open_eth.ram",
> +                                           16 * KiB, 0, &error_fatal);
>      vmstate_register_ram_global(ram);
>      memory_region_add_subregion(address_space, buffers, ram);
>  }

We should change this to memory_region_init_ram(), taking
the compat break (which is fine for xtensa).

thanks
-- PMM


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

* Re: [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate()
  2026-03-03  9:55   ` Peter Maydell
@ 2026-03-03 13:10     ` BALATON Zoltan
  0 siblings, 0 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-03 13:10 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Peter Xu, Akihiko Odaki, Paolo Bonzini,
	Mark Cave-Ayland, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Tue, 3 Mar 2026, Peter Maydell wrote:
> On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>>
>> This is rarely needed and we can use
>> memory_region_init_ram_flags_nomigrate() instead which is now the only
>> nomigrate variant left.
>>
>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>
> I don't think this one is worth doing. We might as well
> wait until we can get rid of the VGA case.

There are two more uses that pass non-0 flags so even with the vga we 
can't completely remove memory_region_init_ram_flags_nomigrate(), the vga 
and xtensa are the ones that can use 
memory_region_init_ram_flags_nomigrate with flags=0 then we don't need 
memory_region_init_ram_nomigrate. But if everybody is so attached to this 
function for only these two uses that are to be removed soon I can drop 
this patch and keep memory_region_init_ram_nomigrate for now but I don't 
see why.

>> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
>> index d427d68e50..b025cc53a8 100644
>> --- a/hw/xtensa/xtfpga.c
>> +++ b/hw/xtensa/xtfpga.c
>> @@ -163,8 +163,8 @@ static void xtfpga_net_init(MemoryRegion *address_space,
>>              sysbus_mmio_get_region(s, 1));
>>
>>      ram = g_malloc(sizeof(*ram));
>> -    memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * KiB,
>> -                           &error_fatal);
>> +    memory_region_init_ram_flags_nomigrate(ram, OBJECT(s), "open_eth.ram",
>> +                                           16 * KiB, 0, &error_fatal);
>>      vmstate_register_ram_global(ram);
>>      memory_region_add_subregion(address_space, buffers, ram);
>>  }
>
> We should change this to memory_region_init_ram(), taking
> the compat break (which is fine for xtensa).

There's a patch in the follow up series that will convert this:

https://patchew.org/QEMU/cover.1770753117.git.balaton@eik.bme.hu/d2407882ecc62a51781dec51791c91d331802fa3.1770753117.git.balaton@eik.bme.hu/

so until then I chose to just preserve this for now as this is the 
simplest change here and we still have a similar one in vga but if we 
finally can get over this series and can discuss the follow ups then this 
should eventually be converted during that. So I don't think it matters 
when we take the migration break for this device and this way it's 
simpler. If we could remove the vga one now then it might worth to do the 
same here but since that's still there I think this is OK too.

Regards,
BALATON Zoltan


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

* Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
  2026-03-03  9:51   ` Peter Maydell
@ 2026-03-05 11:15     ` Mark Cave-Ayland
  2026-03-05 15:30       ` Peter Xu
  0 siblings, 1 reply; 17+ messages in thread
From: Mark Cave-Ayland @ 2026-03-05 11:15 UTC (permalink / raw)
  To: Peter Maydell, BALATON Zoltan
  Cc: qemu-devel, Peter Xu, Akihiko Odaki, Paolo Bonzini, Gerd Hoffmann,
	Max Filippov, Philippe Mathieu-Daudé

On 03/03/2026 09:51, Peter Maydell wrote:

> On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>>
>> Use memory_region_init_rom() instead which is what other devices do.
>> This is breaks migration but these devices are only used on sparc Sun
>> machines which have no migration compatibility guarantee.
>>
>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>> ---
>>   hw/display/cg3.c | 5 ++---
>>   hw/display/tcx.c | 5 ++---
>>   2 files changed, 4 insertions(+), 6 deletions(-)
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> 
> I think the compat break on these machines is worth it
> to make progress on the cleanup of these functions.

Hi Peter,

 From what I can see there is still on-going discussion on this series, however if 
the general consensus is that the removal of the last of these legacy functions is 
now imminent then I won't object if you want to merge this.


ATB,

Mark.



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

* Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
  2026-03-05 11:15     ` Mark Cave-Ayland
@ 2026-03-05 15:30       ` Peter Xu
  2026-03-05 16:06         ` BALATON Zoltan
  0 siblings, 1 reply; 17+ messages in thread
From: Peter Xu @ 2026-03-05 15:30 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: Peter Maydell, BALATON Zoltan, qemu-devel, Akihiko Odaki,
	Paolo Bonzini, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Thu, Mar 05, 2026 at 11:15:59AM +0000, Mark Cave-Ayland wrote:
> On 03/03/2026 09:51, Peter Maydell wrote:
> 
> > On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
> > > 
> > > Use memory_region_init_rom() instead which is what other devices do.
> > > This is breaks migration but these devices are only used on sparc Sun
> > > machines which have no migration compatibility guarantee.
> > > 
> > > Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> > > ---
> > >   hw/display/cg3.c | 5 ++---
> > >   hw/display/tcx.c | 5 ++---
> > >   2 files changed, 4 insertions(+), 6 deletions(-)
> > 
> > Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> > 
> > I think the compat break on these machines is worth it
> > to make progress on the cleanup of these functions.
> 
> Hi Peter,

Hi, Mark,

[some pure thoughts before PeterM chimes in..]

> 
> From what I can see there is still on-going discussion on this series,
> however if the general consensus is that the removal of the last of these
> legacy functions is now imminent then I won't object if you want to merge
> this.

In this case it's not easy to reach a consensus collecting "yes"s but
"no"s, that who still prefer this ABI to be kept.

Personally, I would respect your opinion, and I queued them because from
what I read the impact seems under control, please correct me otherwise.

There's indeed the dilemma that since sparc machines are not versioned,
then it's easier to be treated as a system that may not demand the highest
level of ABI guarantees.

It's also harder to consider ABI compatibility for un-versioned machs
comparing to versioned.

It's because for other versioned machines, we have the ~6 years lifespan
nowadays for them so we can drop old things over specific period of time.
While when a machine is not versioned, it's almost impossible to mark the
time of deprecation.

We either need to choose to maintain ABI for those machines forever, or we
allow ABI break to some degree.  When a machine is not versioned, it's
harder to justify we maintain these machines' ABI even longer than
versioned machines (which we deemed to be "relatively serious" users).

So if we want to stick with that machine versioning plan, maybe we should
start version machines that we may care on ABIs.  IIUC it doesn't need to
introduce one machine type every release, however when versioned we will be
able to follow the same ~6 years obsoletion phase at least.

Thanks,

-- 
Peter Xu



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

* Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
  2026-03-05 15:30       ` Peter Xu
@ 2026-03-05 16:06         ` BALATON Zoltan
  0 siblings, 0 replies; 17+ messages in thread
From: BALATON Zoltan @ 2026-03-05 16:06 UTC (permalink / raw)
  To: Peter Xu
  Cc: Mark Cave-Ayland, Peter Maydell, qemu-devel, Akihiko Odaki,
	Paolo Bonzini, Gerd Hoffmann, Max Filippov,
	Philippe Mathieu-Daudé

On Thu, 5 Mar 2026, Peter Xu wrote:
> On Thu, Mar 05, 2026 at 11:15:59AM +0000, Mark Cave-Ayland wrote:
>> On 03/03/2026 09:51, Peter Maydell wrote:
>>
>>> On Sun, 1 Mar 2026 at 21:03, BALATON Zoltan <balaton@eik.bme.hu> wrote:
>>>>
>>>> Use memory_region_init_rom() instead which is what other devices do.
>>>> This is breaks migration but these devices are only used on sparc Sun
>>>> machines which have no migration compatibility guarantee.
>>>>
>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>> ---
>>>>   hw/display/cg3.c | 5 ++---
>>>>   hw/display/tcx.c | 5 ++---
>>>>   2 files changed, 4 insertions(+), 6 deletions(-)
>>>
>>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>>>
>>> I think the compat break on these machines is worth it
>>> to make progress on the cleanup of these functions.
>>
>> Hi Peter,
>
> Hi, Mark,
>
> [some pure thoughts before PeterM chimes in..]
>
>>
>> From what I can see there is still on-going discussion on this series,
>> however if the general consensus is that the removal of the last of these
>> legacy functions is now imminent then I won't object if you want to merge
>> this.
>
> In this case it's not easy to reach a consensus collecting "yes"s but
> "no"s, that who still prefer this ABI to be kept.
>
> Personally, I would respect your opinion, and I queued them because from
> what I read the impact seems under control, please correct me otherwise.
>
> There's indeed the dilemma that since sparc machines are not versioned,
> then it's easier to be treated as a system that may not demand the highest
> level of ABI guarantees.
>
> It's also harder to consider ABI compatibility for un-versioned machs
> comparing to versioned.
>
> It's because for other versioned machines, we have the ~6 years lifespan
> nowadays for them so we can drop old things over specific period of time.
> While when a machine is not versioned, it's almost impossible to mark the
> time of deprecation.
>
> We either need to choose to maintain ABI for those machines forever, or we
> allow ABI break to some degree.  When a machine is not versioned, it's
> harder to justify we maintain these machines' ABI even longer than
> versioned machines (which we deemed to be "relatively serious" users).
>
> So if we want to stick with that machine versioning plan, maybe we should
> start version machines that we may care on ABIs.  IIUC it doesn't need to
> introduce one machine type every release, however when versioned we will be
> able to follow the same ~6 years obsoletion phase at least.

Considering that this was intruduced in 2017 around commit 1cfe48c1ce2 and 
most other users were converted back then it's well over 6 years now even 
without versioning. Thanks to Mark for accepting changing it now.

I've dropped the debated part about errp from the v7 of the series so all 
remaining clean ups should be simple enough to review and merge before the 
freeze. Could you please have a look at those too?

Regards,
BALATON Zoltan


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

end of thread, other threads:[~2026-03-05 16:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-01 21:03 [PATCH v5 0/8] memory: Remove most _nomigrate variants BALATON Zoltan
2026-03-01 21:03 ` [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate() BALATON Zoltan
2026-03-03  9:51   ` Peter Maydell
2026-03-05 11:15     ` Mark Cave-Ayland
2026-03-05 15:30       ` Peter Xu
2026-03-05 16:06         ` BALATON Zoltan
2026-03-01 21:03 ` [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate() BALATON Zoltan
2026-03-03  9:52   ` Peter Maydell
2026-03-01 21:03 ` [PATCH v5 3/8] sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate() BALATON Zoltan
2026-03-03  9:53   ` [PATCH v5 3/8] sun4m, sun4u, tcx: " Peter Maydell
2026-03-01 21:03 ` [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate() BALATON Zoltan
2026-03-03  9:55   ` Peter Maydell
2026-03-03 13:10     ` BALATON Zoltan
2026-03-01 21:03 ` [PATCH v5 5/8] memory: Factor out common ram region initialization BALATON Zoltan
2026-03-01 21:03 ` [PATCH v5 6/8] memory: Add internal memory_region_register_ram function BALATON Zoltan
2026-03-01 21:03 ` [PATCH v5 7/8] memory: Shorten memory_region_init_ram_device_ptr and memory_region_init_rom_device BALATON Zoltan
2026-03-01 21:03 ` [PATCH v5 8/8] memory: Factor out more common ram region initialization BALATON Zoltan

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.