[RFC PATCH v2 105/137] hw/remote: Give memory regions an explicit owner

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
remote_machine_init() passes OBJECT(machine). remote_sysmem_reconfig()
runs in the multi-process remote and creates system-memory subregions
on behalf of the machine; use qdev_get_machine() as owner.
dma_register() in the vfio-user server creates DMA windows for a
VfuObject; use it as owner.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine
or SysBus devices, and memory_region_register_ram() maps both to
dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/remote/machine.c       | 2 +-
 hw/remote/memory.c        | 3 ++-
 hw/remote/vfio-user-obj.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/remote/machine.c b/hw/remote/machine.c
index e8e9cf259f..09154fa122 100644
--- a/hw/remote/machine.c
+++ b/hw/remote/machine.c
@@ -37,7 +37,7 @@ static void remote_machine_init(MachineState *machine)
     system_io = get_system_io();
 
     pci_memory = g_new(MemoryRegion, 1);
-    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+    memory_region_init(pci_memory, OBJECT(machine), "pci", UINT64_MAX);
 
     rem_host = REMOTE_PCIHOST(qdev_new(OBJECT(s), "remote-pcihost",
                                        TYPE_REMOTE_PCIHOST));
diff --git a/hw/remote/memory.c b/hw/remote/memory.c
index 8195aa5fb8..3f8fe54bac 100644
--- a/hw/remote/memory.c
+++ b/hw/remote/memory.c
@@ -12,6 +12,7 @@
 
 #include "hw/remote/memory.h"
 #include "qapi/error.h"
+#include "hw/core/qdev.h"
 
 static void remote_sysmem_reset(void)
 {
@@ -42,7 +43,7 @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
     for (region = 0; region < msg->num_fds; region++, suffix++) {
         g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix);
         subregion = g_new(MemoryRegion, 1);
-        memory_region_init_ram_from_fd(subregion, NULL,
+        memory_region_init_ram_from_fd(subregion, qdev_get_machine(),
                                        name, sysmem_info->sizes[region],
                                        RAM_SHARED, msg->fds[region],
                                        sysmem_info->offsets[region],
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 87fa7b6572..685d4c2baf 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -324,7 +324,7 @@ static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
 
     subregion = g_new0(MemoryRegion, 1);
 
-    memory_region_init_ram_ptr(subregion, NULL, name,
+    memory_region_init_ram_ptr(subregion, OBJECT(o), name,
                                iov->iov_len, info->vaddr);
 
     dma_as = pci_device_iommu_address_space(o->pci_dev);
-- 
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.