memory: Forbid mapping AddressSpace root MemoryRegion
cover memory: Forbid mapping AddressSpace root MemoryRegion
Hi,
This series is the result of a long thread with Peter:
https://www.mail-archive.com/[email protected]/msg788366.html
AddressSpace are physical address view and shouldn't be using non-zero base address. The correct way to map a MR used as AS root is to use a MR alias.
Fix the current incorrect uses, then forbid further use.
Peter Xu (1):
memory: Make sure root MR won't be added as subregion
Philippe Mathieu-Daudé (4):
hw/arm/aspeed: Do not directly map ram container onto main address bus hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias hw/pci-host/prep: Remove unuseful memory region mapping hw/pci-host/prep: Do not directly map bus-master region onto main bus
include/exec/memory.h | 1 + include/hw/ssi/aspeed_smc.h | 1 + hw/arm/aspeed.c | 6 +++++- hw/pci-host/prep.c | 17 ++++++++--------- hw/ssi/aspeed_smc.c | 4 +++- softmmu/memory.c | 2 ++ 6 files changed, 20 insertions(+), 11 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/5 hw/arm/aspeed: Do not directly map ram container onto main address bus
The RAM container is exposed as an AddressSpace. AddressSpaces root MemoryRegion must not be mapped into other MemoryRegion, therefore map the RAM container using an alias.
--- hw/arm/aspeed.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/arm/aspeed.c +5 -1
@@ -40,6 +40,7 @@ struct AspeedMachineState {AspeedSoCState soc;MemoryRegion ram_container; +MemoryRegion ram_container_alias;MemoryRegion max_ram;bool mmio_exec;char *fmc_model;
@@ -339,9 +340,12 @@ static void aspeed_machine_init(MachineState *machine) }qdev_realize (DEVICE (&bmc->soc),NULL , &error_abort); +memory_region_init_alias (&bmc->ram_container_alias,NULL , +"ram-container-alias" , &bmc->ram_container,0 , +memory_region_size (&bmc->ram_container));memory_region_add_subregion (get_system_memory (), sc->memmap[ASPEED_DEV_SDRAM ], - &bmc->ram_container); + &bmc->ram_container_alias); max_ram_size =object_property_get_uint (OBJECT (&bmc->soc),"max-ram-size" , &error_abort);
Signature · 1 line
2.26.2
Re: [PATCH 1/5] hw/arm/aspeed: Do not directly map ram container onto main address bus
Quoted 26 lines · Philippe Mathieu-Daudé
The RAM container is exposed as an AddressSpace. AddressSpaces root MemoryRegion must not be mapped into other MemoryRegion, therefore map the RAM container using an alias.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/aspeed.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/arm/aspeed.c +1
-0@@ -40,6 +40,7 @@ struct AspeedMachineState {AspeedSoCState soc;MemoryRegion ram_container; +MemoryRegion ram_container_alias;MemoryRegion max_ram;bool mmio_exec;char *fmc_model;@@ -339,9 +340,12 @@ static void aspeed_machine_init(MachineState *machine) }qdev_realize (DEVICE (&bmc->soc),NULL , &error_abort);
hw/arm/aspeed.c static void aspeed_machine_init(MachineState *machine) · line 351
Quoted 10 lines
hw/arm/aspeed.c +4
-1+memory_region_init_alias (&bmc->ram_container_alias,NULL , +"ram-container-alias" , &bmc->ram_container,0 , +memory_region_size (&bmc->ram_container));memory_region_add_subregion (get_system_memory (), sc->memmap[ASPEED_DEV_SDRAM ], - &bmc->ram_container); + &bmc->ram_container_alias); max_ram_size =object_property_get_uint (OBJECT (&bmc->soc),"max-ram-size" , &error_abort);
RAM is now initialized before the SoC. So we should be able to use machine->ram instead of the bmc->ram_container MR and simplify the Aspeed SMC model below the SoC.
Thanks,
C.
PATCH 2/5 hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
In reply to Philippe Mathieu-DaudéThe flash mmio region is exposed as an AddressSpace. AddressSpaces must not be sysbus-mapped, therefore map the region using an alias.
--- include/hw/ssi/aspeed_smc.h | 1 + hw/ssi/aspeed_smc.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
include/hw/ssi/aspeed_smc.h +1 -0
@@ -84,6 +84,7 @@ struct AspeedSMCState {MemoryRegion mmio;MemoryRegion mmio_flash; +MemoryRegion mmio_flash_alias;qemu_irq irq;int irqline;
hw/ssi/aspeed_smc.c +3 -1
@@ -1386,7 +1386,9 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->mmio_flash,OBJECT (s), &aspeed_smc_flash_default_ops, s, name, s->ctrl->flash_window_size); -sysbus_init_mmio (sbd, &s->mmio_flash); +memory_region_init_alias (&s->mmio_flash_alias,OBJECT (s), name, + &s->mmio_flash,0 , s->ctrl->flash_window_size); +sysbus_init_mmio (sbd, &s->mmio_flash_alias); s->flashes =g_new0 (AspeedSMCFlash, s->ctrl->max_peripherals);
Signature · 1 line
2.26.2
Re: [PATCH 2/5] hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
Incorrect subject prefix, should be "hw/ssi/aspeed_smc"
Quoted 36 lines · Philippe Mathieu-Daudé
The flash mmio region is exposed as an AddressSpace. AddressSpaces must not be sysbus-mapped, therefore map the region using an alias.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/ssi/aspeed_smc.h | 1 + hw/ssi/aspeed_smc.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)include/hw/ssi/aspeed_smc.h +1
-0@@ -84,6 +84,7 @@ struct AspeedSMCState {MemoryRegion mmio;MemoryRegion mmio_flash; +MemoryRegion mmio_flash_alias;qemu_irq irq;int irqline;hw/ssi/aspeed_smc.c +3
-1@@ -1386,7 +1386,9 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->mmio_flash,OBJECT (s), &aspeed_smc_flash_default_ops, s, name, s->ctrl->flash_window_size); -sysbus_init_mmio (sbd, &s->mmio_flash); +memory_region_init_alias (&s->mmio_flash_alias,OBJECT (s), name, + &s->mmio_flash,0 , s->ctrl->flash_window_size); +sysbus_init_mmio (sbd, &s->mmio_flash_alias); s->flashes =g_new0 (AspeedSMCFlash, s->ctrl->max_peripherals);
Re: [PATCH 2/5] hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
Quoted 1 line · Philippe Mathieu-Daudé
Incorrect subject prefix, should be "hw/ssi/aspeed_smc"
Is this just good practice or something that was agreed upon ? We should update checkpatch if so.
Thanks,
C.
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 36 lines
The flash mmio region is exposed as an AddressSpace. AddressSpaces must not be sysbus-mapped, therefore map the region using an alias.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/ssi/aspeed_smc.h | 1 + hw/ssi/aspeed_smc.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)include/hw/ssi/aspeed_smc.h +1
-0@@ -84,6 +84,7 @@ struct AspeedSMCState {MemoryRegion mmio;MemoryRegion mmio_flash; +MemoryRegion mmio_flash_alias;qemu_irq irq;int irqline;hw/ssi/aspeed_smc.c +3
-1@@ -1386,7 +1386,9 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->mmio_flash,OBJECT (s), &aspeed_smc_flash_default_ops, s, name, s->ctrl->flash_window_size); -sysbus_init_mmio (sbd, &s->mmio_flash); +memory_region_init_alias (&s->mmio_flash_alias,OBJECT (s), name, + &s->mmio_flash,0 , s->ctrl->flash_window_size); +sysbus_init_mmio (sbd, &s->mmio_flash_alias); s->flashes =g_new0 (AspeedSMCFlash, s->ctrl->max_peripherals);
Re: [PATCH 2/5] hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
Quoted 4 lines · Cédric Le Goater
Quoted 1 line · Philippe Mathieu-Daudé
Incorrect subject prefix, should be "hw/ssi/aspeed_smc"
Is this just good practice or something that was agreed upon ?
Not sure, maybe "good practice"? Anyway here I only meant to correct my own patch without respining the series just for this.
Quoted 1 line
We should update checkpatch if so.
Certainly a waste of time =)
Quoted 4 lines
Thanks,
C.
Re: [PATCH 2/5] hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
The flash mmio region is exposed as an AddressSpace. AddressSpaces must not be sysbus-mapped, therefore map the region using an alias.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
That does the trick but you need an extra change in the model.
The fixes are in my aspeed-6.0 branch on GH and they survive the last patch of your series :
[PATCH 5/5] memory: Make sure root MR won't be added as subregion
I will upstream for 6.1.
Thanks,
C.
Quoted 33 lines
--- include/hw/ssi/aspeed_smc.h | 1 + hw/ssi/aspeed_smc.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)include/hw/ssi/aspeed_smc.h +1
-0@@ -84,6 +84,7 @@ struct AspeedSMCState {MemoryRegion mmio;MemoryRegion mmio_flash; +MemoryRegion mmio_flash_alias;qemu_irq irq;int irqline;hw/ssi/aspeed_smc.c +3
-1@@ -1386,7 +1386,9 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->mmio_flash,OBJECT (s), &aspeed_smc_flash_default_ops, s, name, s->ctrl->flash_window_size); -sysbus_init_mmio (sbd, &s->mmio_flash); +memory_region_init_alias (&s->mmio_flash_alias,OBJECT (s), name, + &s->mmio_flash,0 , s->ctrl->flash_window_size); +sysbus_init_mmio (sbd, &s->mmio_flash_alias); s->flashes =g_new0 (AspeedSMCFlash, s->ctrl->max_peripherals);
Re: [PATCH 2/5] hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
Quoted 5 lines · Cédric Le Goater
Quoted 4 lines · Philippe Mathieu-Daudé
The flash mmio region is exposed as an AddressSpace. AddressSpaces must not be sysbus-mapped, therefore map the region using an alias.
Quoted 8 lines
Quoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>That does the trick but you need an extra change in the model.
The fixes are in my aspeed-6.0 branch on GH and they survive the last patch of your series :
[PATCH 5/5] memory: Make sure root MR won't be added as subregion
I wondered about changing DMA_FLASH_ADDR() wasn't sure the tests would use the flash.
Quoted 1 line
I will upstream for 6.1.
Thanks!
Phil.
Re: [PATCH 2/5] hw/arm/aspeed: Do not sysbus-map mmio flash region directly, use alias
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Cédric Le Goater
Quoted 5 lines · Philippe Mathieu-Daudé
The flash mmio region is exposed as an AddressSpace. AddressSpaces must not be sysbus-mapped, therefore map the region using an alias.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>That does the trick but you need an extra change in the model.
Quoted 7 lines
Quoted 4 lines
The fixes are in my aspeed-6.0 branch on GH and they survive the last patch of your series :
[PATCH 5/5] memory: Make sure root MR won't be added as subregion
I wondered about changing
DMA_FLASH_ADDR()wasn't sure the tests would use the flash.
The acceptance tests (not merged yet) download firmware images in which u-boot does DMA accesses to calibrate the reads on the flash device.
C.
Quoted 7 lines
Quoted 2 lines
I will upstream for 6.1.
Thanks!
Phil.
PATCH 3/5 hw/pci-host/prep: Remove unuseful memory region mapping
In reply to Philippe Mathieu-DaudéThe pci_io_non_contiguous region is mapped on top of pci_io with higher priority, but simply dispatch into this region address space. Simplify by directly registering the former region in place, and adapt the address space dispatch offsets.
--- hw/pci-host/prep.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
hw/pci-host/prep.c +4 -7
@@ -159,8 +159,7 @@ static uint64_t raven_io_read(void *opaque, hwaddr addr,uint8_t buf[4 ]; addr =raven_io_address (s, addr); -address_space_read (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_read (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);if (size ==1 ) {return buf[0 ];
@@ -191,8 +190,7 @@ static void raven_io_write(void *opaque, hwaddr addr,g_assert_not_reached (); } -address_space_write (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_write (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size); }static const MemoryRegionOps raven_io_ops = {
@@ -294,9 +292,8 @@ static void raven_pcihost_initfn(Object *obj)address_space_init (&s->pci_io_as, &s->pci_io,"raven-io" );/* CPU address space */ -memory_region_add_subregion (address_space_mem,0x80000000 , &s->pci_io); -memory_region_add_subregion_overlap (address_space_mem,0x80000000 , - &s->pci_io_non_contiguous,1 ); +memory_region_add_subregion (address_space_mem,0x80000000 , + &s->pci_io_non_contiguous);memory_region_add_subregion (address_space_mem,0xc0000000 , &s->pci_memory);pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , &s->pci_memory, &s->pci_io,0 ,TYPE_PCI_BUS );
Signature · 1 line
2.26.2
Re: [PATCH 3/5] hw/pci-host/prep: Remove unuseful memory region mapping
Quoted 25 lines · Philippe Mathieu-Daudé
The
pci_io_non_contiguousregion is mapped on top ofpci_iowith higher priority, but simply dispatch into this region address space. Simplify by directly registering the former region in place, and adapt the address space dispatch offsets.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/pci-host/prep.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)hw/pci-host/prep.c +1
-2@@ -159,8 +159,7 @@ static uint64_t raven_io_read(void *opaque, hwaddr addr,uint8_t buf[4 ]; addr =raven_io_address (s, addr); -address_space_read (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_read (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);if (size ==1 ) {return buf[0 ];
hw/pci-host/prep.c static void raven_io_write(void *opaque, hwaddr addr, · line 193
Quoted 6 lines
hw/pci-host/prep.c +1
-2@@ -191,8 +190,7 @@ static void raven_io_write(void *opaque, hwaddr addr,g_assert_not_reached (); } -address_space_write (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_write (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);
This changes access to s->pci_io_as, but below didn't change s->pci_io_as layout at all (below is about address_space_mem). Is this intended?
hw/pci-host/prep.c static void raven_pcihost_initfn(Object *obj) · line 296
Quoted 12 lines
hw/pci-host/prep.c +2
-3}static const MemoryRegionOps raven_io_ops = {@@ -294,9 +292,8 @@ static void raven_pcihost_initfn(Object *obj)address_space_init (&s->pci_io_as, &s->pci_io,"raven-io" );/* CPU address space */ -memory_region_add_subregion (address_space_mem,0x80000000 , &s->pci_io); -memory_region_add_subregion_overlap (address_space_mem,0x80000000 , - &s->pci_io_non_contiguous,1 ); +memory_region_add_subregion (address_space_mem,0x80000000 , + &s->pci_io_non_contiguous);
I don't know any of this code at all... but it seems the two memory regions are not identical in size:
memory_region_init(&s->pci_io, obj, "pci-io", 0x3f800000);
memory_region_init_io(&s->pci_io_non_contiguous, obj, &raven_io_ops, s,
"pci-io-non-contiguous", 0x00800000);Then it seems the memory access dispatching to (0x00800000, 0x3f800000) would change too, from s->pci_io to nothing. Raise this up too since I don't know either whether it's intended..
Quoted 6 lines
hw/pci-host/prep.c +0
-0memory_region_add_subregion (address_space_mem,0xc0000000 , &s->pci_memory);pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , &s->pci_memory, &s->pci_io,0 ,TYPE_PCI_BUS );Signature · 1 line
2.26.2
Signature · 1 line
Peter Xu
Re: [PATCH 3/5] hw/pci-host/prep: Remove unuseful memory region mapping
Quoted 52 lines · Peter Xu
Quoted 25 lines · Philippe Mathieu-Daudé
The
pci_io_non_contiguousregion is mapped on top ofpci_iowith higher priority, but simply dispatch into this region address space. Simplify by directly registering the former region in place, and adapt the address space dispatch offsets.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/pci-host/prep.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)hw/pci-host/prep.c +1
-2@@ -159,8 +159,7 @@ static uint64_t raven_io_read(void *opaque, hwaddr addr,uint8_t buf[4 ]; addr =raven_io_address (s, addr); -address_space_read (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_read (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);if (size ==1 ) {return buf[0 ];hw/pci-host/prep.c static void raven_io_write(void *opaque, hwaddr addr, · line 193
Quoted 6 lines
hw/pci-host/prep.c +1
-2@@ -191,8 +190,7 @@ static void raven_io_write(void *opaque, hwaddr addr,g_assert_not_reached (); } -address_space_write (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_write (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);This changes access to
s->pci_io_as, but below didn't changes->pci_io_aslayout at all (below is aboutaddress_space_mem). Is this intended?hw/pci-host/prep.c static void raven_pcihost_initfn(Object *obj) · line 296
Quoted 12 lines
hw/pci-host/prep.c +2
-3}static const MemoryRegionOps raven_io_ops = {@@ -294,9 +292,8 @@ static void raven_pcihost_initfn(Object *obj)address_space_init (&s->pci_io_as, &s->pci_io,"raven-io" );/* CPU address space */ -memory_region_add_subregion (address_space_mem,0x80000000 , &s->pci_io); -memory_region_add_subregion_overlap (address_space_mem,0x80000000 , - &s->pci_io_non_contiguous,1 ); +memory_region_add_subregion (address_space_mem,0x80000000 , + &s->pci_io_non_contiguous);I don't know any of this code at all... but it seems the two memory regions are not identical in size:
Quoted 7 lines
memory_region_init(&s->pci_io, obj, "pci-io", 0x3f800000); memory_region_init_io(&s->pci_io_non_contiguous, obj, &raven_io_ops, s, "pci-io-non-contiguous", 0x00800000);Then it seems the memory access dispatching to (
0x00800000,0x3f800000) would change too, froms->pci_ioto nothing. Raise this up too since I don't know either whether it's intended..
Right, it seems like this removes the mapping of s->pci_io entirely.
Quoted 5 lines
Quoted 4 lines
hw/pci-host/prep.c +0
-0memory_region_add_subregion (address_space_mem,0xc0000000 , &s->pci_memory);pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , &s->pci_memory, &s->pci_io,0 ,TYPE_PCI_BUS );
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH 3/5] hw/pci-host/prep: Remove unuseful memory region mapping
Quoted 57 lines · David Gibson
Quoted 56 lines · Peter Xu
Quoted 25 lines · Philippe Mathieu-Daudé
The
pci_io_non_contiguousregion is mapped on top ofpci_iowith higher priority, but simply dispatch into this region address space. Simplify by directly registering the former region in place, and adapt the address space dispatch offsets.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/pci-host/prep.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)hw/pci-host/prep.c +1
-2@@ -159,8 +159,7 @@ static uint64_t raven_io_read(void *opaque, hwaddr addr,uint8_t buf[4 ]; addr =raven_io_address (s, addr); -address_space_read (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_read (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);if (size ==1 ) {return buf[0 ];hw/pci-host/prep.c static void raven_io_write(void *opaque, hwaddr addr, · line 193
Quoted 6 lines
hw/pci-host/prep.c +1
-2@@ -191,8 +190,7 @@ static void raven_io_write(void *opaque, hwaddr addr,g_assert_not_reached (); } -address_space_write (&s->pci_io_as, addr +0x80000000 , -MEMTXATTRS_UNSPECIFIED , buf, size); +address_space_write (&s->pci_io_as, addr,MEMTXATTRS_UNSPECIFIED , buf, size);This changes access to
s->pci_io_as, but below didn't changes->pci_io_aslayout at all (below is aboutaddress_space_mem). Is this intended?hw/pci-host/prep.c static void raven_pcihost_initfn(Object *obj) · line 296
Quoted 12 lines
hw/pci-host/prep.c +2
-3}static const MemoryRegionOps raven_io_ops = {@@ -294,9 +292,8 @@ static void raven_pcihost_initfn(Object *obj)address_space_init (&s->pci_io_as, &s->pci_io,"raven-io" );/* CPU address space */ -memory_region_add_subregion (address_space_mem,0x80000000 , &s->pci_io); -memory_region_add_subregion_overlap (address_space_mem,0x80000000 , - &s->pci_io_non_contiguous,1 ); +memory_region_add_subregion (address_space_mem,0x80000000 , + &s->pci_io_non_contiguous);I don't know any of this code at all... but it seems the two memory regions are not identical in size:
memory_region_init(&s->pci_io, obj, "pci-io", 0x3f800000); memory_region_init_io(&s->pci_io_non_contiguous, obj, &raven_io_ops, s, "pci-io-non-contiguous", 0x00800000);
Quoted 5 lines
Quoted 3 lines
Then it seems the memory access dispatching to (
0x00800000,0x3f800000) would change too, froms->pci_ioto nothing. Raise this up too since I don't know either whether it's intended..Right, it seems like this removes the mapping of
s->pci_ioentirely.
Yes, this is on purpose. The dispatching is done via raven_io_ops:
address_space_init(&s->pci_io_as, &s->pci_io, "raven-io");
raven_io_ops uses raven_io_address() which returns an address in "pci-io" range if < 0x800000, else it returns io_mem_unassigned because the address is outside the pci_io_as AddressSpace.
Note, the flatview is unchanged with this patch.
My take here is 1/ I squashed too much changes and 2/ I didn't documented enough. I'll respin improved.
Thanks for your reviews!
Phil.
PATCH 4/5 hw/pci-host/prep: Do not directly map bus-master region onto main bus
In reply to Philippe Mathieu-DaudéThe raven bus-master memory region is exposed as an AddressSpace. AddressSpaces root MemoryRegion must not be mapped into other MemoryRegion, therefore map the region using its alias.
--- hw/pci-host/prep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci-host/prep.c +4 -2
@@ -295,8 +295,6 @@ static void raven_pcihost_initfn(Object *obj)memory_region_add_subregion (address_space_mem,0x80000000 , &s->pci_io_non_contiguous);memory_region_add_subregion (address_space_mem,0xc0000000 , &s->pci_memory); -pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , - &s->pci_memory, &s->pci_io,0 ,TYPE_PCI_BUS );/* Bus master address space */ memory_region_init (&s->bm, obj,"bm-raven" ,4 * GiB);
@@ -308,6 +306,10 @@ static void raven_pcihost_initfn(Object *obj)memory_region_add_subregion (&s->bm,0 , &s->bm_pci_memory_alias);memory_region_add_subregion (&s->bm,0x80000000 , &s->bm_ram_alias);address_space_init (&s->bm_as, &s->bm,"raven-bm" ); + +pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , + &s->bm_pci_memory_alias, &s->pci_io,0 , +TYPE_PCI_BUS );pci_setup_iommu (&s->pci_bus, raven_pcihost_set_iommu, s); h->bus = &s->pci_bus;
Signature · 1 line
2.26.2
Re: [PATCH 4/5] hw/pci-host/prep: Do not directly map bus-master region onto main bus
Quoted 5 lines · Philippe Mathieu-Daudé
The raven bus-master memory region is exposed as an AddressSpace. AddressSpaces root MemoryRegion must not be mapped into other MemoryRegion, therefore map the region using its alias.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 28 lines
--- hw/pci-host/prep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/pci-host/prep.c +4
-2@@ -295,8 +295,6 @@ static void raven_pcihost_initfn(Object *obj)memory_region_add_subregion (address_space_mem,0x80000000 , &s->pci_io_non_contiguous);memory_region_add_subregion (address_space_mem,0xc0000000 , &s->pci_memory); -pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , - &s->pci_memory, &s->pci_io,0 ,TYPE_PCI_BUS );/* Bus master address space */ memory_region_init (&s->bm, obj,"bm-raven" ,4 * GiB);@@ -308,6 +306,10 @@ static void raven_pcihost_initfn(Object *obj)memory_region_add_subregion (&s->bm,0 , &s->bm_pci_memory_alias);memory_region_add_subregion (&s->bm,0x80000000 , &s->bm_ram_alias);address_space_init (&s->bm_as, &s->bm,"raven-bm" ); + +pci_root_bus_new_inplace (&s->pci_bus,sizeof (s->pci_bus),DEVICE (obj),NULL , + &s->bm_pci_memory_alias, &s->pci_io,0 , +TYPE_PCI_BUS );pci_setup_iommu (&s->pci_bus, raven_pcihost_set_iommu, s); h->bus = &s->pci_bus;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 5/5 memory: Make sure root MR won't be added as subregion
In reply to Philippe Mathieu-DaudéFrom: Peter Xu <[email protected]>
Add a bool for MR to mark whether this MR is a root MR of an AS. We bail out asap if this MR is added as a subregion of another MR.
--- include/exec/memory.h | 1 + softmmu/memory.c | 2 ++ 2 files changed, 3 insertions(+)
include/exec/memory.h +1 -0
@@ -477,6 +477,7 @@ struct MemoryRegion {bool ram_device;bool enabled;bool warning_printed;/* For reservations */ +bool is_root_mr;uint8_t vga_logging_count;MemoryRegion *alias;hwaddr alias_offset;
softmmu/memory.c +2 -0
@@ -2442,6 +2442,7 @@ static void memory_region_add_subregion_common(MemoryRegion *mr, MemoryRegion *subregion) {assert (!subregion->container); +assert (!subregion->is_root_mr); subregion->container = mr; subregion->addr = offset;memory_region_update_container_subregions (subregion);
@@ -2819,6 +2820,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) {memory_region_ref (root); as->root = root; + root->is_root_mr = true; as->current_map =NULL ; as->ioeventfd_nb =0 ; as->ioeventfds =NULL ;
Signature · 1 line
2.26.2
Re: [PATCH 5/5] memory: Make sure root MR won't be added as subregion
Hi Peter,
Quoted 28 lines · Philippe Mathieu-Daudé
From: Peter Xu <[email protected]>
Add a bool for MR to mark whether this MR is a root MR of an AS. We bail out asap if this MR is added as a subregion of another MR.
Signed-off-by Peter Xu <[email protected]>--- include/exec/memory.h | 1 + softmmu/memory.c | 2 ++ 2 files changed, 3 insertions(+)include/exec/memory.h +1
-0@@ -477,6 +477,7 @@ struct MemoryRegion {bool ram_device;bool enabled;bool warning_printed;/* For reservations */ +bool is_root_mr;uint8_t vga_logging_count;MemoryRegion *alias;hwaddr alias_offset;softmmu/memory.c +0
-0
softmmu/memory.c static void memory_region_add_subregion_common(MemoryRegion *mr, · line 2445
Quoted 4 lines
softmmu/memory.c +1
-0@@ -2442,6 +2442,7 @@ static void memory_region_add_subregion_common(MemoryRegion *mr, MemoryRegion *subregion) {assert (!subregion->container); +assert (!subregion->is_root_mr);
Not all containers have to be backed by AddressSpace.
This check is too strict IMO.
Quoted 12 lines
softmmu/memory.c +1
-0subregion->container = mr; subregion->addr = offset;memory_region_update_container_subregions (subregion);@@ -2819,6 +2820,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) {memory_region_ref (root); as->root = root; + root->is_root_mr = true; as->current_map =NULL ; as->ioeventfd_nb =0 ; as->ioeventfds =NULL ;