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> --- hw/mem/cxl_type3.c | 44 ++++++++++++-------------------------------- hw/mem/memory-device.c | 4 ++-- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 1a726b834b02..968594ae65e2 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -727,8 +727,6 @@ static void cxl_destroy_dc_regions(CXLType3Dev *ct3d) static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) { - DeviceState *ds = DEVICE(ct3d); - if (!ct3d->hostmem && !ct3d->hostvmem && !ct3d->hostpmem && !ct3d->dc.num_regions) { error_setg(errp, "at least one memdev property must be set"); @@ -750,7 +748,6 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) if (ct3d->hostvmem) { MemoryRegion *vmr; - char *v_name; vmr = host_memory_backend_get_memory(ct3d->hostvmem); if (!vmr) { @@ -765,20 +762,14 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) memory_region_set_nonvolatile(vmr, false); memory_region_set_enabled(vmr, true); host_memory_backend_set_mapped(ct3d->hostvmem, true); - if (ds->id) { - v_name = g_strdup_printf("cxl-type3-dpa-vmem-space:%s", ds->id); - } else { - v_name = g_strdup("cxl-type3-dpa-vmem-space"); - } - address_space_init(&ct3d->hostvmem_as, NULL, vmr, v_name); + address_space_init(&ct3d->hostvmem_as, OBJECT(ct3d), vmr, + "volatile-as"); ct3d->cxl_dstate.vmem_size = memory_region_size(vmr); ct3d->cxl_dstate.static_mem_size += memory_region_size(vmr); - g_free(v_name); } if (ct3d->hostpmem) { MemoryRegion *pmr; - char *p_name; pmr = host_memory_backend_get_memory(ct3d->hostpmem); if (!pmr) { @@ -793,21 +784,15 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) memory_region_set_nonvolatile(pmr, true); memory_region_set_enabled(pmr, true); host_memory_backend_set_mapped(ct3d->hostpmem, true); - if (ds->id) { - p_name = g_strdup_printf("cxl-type3-dpa-pmem-space:%s", ds->id); - } else { - p_name = g_strdup("cxl-type3-dpa-pmem-space"); - } - address_space_init(&ct3d->hostpmem_as, NULL, pmr, p_name); + address_space_init(&ct3d->hostpmem_as, OBJECT(ct3d), pmr, + "persistent-as"); ct3d->cxl_dstate.pmem_size = memory_region_size(pmr); ct3d->cxl_dstate.static_mem_size += memory_region_size(pmr); - g_free(p_name); } ct3d->dc.total_capacity = 0; if (ct3d->dc.num_regions > 0) { MemoryRegion *dc_mr; - char *dc_name; if (!ct3d->dc.host_dc) { error_setg(errp, "dynamic capacity must have a backing device"); @@ -832,13 +817,8 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) memory_region_set_nonvolatile(dc_mr, false); memory_region_set_enabled(dc_mr, true); host_memory_backend_set_mapped(ct3d->dc.host_dc, true); - if (ds->id) { - dc_name = g_strdup_printf("cxl-dcd-dpa-dc-space:%s", ds->id); - } else { - dc_name = g_strdup("cxl-dcd-dpa-dc-space"); - } - address_space_init(&ct3d->dc.host_dc_as, NULL, dc_mr, dc_name); - g_free(dc_name); + address_space_init(&ct3d->dc.host_dc_as, OBJECT(ct3d), dc_mr, + "volatile-dc-as"); if (!cxl_create_dc_regions(ct3d, errp)) { error_append_hint(errp, "setup DC regions failed"); @@ -974,13 +954,13 @@ err_free_special_ops: g_free(regs->special_ops); if (ct3d->dc.host_dc) { cxl_destroy_dc_regions(ct3d); - address_space_destroy(&ct3d->dc.host_dc_as); + object_unparent(OBJECT(&ct3d->dc.host_dc_as)); } if (ct3d->hostpmem) { - address_space_destroy(&ct3d->hostpmem_as); + object_unparent(OBJECT(&ct3d->hostpmem_as)); } if (ct3d->hostvmem) { - address_space_destroy(&ct3d->hostvmem_as); + object_unparent(OBJECT(&ct3d->hostvmem_as)); } } @@ -997,13 +977,13 @@ static void ct3_exit(PCIDevice *pci_dev) cxl_destroy_cci(&ct3d->cci); if (ct3d->dc.host_dc) { cxl_destroy_dc_regions(ct3d); - address_space_destroy(&ct3d->dc.host_dc_as); + object_unparent(OBJECT(&ct3d->dc.host_dc_as)); } if (ct3d->hostpmem) { - address_space_destroy(&ct3d->hostpmem_as); + object_unparent(OBJECT(&ct3d->hostpmem_as)); } if (ct3d->hostvmem) { - address_space_destroy(&ct3d->hostvmem_as); + object_unparent(OBJECT(&ct3d->hostvmem_as)); } } diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index a4a8efdd869b..165866f10b25 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -535,8 +535,8 @@ void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size) memory_region_init(&ms->device_memory->mr, OBJECT(ms), "device-memory", size); - address_space_init(&ms->device_memory->as, NULL, &ms->device_memory->mr, - "device-memory"); + address_space_init(&ms->device_memory->as, OBJECT(ms), + &ms->device_memory->mr, "device-memory-as"); memory_region_add_subregion(get_system_memory(), ms->device_memory->base, &ms->device_memory->mr); -- 2.51.0