[RFC PATCH v2 125/137] hw/s390x, hw/remote: Parent per-devfn IOMMU objects

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
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.

AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/remote/iommu.c       | 7 ++++---
 hw/s390x/s390-pci-bus.c | 9 +++++++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c
index 3e0758a21e..52ee9765e6 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);
     }
 
@@ -75,7 +76,7 @@ void remote_iommu_unplug_dev(PCIDevice *pci_dev)
 
     address_space_destroy(&elem->as);
 
-    object_unref(elem->mr);
+    object_unparent(OBJECT(elem->mr));
 
     elem->mr = NULL;
 }
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 4f0a8a787b..da8406cc4e 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),
@@ -798,7 +804,6 @@ static void s390_pci_iommu_free(S390pciState *s, PCIBus *bus, int32_t devfn)
     address_space_destroy(&iommu->as);
     object_unparent(OBJECT(&iommu->mr));
     object_unparent(OBJECT(iommu));
-    object_unref(OBJECT(iommu));
 }
 
 S390PCIGroup *s390_group_create(int id, int host_id)
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.