memory: Remove most _nomigrate variants
v5 cover memory: Remove most _nomigrate variants
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(-)
Signature · 1 line
2.41.3
PATCH v5 1/8 hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
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.
--- hw/display/cg3.c | 5 ++--- hw/display/tcx.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
hw/display/cg3.c +2 -3
@@ -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);
hw/display/tcx.c +2 -3
@@ -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);
Signature · 1 line
2.41.3
Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
Quoted 10 lines · BALATON Zoltan
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 <[email protected]>--- hw/display/cg3.c | 5 ++--- hw/display/tcx.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
I think the compat break on these machines is worth it to make progress on the cleanup of these functions.
thanks
-- PMM
Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
Quoted 12 lines · Peter Maydell
Quoted 10 lines · BALATON Zoltan
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 <[email protected]>--- hw/display/cg3.c | 5 ++--- hw/display/tcx.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
Quoted 4 lines
Reviewed-by Peter Maydell <[email protected]>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.
Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
Quoted 14 lines · Mark Cave-Ayland
Quoted 12 lines · Peter Maydell
Quoted 10 lines · BALATON Zoltan
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 <[email protected]>--- hw/display/cg3.c | 5 ++--- hw/display/tcx.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 4 lines
Reviewed-by Peter Maydell <[email protected]>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..]
Quoted 5 lines
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,
Signature · 1 line
Peter Xu
Re: [PATCH v5 1/8] hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate()
Quoted 55 lines · Peter Xu
Quoted 14 lines · Mark Cave-Ayland
Quoted 12 lines · Peter Maydell
Quoted 10 lines · BALATON Zoltan
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 <[email protected]>--- hw/display/cg3.c | 5 ++--- hw/display/tcx.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)Quoted 6 lines
Quoted 4 lines
Reviewed-by Peter Maydell <[email protected]>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..]
Quoted 5 lines
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).
Quoted 4 lines
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
PATCH v5 2/8 memory: Remove memory_region_init_rom_nomigrate()
In reply to BALATON ZoltanAll users were converted so no longer needed.
--- 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(-)
docs/devel/memory.rst +0 -1
@@ -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.
include/system/memory.h +0 -26
@@ -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
scripts/coccinelle/memory-region-housekeeping.cocci +0 -28
@@ -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;
system/memory.c +3 -16
@@ -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
Signature · 1 line
2.41.3
Re: [PATCH v5 2/8] memory: Remove memory_region_init_rom_nomigrate()
Quoted 10 lines · BALATON Zoltan
All users were converted so no longer needed.
Signed-off-by BALATON Zoltan <[email protected]>--- 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(-)
thanks
-- PMM
PATCH v5 3/8 sun4m,sun4u,tcx: Do not use memory_region_init_ram_nomigrate()
In reply to BALATON ZoltanConvert 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.
--- hw/display/tcx.c | 3 +-- hw/sparc/sun4m.c | 19 +++++-------------- hw/sparc64/sun4u.c | 10 +++------- 3 files changed, 9 insertions(+), 23 deletions(-)
hw/display/tcx.c +1 -2
@@ -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);
hw/sparc/sun4m.c +5 -14
@@ -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); }
hw/sparc64/sun4u.c +3 -7
@@ -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); }
Signature · 1 line
2.41.3
Re: [PATCH v5 3/8] sun4m, sun4u, tcx: Do not use memory_region_init_ram_nomigrate()
Quoted 11 lines · BALATON Zoltan
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 <[email protected]>--- hw/display/tcx.c | 3 +-- hw/sparc/sun4m.c | 19 +++++-------------- hw/sparc64/sun4u.c | 10 +++------- 3 files changed, 9 insertions(+), 23 deletions(-)
thanks
-- PMM
PATCH v5 4/8 memory: Remove memory_region_init_ram_nomigrate()
In reply to BALATON ZoltanThis is rarely needed and we can use memory_region_init_ram_flags_nomigrate() instead which is now the only nomigrate variant left.
--- 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(-)
docs/devel/memory.rst +3 -5
@@ -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:
hw/display/vga.c +2 -2
@@ -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;
hw/xtensa/xtfpga.c +2 -2
@@ -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); }
include/system/memory.h +0 -23
@@ -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
scripts/coccinelle/memory-region-housekeeping.cocci +0 -19
@@ -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;
system/memory.c +2 -11
@@ -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.
Signature · 1 line
2.41.3
Re: [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate()
Quoted 6 lines · BALATON Zoltan
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 <[email protected]>
I don't think this one is worth doing. We might as well wait until we can get rid of the VGA case.
Quoted 5 lines
hw/xtensa/xtfpga.c +0
-0
hw/xtensa/xtfpga.c static void xtfpga_net_init(MemoryRegion *address_space, · line 170
Quoted 10 lines
hw/xtensa/xtfpga.c +2
-2@@ -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
Re: [PATCH v5 4/8] memory: Remove memory_region_init_ram_nomigrate()
Quoted 10 lines · Peter Maydell
Quoted 6 lines · BALATON Zoltan
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 <[email protected]>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.
Quoted 7 lines
Quoted 7 lines
hw/xtensa/xtfpga.c +0
-0@@ -163,8 +163,8 @@ static void xtfpga_net_init(MemoryRegion *address_space, sysbus_mmio_get_region(s, 1));
Quoted 11 lines
hw/xtensa/xtfpga.c static void xtfpga_net_init(MemoryRegion *address_space, · line 170
Quoted 8 lines
hw/xtensa/xtfpga.c +2
-2ram =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:
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
PATCH v5 5/8 memory: Factor out common ram region initialization
In reply to BALATON ZoltanIntroduce internal helper functions to remove duplicated code from different memory_region_init_*ram functions.
--- system/memory.c | 132 ++++++++++++++++++------------------------------ 1 file changed, 50 insertions(+), 82 deletions(-)
system/memory.c +50 -82
@@ -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
Signature · 1 line
2.41.3
PATCH v5 6/8 memory: Add internal memory_region_register_ram function
In reply to BALATON ZoltanFactor 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.
--- system/memory.c | 76 ++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 55 deletions(-)
system/memory.c +21 -55
@@ -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; }
Signature · 1 line
2.41.3
PATCH v5 7/8 memory: Shorten memory_region_init_ram_device_ptr and memory_region_init_rom_device
In reply to BALATON ZoltanWe can reuse memory_region_init_io in these functions. Also shorten some other function prototypes.
--- system/memory.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
system/memory.c +8 -16
@@ -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)) {
Signature · 1 line
2.41.3
PATCH v5 8/8 memory: Factor out more common ram region initialization
In reply to BALATON ZoltanIntroduce internal memory_region_setup_ram_ptr() function to remove duplicated code from different memory_region_init_ram_*ptr functions.
--- system/memory.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
system/memory.c +10 -7
@@ -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; }
Signature · 1 line
2.41.3