Make AddressSpaces QOM objects to ensure that they are destroyed when
their owners are finalized and also to get a unique path for debugging
output.

The name arguments were used to distinguish AddresSpaces in debugging
output, but they will represent property names after QOM-ification and
debugging output will show QOM paths. So change them to make them more
concise and also avoid conflicts with other properties.

Signed-off-by: Akihiko Odaki <od...@rsg.ci.i.u-tokyo.ac.jp>
---
 include/exec/cpu-common.h |  4 ++--
 system/physmem.c          | 17 ++++++++---------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 9b658a3f48f7..420e7a71001a 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -105,7 +105,7 @@ size_t qemu_ram_pagesize_largest(void);
  * cpu_address_space_init:
  * @cpu: CPU to add this address space to
  * @asidx: integer index of this address space
- * @prefix: prefix to be used as name of address space
+ * @name: name of address space
  * @mr: the root memory region of address space
  *
  * Add the specified address space to the CPU's cpu_ases list.
@@ -121,7 +121,7 @@ size_t qemu_ram_pagesize_largest(void);
  * Note that with KVM only one address space is supported.
  */
 void cpu_address_space_init(CPUState *cpu, int asidx,
-                            const char *prefix, MemoryRegion *mr);
+                            const char *name, MemoryRegion *mr);
 /**
  * cpu_address_space_destroy:
  * @cpu: CPU for which address space needs to be destroyed
diff --git a/system/physmem.c b/system/physmem.c
index 6190eca7daed..7fa7b9ee6b76 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -774,16 +774,13 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,
 #endif /* CONFIG_TCG */
 
 void cpu_address_space_init(CPUState *cpu, int asidx,
-                            const char *prefix, MemoryRegion *mr)
+                            const char *name, MemoryRegion *mr)
 {
     CPUAddressSpace *newas;
     AddressSpace *as = g_new0(AddressSpace, 1);
-    char *as_name;
 
     assert(mr);
-    as_name = g_strdup_printf("%s-%d", prefix, cpu->cpu_index);
-    address_space_init(as, NULL, mr, as_name);
-    g_free(as_name);
+    address_space_init(as, OBJECT(cpu), mr, name);
 
     /* Target code should have set num_ases before calling us */
     assert(asidx < cpu->num_ases);
@@ -831,7 +828,7 @@ void cpu_address_space_destroy(CPUState *cpu, int asidx)
         memory_listener_unregister(&cpuas->tcg_as_listener);
     }
 
-    address_space_destroy(cpuas->as);
+    object_unparent(OBJECT(cpuas->as));
     call_rcu1(&cpuas->as->rcu, address_space_free);
 
     if (asidx == 0) {
@@ -2814,15 +2811,17 @@ static void tcg_commit(MemoryListener *listener)
 
 static void memory_map_init(void)
 {
-    system_memory = g_malloc(sizeof(*system_memory));
+    Object *owner = machine_get_container("unattached");
 
+    system_memory = g_malloc(sizeof(*system_memory));
     memory_region_init(system_memory, NULL, "system", UINT64_MAX);
-    address_space_init(&address_space_memory, NULL, system_memory, "memory");
+    address_space_init(&address_space_memory, owner, system_memory,
+                       "system-as");
 
     system_io = g_malloc(sizeof(*system_io));
     memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
                           65536);
-    address_space_init(&address_space_io, NULL, system_io, "I/O");
+    address_space_init(&address_space_io, owner, system_io, "io-as");
 }
 
 MemoryRegion *get_system_memory(void)

-- 
2.51.0


Reply via email to