arm: xlnx-versal: fix virtio-mmio base address assignment
PATCH v2 1/1 arm: xlnx-versal: fix virtio-mmio base address assignment
At the moment the following QEMU command line triggers an assertion failure On xlnx-versal SOC:
qemu-system-aarch64 \
-machine xlnx-versal-virt -nographic -smp 2 -m 128 \
-fsdev local,id=shareid,path=${HOME}/work,security_model=none \
-device virtio-9p-device,fsdev=shareid,mount_tag=share \
-fsdev local,id=shareid1,path=${HOME}/Music,security_model=none \
-device virtio-9p-device,fsdev=shareid1,mount_tag=share1
qemu-system-aarch64: ../migration/savevm.c:860:
vmstate_register_with_alias_id:
Assertion `!se->compat || se->instance_id == 0' failed.
This problem was fixed on arm virt platform in commit f58b39d2d5b ("virtio-mmio: format transport base address in BusClass.get_dev_path")
It works perfectly on arm virt platform. but there is still there on xlnx-versal SOC.
The main difference between arm virt and xlnx-versal is they use different way to create virtio-mmio qdev. on arm virt, it calls sysbus_create_simple("virtio-mmio", base, pic[irq]); which will call sysbus_mmio_map internally and assign base address to subsys device mmio correctly. but xlnx-versal's implements won't do this.
However, xlnx-versal can't switch to sysbus_create_simple() to create virtio-mmio device. It's because xlnx-versal's cpu use VersalVirt.soc.fpd.apu.mr as it's memory. which is subregion of system_memory. sysbus_create_simple will add virtio to system_memory, which can't be accessed by cpu.
Besides, xlnx-versal can't add sysbus_mmio_map api call too, because this will add memory region to system_memory, and it can't be added to VersalVirt.soc.fpd.apu.mr again.
We can solve this by simply assign mmio[0].addr directly. makes virtio_mmio_bus_get_dev_path to produce correct unique device path.
---
hw/arm/xlnx-versal-virt.c | 1 +
1 file changed, 1 insertion(+)
hw/arm/xlnx-versal-virt.c +0 -0
@@ -490,6 +490,7 @@ static void create_virtio_regions(VersalVirt *s)
object_property_add_child(OBJECT(&s->soc), name, OBJECT(dev)); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic_irq); + SYS_BUS_DEVICE(dev)->mmio[0].addr = base;
mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); memory_region_add_subregion(&s->soc.mr_ps, base, mr); g_free(name);
Signature · 1 line
2.30.0
Quoted 50 lines · schspa
At the moment the following QEMU command line triggers an assertion failure On xlnx-versal SOC:
qemu-system-aarch64 \ -machine xlnx-versal-virt -nographic -smp 2 -m 128 \ -fsdev local,id=shareid,path=${HOME}/work,security_model=none \ -device virtio-9p-device,fsdev=shareid,mount_tag=share \ -fsdev local,id=shareid1,path=${HOME}/Music,security_model=none \ -device virtio-9p-device,fsdev=shareid1,mount_tag=share1qemu-system-aarch64:
../migration/savevm.c:860:
vmstate_register_with_alias_id:
Assertion `!se->compat ||se->instance_id== 0' failed.This problem was fixed on arm virt platform in commit
f58b39d2d5b("virtio-mmio: format transport base address in BusClass.get_dev_path")It works perfectly on arm virt platform. but there is still there on xlnx-versal SOC.
The main difference between arm virt and xlnx-versal is they use different way to create virtio-mmio qdev. on arm virt, it calls
sysbus_create_simple("virtio-mmio", base, pic[irq]); which will callsysbus_mmio_mapinternally and assign base address to subsys device mmio correctly. but xlnx-versal's implements won't do this.However, xlnx-versal can't switch to
sysbus_create_simple()to create virtio-mmio device. It's because xlnx-versal's cpu use VersalVirt.soc.fpd.apu.mr as it's memory. which is subregion ofsystem_memory.sysbus_create_simplewill add virtio tosystem_memory, which can't be accessed by cpu.Besides, xlnx-versal can't add
sysbus_mmio_mapapi call too, because this will add memory region tosystem_memory, and it can't be added to VersalVirt.soc.fpd.apu.mr again.We can solve this by simply assign mmio[0].addr directly. makes
virtio_mmio_bus_get_dev_pathto produce correct unique device path.Signed-off-by schspa <[email protected]>--- hw/arm/xlnx-versal-virt.c | 1 + 1 file changed, 1 insertion(+)hw/arm/xlnx-versal-virt.c +0
-0
hw/arm/xlnx-versal-virt.c static void create_virtio_regions(VersalVirt *s) · line 496
Quoted 7 lines
hw/arm/xlnx-versal-virt.c +1
-0@@ -490,6 +490,7 @@ static void create_virtio_regions(VersalVirt *s)object_property_add_child (OBJECT (&s->soc), name,OBJECT (dev));sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , pic_irq); +SYS_BUS_DEVICE (dev)->mmio[0 ].addr = base; mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 );memory_region_add_subregion (&s->soc.mr_ps, base, mr);g_free (name);
This is definitely not the right way to fix this problem. The 'addr' field in a MemoryRegion is a part of its internal implementation. It is not used solely as a mechanism for setting the virtio-mmio bus name, and it will break things if you just reach in and mess with it.
The right fix here is going to involve improving virtio_mmio_bus_get_dev_path() (which also should not be just reaching into the internals of MemoryRegion structs!) so that it can cope with setups where the MR of the transport is not directly placed into the system memory. I think that probably involves calling memory_region_find() and then looking at the .offset_within_address_space field of the returned MemoryRegionSection, but that would need testing to confirm that it returns the same results for the non-xilinx cases that the current code does, and that it also returns sensible values for xilinx.
thanks
-- PMM