Give the per-devfn S390 PCI IOMMU object a canonical path under the
S390 PCI host state.  s390_pci_iommu_free() already calls
object_unparent(), which was previously a no-op; it now performs
the actual release.

For the multi-process remote IOMMU, replace the raw
object_new(TYPE_MEMORY_REGION) with a proper memory_region_init()
under the RemoteIommu object so the MR gets an owner like every
other MR in the tree.

Assisted-by: Kiro
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/remote/iommu.c       | 5 +++--
 hw/s390x/s390-pci-bus.c | 8 +++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c
index 3e0758a21e..09f79e805c 100644
--- a/hw/remote/iommu.c
+++ b/hw/remote/iommu.c
@@ -52,8 +52,9 @@ static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus,
     }
 
     if (!elem->mr) {
-        elem->mr = MEMORY_REGION(object_new(TYPE_MEMORY_REGION));
-        memory_region_set_size(elem->mr, UINT64_MAX);
+        g_autofree char *name = g_strdup_printf("mr-devfn-%02x", devfn);
+        elem->mr = g_new0(MemoryRegion, 1);
+        memory_region_init(elem->mr, OBJECT(iommu), name, UINT64_MAX);
         address_space_init(&elem->as, elem->mr, NULL);
     }
 
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 4f0a8a787b..557ecbb977 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -618,7 +618,13 @@ static S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, 
PCIBus *bus,
 
     iommu = table->iommu[PCI_SLOT(devfn)];
     if (!iommu) {
-        iommu = S390_PCI_IOMMU(object_new(TYPE_S390_PCI_IOMMU));
+        char *ch_name = g_strdup_printf("iommu[%02x:%02x.%01x]",
+                                        pci_bus_num(bus),
+                                        PCI_SLOT(devfn),
+                                        PCI_FUNC(devfn));
+        iommu = S390_PCI_IOMMU(object_new_child(OBJECT(s), ch_name,
+                                                TYPE_S390_PCI_IOMMU));
+        g_free(ch_name);
 
         char *mr_name = g_strdup_printf("iommu-root-%02x:%02x.%01x",
                                         pci_bus_num(bus),
-- 
2.47.1


Reply via email to