@samitouri / QOSamiQemu / commits / ead7c5b06f

hw/sparc/sun4m_iommu: Fix crash when introspecting sun4m-iommu from the CLI

QEMU currently crashes when introspecting the sun4m-iommu device from the command line interface: $ ./qemu-system-sparc -display none -device sun4m-iommu,help qemu-system-sparc: ../../devel/qemu/system/physmem.c:1401: register_multipage: Assertion `num_pages' failed. Aborted (core dumped) There does not seem to be a compelling reason for initializing the memory regions from the instance_init function, so let's simply move the code into a realize() function instead to fix this issue. Reported-by: Markus Armbruster <armbru@redhat.com> Tested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> Message-ID: <20260317084450.442071-1-thuth@redhat.com>

Thomas Huth committed Mar 17, 2026 at 09:44 UTC ead7c5b06fbb87c61abab6d5885f19fea7f54d24
1 file changed +6 -5
hw/sparc/sun4m_iommu.c
+6 -5
@@ -351,13 +351,14 @@ static void iommu_reset(DeviceState *d)
351 s->regs[IOMMU_MASK_ID] = IOMMU_TS_MASK;
352 }
353
354 -static void iommu_init(Object *obj)
354 +static void iommu_realize(DeviceState *ds, Error **errp)
355 {
356 - IOMMUState *s = SUN4M_IOMMU(obj);
357 - SysBusDevice *dev = SYS_BUS_DEVICE(obj);
356 + IOMMUState *s = SUN4M_IOMMU(ds);
357 + SysBusDevice *dev = SYS_BUS_DEVICE(ds);
358 + Object *obj = OBJECT(ds);
359
360 memory_region_init_iommu(&s->iommu, sizeof(s->iommu),
360 - TYPE_SUN4M_IOMMU_MEMORY_REGION, OBJECT(dev),
361 + TYPE_SUN4M_IOMMU_MEMORY_REGION, obj,
362 "iommu-sun4m", UINT64_MAX);
363 address_space_init(&s->iommu_as, MEMORY_REGION(&s->iommu), "iommu-as");
364
@@ -377,6 +378,7 @@ static void iommu_class_init(ObjectClass *klass, const void *data)
378 DeviceClass *dc = DEVICE_CLASS(klass);
379
380 device_class_set_legacy_reset(dc, iommu_reset);
381 + dc->realize = iommu_realize;
382 dc->vmsd = &vmstate_iommu;
383 device_class_set_props(dc, iommu_properties);
384 }
@@ -385,7 +387,6 @@ static const TypeInfo iommu_info = {
387 .name = TYPE_SUN4M_IOMMU,
388 .parent = TYPE_SYS_BUS_DEVICE,
389 .instance_size = sizeof(IOMMUState),
388 - .instance_init = iommu_init,
390 .class_init = iommu_class_init,
391 };
392