Some more pegasos patches
cover Some more pegasos patches
Some more short patches to finish the already merged pegasos clean up series.
BALATON Zoltan (4):
hw/ppc/pegasos2: Add /chosen/stdin node with VOF hw/pci-host/articia: Map PCI memory windows in realize hw/ppc/pegasos2: Rename to pegasos hw/ppc/pegasos: Update documentation for pegasos1
MAINTAINERS | 4 ++--
configs/devices/ppc-softmmu/default.mak | 7 +++---
docs/system/ppc/amigang.rst | 29 +++++++++++++++----------
hw/pci-host/articia.c | 15 ++++++++++++-
hw/ppc/Kconfig | 2 +-
hw/ppc/amigaone.c | 28 +++++-------------------
hw/ppc/meson.build | 4 ++--
hw/ppc/{pegasos2.c => pegasos.c} | 14 +-----------
8 files changed, 45 insertions(+), 58 deletions(-)
rename hw/ppc/{pegasos2.c => pegasos.c} (98%)Signature · 1 line
2.41.3
PATCH 1/4 hw/ppc/pegasos2: Add /chosen/stdin node with VOF
Some very old Linux kernels fail to start if /chosen/stdin is not found so add it to the device tree when using VOF.
--- hw/ppc/pegasos2.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/pegasos2.c +1 -0
@@ -565,6 +565,7 @@ static void pegasos_machine_reset(MachineState *machine, ResetType type)qemu_fdt_setprop (fdt,"/chosen" ,"qemu,boot-kernel" , d,sizeof (d));vof_build_dt (fdt, pm->vof); +vof_client_open_store (fdt, pm->vof,"/chosen" ,"stdin" ,"/failsafe" );vof_client_open_store (fdt, pm->vof,"/chosen" ,"stdout" ,"/failsafe" );/* Set machine->fdt for 'dumpdtb' QMP/HMP command */
Signature · 1 line
2.41.3
Re: [PATCH 1/4] hw/ppc/pegasos2: Add /chosen/stdin node with VOF
Quoted 13 lines · BALATON Zoltan
Some very old Linux kernels fail to start if /chosen/stdin is not found so add it to the device tree when using VOF.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/ppc/pegasos2.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/pegasos2.c +0
-0
hw/ppc/pegasos2.c static void pegasos_machine_reset(MachineState *machine, ResetType type) · line 568
Quoted 4 lines
hw/ppc/pegasos2.c +1
-0@@ -565,6 +565,7 @@ static void pegasos_machine_reset(MachineState *machine, ResetType type)qemu_fdt_setprop (fdt,"/chosen" ,"qemu,boot-kernel" , d,sizeof (d));vof_build_dt (fdt, pm->vof); +vof_client_open_store (fdt, pm->vof,"/chosen" ,"stdin" ,"/failsafe" );
Quoted 3 lines
hw/ppc/pegasos2.c +0
-0vof_client_open_store (fdt, pm->vof,"/chosen" ,"stdout" ,"/failsafe" );/* Set machine->fdt for 'dumpdtb' QMP/HMP command */
PATCH 2/4 hw/pci-host/articia: Map PCI memory windows in realize
In reply to BALATON ZoltanThese memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
--- hw/pci-host/articia.c | 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 ------------- 3 files changed, 19 insertions(+), 37 deletions(-)
hw/pci-host/articia.c +14 -1
@@ -22,6 +22,11 @@* Most features are missing but those are not needed by firmware and guests. */ +#define PCI_HIGH_ADDR 0x80000000 +#define PCI_HIGH_SIZE 0x7d000000 +#define PCI_LOW_ADDR 0xfd000000 +#define PCI_LOW_SIZE 0x1000000 + OBJECT_DECLARE_SIMPLE_TYPE(ArticiaState, ARTICIA)OBJECT_DECLARE_SIMPLE_TYPE (ArticiaHostState,ARTICIA_PCI_HOST )
@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) {ArticiaState *s =ARTICIA (dev);PCIHostState *h =PCI_HOST_BRIDGE (dev); +MemoryRegion *mr;PCIDevice *pdev;bitbang_i2c_init (&s->smbus,i2c_init_bus (dev,"smbus" ));
@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->reg,OBJECT (s), &articia_reg_ops, s,TYPE_ARTICIA ,0x1000000 );memory_region_add_subregion_overlap (&s->reg,0 , &s->io,1 ); + mr =g_new (MemoryRegion,1 ); +memory_region_init_alias (mr,OBJECT (dev),"pci-mem-low" , &s->mem, +0 ,PCI_LOW_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_LOW_ADDR , mr); + mr =g_new (MemoryRegion,1 ); +memory_region_init_alias (mr,OBJECT (dev),"pci-mem-high" , &s->mem, +PCI_HIGH_ADDR ,PCI_HIGH_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_HIGH_ADDR , mr);/* devfn_min is 8 that matches first PCI slot in AmigaOne */ h->bus = pci_register_root_bus(dev, NULL, articia_pcihost_set_irq,
@@ -191,7 +205,6 @@ static void articia_realize(DeviceState *dev, Error **errp)pci_create_simple (h->bus,PCI_DEVFN (0 ,1 ),TYPE_ARTICIA_PCI_BRIDGE );sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->reg); -sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->mem);qdev_init_gpio_out (dev, s->irq,ARRAY_SIZE (s->irq)); }
hw/ppc/amigaone.c +5 -23
@@ -34,13 +34,6 @@#define INITRD_MIN_ADDR 0x600000#define INIT_RAM_ADDR 0x40000000 -#define PCI_HIGH_ADDR 0x80000000 -#define PCI_HIGH_SIZE 0x7d000000 -#define PCI_LOW_ADDR 0xfd000000 -#define PCI_LOW_SIZE 0xe0000 - -#define ARTICIA_ADDR 0xfe000000 -/* * Firmware binary available at * https://www.hyperion-entertainment.com/index.php/downloads?view=files&parent=28
@@ -266,7 +259,7 @@ static void amigaone_init(MachineState *machine) {PowerPCCPU *cpu;CPUPPCState *env; -MemoryRegion *rom, *pci_mem, *mr; +MemoryRegion *rom, *mr;ssize_t sz;PCIBus *pci_bus;Object *via;
@@ -307,8 +300,8 @@ static void amigaone_init(MachineState *machine)qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (di)); }sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -memory_region_add_subregion (get_system_memory (),NVRAM_ADDR , -sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 )); + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ); +memory_region_add_subregion_overlap (get_system_memory (),NVRAM_ADDR , mr,1 );/* allocate and load firmware */ rom =g_new (MemoryRegion,1 );
@@ -332,8 +325,8 @@ static void amigaone_init(MachineState *machine) }/* Articia S */ - dev =sysbus_create_simple (TYPE_ARTICIA ,ARTICIA_ADDR ,NULL ); - + dev =sysbus_create_simple (TYPE_ARTICIA ,0xfe000000 ,NULL ); + pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); i2c_bus =I2C_BUS (qdev_get_child_bus (dev,"smbus" ));if (machine->ram_size >512 * MiB) { spd_data =spd_data_generate (SDR , machine->ram_size /2 );
@@ -346,17 +339,6 @@ static void amigaone_init(MachineState *machine)smbus_eeprom_init_one (i2c_bus,0x52 , spd_data); } - pci_mem =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),1 ); - mr =g_new (MemoryRegion,1 ); -memory_region_init_alias (mr,OBJECT (dev),"pci-mem-low" , pci_mem, -0 ,PCI_LOW_SIZE ); -memory_region_add_subregion (get_system_memory (),PCI_LOW_ADDR , mr); - mr =g_new (MemoryRegion,1 ); -memory_region_init_alias (mr,OBJECT (dev),"pci-mem-high" , pci_mem, -PCI_HIGH_ADDR ,PCI_HIGH_SIZE ); -memory_region_add_subregion (get_system_memory (),PCI_HIGH_ADDR , mr); - pci_bus =PCI_BUS (qdev_get_child_bus (dev,"pci.0" )); -/* VIA VT82c686B South Bridge (multifunction PCI device) */ via =OBJECT (pci_create_simple_multifunction (pci_bus,PCI_DEVFN (7 ,0 ),TYPE_VT82C686B_ISA ));
hw/ppc/pegasos2.c +0 -13
@@ -211,23 +211,10 @@ static void pegasos_init(MachineState *machine)/* north bridge */ switch (pm->type) {case PEGASOS1 : - { -MemoryRegion *pci_mem, *mr; -/* Articia S */ pm->nb =DEVICE (sysbus_create_simple (TYPE_ARTICIA ,0xfe000000 ,NULL )); - pci_mem =sysbus_mmio_get_region (SYS_BUS_DEVICE (pm->nb),1 ); - mr =g_new (MemoryRegion,1 ); -memory_region_init_alias (mr,OBJECT (pm->nb),"pci-mem-low" , pci_mem, -0 ,0x1000000 ); -memory_region_add_subregion (get_system_memory (),0xfd000000 , mr); - mr =g_new (MemoryRegion,1 ); -memory_region_init_alias (mr,OBJECT (pm->nb),"pci-mem-high" , pci_mem, -0x80000000 ,0x7d000000 ); -memory_region_add_subregion (get_system_memory (),0x80000000 , mr); pci_bus =PCI_BUS (qdev_get_child_bus (pm->nb,"pci.0" ));break ; - }case PEGASOS2 :/* Marvell Discovery II system controller */ pm->nb = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
Signature · 1 line
2.41.3
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 21 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>--- hw/pci-host/articia.c | 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 ------------- 3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) {ArticiaState *s =ARTICIA (dev);PCIHostState *h =PCI_HOST_BRIDGE (dev); +MemoryRegion *mr;PCIDevice *pdev;bitbang_i2c_init (&s->smbus,i2c_init_bus (dev,"smbus" ));
hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error **errp) · line 189
Quoted 4 lines
hw/pci-host/articia.c +1
-0@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->reg,OBJECT (s), &articia_reg_ops, s,TYPE_ARTICIA ,0x1000000 );memory_region_add_subregion_overlap (&s->reg,0 , &s->io,1 ); + mr =g_new (MemoryRegion,1 );
Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
Quoted 7 lines
hw/pci-host/articia.c +7
-0+memory_region_init_alias (mr,OBJECT (dev),"pci-mem-low" , &s->mem, +0 ,PCI_LOW_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_LOW_ADDR , mr); + mr =g_new (MemoryRegion,1 ); +memory_region_init_alias (mr,OBJECT (dev),"pci-mem-high" , &s->mem, +PCI_HIGH_ADDR ,PCI_HIGH_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_HIGH_ADDR , mr);
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>--- hw/pci-host/articia.c | 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 ------------- 3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) {ArticiaState *s =ARTICIA (dev);PCIHostState *h =PCI_HOST_BRIDGE (dev); +MemoryRegion *mr;PCIDevice *pdev;bitbang_i2c_init (&s->smbus,i2c_init_bus (dev,"smbus" ));@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)
Quoted 8 lines
hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error **errp) · line 189
Quoted 4 lines
hw/pci-host/articia.c +1
-0memory_region_init_io (&s->reg,OBJECT (s), &articia_reg_ops, s,TYPE_ARTICIA ,0x1000000 );memory_region_add_subregion_overlap (&s->reg,0 , &s->io,1 ); + mr =g_new (MemoryRegion,1 );Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
According to https://www.qemu.org/docs/master/devel/memory.html#region-lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Can I keep this R-b considering the above?
Regards,
BALATON Zoltan
Quoted 9 lines
Quoted 7 lines
hw/pci-host/articia.c +7
-0+memory_region_init_alias (mr,OBJECT (dev),"pci-mem-low" , &s->mem, +0 ,PCI_LOW_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_LOW_ADDR , mr); + mr =g_new (MemoryRegion,1 ); +memory_region_init_alias (mr,OBJECT (dev),"pci-mem-high" , &s->mem, +PCI_HIGH_ADDR ,PCI_HIGH_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_HIGH_ADDR , mr);
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 33 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) { ArticiaState *s = ARTICIA(dev); PCIHostState *h = PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)Quoted 8 lines
hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error **errp) · line 189
Quoted 4 lines
hw/pci-host/articia.c +1
-0memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); + mr = g_new(MemoryRegion, 1);Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
Quoted 2 lines
According to https://www.qemu.org/docs/master/devel/memory.html#region- lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.
IIUC this doc is about what happens within the allocated MemoryRegion, regardless of where it is allocated.
Quoted 18 lines
Quoted 2 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Can I keep this R-b considering the above?
Regards,
BALATON ZoltanQuoted 10 lines
Quoted 8 lines
hw/pci-host/articia.c +7
-0+ memory_region_init_alias(mr, OBJECT(dev), "pci-mem-low", &s->mem, + 0, PCI_LOW_SIZE); + memory_region_add_subregion(get_system_memory(), PCI_LOW_ADDR, mr); + mr = g_new(MemoryRegion, 1); + memory_region_init_alias(mr, OBJECT(dev), "pci-mem-high", &s->mem, + PCI_HIGH_ADDR, PCI_HIGH_SIZE); + memory_region_add_subregion(get_system_memory(), PCI_HIGH_ADDR, mr);
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 33 lines · BALATON Zoltan
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 21 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) { ArticiaState *s = ARTICIA(dev); PCIHostState *h = PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error · line 190
Quoted 5 lines
hw/pci-host/articia.c +1
-0@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); + mr = g_new(MemoryRegion, 1);Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
Quoted 5 lines
Quoted 2 lines
According to https://www.qemu.org/docs/master/devel/memory.html#region- lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.IIUC this doc is about what happens within the allocated MemoryRegion, regardless of where it is allocated.
That doc explicitely says:
"Destruction of a memory region happens automatically when the owner object dies. When there are multiple memory regions under the same owner object, the memory API will guarantee all memory regions will be properly detached and finalized one by one. The order in which memory regions will be finalized is not guaranteed."
(and these pci-host objects are created once at machine init and never die so the question seems quite theoretical). I'd like to keep object state simple and not keep around references in it that nothing uses and should be managed automatically. I'd only add fields to the state struct that other methods need.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 38 lines · BALATON Zoltan
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 35 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) { ArticiaState *s = ARTICIA(dev); PCIHostState *h = PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)Quoted 8 lines
hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error **errp) · line 189
Quoted 4 lines
hw/pci-host/articia.c +1
-0memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); + mr = g_new(MemoryRegion, 1);Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
According to https://www.qemu.org/docs/master/devel/ memory.html#region- lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.
Quoted 6 lines
Quoted 2 lines
IIUC this doc is about what happens within the allocated MemoryRegion, regardless of where it is allocated.
That doc explicitely says:
"Destruction of a memory region happens automatically when the owner object dies. When there are multiple memory regions under the same owner object, the memory API will guarantee all memory regions will be properly detached and finalized one by one. The order in which memory regions will be finalized is not guaranteed."
Destruction in this context does not imply freeing the storage.
The documentation describes destruction in QOM. QOM performs the following steps during destruction:
1. Delete properties
2. Call finalization callbacks
3. Free the storage
However, 3 will not happen in this case since you allocate the storage by yourself and it is not managed by QOM.
Please also note that the documentation also says:
Quoted 7 lines
If however the memory region is part of a dynamically allocated data structure, you should free the memory region in the
instance_finalizecallback. For an example see VFIOMSIXInfo and VFIOQuirk inhw/vfio/pci.c.(and these pci-host objects are created once at machine init and never die so the question seems quite theoretical). I'd like to keep object state simple and not keep around references in it that nothing uses and should be managed automatically. I'd only add fields to the state struct that other methods need.
It is indeed theoretical. That said, I prefer the memory region to be embedded into the device state struct as it will clarify that the lifetime of the memory region is bound to the device.
Regards,
Akihiko Odaki
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 48 lines · Akihiko Odaki
Quoted 38 lines · BALATON Zoltan
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 35 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) { ArticiaState *s = ARTICIA(dev); PCIHostState *h = PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)Quoted 8 lines
hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error **errp) · line 189
Quoted 4 lines
hw/pci-host/articia.c +1
-0memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); + mr = g_new(MemoryRegion, 1);Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
According to https://www.qemu.org/docs/master/devel/ memory.html#region- lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.Quoted 6 lines
Quoted 2 lines
IIUC this doc is about what happens within the allocated MemoryRegion, regardless of where it is allocated.
That doc explicitely says:
"Destruction of a memory region happens automatically when the owner object dies. When there are multiple memory regions under the same owner object, the memory API will guarantee all memory regions will be properly detached and finalized one by one. The order in which memory regions will be finalized is not guaranteed."
Destruction in this context does not imply freeing the storage.
Quoted 12 lines
The documentation describes destruction in QOM. QOM performs the following steps during destruction:
1. Delete properties
2. Call finalization callbacks
3. Free the storageHowever, 3 will not happen in this case since you allocate the storage by yourself and it is not managed by QOM.
Please also note that the documentation also says:
Quoted 4 lines
If however the memory region is part of a dynamically allocated data structure, you should free the memory region in the
instance_finalizecallback. For an example see VFIOMSIXInfo and VFIOQuirk inhw/vfio/pci.c.
So the problem is probably using g_new() to allocate it. Maybe this should be object_new() instead? I was trying to figure out how this should work but not sure I understand everything. It looks like as long as the mr has a name, memory_region_init() will add the mr as a child property to the owner and unref it so the reference will be passed to the owner which will own this mr after that. On destructing the owner it will delete all its properties which should dereference the memory region so it would be freed then if it had a free function set but it seems allocating with g_new and init-ing the region with memory_region_init() won't set the free function. Only way to set that seems to be object_new() but that also inits the object so maybe using it would double init the mr or add an extra reference so that may also not work. The extra ref could be solved by unref'ing after memory_region_init() but double init seems to be unnecessary. Maybe we need a memory_region_new_* set of functions or simpler than that an object_alloc() that allocates the object without init it that could be used in this case when init is done by other function like memory_region_init in this case?
Quoted 3 lines
Quoted 1 line
(and these pci-host objects are created once at machine init and never die so the question seems quite theoretical). I'd like to keep object state simple and not keep around references in it that nothing uses and should be managed automatically. I'd only add fields to the state struct that other methods need.
It is indeed theoretical. That said, I prefer the memory region to be embedded into the device state struct as it will clarify that the lifetime of the memory region is bound to the device.
But that way a lot of otherwise not needed fields would make the state struct more crowded and harder to see what's actually used there. Maybe this could be remedied by grouping these at the end below a comment but if ref counting worked as the docs state it this should not be necessary.
Before my cleanup the state strcut in raven.c looked like this:
struct PRePPCIState {
PCIHostState parent_obj;
OrIRQState *or_irq;
qemu_irq pci_irqs[PCI_NUM_PINS];
PCIBus pci_bus;
AddressSpace pci_io_as;
MemoryRegion pci_io;
MemoryRegion pci_io_non_contiguous;
MemoryRegion pci_memory;
MemoryRegion pci_intack;
MemoryRegion bm;
MemoryRegion bm_ram_alias;
MemoryRegion bm_pci_memory_alias;
AddressSpace bm_as;
RavenPCIState pci_dev;
int contiguous_map;
};which would become this after this series:
struct PREPPCIState {
PCIHostState parent_obj;
qemu_irq irq;
MemoryRegion pci_io;
MemoryRegion pci_discontiguous_io;
MemoryRegion pci_memory;
MemoryRegion pci_intack;
AddressSpace bm_as;
};if we don't have to keep regions we don't use after realize so those can be managed by QOM which is much more readable and comprehensible to me.
(Unrelated question but I'm still not sure what the bm_as is for. This seems to be present in some pci-hosts and may be needed for bus master cards but I just carried it over to my devices as a cargo cult without really getting why is it needed and why is it needed here and not in PCIHostState. Is there any explanation on that somewhere?)
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 56 lines · BALATON Zoltan
Quoted 55 lines · Akihiko Odaki
Quoted 38 lines · BALATON Zoltan
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 35 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)(quoted diff) +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) { ArticiaState *s = ARTICIA(dev); PCIHostState *h = PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)Quoted 8 lines
Review static void articia_realize(DeviceState · line 190
Quoted 4 lines
(quoted diff) +1
-0memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); + mr = g_new(MemoryRegion, 1);Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
According to https://www.qemu.org/docs/master/devel/ memory.html#region- lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.Quoted 6 lines
Quoted 2 lines
IIUC this doc is about what happens within the allocated MemoryRegion, regardless of where it is allocated.
That doc explicitely says:
"Destruction of a memory region happens automatically when the owner object dies. When there are multiple memory regions under the same owner object, the memory API will guarantee all memory regions will be properly detached and finalized one by one. The order in which memory regions will be finalized is not guaranteed."
Destruction in this context does not imply freeing the storage.
The documentation describes destruction in QOM. QOM performs the following steps during destruction:
1. Delete properties
2. Call finalization callbacks
3. Free the storageHowever, 3 will not happen in this case since you allocate the storage by yourself and it is not managed by QOM.
Quoted 8 lines
Quoted 5 lines
Please also note that the documentation also says:
Quoted 4 lines
If however the memory region is part of a dynamically allocated data structure, you should free the memory region in the
instance_finalizecallback. For an example see VFIOMSIXInfo and VFIOQuirk inhw/vfio/pci.c.So the problem is probably using
g_new()to allocate it. Maybe this should beobject_new()instead? I was trying to figure out how this should work but not sure I understand everything. It looks like as long as the mr has a name,memory_region_init()will add the mr as a child property to the owner and unref it so the reference will be passed to the owner which will own this mr after that. On destructing the owner it will delete all its properties which should dereference the memory region so it would be freed then if it had a free function set but it seems allocating withg_newand init-ing the region withmemory_region_init()won't set the free function. Only way to set that seems to beobject_new()but that also inits the object so maybe using it would double init the mr or add an extra reference so that may also not work. The extra ref could be solved by unref'ing aftermemory_region_init()but double init seems to be unnecessary. Maybe we need a memory_region_new_* set of functions or simpler than that anobject_alloc()that allocates the object without init it that could be used in this case when init is done by other function likememory_region_initin this case?
memory_region_new_* will work, but I don't think removing unnecessary but harmless fields from a device state structure does not sufficiently motivates adding them.
Quoted 42 lines
Quoted 4 lines
Quoted 2 lines
(and these pci-host objects are created once at machine init and never die so the question seems quite theoretical). I'd like to keep object state simple and not keep around references in it that nothing uses and should be managed automatically. I'd only add fields to the state struct that other methods need.
It is indeed theoretical. That said, I prefer the memory region to be embedded into the device state struct as it will clarify that the lifetime of the memory region is bound to the device.
But that way a lot of otherwise not needed fields would make the state struct more crowded and harder to see what's actually used there. Maybe this could be remedied by grouping these at the end below a comment but if ref counting worked as the docs state it this should not be necessary.
Before my cleanup the state strcut in
raven.clooked like this:struct PRePPCIState {
PCIHostStateparent_obj;OrIRQState
*or_irq;
qemu_irqpci_irqs[PCI_NUM_PINS];
PCIBuspci_bus;
AddressSpacepci_io_as;
MemoryRegionpci_io;
MemoryRegionpci_io_non_contiguous;
MemoryRegionpci_memory;
MemoryRegionpci_intack;
MemoryRegion bm;
MemoryRegionbm_ram_alias;
MemoryRegionbm_pci_memory_alias;
AddressSpacebm_as;
RavenPCIStatepci_dev;int
contiguous_map;
};which would become this after this series:
struct PREPPCIState {
PCIHostStateparent_obj;
qemu_irqirq;
MemoryRegionpci_io;
MemoryRegionpci_discontiguous_io;
MemoryRegionpci_memory;
MemoryRegionpci_intack;
AddressSpacebm_as;
};
Quoted 1 line
if we don't have to keep regions we don't use after realize so those can be managed by QOM which is much more readable and comprehensible to me.
It still requires a trade-off that obscures the duration of MemoryRegion and may confuse Coverity or other tools. I also prefer the fields present in the state as I can be immediately sure they do not leak even without checking that the device is not hotpluggable.
I don't think it needs comments. It is a common pattern that MemoryRegions are directly referenced only at initialization and uninitialization. The presence of MemoryRegions in a device state structure only tells that they are alive as long as the device is alive, and does not imply that it is directly referenced later.
Regards,
Akihiko Odaki
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 63 lines · Akihiko Odaki
Quoted 62 lines · BALATON Zoltan
Quoted 60 lines · Akihiko Odaki
Quoted 38 lines · BALATON Zoltan
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 35 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)(quoted diff) +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) { ArticiaState *s = ARTICIA(dev); PCIHostState *h = PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)Quoted 8 lines
Review static void articia_realize(DeviceState *dev, · line 190
Quoted 4 lines
(quoted diff) +1
-0memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); + mr = g_new(MemoryRegion, 1);Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
According to https://www.qemu.org/docs/master/devel/ memory.html#region- lifecycle
there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.Quoted 6 lines
Quoted 2 lines
IIUC this doc is about what happens within the allocated MemoryRegion, regardless of where it is allocated.
That doc explicitely says:
"Destruction of a memory region happens automatically when the owner object dies. When there are multiple memory regions under the same owner object, the memory API will guarantee all memory regions will be properly detached and finalized one by one. The order in which memory regions will be finalized is not guaranteed."
Destruction in this context does not imply freeing the storage.
The documentation describes destruction in QOM. QOM performs the following steps during destruction:
1. Delete properties
2. Call finalization callbacks
3. Free the storageHowever, 3 will not happen in this case since you allocate the storage by yourself and it is not managed by QOM.
Please also note that the documentation also says:
Quoted 4 lines
If however the memory region is part of a dynamically allocated data structure, you should free the memory region in the
instance_finalizecallback. For an example see VFIOMSIXInfo and VFIOQuirk inhw/vfio/pci.c.
Quoted 4 lines
Quoted 2 lines
So the problem is probably using
g_new()to allocate it. Maybe this should beobject_new()instead? I was trying to figure out how this should work but not sure I understand everything. It looks like as long as the mr has a name,memory_region_init()will add the mr as a child property to the owner and unref it so the reference will be passed to the owner which will own this mr after that. On destructing the owner it will delete all its properties which should dereference the memory region so it would be freed then if it had a free function set but it seems allocating withg_newand init-ing the region withmemory_region_init()won't set the free function. Only way to set that seems to beobject_new()but that also inits the object so maybe using it would double init the mr or add an extra reference so that may also not work. The extra ref could be solved by unref'ing aftermemory_region_init()but double init seems to be unnecessary. Maybe we need a memory_region_new_* set of functions or simpler than that anobject_alloc()that allocates the object without init it that could be used in this case when init is done by other function likememory_region_initin this case?memory_region_new_* will work, but I don't think removing unnecessary but harmless fields from a device state structure does not sufficiently motivates adding them.
I haven't given up on this yet, that's why I alternatively proposed
object_alloc (same as object_new without object_initialize) memory_region_init
which is just a small change but should also work without adding memory_region_new convenience functions. Then only object_alloc needs to be added.
Quoted 41 lines
Quoted 41 lines
Quoted 3 lines
Quoted 1 line
(and these pci-host objects are created once at machine init and never die so the question seems quite theoretical). I'd like to keep object state simple and not keep around references in it that nothing uses and should be managed automatically. I'd only add fields to the state struct that other methods need.
It is indeed theoretical. That said, I prefer the memory region to be embedded into the device state struct as it will clarify that the lifetime of the memory region is bound to the device.
But that way a lot of otherwise not needed fields would make the state struct more crowded and harder to see what's actually used there. Maybe this could be remedied by grouping these at the end below a comment but if ref counting worked as the docs state it this should not be necessary.
Before my cleanup the state strcut in
raven.clooked like this:struct PRePPCIState {
PCIHostStateparent_obj;OrIRQState
*or_irq;
qemu_irqpci_irqs[PCI_NUM_PINS];
PCIBuspci_bus;
AddressSpacepci_io_as;
MemoryRegionpci_io;
MemoryRegionpci_io_non_contiguous;
MemoryRegionpci_memory;
MemoryRegionpci_intack;
MemoryRegion bm;
MemoryRegionbm_ram_alias;
MemoryRegionbm_pci_memory_alias;
AddressSpacebm_as;
RavenPCIStatepci_dev;int
contiguous_map;
};which would become this after this series:
struct PREPPCIState {
PCIHostStateparent_obj;
qemu_irqirq;
MemoryRegionpci_io;
MemoryRegionpci_discontiguous_io;
MemoryRegionpci_memory;
MemoryRegionpci_intack;
AddressSpacebm_as;
};
Quoted 3 lines
Quoted 1 line
if we don't have to keep regions we don't use after realize so those can be managed by QOM which is much more readable and comprehensible to me.
It still requires a trade-off that obscures the duration of MemoryRegion and may confuse Coverity or other tools. I also prefer the fields present in the state as I can be immediately sure they do not leak even without checking that the device is not hotpluggable.
What I don't like is that it blows up the object state and makes it look more complex than needed. Memory regions are often created at realize then never used again. The documentation also says that these should be managed automatically and when memory_region_init'ing it adds a reference to the owner that should be enough to manage the lifetime of the mr. Also when using sysbus_init_mmio it also stores a pointer to the mr so actually no need to store those MemoryRegions in the object state for SysBusDevices. Then most simple devices could do without a subclass or only a few fields in their state that they add to their superclass but now we have these full of these memory regions unnecessarily.
Quoted 1 line
I don't think it needs comments. It is a common pattern that MemoryRegions are directly referenced only at initialization and uninitialization. The presence of MemoryRegions in a device state structure only tells that they are alive as long as the device is alive, and does not imply that it is directly referenced later.
But this makes the device more difficult to comprehend. As in the raven device above we had a lot of memory regions plus an unneeded init method that we could do without to make the device simpler and easier to understand what actual functionality it adds. Having additional fields in the state struct just distracts from that.
It looks like we won't be able to come to an agreement before the freeze and I don't have time now to change this patch but don't want to miss the release with this series that finishes pegasos renaming because of this. So for this patch I'd say since this is already how it is now and it does not make it worse and this object is not user creatable anyway so cannot leak please take it as it is and we'll do a clean up later after we finish discussion.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 19 lines · BALATON Zoltan
Quoted 18 lines · Akihiko Odaki
Quoted 17 lines · BALATON Zoltan
Quoted 16 lines · Akihiko Odaki
Quoted 15 lines · BALATON Zoltan
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · BALATON Zoltan
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)
[...]
Quoted 1 line
It looks like we won't be able to come to an agreement before the freeze and I don't have time now to change this patch but don't want to miss the release with this series that finishes pegasos renaming because of this. So for this patch I'd say since this is already how it is now and it does not make it worse and this object is not user creatable anyway so cannot leak please take it as it is and we'll do a clean up later after we finish discussion.
As for all of these files I'm the maintainer let me make an executive decision here to keep this patch without Philippe's reviewed-by for now to be able to move on with this series before the freeze. Fixing the theoretical leak can be done on top and since that's a fix it can be done during soft freeze that would give us more time. So Harsh please go ahead and merge this series too if there are no other concerns. I'll then address this later together with other similar issues elsewhere.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 20 lines · BALATON Zoltan
Quoted 11 lines · BALATON Zoltan
Quoted 10 lines · Akihiko Odaki
Quoted 9 lines · BALATON Zoltan
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · BALATON Zoltan
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 5 lines · BALATON Zoltan
Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 3 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)
Quoted 4 lines
[...]
Quoted 1 line
It looks like we won't be able to come to an agreement before the freeze and I don't have time now to change this patch but don't want to miss the release with this series that finishes pegasos renaming because of this. So for this patch I'd say since this is already how it is now and it does not make it worse and this object is not user creatable anyway so cannot leak please take it as it is and we'll do a clean up later after we finish discussion.
As for all of these files I'm the maintainer let me make an executive decision here to keep this patch without Philippe's reviewed-by for now to be able to move on with this series before the freeze. Fixing the theoretical leak can be done on top and since that's a fix it can be done during soft freeze that would give us more time. So Harsh please go ahead and merge this series too if there are no other concerns. I'll then address this later together with other similar issues elsewhere.
I think the issue here is that several people have now raised concerns as to the way you are trying to use MemoryRegions (both here and in the raven series): simply put, if reviewers didn't see any problems with this approach, your series would already have review tags.
If you want to suggest a different approach to managing MemoryRegions, then I would suggest you send a proposal to the mailing list so it can be reviewed by the QOM and memory people (along with updated code style documentation so we can all use it). But with freeze coming up in a few days this is certainly out of scope for 10.2.
For now I would suggest the easiest way to get review tags is to stick with the existing inline MemoryRegion approach for 10.2 to aid getting your patches merged: it's simply not fair to put time pressure on Harsh to merge patches in this way.
ATB,
Mark.
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 21 lines · Mark Cave-Ayland
Quoted 20 lines · BALATON Zoltan
Quoted 19 lines · BALATON Zoltan
Quoted 18 lines · Akihiko Odaki
Quoted 17 lines · BALATON Zoltan
Quoted 16 lines · Akihiko Odaki
Quoted 15 lines · BALATON Zoltan
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · BALATON Zoltan
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>---
hw/pci-host/articia.c| 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 -------------3 files changed, 19 insertions(+), 37 deletions(-)
Quoted 6 lines
Quoted 4 lines
[...]
Quoted 1 line
It looks like we won't be able to come to an agreement before the freeze and I don't have time now to change this patch but don't want to miss the release with this series that finishes pegasos renaming because of this. So for this patch I'd say since this is already how it is now and it does not make it worse and this object is not user creatable anyway so cannot leak please take it as it is and we'll do a clean up later after we finish discussion.
As for all of these files I'm the maintainer let me make an executive decision here to keep this patch without Philippe's reviewed-by for now to be able to move on with this series before the freeze. Fixing the theoretical leak can be done on top and since that's a fix it can be done during soft freeze that would give us more time. So Harsh please go ahead and merge this series too if there are no other concerns. I'll then address this later together with other similar issues elsewhere.
I think the issue here is that several people have now raised concerns as to the way you are trying to use MemoryRegions (both here and in the raven series): simply put, if reviewers didn't see any problems with this approach, your series would already have review tags.
I got that and did not mean to ignore those comments forever.
Quoted 1 line
If you want to suggest a different approach to managing MemoryRegions, then I would suggest you send a proposal to the mailing list so it can be reviewed by the QOM and memory people (along with updated code style documentation so
That's what I plan to do but got no time right now.
Quoted 1 line
we can all use it). But with freeze coming up in a few days this is certainly out of scope for 10.2.
That's why I proposed to take this patch for now as it only moves existing code to another place so it does not introduce a new problem that's not already there. And the problem is theoretical as it does not cause a leak in this case and nobody raised concerns so far and it was only noticed by this patch making it clearer removing duplicated code. So I still think this patch has merit, it helped to find a bug and would make code simpler without making it worse so it could be taken for that. But I'm OK with dropping it too, I'll include it again in the series with the other proposed changes to fix the problem.
Quoted 1 line
For now I would suggest the easiest way to get review tags is to stick with the existing inline MemoryRegion approach for 10.2 to aid getting your patches merged: it's simply not fair to put time pressure on Harsh to merge patches in this way.
I'm not putting time pressure on Harsh, the coming freeze does and I don't have time right now to change patches only later but I don't want to miss a release again. I've already submitted these pegasos1 emulation series for the previous release but due to missing maintainer it was missed then. I think it's now resolved by dropping this patch and taking the rest of the series which is fine with me. Thanks everybody for the reviews and help. I'll prepare patches to resolve concerns when I'll have time again.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
In reply to BALATON ZoltanQuoted 4 lines · BALATON Zoltan
Quoted 3 lines
memory_region_new_* will work, but I don't think removing unnecessary but harmless fields from a device state structure does not sufficiently motivates adding them.
Quoted 8 lines
I haven't given up on this yet, that's why I alternatively proposed
object_alloc(same asobject_newwithoutobject_initialize)memory_region_initwhich is just a small change but should also work without adding
memory_region_newconvenience functions. Then onlyobject_allocneeds to be added.
IMHO if this will ever happen, memory_region_new*() is better, unless object_alloc() can be used anywhere besides MemoryRegion..
It seems to me, MemoryRegion is the only one I'm aware of that may need such tweak, rather than using object_new() directly.
Signature · 1 line
Peter Xu
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 14 lines · Peter Xu
Quoted 4 lines · BALATON Zoltan
Quoted 3 lines
memory_region_new_* will work, but I don't think removing unnecessary but harmless fields from a device state structure does not sufficiently motivates adding them.
Quoted 8 lines
I haven't given up on this yet, that's why I alternatively proposed
object_alloc(same asobject_newwithoutobject_initialize)memory_region_initwhich is just a small change but should also work without adding
memory_region_newconvenience functions. Then onlyobject_allocneeds to be added.
Quoted 5 lines
IMHO if this will ever happen, memory_region_new*() is better, unless
object_alloc()can be used anywhere besides MemoryRegion..It seems to me, MemoryRegion is the only one I'm aware of that may need such tweak, rather than using
object_new()directly.
Yes, pretty much. Anyhow, leaking on purpose with g_new is not a good idea. It's g_new, not g_leak; and everyone else is using a field in the device structure so I don't see why one would want to do differently.
Paolo
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Peter Xu
Quoted 12 lines · BALATON Zoltan
Quoted 3 lines
memory_region_new_* will work, but I don't think removing unnecessary but harmless fields from a device state structure does not sufficiently motivates adding them.
I haven't given up on this yet, that's why I alternatively proposed
object_alloc(same asobject_newwithoutobject_initialize)memory_region_initwhich is just a small change but should also work without adding
memory_region_newconvenience functions. Then onlyobject_allocneeds to be added.
Quoted 7 lines
Quoted 5 lines
IMHO if this will ever happen, memory_region_new*() is better, unless
object_alloc()can be used anywhere besides MemoryRegion..It seems to me, MemoryRegion is the only one I'm aware of that may need such tweak, rather than using
object_new()directly.Yes, pretty much. Anyhow, leaking on purpose with
g_newis not a good idea. It'sg_new, notg_leak; and everyone else is using a field in the device structure so I don't see why one would want to do differently.
I've tried to explain why I dislike that way in previous replies in this thread but here's a short summary:
- Not piling memory regions not otherwise needed in device struct makes it easier to understand. (Could you spot errors within the lot of boiler plate code before clean up? Having less code makes it more comprehensible.)
- Documentation says it should work this way QOM managing memory regions so it was meant to be that way. I'd rather fix code than documentation as I think if it just works that's easier than loosing that convenience.
- Allows simpler device models reusing superclasses without having to write much boiler plate code to create a subclass.
I'll send some patches that can be discussed later.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 4 lines · BALATON Zoltan
I've tried to explain why I dislike that way in previous replies in this thread but here's a short summary:
- Not piling memory regions not otherwise needed in device struct makes
it easier to understand. (Could you spot errors within the lot of boiler plate code before clean up? Having less code makes it more comprehensible.)
Not sure what's different between
MemoryRegion foo_mr;
in the struct, versus
mr = g_new(MemoryRegion, 1);
in the realize function. It's one line either way.
Quoted 2 lines
- Documentation says it should work this way QOM managing memory regions
so it was meant to be that way. I'd rather fix code than documentation as I think if it just works that's easier than loosing that convenience.No, that's *your* reading of the documentation, and it's based on the
incorrect assumption that destruction implies freeing the memory. Akihiko explained that (https://lore.kernel.org/qemu-devel/[email protected]/).
The memory region documentation does not exist in a void, the difference between QOM object_initialize() and object_new() exists independent of that documentation. It may be worth improving the QOM documentation on the object lifecycle; that could be.
Paolo
Quoted 4 lines
- Allows simpler device models reusing superclasses without having to write much boiler plate code to create a subclass.
I'll send some patches that can be discussed later.
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · BALATON Zoltan
I've tried to explain why I dislike that way in previous replies in this thread but here's a short summary:
- Not piling memory regions not otherwise needed in device struct makes it
easier to understand. (Could you spot errors within the lot of boiler plate code before clean up? Having less code makes it more comprehensible.)Not sure what's different between
Quoted 7 lines
MemoryRegion foo_mr;in the struct, versus
mr = g_new(MemoryRegion, 1);in the realize function. It's one line either way.
Please read back in thread. An example here:
https://lists.nongnu.org/archive/html/qemu-ppc/2025-10/msg00785.html
from this series
https://patchew.org/QEMU/[email protected]/
Quoted 5 lines
Quoted 2 lines
- Documentation says it should work this way QOM managing memory regions so
it was meant to be that way. I'd rather fix code than documentation as I think if it just works that's easier than loosing that convenience.No, that's *your* reading of the documentation, and it's based on theincorrect assumption that destruction implies freeing the memory. Akihiko explained that (https://lore.kernel.org/qemu-devel/[email protected]/).
The memory region documentation does not exist in a void, the difference between QOM
object_initialize()andobject_new()exists independent of that documentation. It may be worth improving the QOM documentation on the object lifecycle; that could be.
I'll try to also clarify documentation but IMO the fix is not dropping this intended feature but fixing and using it where helps.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Il gio 30 ott 2025, 12:01 BALATON Zoltan <[email protected]> ha scritto:
Quoted 6 lines
Quoted 6 lines
Not sure what's different between
MemoryRegion foo_mr;in the struct, versus
Quoted 8 lines
Quoted 3 lines
mr = g_new(MemoryRegion, 1);in the realize function. It's one line either way.
Please read back in thread. An example here:
https://lists.nongnu.org/archive/html/qemu-ppc/2025-10/msg00785.html
from this series
https://patchew.org/QEMU/[email protected]/
I did read it of course.
There's four people in this thread telling you not to do something. Just stop arguing please.
Paolo
Quoted 27 lines
Quoted 1 line
Quoted 1 line
- Documentation says it should work this way QOM managing memory
regions so
Quoted 1 line
Quoted 1 line
it was meant to be that way. I'd rather fix code than documentation as
I
Quoted 3 lines
Quoted 2 lines
think if it just works that's easier than loosing that convenience.No, that's *your* reading of the documentation, and it's based on the
incorrect assumption that destruction implies freeing the memory.
Akihiko
Quoted 2 lines
explained that
(https://lore.kernel.org/qemu-devel/[email protected]/
).Quoted 3 lines
The memory region documentation does not exist in a void, the difference between QOM
object_initialize()andobject_new()exists independent ofthat
Quoted 1 line
documentation. It may be worth improving the QOM documentation on the
object
Quoted 1 line
lifecycle; that could be.
I'll try to also clarify documentation but IMO the fix is not dropping this intended feature but fixing and using it where helps.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
Quoted 18 lines · Paolo Bonzini
Il gio 30 ott 2025, 12:01 BALATON Zoltan <[email protected]> ha scritto:
Quoted 6 lines
Quoted 6 lines
Not sure what's different between
MemoryRegion foo_mr;in the struct, versus
Quoted 8 lines
Quoted 3 lines
mr = g_new(MemoryRegion, 1);in the realize function. It's one line either way.
Please read back in thread. An example here:
https://lists.nongnu.org/archive/html/qemu-ppc/2025-10/msg00785.html
from this series
https://patchew.org/QEMU/[email protected]/
Quoted 4 lines
I did read it of course.
There's four people in this thread telling you not to do something. Just stop arguing please.
I've already stopped and wasn't arguing just trying to answer your questions.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
In reply to Paolo BonziniQuoted 11 lines · Paolo Bonzini
Quoted 10 lines · Peter Xu
Quoted 9 lines · BALATON Zoltan
Quoted 3 lines
memory_region_new_* will work, but I don't think removing unnecessary but harmless fields from a device state structure does not sufficiently motivates adding them.
I haven't given up on this yet, that's why I alternatively proposed
object_alloc(same asobject_newwithoutobject_initialize)memory_region_init
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
which is just a small change but should also work without adding
memory_region_newconvenience functions. Then onlyobject_allocneeds to be added.IMHO if this will ever happen, memory_region_new*() is better, unless
object_alloc()can be used anywhere besides MemoryRegion..
Objective-C (*step/macOS and derivatives) have two methods for creating objects: alloc then init. It also has "new" to combine both but exposing alloc is sometimes useful especially when having different init methods. I was thinking doing it that way which should be familiar to at least to some people. I'll explore that in a proposed series.
Quoted 4 lines
Quoted 2 lines
It seems to me, MemoryRegion is the only one I'm aware of that may need such tweak, rather than using
object_new()directly.Yes, pretty much. Anyhow, leaking on purpose with
g_newis not a good idea.
It does not leak in this case. This object is a host bridge created once and start and never removed and is not user creatable being a sysbus device. It's still theoretically incorrect but this patch did not introduce any new problems just made it clearer by moving it from board to device.
Regards,
BALATON Zoltan
Re: [PATCH 2/4] hw/pci-host/articia: Map PCI memory windows in realize
In reply to Philippe Mathieu-DaudéQuoted 32 lines · Philippe Mathieu-Daudé
Quoted 21 lines · BALATON Zoltan
These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by BALATON Zoltan <[email protected]>--- hw/pci-host/articia.c | 15 ++++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos2.c | 13 ------------- 3 files changed, 19 insertions(+), 37 deletions(-)hw/pci-host/articia.c +1
-0@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp) {ArticiaState *s =ARTICIA (dev);PCIHostState *h =PCI_HOST_BRIDGE (dev); +MemoryRegion *mr;PCIDevice *pdev;bitbang_i2c_init (&s->smbus,i2c_init_bus (dev,"smbus" ));hw/pci-host/articia.c static void articia_realize(DeviceState *dev, Error · line 190
Quoted 5 lines
hw/pci-host/articia.c +1
-0@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->reg,OBJECT (s), &articia_reg_ops, s,TYPE_ARTICIA ,0x1000000 );memory_region_add_subregion_overlap (&s->reg,0 , &s->io,1 ); + mr =g_new (MemoryRegion,1 );Won't Coverity or other analysis tools complain about the leak? (this is why we usually keep a reference in the device state, here ArticiaState). Otherwise:
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
In any case, this same code is already present in amigaone.c and pegasos2.c and this patch just moves it to articia.c so it should not make it worse than it already is. Therefore can we take it for this release with or without your R-b just to not block the whole series and come back to clean this up later? Otherwise I'll have to send a v2 dropping this patch and redo the next one without it but since this is preexisting I'd avoid that and go with it for now that then leaves us time to find a solution for it and other simliar code which then can be fixed together. Is that OK with you or should I go for a v2?
Regards,
BALATON Zoltan
Quoted 9 lines
Quoted 7 lines
hw/pci-host/articia.c +7
-0+memory_region_init_alias (mr,OBJECT (dev),"pci-mem-low" , &s->mem, +0 ,PCI_LOW_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_LOW_ADDR , mr); + mr =g_new (MemoryRegion,1 ); +memory_region_init_alias (mr,OBJECT (dev),"pci-mem-high" , &s->mem, +PCI_HIGH_ADDR ,PCI_HIGH_SIZE ); +memory_region_add_subregion (get_system_memory (),PCI_HIGH_ADDR , mr);
PATCH 3/4 hw/ppc/pegasos2: Rename to pegasos
In reply to BALATON ZoltanNow that we also emulate pegasos1 it is not only about pegasos2 so rename to a more generic name encompassing both.
---
MAINTAINERS | 4 ++--
configs/devices/ppc-softmmu/default.mak | 7 +++----
hw/ppc/Kconfig | 2 +-
hw/ppc/meson.build | 4 ++--
hw/ppc/{pegasos2.c => pegasos.c} | 0
5 files changed, 8 insertions(+), 9 deletions(-)
rename hw/ppc/{pegasos2.c => pegasos.c} (100%)MAINTAINERS +2 -2
@@ -1646,11 +1646,11 @@ F: roms/u-boot-sam460ex F: docs/system/ppc/amigang.rst F: tests/functional/ppc/test_sam460ex.py -pegasos2 +pegasos M: BALATON Zoltan <[email protected]> L: [email protected] S: Maintained -F: hw/ppc/pegasos2.c +F: hw/ppc/pegasos.c F: hw/pci-host/mv64361.c F: hw/pci-host/mv643xx.h F: include/hw/pci-host/mv64361.h
configs/devices/ppc-softmmu/default.mak +3 -4
@@ -13,15 +13,14 @@ # CONFIG_PPC440=n # CONFIG_VIRTEX=n -# For Sam460ex +# AmigaNG +# CONFIG_AMIGAONE=n +# CONFIG_PEGASOS=n # CONFIG_SAM460EX=n # For Macs # CONFIG_MAC_OLDWORLD=n # CONFIG_MAC_NEWWORLD=n -# CONFIG_AMIGAONE=n -# CONFIG_PEGASOS2=n - # For PReP # CONFIG_PREP=n
hw/ppc/Kconfig +1 -1
@@ -92,7 +92,7 @@ config AMIGAONE select VT82C686 select SMBUS_EEPROM -config PEGASOS2 +config PEGASOS bool default y depends on PPC
hw/ppc/meson.build +2 -2
@@ -87,8 +87,8 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files( ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c')) # AmigaOne ppc_ss.add(when: 'CONFIG_AMIGAONE', if_true: files('amigaone.c')) -# Pegasos2 -ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c')) +# Pegasos +ppc_ss.add(when: 'CONFIG_PEGASOS', if_true: files('pegasos.c')) ppc_ss.add(when: 'CONFIG_VOF', if_true: files('vof.c')) ppc_ss.add(when: ['CONFIG_VOF', 'CONFIG_PSERIES'], if_true: files('spapr_vof.c'))
hw/ppc/pegasos.c renamed from hw/ppc/pegasos2.c +0 -0
Signature · 1 line
2.41.3
Re: [PATCH 3/4] hw/ppc/pegasos2: Rename to pegasos
Quoted 4 lines · BALATON Zoltan
Now that we also emulate pegasos1 it is not only about pegasos2 so rename to a more generic name encompassing both.
Signed-off-by BALATON Zoltan <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 4 ++-- configs/devices/ppc-softmmu/default.mak | 7 +++---- hw/ppc/Kconfig | 2 +- hw/ppc/meson.build | 4 ++-- hw/ppc/{pegasos2.c => pegasos.c} | 0 5 files changed, 8 insertions(+), 9 deletions(-)rename
hw/ppc/{pegasos2.c=>pegasos.c} (100%)
PATCH 4/4 hw/ppc/pegasos: Update documentation for pegasos1
In reply to BALATON Zoltan--- docs/system/ppc/amigang.rst | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
docs/system/ppc/amigang.rst +17 -12
@@ -1,6 +1,6 @@ -========================================================= -AmigaNG boards (``amigaone``, ``pegasos2``, ``sam460ex``) -========================================================= +======================================================================= +AmigaNG boards (``amigaone``, ``pegasos1``, ``pegasos2``, ``sam460ex``) +======================================================================= These PowerPC machines emulate boards that are primarily used for running Amiga like OSes (AmigaOS 4, MorphOS and AROS) but these can
@@ -64,18 +64,23 @@ eventually it boots and the installer becomes visible. The ``ati-vga`` RV100 emulation is not complete yet so only frame buffer works, DRM and 3D is not available. -Genesi/bPlan Pegasos II (``pegasos2``) -====================================== +Genesi/bPlan Pegasos (``pegasos1``, ``pegasos2``) +================================================= -The ``pegasos2`` machine emulates the Pegasos II sold by Genesi and -designed by bPlan. Its schematics are available at -https://www.powerdeveloper.org/platforms/pegasos/schematics. +The ``pegasos1`` machine emulates the original Pegasos (later marked I) sold by +Genesi and designed by bPlan. It uses the same Articia S north bridge as the +``amigaone`` machine, otherwise it is mostly the same as the later Pegasos II. + +The ``pegasos2`` machine emulates the Pegasos II which is a redesigned version +of Pegasos I to fix problems with its north bridge. Its schematics are available +at https://www.powerdeveloper.org/platforms/pegasos/schematics. Emulated devices ---------------- * PowerPC 7457 CPU (can also use ``-cpu g3`` or ``750cxe``) - * Marvell MV64361 Discovery II north bridge + * Articia S north bridge (for ``pegasos1``) + * Marvell MV64361 Discovery II north bridge (for ``pegasos2``) * VIA VT8231 south bridge * PCI VGA compatible card (guests may need other card instead) * PS/2 keyboard and mouse
@@ -83,9 +88,9 @@ Emulated devices Firmware -------- -The Pegasos II board has an Open Firmware compliant ROM based on +The Pegasos boards have an Open Firmware compliant ROM based on SmartFirmware with some changes that are not open-sourced therefore -the ROM binary cannot be included in QEMU. An updater was available +the ROM binary cannot be included in QEMU. A Pegasos II updater was available from bPlan, it can be found in the `Internet Archive <http://web.archive.org/web/20071021223056/http://www.bplan-gmbh.de/up050404/up050404>`_. The ROM image can be extracted from it with the following command:
@@ -111,7 +116,7 @@ At the firmware ``ok`` prompt enter ``boot cd install/pegasos``. Alternatively, it is possible to boot the kernel directly without firmware ROM using the QEMU built-in minimal Virtual Open Firmware -(VOF) emulation which is also supported on ``pegasos2``. For this, +(VOF) emulation which is also supported on ``pegasos1`` and ``pegasos2``. For this, extract the kernel ``install/powerpc/vmlinuz-chrp.initrd`` from the CD image, then run:
Signature · 1 line
2.41.3
Re: [PATCH 4/4] hw/ppc/pegasos: Update documentation for pegasos1
Quoted 4 lines · BALATON Zoltan
Signed-off-by BALATON Zoltan <[email protected]>--- docs/system/ppc/amigang.rst | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)