On 06/09/2025 03:11, Akihiko Odaki wrote:
> sun4m-iommu is not hotpluggable but its instance can still be created
> and finalized when processing the device-list-properties QMP command.
> Exposing such a temporary instance to AddressSpace should be
> avoided because it leaks the instance.
>
> Expose instances to the AddressSpace at their realization time so that
> it won't happen for the temporary instances.
>
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
> hw/sparc/sun4m_iommu.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/hw/sparc/sun4m_iommu.c b/hw/sparc/sun4m_iommu.c
> index a7ff36ee78c1d6295efea6499dffc2a481022167..0997f29ccb97d3dec4e3d34db49f2e51b6807a1a 100644
> --- a/hw/sparc/sun4m_iommu.c
> +++ b/hw/sparc/sun4m_iommu.c
> @@ -359,7 +359,6 @@ static void iommu_init(Object *obj)
> memory_region_init_iommu(&s->iommu, sizeof(s->iommu),
> TYPE_SUN4M_IOMMU_MEMORY_REGION, OBJECT(dev),
> "iommu-sun4m", UINT64_MAX);
> - address_space_init(&s->iommu_as, MEMORY_REGION(&s->iommu), "iommu-as");
>
> sysbus_init_irq(dev, &s->irq);
>
> @@ -368,6 +367,13 @@ static void iommu_init(Object *obj)
> sysbus_init_mmio(dev, &s->iomem);
> }
>
> +static void iommu_realize(DeviceState *dev, Error **errp)
> +{
> + IOMMUState *s = SUN4M_IOMMU(dev);
> +
> + address_space_init(&s->iommu_as, MEMORY_REGION(&s->iommu), "iommu-as");
> +}
> +
> static const Property iommu_properties[] = {
> DEFINE_PROP_UINT32("version", IOMMUState, version, 0),
> };
> @@ -377,6 +383,7 @@ static void iommu_class_init(ObjectClass *klass, const void *data)
> DeviceClass *dc = DEVICE_CLASS(klass);
>
> device_class_set_legacy_reset(dc, iommu_reset);
> + dc->realize = iommu_realize;
> dc->vmsd = &vmstate_iommu;
> device_class_set_props(dc, iommu_properties);
> }
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
ATB,
Mark.