Skip to contentSkip to conversation

memory: remove memory_region_destroy

PATCH In review Paolo Bonzini 3 participants 23 messages Jul 30, 2014 – Aug 15, 2014 Arm STM32

lore
Share & tools
lore
#0 lore raw

cover memory: remove memory_region_destroy

Now that a memory region's owner is used in the QOM tree, there is no need to use memory_region_destroy explicitly. The last reference to keep a region alive will disappear simply when the parent is finalized and destroys all its properties.

Paolo

Paolo Bonzini (9):
qom: object: delete properties before calling instance_finalize
qom: object: move unparenting to the child property's release callback
sysbus: remove unused function sysbus_del_io
vga: do not dynamically allocate chain4_alias
nic: do not destroy memory regions in cleanup functions
ioport: split deletion and destruction
memory: convert memory_region_destroy to object_unparent
memory: remove memory_region_destroy
tpm_tis: remove instance_finalize callback

 backends/hostmem.c             | 10 ----------
 docs/memory.txt                | 15 ++++++++++-----
 hw/audio/ac97.c                |  9 ---------
 hw/audio/es1370.c              |  8 --------
 hw/audio/intel-hda.c           |  1 -
 hw/block/nvme.c                |  1 -
 hw/block/pflash_cfi01.c        |  1 -
 hw/block/pflash_cfi02.c        |  1 -
 hw/char/serial-pci.c           |  3 ---
 hw/core/sysbus.c               |  5 -----
 hw/display/vga.c               | 24 ++++++++++--------------
 hw/display/vga_int.h           |  3 ++-
 hw/i386/kvm/pci-assign.c       |  8 --------
 hw/i386/kvmvapic.c             |  2 +-
 hw/ide/ahci.c                  |  2 --
 hw/ide/cmd646.c                |  5 -----
 hw/ide/piix.c                  |  3 ---
 hw/ide/via.c                   |  3 ---
 hw/ipack/tpci200.c             | 13 -------------
 hw/mips/gt64xxx_pci.c          |  2 +-
 hw/misc/ivshmem.c              |  3 ---
 hw/misc/omap_gpmc.c            |  2 +-
 hw/misc/pci-testdev.c          |  2 --
 hw/misc/vfio.c                 | 11 ++---------
 hw/net/dp8393x.c               |  3 ---
 hw/net/e1000.c                 |  2 --
 hw/net/eepro100.c              |  3 ---
 hw/net/mcf_fec.c               |  3 ---
 hw/net/ne2000.c                |  1 -
 hw/net/pcnet-pci.c             |  2 --
 hw/net/rtl8139.c               |  2 --
 hw/net/stellaris_enet.c        |  8 --------
 hw/net/vmxnet3.c               |  4 ----
 hw/pci-bridge/pci_bridge_dev.c |  2 --
 hw/pci/msix.c                  |  4 ----
 hw/pci/pci.c                   |  2 --
 hw/pci/pci_bridge.c            |  8 --------
 hw/pci/pcie_host.c             |  1 -
 hw/pci/shpc.c                  |  1 -
 hw/scsi/esp-pci.c              |  1 -
 hw/scsi/lsi53c895a.c           | 10 ----------
 hw/scsi/megasas.c              |  3 ---
 hw/scsi/vmw_pvscsi.c           |  3 ---
 hw/tpm/tpm_tis.c               |  9 ---------
 hw/usb/hcd-uhci.c              |  8 --------
 hw/virtio/virtio-pci.c         |  3 ---
 hw/watchdog/wdt_i6300esb.c     |  8 --------
 hw/xen/xen_pt.c                | 20 --------------------
 hw/xen/xen_pt_msi.c            |  2 --
 include/exec/memory.h          |  9 ---------
 include/hw/sysbus.h            |  1 -
 ioport.c                       | 11 ++++++++---
 memory.c                       |  6 ------
 qom/object.c                   | 16 +++++-----------
 54 files changed, 40 insertions(+), 253 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/9 qom: object: delete properties before calling instance_finalize

This ensures that the children's unparent callback will still have a usable parent.

---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qom/object.c +1 -1
index 0e8267b..f301bc2 100644
@@ -418,8 +418,8 @@ static void object_finalize(void *data)
     Object *obj = data;
     TypeImpl *ti = obj->class->type;
 
-    object_deinit(obj, ti);
     object_property_del_all(obj);
+    object_deinit(obj, ti);
 
     g_assert(obj->ref == 0);
     if (obj->free) {
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/9
#2 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom: object: delete properties before calling instance_finalize

Quoted 4 lines · Paolo Bonzini

This ensures that the children's unparent callback will still have a usable parent.

Quoted 23 lines
---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qom/object.c +1 -2
index 0e8267b..f301bc2 100644
@@ -418,8 +418,8 @@ static void object_finalize(void *data)
     Object *obj = data;
     TypeImpl *ti = obj->class->type;
 
-    object_deinit(obj, ti);
     object_property_del_all(obj);
+    object_deinit(obj, ti);
 
     g_assert(obj->ref == 0);
     if (obj->free) {
--

1.8.3.1

#3 lore raw

PATCH 2/9 qom: object: move unparenting to the child property's release callback

In reply to Paolo Bonzini

This ensures that the unparent callback is called automatically when the parent object is finalized.

Note that there's no need to keep a reference neither in object_unparent nor in object_finalize_child_property. The reference held by the child property itself will do.

---
 qom/object.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
qom/object.c +4 -10
index f301bc2..1b00831 100644
@@ -387,19 +387,9 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
 
 void object_unparent(Object *obj)
 {
-    if (!obj->parent) {
-        return;
-    }
-
-    object_ref(obj);
-    if (obj->class->unparent) {
-        (obj->class->unparent)(obj);
-    }
     if (obj->parent) {
         object_property_del_child(obj->parent, obj, NULL);
-        obj->parent = NULL;
     }
-    object_unref(obj);
 }
 
 static void object_deinit(Object *obj, TypeImpl *type)
@@ -1042,6 +1032,10 @@ static void object_finalize_child_property(Object *obj, const char *name,
 {
     Object *child = opaque;
 
+    if (child->class->unparent) {
+        (child->class->unparent)(child);
+    }
+    child->parent = NULL;
     object_unref(child);
 }
 
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 3/9 sysbus: remove unused function sysbus_del_io

In reply to Paolo Bonzini
---
 hw/core/sysbus.c    | 5 -----
 include/hw/sysbus.h | 1 -
 2 files changed, 6 deletions(-)
hw/core/sysbus.c +0 -5
index f4e760d..414e2a1 100644
@@ -242,11 +242,6 @@ void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
     memory_region_add_subregion(get_system_io(), addr, mem);
 }
 
-void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem)
-{
-    memory_region_del_subregion(get_system_io(), mem);
-}
-
 MemoryRegion *sysbus_address_space(SysBusDevice *dev)
 {
     return get_system_memory();
include/hw/sysbus.h +0 -1
index f5aaa05..0bb91a8 100644
@@ -71,7 +71,6 @@ void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
                              int priority);
 void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
                    MemoryRegion *mem);
-void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
 MemoryRegion *sysbus_address_space(SysBusDevice *dev);
 
 /* Legacy helper function for creating devices.  */
Signature · 1 line
1.8.3.1
Reviewed-by on v1 3/9
#5 lore raw

Re: [Qemu-devel] [PATCH 3/9] sysbus: remove unused function sysbus_del_io

Quoted 1 line · Paolo Bonzini
Quoted 38 lines
---
 hw/core/sysbus.c    | 5 -----
 include/hw/sysbus.h | 1 -
 2 files changed, 6 deletions(-)
hw/core/sysbus.c +0 -5
index f4e760d..414e2a1 100644
@@ -242,11 +242,6 @@ void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
     memory_region_add_subregion(get_system_io(), addr, mem);
 }
 
-void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem)
-{
-    memory_region_del_subregion(get_system_io(), mem);
-}
-
 MemoryRegion *sysbus_address_space(SysBusDevice *dev)
 {
     return get_system_memory();
include/hw/sysbus.h +0 -2
index f5aaa05..0bb91a8 100644
@@ -71,7 +71,6 @@ void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
                              int priority);
 void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
                    MemoryRegion *mem);
-void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
 MemoryRegion *sysbus_address_space(SysBusDevice *dev);
 
 /* Legacy helper function for creating devices.  */
--

1.8.3.1

#6 lore raw

PATCH 4/9 vga: do not dynamically allocate chain4_alias

In reply to Paolo Bonzini

Instead, add a boolean variable to indicate the presence of the region.

---
 hw/display/vga.c     | 24 ++++++++++--------------
 hw/display/vga_int.h |  3 ++-
 2 files changed, 12 insertions(+), 15 deletions(-)
hw/display/vga.c +10 -14
index 4b089a3..68cfee2 100644
@@ -168,15 +168,18 @@ static uint8_t expand4to8[16];
 
 static void vga_update_memory_access(VGACommonState *s)
 {
-    MemoryRegion *region, *old_region = s->chain4_alias;
     hwaddr base, offset, size;
 
     if (s->legacy_address_space == NULL) {
         return;
     }
 
-    s->chain4_alias = NULL;
-
+    if (s->has_chain4_alias) {
+        memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
+        memory_region_destroy(&s->chain4_alias);
+        s->has_chain4_alias = false;
+        s->plane_updated = 0xf;
+    }
     if ((s->sr[VGA_SEQ_PLANE_WRITE] & VGA_SR02_ALL_PLANES) ==
         VGA_SR02_ALL_PLANES && s->sr[VGA_SEQ_MEMORY_MODE] & VGA_SR04_CHN_4M) {
         offset = 0;
@@ -201,18 +204,11 @@ static void vga_update_memory_access(VGACommonState *s)
             break;
         }
         base += isa_mem_base;
-        region = g_malloc(sizeof(*region));
-        memory_region_init_alias(region, memory_region_owner(&s->vram),
+        memory_region_init_alias(&s->chain4_alias, memory_region_owner(&s->vram),
                                  "vga.chain4", &s->vram, offset, size);
         memory_region_add_subregion_overlap(s->legacy_address_space, base,
-                                            region, 2);
-        s->chain4_alias = region;
-    }
-    if (old_region) {
-        memory_region_del_subregion(s->legacy_address_space, old_region);
-        memory_region_destroy(old_region);
-        g_free(old_region);
-        s->plane_updated = 0xf;
+                                            &s->chain4_alias, 2);
+        s->has_chain4_alias = true;
     }
 }
 
@@ -1321,7 +1317,7 @@ static void vga_draw_text(VGACommonState *s, int full_update)
         s->font_offsets[1] = offset;
         full_update = 1;
     }
-    if (s->plane_updated & (1 << 2) || s->chain4_alias) {
+    if (s->plane_updated & (1 << 2) || s->has_chain4_alias) {
         /* if the plane 2 was modified since the last display, it
            indicates the font may have been modified */
         s->plane_updated = 0;
hw/display/vga_int.h +2 -1
index 5320abd..641f8f4 100644
@@ -94,7 +94,8 @@ typedef struct VGACommonState {
     uint32_t vram_size;
     uint32_t vram_size_mb; /* property */
     uint32_t latch;
-    MemoryRegion *chain4_alias;
+    bool has_chain4_alias;
+    MemoryRegion chain4_alias;
     uint8_t sr_index;
     uint8_t sr[256];
     uint8_t gr_index;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 4/9
#7 lore raw

Re: [Qemu-devel] [PATCH 4/9] vga: do not dynamically allocate chain4_alias

Quoted 2 lines · Paolo Bonzini

Instead, add a boolean variable to indicate the presence of the region.

Patch is good. Can you add a sentence on why you are doing this though? Is it just the save on the repeated malloc and free (which is sane in its own right) or something bigger in the context of your series?

Quoted 1 line

Otherwise,

Quoted 81 lines
---
 hw/display/vga.c     | 24 ++++++++++--------------
 hw/display/vga_int.h |  3 ++-
 2 files changed, 12 insertions(+), 15 deletions(-)
hw/display/vga.c +10 -14
index 4b089a3..68cfee2 100644
@@ -168,15 +168,18 @@ static uint8_t expand4to8[16];
 
 static void vga_update_memory_access(VGACommonState *s)
 {
-    MemoryRegion *region, *old_region = s->chain4_alias;
     hwaddr base, offset, size;
 
     if (s->legacy_address_space == NULL) {
         return;
     }
 
-    s->chain4_alias = NULL;
-
+    if (s->has_chain4_alias) {
+        memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
+        memory_region_destroy(&s->chain4_alias);
+        s->has_chain4_alias = false;
+        s->plane_updated = 0xf;
+    }
     if ((s->sr[VGA_SEQ_PLANE_WRITE] & VGA_SR02_ALL_PLANES) ==
         VGA_SR02_ALL_PLANES && s->sr[VGA_SEQ_MEMORY_MODE] & VGA_SR04_CHN_4M) {
         offset = 0;
@@ -201,18 +204,11 @@ static void vga_update_memory_access(VGACommonState *s)
             break;
         }
         base += isa_mem_base;
-        region = g_malloc(sizeof(*region));
-        memory_region_init_alias(region, memory_region_owner(&s->vram),
+        memory_region_init_alias(&s->chain4_alias, memory_region_owner(&s->vram),
                                  "vga.chain4", &s->vram, offset, size);
         memory_region_add_subregion_overlap(s->legacy_address_space, base,
-                                            region, 2);
-        s->chain4_alias = region;
-    }
-    if (old_region) {
-        memory_region_del_subregion(s->legacy_address_space, old_region);
-        memory_region_destroy(old_region);
-        g_free(old_region);
-        s->plane_updated = 0xf;
+                                            &s->chain4_alias, 2);
+        s->has_chain4_alias = true;
     }
 }
 
@@ -1321,7 +1317,7 @@ static void vga_draw_text(VGACommonState *s, int full_update)
         s->font_offsets[1] = offset;
         full_update = 1;
     }
-    if (s->plane_updated & (1 << 2) || s->chain4_alias) {
+    if (s->plane_updated & (1 << 2) || s->has_chain4_alias) {
         /* if the plane 2 was modified since the last display, it
            indicates the font may have been modified */
         s->plane_updated = 0;
hw/display/vga_int.h +2 -2
index 5320abd..641f8f4 100644
@@ -94,7 +94,8 @@ typedef struct VGACommonState {
     uint32_t vram_size;
     uint32_t vram_size_mb; /* property */
     uint32_t latch;
-    MemoryRegion *chain4_alias;
+    bool has_chain4_alias;
+    MemoryRegion chain4_alias;
     uint8_t sr_index;
     uint8_t sr[256];
     uint8_t gr_index;
--

1.8.3.1

#8 lore raw

Re: [Qemu-devel] [PATCH 4/9] vga: do not dynamically allocate chain4_alias

Il 31/07/2014 14:01, Peter Crosthwaite ha scritto:

Quoted 8 lines · Paolo Bonzini
Quoted 2 lines

Instead, add a boolean variable to indicate the presence of the region.

Patch is good. Can you add a sentence on why you are doing this though? Is it just the save on the repeated malloc and free (which is sane in its own right) or something bigger in the context of your series?

Even more than the repeated malloc and free, it's the repeated add_child/unparent.

Paolo

Quoted 87 lines
Quoted 1 line

Otherwise,

Quoted 81 lines
---
 hw/display/vga.c     | 24 ++++++++++--------------
 hw/display/vga_int.h |  3 ++-
 2 files changed, 12 insertions(+), 15 deletions(-)
hw/display/vga.c +10 -14
index 4b089a3..68cfee2 100644
@@ -168,15 +168,18 @@ static uint8_t expand4to8[16];
 
 static void vga_update_memory_access(VGACommonState *s)
 {
-    MemoryRegion *region, *old_region = s->chain4_alias;
     hwaddr base, offset, size;
 
     if (s->legacy_address_space == NULL) {
         return;
     }
 
-    s->chain4_alias = NULL;
-
+    if (s->has_chain4_alias) {
+        memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
+        memory_region_destroy(&s->chain4_alias);
+        s->has_chain4_alias = false;
+        s->plane_updated = 0xf;
+    }
     if ((s->sr[VGA_SEQ_PLANE_WRITE] & VGA_SR02_ALL_PLANES) ==
         VGA_SR02_ALL_PLANES && s->sr[VGA_SEQ_MEMORY_MODE] & VGA_SR04_CHN_4M) {
         offset = 0;
@@ -201,18 +204,11 @@ static void vga_update_memory_access(VGACommonState *s)
             break;
         }
         base += isa_mem_base;
-        region = g_malloc(sizeof(*region));
-        memory_region_init_alias(region, memory_region_owner(&s->vram),
+        memory_region_init_alias(&s->chain4_alias, memory_region_owner(&s->vram),
                                  "vga.chain4", &s->vram, offset, size);
         memory_region_add_subregion_overlap(s->legacy_address_space, base,
-                                            region, 2);
-        s->chain4_alias = region;
-    }
-    if (old_region) {
-        memory_region_del_subregion(s->legacy_address_space, old_region);
-        memory_region_destroy(old_region);
-        g_free(old_region);
-        s->plane_updated = 0xf;
+                                            &s->chain4_alias, 2);
+        s->has_chain4_alias = true;
     }
 }
 
@@ -1321,7 +1317,7 @@ static void vga_draw_text(VGACommonState *s, int full_update)
         s->font_offsets[1] = offset;
         full_update = 1;
     }
-    if (s->plane_updated & (1 << 2) || s->chain4_alias) {
+    if (s->plane_updated & (1 << 2) || s->has_chain4_alias) {
         /* if the plane 2 was modified since the last display, it
            indicates the font may have been modified */
         s->plane_updated = 0;
hw/display/vga_int.h +2 -2
index 5320abd..641f8f4 100644
@@ -94,7 +94,8 @@ typedef struct VGACommonState {
     uint32_t vram_size;
     uint32_t vram_size_mb; /* property */
     uint32_t latch;
-    MemoryRegion *chain4_alias;
+    bool has_chain4_alias;
+    MemoryRegion chain4_alias;
     uint8_t sr_index;
     uint8_t sr[256];
     uint8_t gr_index;
--

1.8.3.1

#9 lore raw

PATCH 5/9 nic: do not destroy memory regions in cleanup functions

In reply to Paolo Bonzini

The memory regions should be destroyed in the unrealize function; since these NICs are not even qdev-ified, they cannot be unplugged and they do not have to do anything to destroy their memory regions.

---
 hw/net/dp8393x.c | 3 ---
 hw/net/mcf_fec.c | 3 ---
 2 files changed, 6 deletions(-)
hw/net/dp8393x.c +0 -3
index 789d385..7eab7ad 100644
@@ -863,9 +863,6 @@ static void nic_cleanup(NetClientState *nc)
 {
     dp8393xState *s = qemu_get_nic_opaque(nc);
 
-    memory_region_del_subregion(s->address_space, &s->mmio);
-    memory_region_destroy(&s->mmio);
-
     timer_del(s->watchdog);
     timer_free(s->watchdog);
 
hw/net/mcf_fec.c +0 -3
index 4bff3de..22cd7cf 100644
@@ -443,9 +443,6 @@ static void mcf_fec_cleanup(NetClientState *nc)
 {
     mcf_fec_state *s = qemu_get_nic_opaque(nc);
 
-    memory_region_del_subregion(s->sysmem, &s->iomem);
-    memory_region_destroy(&s->iomem);
-
     g_free(s);
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 5/9
#10 lore raw

Re: [Qemu-devel] [PATCH 5/9] nic: do not destroy memory regions in cleanup functions

Quoted 10 lines · Paolo Bonzini

The memory regions should be destroyed in the unrealize function; since these NICs are not even qdev-ified, they cannot be unplugged and they do not have to do anything to destroy their memory regions.

---
 hw/net/dp8393x.c | 3 ---
 hw/net/mcf_fec.c | 3 ---
 2 files changed, 6 deletions(-)
Reviewed-by
#11 lore raw

Re: [Qemu-devel] [PATCH 5/9] nic: do not destroy memory regions in cleanup functions

Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · Paolo Bonzini

The memory regions should be destroyed in the unrealize function; since these NICs are not even qdev-ified, they cannot be unplugged and they do not have to do anything to destroy their memory regions.

Quoted 8 lines
Quoted 6 lines
---
 hw/net/dp8393x.c | 3 ---
 hw/net/mcf_fec.c | 3 ---
 2 files changed, 6 deletions(-)
#12 lore raw

PATCH 6/9 ioport: split deletion and destruction

In reply to Paolo Bonzini

Of the two functions portio_list_del and portio_list_destroy, the latter is just freeing a memory area. However, portio_list_del is the logical equivalent of memory_region_del_subregion so destruction of memory regions does not belong there.

---
 ioport.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
ioport.c +8 -3
index 3d91e79..dce94a3 100644
@@ -149,6 +149,14 @@ void portio_list_set_flush_coalesced(PortioList *piolist)
 
 void portio_list_destroy(PortioList *piolist)
 {
+    MemoryRegionPortioList *mrpio;
+    unsigned i;
+
+    for (i = 0; i < piolist->nr; ++i) {
+        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
+        memory_region_destroy(&mrpio->mr);
+        g_free(mrpio);
+    }
     g_free(piolist->regions);
 }
 
@@ -291,8 +299,5 @@ void portio_list_del(PortioList *piolist)
     for (i = 0; i < piolist->nr; ++i) {
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
         memory_region_del_subregion(piolist->address_space, &mrpio->mr);
-        memory_region_destroy(&mrpio->mr);
-        g_free(mrpio);
-        piolist->regions[i] = NULL;
     }
 }
Signature · 1 line
1.8.3.1
#13 lore raw

Re: [Qemu-devel] [PATCH 6/9] ioport: split deletion and destruction

Quoted 5 lines · Paolo Bonzini

Of the two functions portio_list_del and portio_list_destroy, the latter is just freeing a memory area. However, portio_list_del is the logical equivalent of memory_region_del_subregion so destruction of memory regions does not belong there.

So I found the original implementation made sense to me, in that _del is the converse of _add and _destroy _init WRT to the MR ops.

Currently
_init = malloc array
_add = mr_init + mr_add_subregion
_del = mr_del_subregion + mr_destroy
_destory = free array

This delays mr_destory to _destroy breaking the symmetry.

With this change is is still possible to:

_init()
_add()
_del()
_add()
_del()
_destrory()

And not leak a ref, with the reinited memory region on second add?

Then again I may be misunderstanding, as apparently neither of these API have any users so I'm having trouble getting a handle on intended usage:

$ git grep portio_list_del
include/exec/ioport.h:void portio_list_del(PortioList *piolist);
ioport.c:void portio_list_del(PortioList *piolist)
$ git grep portio_list_destroy
include/exec/ioport.h:void portio_list_destroy(PortioList *piolist);
ioport.c:void portio_list_destroy(PortioList *piolist)

Regards,
Peter

Quoted 38 lines
---
 ioport.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
ioport.c +8 -4
index 3d91e79..dce94a3 100644
@@ -149,6 +149,14 @@ void portio_list_set_flush_coalesced(PortioList *piolist)
 
 void portio_list_destroy(PortioList *piolist)
 {
+    MemoryRegionPortioList *mrpio;
+    unsigned i;
+
+    for (i = 0; i < piolist->nr; ++i) {
+        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
+        memory_region_destroy(&mrpio->mr);
+        g_free(mrpio);
+    }
     g_free(piolist->regions);
 }
 
@@ -291,8 +299,5 @@ void portio_list_del(PortioList *piolist)
     for (i = 0; i < piolist->nr; ++i) {
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
         memory_region_del_subregion(piolist->address_space, &mrpio->mr);
-        memory_region_destroy(&mrpio->mr);
-        g_free(mrpio);
-        piolist->regions[i] = NULL;
     }
 }
--

1.8.3.1

#14 lore raw

Re: [Qemu-devel] [PATCH 6/9] ioport: split deletion and destruction

Il 31/07/2014 14:34, Peter Crosthwaite ha scritto:

Quoted 10 lines

So I found the original implementation made sense to me, in that _del is the converse of _add and _destroy _init WRT to the MR ops.

Currently
_init = malloc array
_add = mr_init + mr_add_subregion
_del = mr_del_subregion + mr_destroy
_destory = free array

This delays mr_destory to _destroy breaking the symmetry.

Note that there is a fundamental difference between init and destroy:
when you do init, the MemoryRegion should not be providing references to the MemoryRegion's owner. So you can do it pretty much whenever you want.

However, after del_subregion the device models can have references to the MemoryRegion's owner (via address_space_map/unmap) and destroy has to be delayed to a point when these references have disappeared. This is why I'm keen on making memory_region_destroy happen automatically at finalize time, as I do later in this series: last year I had tried doing it manually with instance_finalize, and it was an unreviewable mess.

With this patch, you still would need manual portio_list_destroy calls in instance_finalize, but PortioLists are used sparingly so it's much simpler to manage them.

This difference is why in this patch I focused only on portio_list_del/destroy. However, I can try and move init to portio_list_add; then the symmetry is restored.

Quoted 9 lines

With this change is is still possible to:

_init()
_add()
_del()
_add()
_del()
_destrory()

Quoted 5 lines

And not leak a ref, with the reinited memory region on second add?

Then again I may be misunderstanding, as apparently neither of these API have any users so I'm having trouble getting a handle on intended usage:

Yes, that's because these patches are mostly used by ISA devices or VGAs, and currently neither is hot-unpluggable.

Paolo

#15 lore raw

PATCH 7/9 memory: convert memory_region_destroy to object_unparent

In reply to Paolo Bonzini

Explicitly call object_unparent in the few places where we will re-create the memory region. If the memory region is simply being destroyed as part of device teardown, let QOM handle it.

---
 docs/memory.txt       | 15 ++++++++++-----
 hw/display/vga.c      |  2 +-
 hw/i386/kvmvapic.c    |  2 +-
 hw/mips/gt64xxx_pci.c |  2 +-
 hw/misc/omap_gpmc.c   |  2 +-
 hw/misc/vfio.c        |  4 ++--
 ioport.c              |  2 +-
 memory.c              |  1 -
 8 files changed, 17 insertions(+), 13 deletions(-)
docs/memory.txt +9 -5
index 5bdbdb3..b12f1f0 100644
@@ -74,11 +74,15 @@ Region lifecycle
 ----------------
 
 A region is created by one of the constructor functions (memory_region_init*())
-and destroyed by the destructor (memory_region_destroy()).  In between,
-a region can be added to an address space by using memory_region_add_subregion()
-and removed using memory_region_del_subregion().  Region attributes may be
-changed at any point; they take effect once the region becomes exposed to the
-guest.
+and attached to an object.  It is then destroyed by object_unparent() or simply
+when the parent object dies.
+
+In between, a region can be added to an address space
+by using memory_region_add_subregion() and removed using
+memory_region_del_subregion().
+
+Region attributes may be changed at any point; they take effect once
+the region becomes exposed to the guest.
 
 Overlapping regions and priority
 --------------------------------
hw/display/vga.c +1 -1
index 68cfee2..65dab8d 100644
@@ -176,7 +176,7 @@ static void vga_update_memory_access(VGACommonState *s)
 
     if (s->has_chain4_alias) {
         memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
-        memory_region_destroy(&s->chain4_alias);
+        object_unparent(OBJECT(&s->chain4_alias));
         s->has_chain4_alias = false;
         s->plane_updated = 0xf;
     }
hw/i386/kvmvapic.c +1 -1
index cb855c7..ee95963 100644
@@ -584,7 +584,7 @@ static int vapic_map_rom_writable(VAPICROMState *s)
 
     if (s->rom_mapped_writable) {
         memory_region_del_subregion(as, &s->rom);
-        memory_region_destroy(&s->rom);
+        object_unparent(OBJECT(&s->rom));
     }
 
     /* grab RAM memory region (region @rom_paddr may still be pc.rom) */
hw/mips/gt64xxx_pci.c +1 -1
index 22f63ce..1f2fe5f 100644
@@ -297,7 +297,7 @@ static void gt64120_pci_mapping(GT64120State *s)
       if (s->PCI0IO_length)
       {
           memory_region_del_subregion(get_system_memory(), &s->PCI0IO_mem);
-          memory_region_destroy(&s->PCI0IO_mem);
+          object_unparent(OBJECT(&s->PCI0IO_mem));
       }
       /* Map new IO address */
       s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;
hw/misc/omap_gpmc.c +1 -1
index cddea24..fbbe2ff 100644
@@ -436,7 +436,7 @@ static void omap_gpmc_cs_unmap(struct omap_gpmc_s *s, int cs)
     }
     memory_region_del_subregion(get_system_memory(), &f->container);
     memory_region_del_subregion(&f->container, omap_gpmc_cs_memregion(s, cs));
-    memory_region_destroy(&f->container);
+    object_unparent(OBJECT(&f->container));
 }
 
 void omap_gpmc_reset(struct omap_gpmc_s *s)
hw/misc/vfio.c +2 -2
index 0b9eba0..af9ae1f 100644
@@ -2266,7 +2266,7 @@ static void vfio_vga_quirk_teardown(VFIODevice *vdev)
         while (!QLIST_EMPTY(&vdev->vga.region[i].quirks)) {
             VFIOQuirk *quirk = QLIST_FIRST(&vdev->vga.region[i].quirks);
             memory_region_del_subregion(&vdev->vga.region[i].mem, &quirk->mem);
-            memory_region_destroy(&quirk->mem);
+            object_unparent(OBJECT(&quirk->mem));
             QLIST_REMOVE(quirk, next);
             g_free(quirk);
         }
@@ -2290,7 +2290,7 @@ static void vfio_bar_quirk_teardown(VFIODevice *vdev, int nr)
     while (!QLIST_EMPTY(&bar->quirks)) {
         VFIOQuirk *quirk = QLIST_FIRST(&bar->quirks);
         memory_region_del_subregion(&bar->mem, &quirk->mem);
-        memory_region_destroy(&quirk->mem);
+        object_unparent(OBJECT(&quirk->mem));
         QLIST_REMOVE(quirk, next);
         g_free(quirk);
     }
ioport.c +1 -1
index dce94a3..783a3ae 100644
@@ -154,7 +154,7 @@ void portio_list_destroy(PortioList *piolist)
 
     for (i = 0; i < piolist->nr; ++i) {
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        memory_region_destroy(&mrpio->mr);
+        object_unparent(OBJECT(&mrpio->mr));
         g_free(mrpio);
     }
     g_free(piolist->regions);
memory.c +0 -1
index 64d7176..23c5269 100644
@@ -1266,7 +1266,6 @@ static void memory_region_finalize(Object *obj)
 
 void memory_region_destroy(MemoryRegion *mr)
 {
-    object_unparent(OBJECT(mr));
 }
 
 
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH 8/9 memory: remove memory_region_destroy

In reply to Paolo Bonzini

The function is empty after the previous patch, so remove it.

---
 backends/hostmem.c             | 10 ----------
 hw/audio/ac97.c                |  9 ---------
 hw/audio/es1370.c              |  8 --------
 hw/audio/intel-hda.c           |  1 -
 hw/block/nvme.c                |  1 -
 hw/block/pflash_cfi01.c        |  1 -
 hw/block/pflash_cfi02.c        |  1 -
 hw/char/serial-pci.c           |  3 ---
 hw/i386/kvm/pci-assign.c       |  8 --------
 hw/ide/ahci.c                  |  2 --
 hw/ide/cmd646.c                |  5 -----
 hw/ide/piix.c                  |  3 ---
 hw/ide/via.c                   |  3 ---
 hw/ipack/tpci200.c             | 13 -------------
 hw/misc/ivshmem.c              |  3 ---
 hw/misc/pci-testdev.c          |  2 --
 hw/misc/vfio.c                 |  7 -------
 hw/net/e1000.c                 |  2 --
 hw/net/eepro100.c              |  3 ---
 hw/net/ne2000.c                |  1 -
 hw/net/pcnet-pci.c             |  2 --
 hw/net/rtl8139.c               |  2 --
 hw/net/stellaris_enet.c        |  8 --------
 hw/net/vmxnet3.c               |  4 ----
 hw/pci-bridge/pci_bridge_dev.c |  2 --
 hw/pci/msix.c                  |  4 ----
 hw/pci/pci.c                   |  2 --
 hw/pci/pci_bridge.c            |  8 --------
 hw/pci/pcie_host.c             |  1 -
 hw/pci/shpc.c                  |  1 -
 hw/scsi/esp-pci.c              |  1 -
 hw/scsi/lsi53c895a.c           | 10 ----------
 hw/scsi/megasas.c              |  3 ---
 hw/scsi/vmw_pvscsi.c           |  3 ---
 hw/tpm/tpm_tis.c               |  1 -
 hw/usb/hcd-uhci.c              |  8 --------
 hw/virtio/virtio-pci.c         |  3 ---
 hw/watchdog/wdt_i6300esb.c     |  8 --------
 hw/xen/xen_pt.c                | 20 --------------------
 hw/xen/xen_pt_msi.c            |  2 --
 include/exec/memory.h          |  9 ---------
 memory.c                       |  5 -----
 42 files changed, 193 deletions(-)
backends/hostmem.c +0 -10
index ca10c51..e7eec37 100644
@@ -257,15 +257,6 @@ static void host_memory_backend_init(Object *obj)
                         host_memory_backend_set_policy, NULL, NULL, NULL);
 }
 
-static void host_memory_backend_finalize(Object *obj)
-{
-    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
-
-    if (memory_region_size(&backend->mr)) {
-        memory_region_destroy(&backend->mr);
-    }
-}
-
 MemoryRegion *
 host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
 {
@@ -360,7 +351,6 @@ static const TypeInfo host_memory_backend_info = {
     .class_init = host_memory_backend_class_init,
     .instance_size = sizeof(HostMemoryBackend),
     .instance_init = host_memory_backend_init,
-    .instance_finalize = host_memory_backend_finalize,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
         { }
hw/audio/ac97.c +0 -9
index 45cb118..0e22bb9 100644
@@ -1388,14 +1388,6 @@ static int ac97_initfn (PCIDevice *dev)
     return 0;
 }
 
-static void ac97_exitfn (PCIDevice *dev)
-{
-    AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev);
-
-    memory_region_destroy (&s->io_nam);
-    memory_region_destroy (&s->io_nabm);
-}
-
 static int ac97_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "AC97");
@@ -1413,7 +1405,6 @@ static void ac97_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->init = ac97_initfn;
-    k->exit = ac97_exitfn;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
     k->revision = 0x01;
hw/audio/es1370.c +0 -8
index 5dbf803..e67d1ea 100644
@@ -1042,13 +1042,6 @@ static int es1370_initfn (PCIDevice *dev)
     return 0;
 }
 
-static void es1370_exitfn (PCIDevice *dev)
-{
-    ES1370State *s = DO_UPCAST (ES1370State, dev, dev);
-
-    memory_region_destroy (&s->io);
-}
-
 static int es1370_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "ES1370");
@@ -1061,7 +1054,6 @@ static void es1370_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->init = es1370_initfn;
-    k->exit = es1370_exitfn;
     k->vendor_id = PCI_VENDOR_ID_ENSONIQ;
     k->device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
     k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
hw/audio/intel-hda.c +0 -1
index aa49b47..aba45fc 100644
@@ -1155,7 +1155,6 @@ static void intel_hda_exit(PCIDevice *pci)
     IntelHDAState *d = INTEL_HDA(pci);
 
     msi_uninit(&d->pci);
-    memory_region_destroy(&d->mmio);
 }
 
 static int intel_hda_post_load(void *opaque, int version)
hw/block/nvme.c +0 -1
index 5fd8f89..6d9a065 100644
@@ -839,7 +839,6 @@ static void nvme_exit(PCIDevice *pci_dev)
     g_free(n->cq);
     g_free(n->sq);
     msix_uninit_exclusive_bar(pci_dev);
-    memory_region_destroy(&n->iomem);
 }
 
 static Property nvme_props[] = {
hw/block/pflash_cfi01.c +0 -1
index f9507b4..2238f39 100644
@@ -781,7 +781,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
 
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
-            memory_region_destroy(&pfl->mem);
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
hw/block/pflash_cfi02.c +0 -1
index 8d4b828..e196f4d 100644
@@ -617,7 +617,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
         ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9);
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl));
-            memory_region_destroy(&pfl->orig_mem);
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
hw/char/serial-pci.c +0 -3
index c133c33..f05c9b4 100644
@@ -135,7 +135,6 @@ static void serial_pci_exit(PCIDevice *dev)
     SerialState *s = &pci->state;
 
     serial_exit_core(s);
-    memory_region_destroy(&s->io);
     qemu_free_irq(s->irq);
 }
 
@@ -149,10 +148,8 @@ static void multi_serial_pci_exit(PCIDevice *dev)
         s = pci->state + i;
         serial_exit_core(s);
         memory_region_del_subregion(&pci->iobar, &s->io);
-        memory_region_destroy(&s->io);
         g_free(pci->name[i]);
     }
-    memory_region_destroy(&pci->iobar);
     qemu_free_irqs(pci->irqs, pci->ports);
 }
 
hw/i386/kvm/pci-assign.c +0 -8
index de33657..17c7d6dc 100644
@@ -697,8 +697,6 @@ static void free_assigned_device(AssignedDevice *dev)
             if (region->u.r_baseport) {
                 memory_region_del_subregion(&region->container,
                                             &region->real_iomem);
-                memory_region_destroy(&region->real_iomem);
-                memory_region_destroy(&region->container);
             }
         } else if (pci_region->type & IORESOURCE_MEM) {
             if (region->u.r_virtbase) {
@@ -712,9 +710,6 @@ static void free_assigned_device(AssignedDevice *dev)
                     memory_region_del_subregion(&region->container,
                                                 &dev->mmio);
                 }
-
-                memory_region_destroy(&region->real_iomem);
-                memory_region_destroy(&region->container);
                 if (munmap(region->u.r_virtbase,
                            (pci_region->size + 0xFFF) & 0xFFFFF000)) {
                     error_report("Failed to unmap assigned device region: %s",
@@ -1680,8 +1675,6 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
         return;
     }
 
-    memory_region_destroy(&dev->mmio);
-
     if (munmap(dev->msix_table, MSIX_PAGE_SIZE) == -1) {
         error_report("error unmapping msix_table! %s", strerror(errno));
     }
@@ -1953,7 +1946,6 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev)
         error_printf("Device option ROM contents are probably invalid "
                      "(check dmesg).\nSkip option ROM probe with rombar=0, "
                      "or load from file with romfile=\n");
-        memory_region_destroy(&dev->dev.rom);
         goto close_rom;
     }
 
hw/ide/ahci.c +0 -2
index 604152a..aa0ef42 100644
@@ -1197,8 +1197,6 @@ void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
 
 void ahci_uninit(AHCIState *s)
 {
-    memory_region_destroy(&s->mem);
-    memory_region_destroy(&s->idp);
     g_free(s->dev);
 }
 
hw/ide/cmd646.c +0 -5
index a8e35fe..1295ed0 100644
@@ -310,13 +310,8 @@ static void pci_cmd646_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->cmd646_bar[i].cmd);
-        memory_region_destroy(&d->cmd646_bar[i].data);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
hw/ide/piix.c +0 -3
index 8651726..59319eb 100644
@@ -207,11 +207,8 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 /* hd_table must contain 4 block drivers */
hw/ide/via.c +0 -3
index 198123b..89d27b4 100644
@@ -198,11 +198,8 @@ static void vt82c686b_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
hw/ipack/tpci200.c +0 -13
index 42ca923..b7031a0 100644
@@ -613,18 +613,6 @@ static int tpci200_initfn(PCIDevice *pci_dev)
     return 0;
 }
 
-static void tpci200_exitfn(PCIDevice *pci_dev)
-{
-    TPCI200State *s = TPCI200(pci_dev);
-
-    memory_region_destroy(&s->mmio);
-    memory_region_destroy(&s->io);
-    memory_region_destroy(&s->las0);
-    memory_region_destroy(&s->las1);
-    memory_region_destroy(&s->las2);
-    memory_region_destroy(&s->las3);
-}
-
 static const VMStateDescription vmstate_tpci200 = {
     .name = "tpci200",
     .version_id = 1,
@@ -645,7 +633,6 @@ static void tpci200_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = tpci200_initfn;
-    k->exit = tpci200_exitfn;
     k->vendor_id = PCI_VENDOR_ID_TEWS;
     k->device_id = PCI_DEVICE_ID_TEWS_TPCI200;
     k->class_id = PCI_CLASS_BRIDGE_OTHER;
hw/misc/ivshmem.c +0 -3
index 768e528..156edd2 100644
@@ -789,11 +789,8 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         error_free(s->migration_blocker);
     }
 
-    memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
     vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
-    memory_region_destroy(&s->ivshmem);
-    memory_region_destroy(&s->bar);
     unregister_savevm(DEVICE(dev), "ivshmem", s);
 }
 
hw/misc/pci-testdev.c +0 -2
index ca53b3f..c78a63e 100644
@@ -293,8 +293,6 @@ pci_testdev_uninit(PCIDevice *dev)
         g_free(d->tests[i].hdr);
     }
     g_free(d->tests);
-    memory_region_destroy(&d->mmio);
-    memory_region_destroy(&d->portio);
 }
 
 static void qdev_pci_testdev_reset(DeviceState *dev)
hw/misc/vfio.c +0 -7
index af9ae1f..813c2cc 100644
@@ -2857,15 +2857,11 @@ static void vfio_unmap_bar(VFIODevice *vdev, int nr)
 
     memory_region_del_subregion(&bar->mem, &bar->mmap_mem);
     munmap(bar->mmap, memory_region_size(&bar->mmap_mem));
-    memory_region_destroy(&bar->mmap_mem);
 
     if (vdev->msix && vdev->msix->table_bar == nr) {
         memory_region_del_subregion(&bar->mem, &vdev->msix->mmap_mem);
         munmap(vdev->msix->mmap, memory_region_size(&vdev->msix->mmap_mem));
-        memory_region_destroy(&vdev->msix->mmap_mem);
     }
-
-    memory_region_destroy(&bar->mem);
 }
 
 static int vfio_mmap_bar(VFIODevice *vdev, VFIOBAR *bar,
@@ -3018,9 +3014,6 @@ static void vfio_unmap_bars(VFIODevice *vdev)
     if (vdev->has_vga) {
         vfio_vga_quirk_teardown(vdev);
         pci_unregister_vga(&vdev->pdev);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_MEM].mem);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_IO_LO].mem);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_IO_HI].mem);
     }
 }
 
hw/net/e1000.c +0 -2
index 0fc29a0..21c38fa 100644
@@ -1496,8 +1496,6 @@ pci_e1000_uninit(PCIDevice *dev)
     timer_free(d->autoneg_timer);
     timer_del(d->mit_timer);
     timer_free(d->mit_timer);
-    memory_region_destroy(&d->mmio);
-    memory_region_destroy(&d->io);
     qemu_del_nic(d->nic);
 }
 
hw/net/eepro100.c +0 -3
index 3263e3f..3cd826a 100644
@@ -1843,9 +1843,6 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
 {
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 
-    memory_region_destroy(&s->mmio_bar);
-    memory_region_destroy(&s->io_bar);
-    memory_region_destroy(&s->flash_bar);
     vmstate_unregister(&pci_dev->qdev, s->vmstate, s);
     eeprom93xx_free(&pci_dev->qdev, s->eeprom);
     qemu_del_nic(s->nic);
hw/net/ne2000.c +0 -1
index d558b8c..a62d12d 100644
@@ -748,7 +748,6 @@ static void pci_ne2000_exit(PCIDevice *pci_dev)
     PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
     NE2000State *s = &d->ne2000;
 
-    memory_region_destroy(&s->io);
     qemu_del_nic(s->nic);
     qemu_free_irq(s->irq);
 }
hw/net/pcnet-pci.c +0 -2
index b25d789..50ffe91 100644
@@ -282,8 +282,6 @@ static void pci_pcnet_uninit(PCIDevice *dev)
     PCIPCNetState *d = PCI_PCNET(dev);
 
     qemu_free_irq(d->state.irq);
-    memory_region_destroy(&d->state.mmio);
-    memory_region_destroy(&d->io_bar);
     timer_del(d->state.poll_timer);
     timer_free(d->state.poll_timer);
     qemu_del_nic(d->state.nic);
hw/net/rtl8139.c +0 -2
index 90bc5ec..6e59f38 100644
@@ -3462,8 +3462,6 @@ static void pci_rtl8139_uninit(PCIDevice *dev)
 {
     RTL8139State *s = RTL8139(dev);
 
-    memory_region_destroy(&s->bar_io);
-    memory_region_destroy(&s->bar_mem);
     if (s->cplus_txbuffer) {
         g_free(s->cplus_txbuffer);
         s->cplus_txbuffer = NULL;
hw/net/stellaris_enet.c +0 -8
index c9ee5d3..c07e513 100644
@@ -485,13 +485,6 @@ static int stellaris_enet_init(SysBusDevice *sbd)
     return 0;
 }
 
-static void stellaris_enet_unrealize(DeviceState *dev, Error **errp)
-{
-    stellaris_enet_state *s = STELLARIS_ENET(dev);
-
-    memory_region_destroy(&s->mmio);
-}
-
 static Property stellaris_enet_properties[] = {
     DEFINE_NIC_PROPERTIES(stellaris_enet_state, conf),
     DEFINE_PROP_END_OF_LIST(),
@@ -503,7 +496,6 @@ static void stellaris_enet_class_init(ObjectClass *klass, void *data)
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = stellaris_enet_init;
-    dc->unrealize = stellaris_enet_unrealize;
     dc->props = stellaris_enet_properties;
     dc->vmsd = &vmstate_stellaris_enet;
 }
hw/net/vmxnet3.c +0 -4
index 77bea6f..f11525c 100644
@@ -2182,10 +2182,6 @@ static void vmxnet3_pci_uninit(PCIDevice *pci_dev)
     vmxnet3_cleanup_msix(s);
 
     vmxnet3_cleanup_msi(s);
-
-    memory_region_destroy(&s->bar0);
-    memory_region_destroy(&s->bar1);
-    memory_region_destroy(&s->msix_bar);
 }
 
 static void vmxnet3_qdev_reset(DeviceState *dev)
hw/pci-bridge/pci_bridge_dev.c +0 -2
index e68145c..92799d0 100644
@@ -81,7 +81,6 @@ msi_error:
 slotid_error:
     shpc_cleanup(dev, &bridge_dev->bar);
 shpc_error:
-    memory_region_destroy(&bridge_dev->bar);
     pci_bridge_exitfn(dev);
 bridge_error:
     return err;
@@ -95,7 +94,6 @@ static void pci_bridge_dev_exitfn(PCIDevice *dev)
     }
     slotid_cap_cleanup(dev);
     shpc_cleanup(dev, &bridge_dev->bar);
-    memory_region_destroy(&bridge_dev->bar);
     pci_bridge_exitfn(dev);
 }
 
hw/pci/msix.c +0 -4
index 5c49bfc..3c07d22 100644
@@ -319,7 +319,6 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
                     bar_nr, MSIX_EXCLUSIVE_BAR_PBA_OFFSET,
                     MSIX_EXCLUSIVE_CAP_OFFSET);
     if (ret) {
-        memory_region_destroy(&dev->msix_exclusive_bar);
         return ret;
     }
 
@@ -359,11 +358,9 @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar)
     msix_free_irq_entries(dev);
     dev->msix_entries_nr = 0;
     memory_region_del_subregion(pba_bar, &dev->msix_pba_mmio);
-    memory_region_destroy(&dev->msix_pba_mmio);
     g_free(dev->msix_pba);
     dev->msix_pba = NULL;
     memory_region_del_subregion(table_bar, &dev->msix_table_mmio);
-    memory_region_destroy(&dev->msix_table_mmio);
     g_free(dev->msix_table);
     dev->msix_table = NULL;
     g_free(dev->msix_entry_used);
@@ -375,7 +372,6 @@ void msix_uninit_exclusive_bar(PCIDevice *dev)
 {
     if (msix_present(dev)) {
         msix_uninit(dev, &dev->msix_exclusive_bar, &dev->msix_exclusive_bar);
-        memory_region_destroy(&dev->msix_exclusive_bar);
     }
 }
 
hw/pci/pci.c +0 -2
index 351d320..daeaeac 100644
@@ -799,7 +799,6 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
     pci_config_free(pci_dev);
 
     address_space_destroy(&pci_dev->bus_master_as);
-    memory_region_destroy(&pci_dev->bus_master_enable_region);
 }
 
 /* -1 for devfn means auto assign */
@@ -1996,7 +1995,6 @@ static void pci_del_option_rom(PCIDevice *pdev)
         return;
 
     vmstate_unregister_ram(&pdev->rom, &pdev->qdev);
-    memory_region_destroy(&pdev->rom);
     pdev->has_rom = false;
 }
 
hw/pci/pci_bridge.c +0 -8
index 4becdc1..1307265 100644
@@ -219,12 +219,6 @@ static void pci_bridge_region_del(PCIBridge *br, PCIBridgeWindows *w)
 
 static void pci_bridge_region_cleanup(PCIBridge *br, PCIBridgeWindows *w)
 {
-    memory_region_destroy(&w->alias_io);
-    memory_region_destroy(&w->alias_mem);
-    memory_region_destroy(&w->alias_pref_mem);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_IO_LO]);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_IO_HI]);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_MEM]);
     g_free(w);
 }
 
@@ -389,8 +383,6 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
     QLIST_REMOVE(&s->sec_bus, sibling);
     pci_bridge_region_del(s, s->windows);
     pci_bridge_region_cleanup(s, s->windows);
-    memory_region_destroy(&s->address_space_mem);
-    memory_region_destroy(&s->address_space_io);
     /* object_unparent() is called automatically during device deletion */
 }
 
hw/pci/pcie_host.c +0 -1
index 7c88a1d..3db038f 100644
@@ -94,7 +94,6 @@ void pcie_host_mmcfg_unmap(PCIExpressHost *e)
 {
     if (e->base_addr != PCIE_BASE_ADDR_UNMAPPED) {
         memory_region_del_subregion(get_system_memory(), &e->mmio);
-        memory_region_destroy(&e->mmio);
         e->base_addr = PCIE_BASE_ADDR_UNMAPPED;
     }
 }
hw/pci/shpc.c +0 -1
index 180faa7..1fcb8c4 100644
@@ -667,7 +667,6 @@ void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
     g_free(shpc->cmask);
     g_free(shpc->wmask);
     g_free(shpc->w1cmask);
-    memory_region_destroy(&shpc->mmio);
     g_free(shpc);
 }
 
hw/scsi/esp-pci.c +0 -1
index 9971bbf..82795e6 100644
@@ -378,7 +378,6 @@ static void esp_pci_scsi_uninit(PCIDevice *d)
     PCIESPState *pci = PCI_ESP(d);
 
     qemu_free_irq(pci->esp.irq);
-    memory_region_destroy(&pci->io);
 }
 
 static void esp_pci_class_init(ObjectClass *klass, void *data)
hw/scsi/lsi53c895a.c +0 -10
index 786d848..513ea47 100644
@@ -2072,15 +2072,6 @@ static const VMStateDescription vmstate_lsi_scsi = {
     }
 };
 
-static void lsi_scsi_uninit(PCIDevice *d)
-{
-    LSIState *s = LSI53C895A(d);
-
-    memory_region_destroy(&s->mmio_io);
-    memory_region_destroy(&s->ram_io);
-    memory_region_destroy(&s->io_io);
-}
-
 static const struct SCSIBusInfo lsi_scsi_info = {
     .tcq = true,
     .max_target = LSI_MAX_DEVS,
@@ -2134,7 +2125,6 @@ static void lsi_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = lsi_scsi_init;
-    k->exit = lsi_scsi_uninit;
     k->vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
     k->device_id = PCI_DEVICE_ID_LSI_53C895A;
     k->class_id = PCI_CLASS_STORAGE_SCSI;
hw/scsi/megasas.c +0 -3
index c68a873..eedc992 100644
@@ -2129,9 +2129,6 @@ static void megasas_scsi_uninit(PCIDevice *d)
     if (megasas_use_msi(s)) {
         msi_uninit(d);
     }
-    memory_region_destroy(&s->mmio_io);
-    memory_region_destroy(&s->port_io);
-    memory_region_destroy(&s->queue_io);
 }
 
 static const struct SCSIBusInfo megasas_scsi_info = {
hw/scsi/vmw_pvscsi.c +0 -3
index f9ed926..5734d19 100644
@@ -1087,7 +1087,6 @@ pvscsi_init(PCIDevice *pci_dev)
     s->completion_worker = qemu_bh_new(pvscsi_process_completion_queue, s);
     if (!s->completion_worker) {
         pvscsi_cleanup_msi(s);
-        memory_region_destroy(&s->io_space);
         return -ENOMEM;
     }
 
@@ -1107,8 +1106,6 @@ pvscsi_uninit(PCIDevice *pci_dev)
     qemu_bh_delete(s->completion_worker);
 
     pvscsi_cleanup_msi(s);
-
-    memory_region_destroy(&s->io_space);
 }
 
 static void
hw/tpm/tpm_tis.c +0 -1
index 6f0a4d2..d398c16 100644
@@ -901,7 +901,6 @@ static void tpm_tis_uninitfn(Object *obj)
     TPMState *s = TPM(obj);
 
     memory_region_del_subregion(get_system_memory(), &s->mmio);
-    memory_region_destroy(&s->mmio);
 }
 
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
hw/usb/hcd-uhci.c +0 -8
index c3bf72c..ee5f112 100644
@@ -1256,13 +1256,6 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
     return usb_uhci_common_initfn(dev);
 }
 
-static void usb_uhci_exit(PCIDevice *dev)
-{
-    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
-
-    memory_region_destroy(&s->io_bar);
-}
-
 static Property uhci_properties[] = {
     DEFINE_PROP_STRING("masterbus", UHCIState, masterbus),
     DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0),
@@ -1279,7 +1272,6 @@ static void uhci_class_init(ObjectClass *klass, void *data)
     UHCIInfo *info = data;
 
     k->init = info->initfn ? info->initfn : usb_uhci_common_initfn;
-    k->exit = info->unplug ? usb_uhci_exit : NULL;
     k->vendor_id = info->vendor_id;
     k->device_id = info->device_id;
     k->revision  = info->revision;
hw/virtio/virtio-pci.c +0 -3
index 3007319..ddb5da1 100644
@@ -1020,10 +1020,7 @@ static int virtio_pci_init(PCIDevice *pci_dev)
 
 static void virtio_pci_exit(PCIDevice *pci_dev)
 {
-    VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
-
     msix_uninit_exclusive_bar(pci_dev);
-    memory_region_destroy(&proxy->bar);
 }
 
 static void virtio_pci_reset(DeviceState *qdev)
hw/watchdog/wdt_i6300esb.c +0 -8
index b3d6f39..687c8b1 100644
@@ -425,13 +425,6 @@ static int i6300esb_init(PCIDevice *dev)
     return 0;
 }
 
-static void i6300esb_exit(PCIDevice *dev)
-{
-    I6300State *d = DO_UPCAST(I6300State, dev, dev);
-
-    memory_region_destroy(&d->io_mem);
-}
-
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -445,7 +438,6 @@ static void i6300esb_class_init(ObjectClass *klass, void *data)
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->init = i6300esb_init;
-    k->exit = i6300esb_exit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
hw/xen/xen_pt.c +0 -20
index be4220b..c1bf357 100644
@@ -453,25 +453,6 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s)
     return 0;
 }
 
-static void xen_pt_unregister_regions(XenPCIPassthroughState *s)
-{
-    XenHostPCIDevice *d = &s->real_device;
-    int i;
-
-    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
-        XenHostPCIIORegion *r = &d->io_regions[i];
-
-        if (r->base_addr == 0 || r->size == 0) {
-            continue;
-        }
-
-        memory_region_destroy(&s->bar[i]);
-    }
-    if (d->rom.base_addr && d->rom.size) {
-        memory_region_destroy(&s->rom);
-    }
-}
-
 /* region mapping */
 
 static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
@@ -810,7 +791,6 @@ static void xen_pt_unregister_device(PCIDevice *d)
     /* delete all emulated config registers */
     xen_pt_config_delete(s);
 
-    xen_pt_unregister_regions(s);
     memory_listener_unregister(&s->memory_listener);
     memory_listener_unregister(&s->io_listener);
 
hw/xen/xen_pt_msi.c +0 -2
index 12b4c45..9ed9321 100644
@@ -593,7 +593,6 @@ int xen_pt_msix_init(XenPCIPassthroughState *s, uint32_t base)
     return 0;
 
 error_out:
-    memory_region_destroy(&msix->mmio);
     g_free(s->msix);
     s->msix = NULL;
     return rc;
@@ -616,7 +615,6 @@ void xen_pt_msix_delete(XenPCIPassthroughState *s)
     }
 
     memory_region_del_subregion(&s->bar[msix->bar_index], &msix->mmio);
-    memory_region_destroy(&msix->mmio);
 
     g_free(s->msix);
     s->msix = NULL;
include/exec/memory.h +0 -9
index e2c8e3e..5bd10d1 100644
@@ -430,15 +430,6 @@ void memory_region_init_iommu(MemoryRegion *mr,
                               uint64_t size);
 
 /**
- * memory_region_destroy: Destroy a memory region and reclaim all resources.
- *
- * @mr: the region to be destroyed.  May not currently be a subregion
- *      (see memory_region_add_subregion()) or referenced in an alias
- *      (see memory_region_init_alias()).
- */
-void memory_region_destroy(MemoryRegion *mr);
-
-/**
  * memory_region_owner: get a memory region's owner.
  *
  * @mr: the memory region being queried.
memory.c +0 -5
index 23c5269..f11c035 100644
@@ -1264,11 +1264,6 @@ static void memory_region_finalize(Object *obj)
     g_free(mr->ioeventfds);
 }
 
-void memory_region_destroy(MemoryRegion *mr)
-{
-}
-
-
 Object *memory_region_owner(MemoryRegion *mr)
 {
     Object *obj = OBJECT(mr);
Signature · 1 line
1.8.3.1
Acked-by on v1 8/9
#17 lore raw
Quoted 2 lines · Paolo Bonzini

The function is empty after the previous patch, so remove it.

So the bulk of this affects the PCI teardown process which i'm not hugely familiar with but looks largely ok. Especially the few non-PCI bits in there (hostmem, stellaris etc).

Quoted 1 line
Quoted 871 lines
---
 backends/hostmem.c             | 10 ----------
 hw/audio/ac97.c                |  9 ---------
 hw/audio/es1370.c              |  8 --------
 hw/audio/intel-hda.c           |  1 -
 hw/block/nvme.c                |  1 -
 hw/block/pflash_cfi01.c        |  1 -
 hw/block/pflash_cfi02.c        |  1 -
 hw/char/serial-pci.c           |  3 ---
 hw/i386/kvm/pci-assign.c       |  8 --------
 hw/ide/ahci.c                  |  2 --
 hw/ide/cmd646.c                |  5 -----
 hw/ide/piix.c                  |  3 ---
 hw/ide/via.c                   |  3 ---
 hw/ipack/tpci200.c             | 13 -------------
 hw/misc/ivshmem.c              |  3 ---
 hw/misc/pci-testdev.c          |  2 --
 hw/misc/vfio.c                 |  7 -------
 hw/net/e1000.c                 |  2 --
 hw/net/eepro100.c              |  3 ---
 hw/net/ne2000.c                |  1 -
 hw/net/pcnet-pci.c             |  2 --
 hw/net/rtl8139.c               |  2 --
 hw/net/stellaris_enet.c        |  8 --------
 hw/net/vmxnet3.c               |  4 ----
 hw/pci-bridge/pci_bridge_dev.c |  2 --
 hw/pci/msix.c                  |  4 ----
 hw/pci/pci.c                   |  2 --
 hw/pci/pci_bridge.c            |  8 --------
 hw/pci/pcie_host.c             |  1 -
 hw/pci/shpc.c                  |  1 -
 hw/scsi/esp-pci.c              |  1 -
 hw/scsi/lsi53c895a.c           | 10 ----------
 hw/scsi/megasas.c              |  3 ---
 hw/scsi/vmw_pvscsi.c           |  3 ---
 hw/tpm/tpm_tis.c               |  1 -
 hw/usb/hcd-uhci.c              |  8 --------
 hw/virtio/virtio-pci.c         |  3 ---
 hw/watchdog/wdt_i6300esb.c     |  8 --------
 hw/xen/xen_pt.c                | 20 --------------------
 hw/xen/xen_pt_msi.c            |  2 --
 include/exec/memory.h          |  9 ---------
 memory.c                       |  5 -----
 42 files changed, 193 deletions(-)
backends/hostmem.c +0 -10
index ca10c51..e7eec37 100644
@@ -257,15 +257,6 @@ static void host_memory_backend_init(Object *obj)
                         host_memory_backend_set_policy, NULL, NULL, NULL);
 }
 
-static void host_memory_backend_finalize(Object *obj)
-{
-    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
-
-    if (memory_region_size(&backend->mr)) {
-        memory_region_destroy(&backend->mr);
-    }
-}
-
 MemoryRegion *
 host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
 {
@@ -360,7 +351,6 @@ static const TypeInfo host_memory_backend_info = {
     .class_init = host_memory_backend_class_init,
     .instance_size = sizeof(HostMemoryBackend),
     .instance_init = host_memory_backend_init,
-    .instance_finalize = host_memory_backend_finalize,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
         { }
hw/audio/ac97.c +0 -9
index 45cb118..0e22bb9 100644
@@ -1388,14 +1388,6 @@ static int ac97_initfn (PCIDevice *dev)
     return 0;
 }
 
-static void ac97_exitfn (PCIDevice *dev)
-{
-    AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev);
-
-    memory_region_destroy (&s->io_nam);
-    memory_region_destroy (&s->io_nabm);
-}
-
 static int ac97_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "AC97");
@@ -1413,7 +1405,6 @@ static void ac97_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->init = ac97_initfn;
-    k->exit = ac97_exitfn;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
     k->revision = 0x01;
hw/audio/es1370.c +0 -8
index 5dbf803..e67d1ea 100644
@@ -1042,13 +1042,6 @@ static int es1370_initfn (PCIDevice *dev)
     return 0;
 }
 
-static void es1370_exitfn (PCIDevice *dev)
-{
-    ES1370State *s = DO_UPCAST (ES1370State, dev, dev);
-
-    memory_region_destroy (&s->io);
-}
-
 static int es1370_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "ES1370");
@@ -1061,7 +1054,6 @@ static void es1370_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->init = es1370_initfn;
-    k->exit = es1370_exitfn;
     k->vendor_id = PCI_VENDOR_ID_ENSONIQ;
     k->device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
     k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
hw/audio/intel-hda.c +0 -1
index aa49b47..aba45fc 100644
@@ -1155,7 +1155,6 @@ static void intel_hda_exit(PCIDevice *pci)
     IntelHDAState *d = INTEL_HDA(pci);
 
     msi_uninit(&d->pci);
-    memory_region_destroy(&d->mmio);
 }
 
 static int intel_hda_post_load(void *opaque, int version)
hw/block/nvme.c +0 -1
index 5fd8f89..6d9a065 100644
@@ -839,7 +839,6 @@ static void nvme_exit(PCIDevice *pci_dev)
     g_free(n->cq);
     g_free(n->sq);
     msix_uninit_exclusive_bar(pci_dev);
-    memory_region_destroy(&n->iomem);
 }
 
 static Property nvme_props[] = {
hw/block/pflash_cfi01.c +0 -1
index f9507b4..2238f39 100644
@@ -781,7 +781,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
 
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
-            memory_region_destroy(&pfl->mem);
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
hw/block/pflash_cfi02.c +0 -1
index 8d4b828..e196f4d 100644
@@ -617,7 +617,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
         ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9);
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl));
-            memory_region_destroy(&pfl->orig_mem);
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
hw/char/serial-pci.c +0 -3
index c133c33..f05c9b4 100644
@@ -135,7 +135,6 @@ static void serial_pci_exit(PCIDevice *dev)
     SerialState *s = &pci->state;
 
     serial_exit_core(s);
-    memory_region_destroy(&s->io);
     qemu_free_irq(s->irq);
 }
 
@@ -149,10 +148,8 @@ static void multi_serial_pci_exit(PCIDevice *dev)
         s = pci->state + i;
         serial_exit_core(s);
         memory_region_del_subregion(&pci->iobar, &s->io);
-        memory_region_destroy(&s->io);
         g_free(pci->name[i]);
     }
-    memory_region_destroy(&pci->iobar);
     qemu_free_irqs(pci->irqs, pci->ports);
 }
 
hw/i386/kvm/pci-assign.c +0 -8
index de33657..17c7d6dc 100644
@@ -697,8 +697,6 @@ static void free_assigned_device(AssignedDevice *dev)
             if (region->u.r_baseport) {
                 memory_region_del_subregion(&region->container,
                                             &region->real_iomem);
-                memory_region_destroy(&region->real_iomem);
-                memory_region_destroy(&region->container);
             }
         } else if (pci_region->type & IORESOURCE_MEM) {
             if (region->u.r_virtbase) {
@@ -712,9 +710,6 @@ static void free_assigned_device(AssignedDevice *dev)
                     memory_region_del_subregion(&region->container,
                                                 &dev->mmio);
                 }
-
-                memory_region_destroy(&region->real_iomem);
-                memory_region_destroy(&region->container);
                 if (munmap(region->u.r_virtbase,
                            (pci_region->size + 0xFFF) & 0xFFFFF000)) {
                     error_report("Failed to unmap assigned device region: %s",
@@ -1680,8 +1675,6 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
         return;
     }
 
-    memory_region_destroy(&dev->mmio);
-
     if (munmap(dev->msix_table, MSIX_PAGE_SIZE) == -1) {
         error_report("error unmapping msix_table! %s", strerror(errno));
     }
@@ -1953,7 +1946,6 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev)
         error_printf("Device option ROM contents are probably invalid "
                      "(check dmesg).\nSkip option ROM probe with rombar=0, "
                      "or load from file with romfile=\n");
-        memory_region_destroy(&dev->dev.rom);
         goto close_rom;
     }
 
hw/ide/ahci.c +0 -2
index 604152a..aa0ef42 100644
@@ -1197,8 +1197,6 @@ void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
 
 void ahci_uninit(AHCIState *s)
 {
-    memory_region_destroy(&s->mem);
-    memory_region_destroy(&s->idp);
     g_free(s->dev);
 }
 
hw/ide/cmd646.c +0 -5
index a8e35fe..1295ed0 100644
@@ -310,13 +310,8 @@ static void pci_cmd646_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->cmd646_bar[i].cmd);
-        memory_region_destroy(&d->cmd646_bar[i].data);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
hw/ide/piix.c +0 -3
index 8651726..59319eb 100644
@@ -207,11 +207,8 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 /* hd_table must contain 4 block drivers */
hw/ide/via.c +0 -3
index 198123b..89d27b4 100644
@@ -198,11 +198,8 @@ static void vt82c686b_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
hw/ipack/tpci200.c +0 -13
index 42ca923..b7031a0 100644
@@ -613,18 +613,6 @@ static int tpci200_initfn(PCIDevice *pci_dev)
     return 0;
 }
 
-static void tpci200_exitfn(PCIDevice *pci_dev)
-{
-    TPCI200State *s = TPCI200(pci_dev);
-
-    memory_region_destroy(&s->mmio);
-    memory_region_destroy(&s->io);
-    memory_region_destroy(&s->las0);
-    memory_region_destroy(&s->las1);
-    memory_region_destroy(&s->las2);
-    memory_region_destroy(&s->las3);
-}
-
 static const VMStateDescription vmstate_tpci200 = {
     .name = "tpci200",
     .version_id = 1,
@@ -645,7 +633,6 @@ static void tpci200_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = tpci200_initfn;
-    k->exit = tpci200_exitfn;
     k->vendor_id = PCI_VENDOR_ID_TEWS;
     k->device_id = PCI_DEVICE_ID_TEWS_TPCI200;
     k->class_id = PCI_CLASS_BRIDGE_OTHER;
hw/misc/ivshmem.c +0 -3
index 768e528..156edd2 100644
@@ -789,11 +789,8 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         error_free(s->migration_blocker);
     }
 
-    memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
     vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
-    memory_region_destroy(&s->ivshmem);
-    memory_region_destroy(&s->bar);
     unregister_savevm(DEVICE(dev), "ivshmem", s);
 }
 
hw/misc/pci-testdev.c +0 -2
index ca53b3f..c78a63e 100644
@@ -293,8 +293,6 @@ pci_testdev_uninit(PCIDevice *dev)
         g_free(d->tests[i].hdr);
     }
     g_free(d->tests);
-    memory_region_destroy(&d->mmio);
-    memory_region_destroy(&d->portio);
 }
 
 static void qdev_pci_testdev_reset(DeviceState *dev)
hw/misc/vfio.c +0 -7
index af9ae1f..813c2cc 100644
@@ -2857,15 +2857,11 @@ static void vfio_unmap_bar(VFIODevice *vdev, int nr)
 
     memory_region_del_subregion(&bar->mem, &bar->mmap_mem);
     munmap(bar->mmap, memory_region_size(&bar->mmap_mem));
-    memory_region_destroy(&bar->mmap_mem);
 
     if (vdev->msix && vdev->msix->table_bar == nr) {
         memory_region_del_subregion(&bar->mem, &vdev->msix->mmap_mem);
         munmap(vdev->msix->mmap, memory_region_size(&vdev->msix->mmap_mem));
-        memory_region_destroy(&vdev->msix->mmap_mem);
     }
-
-    memory_region_destroy(&bar->mem);
 }
 
 static int vfio_mmap_bar(VFIODevice *vdev, VFIOBAR *bar,
@@ -3018,9 +3014,6 @@ static void vfio_unmap_bars(VFIODevice *vdev)
     if (vdev->has_vga) {
         vfio_vga_quirk_teardown(vdev);
         pci_unregister_vga(&vdev->pdev);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_MEM].mem);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_IO_LO].mem);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_IO_HI].mem);
     }
 }
 
hw/net/e1000.c +0 -2
index 0fc29a0..21c38fa 100644
@@ -1496,8 +1496,6 @@ pci_e1000_uninit(PCIDevice *dev)
     timer_free(d->autoneg_timer);
     timer_del(d->mit_timer);
     timer_free(d->mit_timer);
-    memory_region_destroy(&d->mmio);
-    memory_region_destroy(&d->io);
     qemu_del_nic(d->nic);
 }
 
hw/net/eepro100.c +0 -3
index 3263e3f..3cd826a 100644
@@ -1843,9 +1843,6 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
 {
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 
-    memory_region_destroy(&s->mmio_bar);
-    memory_region_destroy(&s->io_bar);
-    memory_region_destroy(&s->flash_bar);
     vmstate_unregister(&pci_dev->qdev, s->vmstate, s);
     eeprom93xx_free(&pci_dev->qdev, s->eeprom);
     qemu_del_nic(s->nic);
hw/net/ne2000.c +0 -1
index d558b8c..a62d12d 100644
@@ -748,7 +748,6 @@ static void pci_ne2000_exit(PCIDevice *pci_dev)
     PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
     NE2000State *s = &d->ne2000;
 
-    memory_region_destroy(&s->io);
     qemu_del_nic(s->nic);
     qemu_free_irq(s->irq);
 }
hw/net/pcnet-pci.c +0 -2
index b25d789..50ffe91 100644
@@ -282,8 +282,6 @@ static void pci_pcnet_uninit(PCIDevice *dev)
     PCIPCNetState *d = PCI_PCNET(dev);
 
     qemu_free_irq(d->state.irq);
-    memory_region_destroy(&d->state.mmio);
-    memory_region_destroy(&d->io_bar);
     timer_del(d->state.poll_timer);
     timer_free(d->state.poll_timer);
     qemu_del_nic(d->state.nic);
hw/net/rtl8139.c +0 -2
index 90bc5ec..6e59f38 100644
@@ -3462,8 +3462,6 @@ static void pci_rtl8139_uninit(PCIDevice *dev)
 {
     RTL8139State *s = RTL8139(dev);
 
-    memory_region_destroy(&s->bar_io);
-    memory_region_destroy(&s->bar_mem);
     if (s->cplus_txbuffer) {
         g_free(s->cplus_txbuffer);
         s->cplus_txbuffer = NULL;
hw/net/stellaris_enet.c +0 -8
index c9ee5d3..c07e513 100644
@@ -485,13 +485,6 @@ static int stellaris_enet_init(SysBusDevice *sbd)
     return 0;
 }
 
-static void stellaris_enet_unrealize(DeviceState *dev, Error **errp)
-{
-    stellaris_enet_state *s = STELLARIS_ENET(dev);
-
-    memory_region_destroy(&s->mmio);
-}
-
 static Property stellaris_enet_properties[] = {
     DEFINE_NIC_PROPERTIES(stellaris_enet_state, conf),
     DEFINE_PROP_END_OF_LIST(),
@@ -503,7 +496,6 @@ static void stellaris_enet_class_init(ObjectClass *klass, void *data)
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = stellaris_enet_init;
-    dc->unrealize = stellaris_enet_unrealize;
     dc->props = stellaris_enet_properties;
     dc->vmsd = &vmstate_stellaris_enet;
 }
hw/net/vmxnet3.c +0 -4
index 77bea6f..f11525c 100644
@@ -2182,10 +2182,6 @@ static void vmxnet3_pci_uninit(PCIDevice *pci_dev)
     vmxnet3_cleanup_msix(s);
 
     vmxnet3_cleanup_msi(s);
-
-    memory_region_destroy(&s->bar0);
-    memory_region_destroy(&s->bar1);
-    memory_region_destroy(&s->msix_bar);
 }
 
 static void vmxnet3_qdev_reset(DeviceState *dev)
hw/pci-bridge/pci_bridge_dev.c +0 -2
index e68145c..92799d0 100644
@@ -81,7 +81,6 @@ msi_error:
 slotid_error:
     shpc_cleanup(dev, &bridge_dev->bar);
 shpc_error:
-    memory_region_destroy(&bridge_dev->bar);
     pci_bridge_exitfn(dev);
 bridge_error:
     return err;
@@ -95,7 +94,6 @@ static void pci_bridge_dev_exitfn(PCIDevice *dev)
     }
     slotid_cap_cleanup(dev);
     shpc_cleanup(dev, &bridge_dev->bar);
-    memory_region_destroy(&bridge_dev->bar);
     pci_bridge_exitfn(dev);
 }
 
hw/pci/msix.c +0 -4
index 5c49bfc..3c07d22 100644
@@ -319,7 +319,6 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
                     bar_nr, MSIX_EXCLUSIVE_BAR_PBA_OFFSET,
                     MSIX_EXCLUSIVE_CAP_OFFSET);
     if (ret) {
-        memory_region_destroy(&dev->msix_exclusive_bar);
         return ret;
     }
 
@@ -359,11 +358,9 @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar)
     msix_free_irq_entries(dev);
     dev->msix_entries_nr = 0;
     memory_region_del_subregion(pba_bar, &dev->msix_pba_mmio);
-    memory_region_destroy(&dev->msix_pba_mmio);
     g_free(dev->msix_pba);
     dev->msix_pba = NULL;
     memory_region_del_subregion(table_bar, &dev->msix_table_mmio);
-    memory_region_destroy(&dev->msix_table_mmio);
     g_free(dev->msix_table);
     dev->msix_table = NULL;
     g_free(dev->msix_entry_used);
@@ -375,7 +372,6 @@ void msix_uninit_exclusive_bar(PCIDevice *dev)
 {
     if (msix_present(dev)) {
         msix_uninit(dev, &dev->msix_exclusive_bar, &dev->msix_exclusive_bar);
-        memory_region_destroy(&dev->msix_exclusive_bar);
     }
 }
 
hw/pci/pci.c +0 -2
index 351d320..daeaeac 100644
@@ -799,7 +799,6 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
     pci_config_free(pci_dev);
 
     address_space_destroy(&pci_dev->bus_master_as);
-    memory_region_destroy(&pci_dev->bus_master_enable_region);
 }
 
 /* -1 for devfn means auto assign */
@@ -1996,7 +1995,6 @@ static void pci_del_option_rom(PCIDevice *pdev)
         return;
 
     vmstate_unregister_ram(&pdev->rom, &pdev->qdev);
-    memory_region_destroy(&pdev->rom);
     pdev->has_rom = false;
 }
 
hw/pci/pci_bridge.c +0 -8
index 4becdc1..1307265 100644
@@ -219,12 +219,6 @@ static void pci_bridge_region_del(PCIBridge *br, PCIBridgeWindows *w)
 
 static void pci_bridge_region_cleanup(PCIBridge *br, PCIBridgeWindows *w)
 {
-    memory_region_destroy(&w->alias_io);
-    memory_region_destroy(&w->alias_mem);
-    memory_region_destroy(&w->alias_pref_mem);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_IO_LO]);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_IO_HI]);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_MEM]);
     g_free(w);
 }
 
@@ -389,8 +383,6 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
     QLIST_REMOVE(&s->sec_bus, sibling);
     pci_bridge_region_del(s, s->windows);
     pci_bridge_region_cleanup(s, s->windows);
-    memory_region_destroy(&s->address_space_mem);
-    memory_region_destroy(&s->address_space_io);
     /* object_unparent() is called automatically during device deletion */
 }
 
hw/pci/pcie_host.c +0 -1
index 7c88a1d..3db038f 100644
@@ -94,7 +94,6 @@ void pcie_host_mmcfg_unmap(PCIExpressHost *e)
 {
     if (e->base_addr != PCIE_BASE_ADDR_UNMAPPED) {
         memory_region_del_subregion(get_system_memory(), &e->mmio);
-        memory_region_destroy(&e->mmio);
         e->base_addr = PCIE_BASE_ADDR_UNMAPPED;
     }
 }
hw/pci/shpc.c +0 -1
index 180faa7..1fcb8c4 100644
@@ -667,7 +667,6 @@ void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
     g_free(shpc->cmask);
     g_free(shpc->wmask);
     g_free(shpc->w1cmask);
-    memory_region_destroy(&shpc->mmio);
     g_free(shpc);
 }
 
hw/scsi/esp-pci.c +0 -1
index 9971bbf..82795e6 100644
@@ -378,7 +378,6 @@ static void esp_pci_scsi_uninit(PCIDevice *d)
     PCIESPState *pci = PCI_ESP(d);
 
     qemu_free_irq(pci->esp.irq);
-    memory_region_destroy(&pci->io);
 }
 
 static void esp_pci_class_init(ObjectClass *klass, void *data)
hw/scsi/lsi53c895a.c +0 -10
index 786d848..513ea47 100644
@@ -2072,15 +2072,6 @@ static const VMStateDescription vmstate_lsi_scsi = {
     }
 };
 
-static void lsi_scsi_uninit(PCIDevice *d)
-{
-    LSIState *s = LSI53C895A(d);
-
-    memory_region_destroy(&s->mmio_io);
-    memory_region_destroy(&s->ram_io);
-    memory_region_destroy(&s->io_io);
-}
-
 static const struct SCSIBusInfo lsi_scsi_info = {
     .tcq = true,
     .max_target = LSI_MAX_DEVS,
@@ -2134,7 +2125,6 @@ static void lsi_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = lsi_scsi_init;
-    k->exit = lsi_scsi_uninit;
     k->vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
     k->device_id = PCI_DEVICE_ID_LSI_53C895A;
     k->class_id = PCI_CLASS_STORAGE_SCSI;
hw/scsi/megasas.c +0 -3
index c68a873..eedc992 100644
@@ -2129,9 +2129,6 @@ static void megasas_scsi_uninit(PCIDevice *d)
     if (megasas_use_msi(s)) {
         msi_uninit(d);
     }
-    memory_region_destroy(&s->mmio_io);
-    memory_region_destroy(&s->port_io);
-    memory_region_destroy(&s->queue_io);
 }
 
 static const struct SCSIBusInfo megasas_scsi_info = {
hw/scsi/vmw_pvscsi.c +0 -3
index f9ed926..5734d19 100644
@@ -1087,7 +1087,6 @@ pvscsi_init(PCIDevice *pci_dev)
     s->completion_worker = qemu_bh_new(pvscsi_process_completion_queue, s);
     if (!s->completion_worker) {
         pvscsi_cleanup_msi(s);
-        memory_region_destroy(&s->io_space);
         return -ENOMEM;
     }
 
@@ -1107,8 +1106,6 @@ pvscsi_uninit(PCIDevice *pci_dev)
     qemu_bh_delete(s->completion_worker);
 
     pvscsi_cleanup_msi(s);
-
-    memory_region_destroy(&s->io_space);
 }
 
 static void
hw/tpm/tpm_tis.c +0 -1
index 6f0a4d2..d398c16 100644
@@ -901,7 +901,6 @@ static void tpm_tis_uninitfn(Object *obj)
     TPMState *s = TPM(obj);
 
     memory_region_del_subregion(get_system_memory(), &s->mmio);
-    memory_region_destroy(&s->mmio);
 }
 
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
hw/usb/hcd-uhci.c +0 -8
index c3bf72c..ee5f112 100644
@@ -1256,13 +1256,6 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
     return usb_uhci_common_initfn(dev);
 }
 
-static void usb_uhci_exit(PCIDevice *dev)
-{
-    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
-
-    memory_region_destroy(&s->io_bar);
-}
-
 static Property uhci_properties[] = {
     DEFINE_PROP_STRING("masterbus", UHCIState, masterbus),
     DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0),
@@ -1279,7 +1272,6 @@ static void uhci_class_init(ObjectClass *klass, void *data)
     UHCIInfo *info = data;
 
     k->init = info->initfn ? info->initfn : usb_uhci_common_initfn;
-    k->exit = info->unplug ? usb_uhci_exit : NULL;
     k->vendor_id = info->vendor_id;
     k->device_id = info->device_id;
     k->revision  = info->revision;
hw/virtio/virtio-pci.c +0 -3
index 3007319..ddb5da1 100644
@@ -1020,10 +1020,7 @@ static int virtio_pci_init(PCIDevice *pci_dev)
 
 static void virtio_pci_exit(PCIDevice *pci_dev)
 {
-    VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
-
     msix_uninit_exclusive_bar(pci_dev);
-    memory_region_destroy(&proxy->bar);
 }
 
 static void virtio_pci_reset(DeviceState *qdev)
hw/watchdog/wdt_i6300esb.c +0 -8
index b3d6f39..687c8b1 100644
@@ -425,13 +425,6 @@ static int i6300esb_init(PCIDevice *dev)
     return 0;
 }
 
-static void i6300esb_exit(PCIDevice *dev)
-{
-    I6300State *d = DO_UPCAST(I6300State, dev, dev);
-
-    memory_region_destroy(&d->io_mem);
-}
-
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -445,7 +438,6 @@ static void i6300esb_class_init(ObjectClass *klass, void *data)
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->init = i6300esb_init;
-    k->exit = i6300esb_exit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
hw/xen/xen_pt.c +0 -20
index be4220b..c1bf357 100644
@@ -453,25 +453,6 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s)
     return 0;
 }
 
-static void xen_pt_unregister_regions(XenPCIPassthroughState *s)
-{
-    XenHostPCIDevice *d = &s->real_device;
-    int i;
-
-    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
-        XenHostPCIIORegion *r = &d->io_regions[i];
-
-        if (r->base_addr == 0 || r->size == 0) {
-            continue;
-        }
-
-        memory_region_destroy(&s->bar[i]);
-    }
-    if (d->rom.base_addr && d->rom.size) {
-        memory_region_destroy(&s->rom);
-    }
-}
-
 /* region mapping */
 
 static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
@@ -810,7 +791,6 @@ static void xen_pt_unregister_device(PCIDevice *d)
     /* delete all emulated config registers */
     xen_pt_config_delete(s);
 
-    xen_pt_unregister_regions(s);
     memory_listener_unregister(&s->memory_listener);
     memory_listener_unregister(&s->io_listener);
 
hw/xen/xen_pt_msi.c +0 -2
index 12b4c45..9ed9321 100644
@@ -593,7 +593,6 @@ int xen_pt_msix_init(XenPCIPassthroughState *s, uint32_t base)
     return 0;
 
 error_out:
-    memory_region_destroy(&msix->mmio);
     g_free(s->msix);
     s->msix = NULL;
     return rc;
@@ -616,7 +615,6 @@ void xen_pt_msix_delete(XenPCIPassthroughState *s)
     }
 
     memory_region_del_subregion(&s->bar[msix->bar_index], &msix->mmio);
-    memory_region_destroy(&msix->mmio);
 
     g_free(s->msix);
     s->msix = NULL;
include/exec/memory.h +0 -9
index e2c8e3e..5bd10d1 100644
@@ -430,15 +430,6 @@ void memory_region_init_iommu(MemoryRegion *mr,
                               uint64_t size);
 
 /**
- * memory_region_destroy: Destroy a memory region and reclaim all resources.
- *
- * @mr: the region to be destroyed.  May not currently be a subregion
- *      (see memory_region_add_subregion()) or referenced in an alias
- *      (see memory_region_init_alias()).
- */
-void memory_region_destroy(MemoryRegion *mr);
-
-/**
  * memory_region_owner: get a memory region's owner.
  *
  * @mr: the memory region being queried.
memory.c +0 -6
index 23c5269..f11c035 100644
@@ -1264,11 +1264,6 @@ static void memory_region_finalize(Object *obj)
     g_free(mr->ioeventfds);
 }
 
-void memory_region_destroy(MemoryRegion *mr)
-{
-}
-
-
 Object *memory_region_owner(MemoryRegion *mr)
 {
     Object *obj = OBJECT(mr);
--

1.8.3.1

Reviewed-by
#18 lore raw
Quoted 11 lines · Peter Crosthwaite
Quoted 2 lines · Paolo Bonzini

The function is empty after the previous patch, so remove it.

So the bulk of this affects the PCI teardown process which i'm not hugely familiar with but looks largely ok. Especially the few non-PCI bits in there (hostmem, stellaris etc).

Quoted 1 line

Had a closer look at this:

Quoted 872 lines
Quoted 872 lines
---
 backends/hostmem.c             | 10 ----------
 hw/audio/ac97.c                |  9 ---------
 hw/audio/es1370.c              |  8 --------
 hw/audio/intel-hda.c           |  1 -
 hw/block/nvme.c                |  1 -
 hw/block/pflash_cfi01.c        |  1 -
 hw/block/pflash_cfi02.c        |  1 -
 hw/char/serial-pci.c           |  3 ---
 hw/i386/kvm/pci-assign.c       |  8 --------
 hw/ide/ahci.c                  |  2 --
 hw/ide/cmd646.c                |  5 -----
 hw/ide/piix.c                  |  3 ---
 hw/ide/via.c                   |  3 ---
 hw/ipack/tpci200.c             | 13 -------------
 hw/misc/ivshmem.c              |  3 ---
 hw/misc/pci-testdev.c          |  2 --
 hw/misc/vfio.c                 |  7 -------
 hw/net/e1000.c                 |  2 --
 hw/net/eepro100.c              |  3 ---
 hw/net/ne2000.c                |  1 -
 hw/net/pcnet-pci.c             |  2 --
 hw/net/rtl8139.c               |  2 --
 hw/net/stellaris_enet.c        |  8 --------
 hw/net/vmxnet3.c               |  4 ----
 hw/pci-bridge/pci_bridge_dev.c |  2 --
 hw/pci/msix.c                  |  4 ----
 hw/pci/pci.c                   |  2 --
 hw/pci/pci_bridge.c            |  8 --------
 hw/pci/pcie_host.c             |  1 -
 hw/pci/shpc.c                  |  1 -
 hw/scsi/esp-pci.c              |  1 -
 hw/scsi/lsi53c895a.c           | 10 ----------
 hw/scsi/megasas.c              |  3 ---
 hw/scsi/vmw_pvscsi.c           |  3 ---
 hw/tpm/tpm_tis.c               |  1 -
 hw/usb/hcd-uhci.c              |  8 --------
 hw/virtio/virtio-pci.c         |  3 ---
 hw/watchdog/wdt_i6300esb.c     |  8 --------
 hw/xen/xen_pt.c                | 20 --------------------
 hw/xen/xen_pt_msi.c            |  2 --
 include/exec/memory.h          |  9 ---------
 memory.c                       |  5 -----
 42 files changed, 193 deletions(-)
backends/hostmem.c +0 -10
index ca10c51..e7eec37 100644
@@ -257,15 +257,6 @@ static void host_memory_backend_init(Object *obj)
                         host_memory_backend_set_policy, NULL, NULL, NULL);
 }
 
-static void host_memory_backend_finalize(Object *obj)
-{
-    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
-
-    if (memory_region_size(&backend->mr)) {
-        memory_region_destroy(&backend->mr);
-    }
-}
-
 MemoryRegion *
 host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
 {
@@ -360,7 +351,6 @@ static const TypeInfo host_memory_backend_info = {
     .class_init = host_memory_backend_class_init,
     .instance_size = sizeof(HostMemoryBackend),
     .instance_init = host_memory_backend_init,
-    .instance_finalize = host_memory_backend_finalize,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
         { }
hw/audio/ac97.c +0 -9
index 45cb118..0e22bb9 100644
@@ -1388,14 +1388,6 @@ static int ac97_initfn (PCIDevice *dev)
     return 0;
 }
 
-static void ac97_exitfn (PCIDevice *dev)
-{
-    AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev);
-
-    memory_region_destroy (&s->io_nam);
-    memory_region_destroy (&s->io_nabm);
-}
-
 static int ac97_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "AC97");
@@ -1413,7 +1405,6 @@ static void ac97_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->init = ac97_initfn;
-    k->exit = ac97_exitfn;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
     k->revision = 0x01;
hw/audio/es1370.c +0 -8
index 5dbf803..e67d1ea 100644
@@ -1042,13 +1042,6 @@ static int es1370_initfn (PCIDevice *dev)
     return 0;
 }
 
-static void es1370_exitfn (PCIDevice *dev)
-{
-    ES1370State *s = DO_UPCAST (ES1370State, dev, dev);
-
-    memory_region_destroy (&s->io);
-}
-
 static int es1370_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "ES1370");
@@ -1061,7 +1054,6 @@ static void es1370_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->init = es1370_initfn;
-    k->exit = es1370_exitfn;
     k->vendor_id = PCI_VENDOR_ID_ENSONIQ;
     k->device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
     k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
hw/audio/intel-hda.c +0 -1
index aa49b47..aba45fc 100644
@@ -1155,7 +1155,6 @@ static void intel_hda_exit(PCIDevice *pci)
     IntelHDAState *d = INTEL_HDA(pci);
 
     msi_uninit(&d->pci);
-    memory_region_destroy(&d->mmio);
 }
 
 static int intel_hda_post_load(void *opaque, int version)
hw/block/nvme.c +0 -1
index 5fd8f89..6d9a065 100644
@@ -839,7 +839,6 @@ static void nvme_exit(PCIDevice *pci_dev)
     g_free(n->cq);
     g_free(n->sq);
     msix_uninit_exclusive_bar(pci_dev);
-    memory_region_destroy(&n->iomem);
 }
 
 static Property nvme_props[] = {
hw/block/pflash_cfi01.c +0 -1
index f9507b4..2238f39 100644
@@ -781,7 +781,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
 
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
-            memory_region_destroy(&pfl->mem);
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
hw/block/pflash_cfi02.c +0 -1
index 8d4b828..e196f4d 100644
@@ -617,7 +617,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
         ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9);
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl));
-            memory_region_destroy(&pfl->orig_mem);
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
hw/char/serial-pci.c +0 -3
index c133c33..f05c9b4 100644
@@ -135,7 +135,6 @@ static void serial_pci_exit(PCIDevice *dev)
     SerialState *s = &pci->state;
 
     serial_exit_core(s);
-    memory_region_destroy(&s->io);
     qemu_free_irq(s->irq);
 }
 
@@ -149,10 +148,8 @@ static void multi_serial_pci_exit(PCIDevice *dev)
         s = pci->state + i;
         serial_exit_core(s);
         memory_region_del_subregion(&pci->iobar, &s->io);
-        memory_region_destroy(&s->io);
         g_free(pci->name[i]);
     }
-    memory_region_destroy(&pci->iobar);
     qemu_free_irqs(pci->irqs, pci->ports);
 }
 
hw/i386/kvm/pci-assign.c +0 -8
index de33657..17c7d6dc 100644
@@ -697,8 +697,6 @@ static void free_assigned_device(AssignedDevice *dev)
             if (region->u.r_baseport) {
                 memory_region_del_subregion(&region->container,
                                             &region->real_iomem);
-                memory_region_destroy(&region->real_iomem);
-                memory_region_destroy(&region->container);
             }
         } else if (pci_region->type & IORESOURCE_MEM) {
             if (region->u.r_virtbase) {
@@ -712,9 +710,6 @@ static void free_assigned_device(AssignedDevice *dev)
                     memory_region_del_subregion(&region->container,
                                                 &dev->mmio);
                 }
-
-                memory_region_destroy(&region->real_iomem);
-                memory_region_destroy(&region->container);
                 if (munmap(region->u.r_virtbase,
                            (pci_region->size + 0xFFF) & 0xFFFFF000)) {
                     error_report("Failed to unmap assigned device region: %s",
@@ -1680,8 +1675,6 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
         return;
     }
 
-    memory_region_destroy(&dev->mmio);
-
     if (munmap(dev->msix_table, MSIX_PAGE_SIZE) == -1) {
         error_report("error unmapping msix_table! %s", strerror(errno));
     }
@@ -1953,7 +1946,6 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev)
         error_printf("Device option ROM contents are probably invalid "
                      "(check dmesg).\nSkip option ROM probe with rombar=0, "
                      "or load from file with romfile=\n");
-        memory_region_destroy(&dev->dev.rom);
         goto close_rom;
     }
 
hw/ide/ahci.c +0 -2
index 604152a..aa0ef42 100644
@@ -1197,8 +1197,6 @@ void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
 
 void ahci_uninit(AHCIState *s)
 {
-    memory_region_destroy(&s->mem);
-    memory_region_destroy(&s->idp);
     g_free(s->dev);
 }
 
hw/ide/cmd646.c +0 -5
index a8e35fe..1295ed0 100644
@@ -310,13 +310,8 @@ static void pci_cmd646_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->cmd646_bar[i].cmd);
-        memory_region_destroy(&d->cmd646_bar[i].data);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
hw/ide/piix.c +0 -3
index 8651726..59319eb 100644
@@ -207,11 +207,8 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 /* hd_table must contain 4 block drivers */
hw/ide/via.c +0 -3
index 198123b..89d27b4 100644
@@ -198,11 +198,8 @@ static void vt82c686b_ide_exitfn(PCIDevice *dev)
 
     for (i = 0; i < 2; ++i) {
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].extra_io);
-        memory_region_destroy(&d->bmdma[i].extra_io);
         memory_region_del_subregion(&d->bmdma_bar, &d->bmdma[i].addr_ioport);
-        memory_region_destroy(&d->bmdma[i].addr_ioport);
     }
-    memory_region_destroy(&d->bmdma_bar);
 }
 
 void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
hw/ipack/tpci200.c +0 -13
index 42ca923..b7031a0 100644
@@ -613,18 +613,6 @@ static int tpci200_initfn(PCIDevice *pci_dev)
     return 0;
 }
 
-static void tpci200_exitfn(PCIDevice *pci_dev)
-{
-    TPCI200State *s = TPCI200(pci_dev);
-
-    memory_region_destroy(&s->mmio);
-    memory_region_destroy(&s->io);
-    memory_region_destroy(&s->las0);
-    memory_region_destroy(&s->las1);
-    memory_region_destroy(&s->las2);
-    memory_region_destroy(&s->las3);
-}
-
 static const VMStateDescription vmstate_tpci200 = {
     .name = "tpci200",
     .version_id = 1,
@@ -645,7 +633,6 @@ static void tpci200_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = tpci200_initfn;
-    k->exit = tpci200_exitfn;
     k->vendor_id = PCI_VENDOR_ID_TEWS;
     k->device_id = PCI_DEVICE_ID_TEWS_TPCI200;
     k->class_id = PCI_CLASS_BRIDGE_OTHER;
hw/misc/ivshmem.c +0 -3
index 768e528..156edd2 100644
@@ -789,11 +789,8 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         error_free(s->migration_blocker);
     }
 
-    memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
     vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
-    memory_region_destroy(&s->ivshmem);
-    memory_region_destroy(&s->bar);
     unregister_savevm(DEVICE(dev), "ivshmem", s);
 }
 
hw/misc/pci-testdev.c +0 -2
index ca53b3f..c78a63e 100644
@@ -293,8 +293,6 @@ pci_testdev_uninit(PCIDevice *dev)
         g_free(d->tests[i].hdr);
     }
     g_free(d->tests);
-    memory_region_destroy(&d->mmio);
-    memory_region_destroy(&d->portio);
 }
 
 static void qdev_pci_testdev_reset(DeviceState *dev)
hw/misc/vfio.c +0 -7
index af9ae1f..813c2cc 100644
@@ -2857,15 +2857,11 @@ static void vfio_unmap_bar(VFIODevice *vdev, int nr)
 
     memory_region_del_subregion(&bar->mem, &bar->mmap_mem);
     munmap(bar->mmap, memory_region_size(&bar->mmap_mem));
-    memory_region_destroy(&bar->mmap_mem);
 
     if (vdev->msix && vdev->msix->table_bar == nr) {
         memory_region_del_subregion(&bar->mem, &vdev->msix->mmap_mem);
         munmap(vdev->msix->mmap, memory_region_size(&vdev->msix->mmap_mem));
-        memory_region_destroy(&vdev->msix->mmap_mem);
     }
-
-    memory_region_destroy(&bar->mem);
 }
 
 static int vfio_mmap_bar(VFIODevice *vdev, VFIOBAR *bar,
@@ -3018,9 +3014,6 @@ static void vfio_unmap_bars(VFIODevice *vdev)
     if (vdev->has_vga) {
         vfio_vga_quirk_teardown(vdev);
         pci_unregister_vga(&vdev->pdev);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_MEM].mem);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_IO_LO].mem);
-        memory_region_destroy(&vdev->vga.region[QEMU_PCI_VGA_IO_HI].mem);
     }
 }
 
hw/net/e1000.c +0 -2
index 0fc29a0..21c38fa 100644
@@ -1496,8 +1496,6 @@ pci_e1000_uninit(PCIDevice *dev)
     timer_free(d->autoneg_timer);
     timer_del(d->mit_timer);
     timer_free(d->mit_timer);
-    memory_region_destroy(&d->mmio);
-    memory_region_destroy(&d->io);
     qemu_del_nic(d->nic);
 }
 
hw/net/eepro100.c +0 -3
index 3263e3f..3cd826a 100644
@@ -1843,9 +1843,6 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
 {
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 
-    memory_region_destroy(&s->mmio_bar);
-    memory_region_destroy(&s->io_bar);
-    memory_region_destroy(&s->flash_bar);
     vmstate_unregister(&pci_dev->qdev, s->vmstate, s);
     eeprom93xx_free(&pci_dev->qdev, s->eeprom);
     qemu_del_nic(s->nic);
hw/net/ne2000.c +0 -1
index d558b8c..a62d12d 100644
@@ -748,7 +748,6 @@ static void pci_ne2000_exit(PCIDevice *pci_dev)
     PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
     NE2000State *s = &d->ne2000;
 
-    memory_region_destroy(&s->io);
     qemu_del_nic(s->nic);
     qemu_free_irq(s->irq);
 }
hw/net/pcnet-pci.c +0 -2
index b25d789..50ffe91 100644
@@ -282,8 +282,6 @@ static void pci_pcnet_uninit(PCIDevice *dev)
     PCIPCNetState *d = PCI_PCNET(dev);
 
     qemu_free_irq(d->state.irq);
-    memory_region_destroy(&d->state.mmio);
-    memory_region_destroy(&d->io_bar);
     timer_del(d->state.poll_timer);
     timer_free(d->state.poll_timer);
     qemu_del_nic(d->state.nic);
hw/net/rtl8139.c +0 -2
index 90bc5ec..6e59f38 100644
@@ -3462,8 +3462,6 @@ static void pci_rtl8139_uninit(PCIDevice *dev)
 {
     RTL8139State *s = RTL8139(dev);
 
-    memory_region_destroy(&s->bar_io);
-    memory_region_destroy(&s->bar_mem);
     if (s->cplus_txbuffer) {
         g_free(s->cplus_txbuffer);
         s->cplus_txbuffer = NULL;
hw/net/stellaris_enet.c +0 -8
index c9ee5d3..c07e513 100644
@@ -485,13 +485,6 @@ static int stellaris_enet_init(SysBusDevice *sbd)
     return 0;
 }
 
-static void stellaris_enet_unrealize(DeviceState *dev, Error **errp)
-{
-    stellaris_enet_state *s = STELLARIS_ENET(dev);
-
-    memory_region_destroy(&s->mmio);
-}
-
 static Property stellaris_enet_properties[] = {
     DEFINE_NIC_PROPERTIES(stellaris_enet_state, conf),
     DEFINE_PROP_END_OF_LIST(),
@@ -503,7 +496,6 @@ static void stellaris_enet_class_init(ObjectClass *klass, void *data)
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = stellaris_enet_init;
-    dc->unrealize = stellaris_enet_unrealize;
     dc->props = stellaris_enet_properties;
     dc->vmsd = &vmstate_stellaris_enet;
 }
hw/net/vmxnet3.c +0 -4
index 77bea6f..f11525c 100644
@@ -2182,10 +2182,6 @@ static void vmxnet3_pci_uninit(PCIDevice *pci_dev)
     vmxnet3_cleanup_msix(s);
 
     vmxnet3_cleanup_msi(s);
-
-    memory_region_destroy(&s->bar0);
-    memory_region_destroy(&s->bar1);
-    memory_region_destroy(&s->msix_bar);
 }
 
 static void vmxnet3_qdev_reset(DeviceState *dev)
hw/pci-bridge/pci_bridge_dev.c +0 -2
index e68145c..92799d0 100644
@@ -81,7 +81,6 @@ msi_error:
 slotid_error:
     shpc_cleanup(dev, &bridge_dev->bar);
 shpc_error:
-    memory_region_destroy(&bridge_dev->bar);
     pci_bridge_exitfn(dev);
 bridge_error:
     return err;
@@ -95,7 +94,6 @@ static void pci_bridge_dev_exitfn(PCIDevice *dev)
     }
     slotid_cap_cleanup(dev);
     shpc_cleanup(dev, &bridge_dev->bar);
-    memory_region_destroy(&bridge_dev->bar);
     pci_bridge_exitfn(dev);
 }
 
hw/pci/msix.c +0 -4
index 5c49bfc..3c07d22 100644
@@ -319,7 +319,6 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
                     bar_nr, MSIX_EXCLUSIVE_BAR_PBA_OFFSET,
                     MSIX_EXCLUSIVE_CAP_OFFSET);
     if (ret) {
-        memory_region_destroy(&dev->msix_exclusive_bar);
         return ret;
     }
 
@@ -359,11 +358,9 @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar)
     msix_free_irq_entries(dev);
     dev->msix_entries_nr = 0;
     memory_region_del_subregion(pba_bar, &dev->msix_pba_mmio);
-    memory_region_destroy(&dev->msix_pba_mmio);
     g_free(dev->msix_pba);
     dev->msix_pba = NULL;
     memory_region_del_subregion(table_bar, &dev->msix_table_mmio);
-    memory_region_destroy(&dev->msix_table_mmio);
     g_free(dev->msix_table);
     dev->msix_table = NULL;
     g_free(dev->msix_entry_used);
@@ -375,7 +372,6 @@ void msix_uninit_exclusive_bar(PCIDevice *dev)
 {
     if (msix_present(dev)) {
         msix_uninit(dev, &dev->msix_exclusive_bar, &dev->msix_exclusive_bar);
-        memory_region_destroy(&dev->msix_exclusive_bar);
     }
 }
 
hw/pci/pci.c +0 -2
index 351d320..daeaeac 100644
@@ -799,7 +799,6 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
     pci_config_free(pci_dev);
 
     address_space_destroy(&pci_dev->bus_master_as);
-    memory_region_destroy(&pci_dev->bus_master_enable_region);
 }
 
 /* -1 for devfn means auto assign */
@@ -1996,7 +1995,6 @@ static void pci_del_option_rom(PCIDevice *pdev)
         return;
 
     vmstate_unregister_ram(&pdev->rom, &pdev->qdev);
-    memory_region_destroy(&pdev->rom);
     pdev->has_rom = false;
 }
 
hw/pci/pci_bridge.c +0 -8
index 4becdc1..1307265 100644
@@ -219,12 +219,6 @@ static void pci_bridge_region_del(PCIBridge *br, PCIBridgeWindows *w)
 
 static void pci_bridge_region_cleanup(PCIBridge *br, PCIBridgeWindows *w)
 {
-    memory_region_destroy(&w->alias_io);
-    memory_region_destroy(&w->alias_mem);
-    memory_region_destroy(&w->alias_pref_mem);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_IO_LO]);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_IO_HI]);
-    memory_region_destroy(&w->alias_vga[QEMU_PCI_VGA_MEM]);
     g_free(w);
 }
 
@@ -389,8 +383,6 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
     QLIST_REMOVE(&s->sec_bus, sibling);
     pci_bridge_region_del(s, s->windows);
     pci_bridge_region_cleanup(s, s->windows);
-    memory_region_destroy(&s->address_space_mem);
-    memory_region_destroy(&s->address_space_io);
     /* object_unparent() is called automatically during device deletion */
 }
 
hw/pci/pcie_host.c +0 -1
index 7c88a1d..3db038f 100644
@@ -94,7 +94,6 @@ void pcie_host_mmcfg_unmap(PCIExpressHost *e)
 {
     if (e->base_addr != PCIE_BASE_ADDR_UNMAPPED) {
         memory_region_del_subregion(get_system_memory(), &e->mmio);
-        memory_region_destroy(&e->mmio);
         e->base_addr = PCIE_BASE_ADDR_UNMAPPED;
     }
 }
hw/pci/shpc.c +0 -1
index 180faa7..1fcb8c4 100644
@@ -667,7 +667,6 @@ void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
     g_free(shpc->cmask);
     g_free(shpc->wmask);
     g_free(shpc->w1cmask);
-    memory_region_destroy(&shpc->mmio);
     g_free(shpc);
 }
 
hw/scsi/esp-pci.c +0 -1
index 9971bbf..82795e6 100644
@@ -378,7 +378,6 @@ static void esp_pci_scsi_uninit(PCIDevice *d)
     PCIESPState *pci = PCI_ESP(d);
 
     qemu_free_irq(pci->esp.irq);
-    memory_region_destroy(&pci->io);
 }
 
 static void esp_pci_class_init(ObjectClass *klass, void *data)
hw/scsi/lsi53c895a.c +0 -10
index 786d848..513ea47 100644
@@ -2072,15 +2072,6 @@ static const VMStateDescription vmstate_lsi_scsi = {
     }
 };
 
-static void lsi_scsi_uninit(PCIDevice *d)
-{
-    LSIState *s = LSI53C895A(d);
-
-    memory_region_destroy(&s->mmio_io);
-    memory_region_destroy(&s->ram_io);
-    memory_region_destroy(&s->io_io);
-}
-
 static const struct SCSIBusInfo lsi_scsi_info = {
     .tcq = true,
     .max_target = LSI_MAX_DEVS,
@@ -2134,7 +2125,6 @@ static void lsi_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = lsi_scsi_init;
-    k->exit = lsi_scsi_uninit;
     k->vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
     k->device_id = PCI_DEVICE_ID_LSI_53C895A;
     k->class_id = PCI_CLASS_STORAGE_SCSI;
hw/scsi/megasas.c +0 -3
index c68a873..eedc992 100644
@@ -2129,9 +2129,6 @@ static void megasas_scsi_uninit(PCIDevice *d)
     if (megasas_use_msi(s)) {
         msi_uninit(d);
     }
-    memory_region_destroy(&s->mmio_io);
-    memory_region_destroy(&s->port_io);
-    memory_region_destroy(&s->queue_io);
 }
 
 static const struct SCSIBusInfo megasas_scsi_info = {
hw/scsi/vmw_pvscsi.c +0 -3
index f9ed926..5734d19 100644
@@ -1087,7 +1087,6 @@ pvscsi_init(PCIDevice *pci_dev)
     s->completion_worker = qemu_bh_new(pvscsi_process_completion_queue, s);
     if (!s->completion_worker) {
         pvscsi_cleanup_msi(s);
-        memory_region_destroy(&s->io_space);
         return -ENOMEM;
     }
 
@@ -1107,8 +1106,6 @@ pvscsi_uninit(PCIDevice *pci_dev)
     qemu_bh_delete(s->completion_worker);
 
     pvscsi_cleanup_msi(s);
-
-    memory_region_destroy(&s->io_space);
 }
 
 static void
hw/tpm/tpm_tis.c +0 -1
index 6f0a4d2..d398c16 100644
@@ -901,7 +901,6 @@ static void tpm_tis_uninitfn(Object *obj)
     TPMState *s = TPM(obj);
 
     memory_region_del_subregion(get_system_memory(), &s->mmio);
-    memory_region_destroy(&s->mmio);
 }
 
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
hw/usb/hcd-uhci.c +0 -8
index c3bf72c..ee5f112 100644
@@ -1256,13 +1256,6 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
     return usb_uhci_common_initfn(dev);
 }
 
-static void usb_uhci_exit(PCIDevice *dev)
-{
-    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
-
-    memory_region_destroy(&s->io_bar);
-}
-
 static Property uhci_properties[] = {
     DEFINE_PROP_STRING("masterbus", UHCIState, masterbus),
     DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0),
@@ -1279,7 +1272,6 @@ static void uhci_class_init(ObjectClass *klass, void *data)
     UHCIInfo *info = data;
 
     k->init = info->initfn ? info->initfn : usb_uhci_common_initfn;
-    k->exit = info->unplug ? usb_uhci_exit : NULL;
     k->vendor_id = info->vendor_id;
     k->device_id = info->device_id;
     k->revision  = info->revision;
hw/virtio/virtio-pci.c +0 -3
index 3007319..ddb5da1 100644
@@ -1020,10 +1020,7 @@ static int virtio_pci_init(PCIDevice *pci_dev)
 
 static void virtio_pci_exit(PCIDevice *pci_dev)
 {
-    VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
-
     msix_uninit_exclusive_bar(pci_dev);
-    memory_region_destroy(&proxy->bar);
 }
 
 static void virtio_pci_reset(DeviceState *qdev)
hw/watchdog/wdt_i6300esb.c +0 -8
index b3d6f39..687c8b1 100644
@@ -425,13 +425,6 @@ static int i6300esb_init(PCIDevice *dev)
     return 0;
 }
 
-static void i6300esb_exit(PCIDevice *dev)
-{
-    I6300State *d = DO_UPCAST(I6300State, dev, dev);
-
-    memory_region_destroy(&d->io_mem);
-}
-
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -445,7 +438,6 @@ static void i6300esb_class_init(ObjectClass *klass, void *data)
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->init = i6300esb_init;
-    k->exit = i6300esb_exit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
hw/xen/xen_pt.c +0 -20
index be4220b..c1bf357 100644
@@ -453,25 +453,6 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s)
     return 0;
 }
 
-static void xen_pt_unregister_regions(XenPCIPassthroughState *s)
-{
-    XenHostPCIDevice *d = &s->real_device;
-    int i;
-
-    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
-        XenHostPCIIORegion *r = &d->io_regions[i];
-
-        if (r->base_addr == 0 || r->size == 0) {
-            continue;
-        }
-
-        memory_region_destroy(&s->bar[i]);
-    }
-    if (d->rom.base_addr && d->rom.size) {
-        memory_region_destroy(&s->rom);
-    }
-}
-
 /* region mapping */
 
 static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
@@ -810,7 +791,6 @@ static void xen_pt_unregister_device(PCIDevice *d)
     /* delete all emulated config registers */
     xen_pt_config_delete(s);
 
-    xen_pt_unregister_regions(s);
     memory_listener_unregister(&s->memory_listener);
     memory_listener_unregister(&s->io_listener);
 
hw/xen/xen_pt_msi.c +0 -2
index 12b4c45..9ed9321 100644
@@ -593,7 +593,6 @@ int xen_pt_msix_init(XenPCIPassthroughState *s, uint32_t base)
     return 0;
 
 error_out:
-    memory_region_destroy(&msix->mmio);
     g_free(s->msix);
     s->msix = NULL;
     return rc;
@@ -616,7 +615,6 @@ void xen_pt_msix_delete(XenPCIPassthroughState *s)
     }
 
     memory_region_del_subregion(&s->bar[msix->bar_index], &msix->mmio);
-    memory_region_destroy(&msix->mmio);
 
     g_free(s->msix);
     s->msix = NULL;
include/exec/memory.h +0 -9
index e2c8e3e..5bd10d1 100644
@@ -430,15 +430,6 @@ void memory_region_init_iommu(MemoryRegion *mr,
                               uint64_t size);
 
 /**
- * memory_region_destroy: Destroy a memory region and reclaim all resources.
- *
- * @mr: the region to be destroyed.  May not currently be a subregion
- *      (see memory_region_add_subregion()) or referenced in an alias
- *      (see memory_region_init_alias()).
- */
-void memory_region_destroy(MemoryRegion *mr);
-
-/**
  * memory_region_owner: get a memory region's owner.
  *
  * @mr: the memory region being queried.
memory.c +0 -6
index 23c5269..f11c035 100644
@@ -1264,11 +1264,6 @@ static void memory_region_finalize(Object *obj)
     g_free(mr->ioeventfds);
 }
 
-void memory_region_destroy(MemoryRegion *mr)
-{
-}
-
-
 Object *memory_region_owner(MemoryRegion *mr)
 {
     Object *obj = OBJECT(mr);
--

1.8.3.1

#19 lore raw

PATCH 9/9 tpm_tis: remove instance_finalize callback

In reply to Paolo Bonzini

It is never used, since ISA device are not hot-unpluggable.

---
 hw/tpm/tpm_tis.c | 8 --------
 1 file changed, 8 deletions(-)
hw/tpm/tpm_tis.c +0 -8
index d398c16..82747ee 100644
@@ -896,13 +896,6 @@ static void tpm_tis_initfn(Object *obj)
                                 &s->mmio);
 }
 
-static void tpm_tis_uninitfn(Object *obj)
-{
-    TPMState *s = TPM(obj);
-
-    memory_region_del_subregion(get_system_memory(), &s->mmio);
-}
-
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -918,7 +911,6 @@ static const TypeInfo tpm_tis_info = {
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(TPMState),
     .instance_init = tpm_tis_initfn,
-    .instance_finalize = tpm_tis_uninitfn,
     .class_init  = tpm_tis_class_init,
 };
 
Signature · 1 line
1.8.3.1
#20 lore raw

Re: [Qemu-devel] [PATCH 9/9] tpm_tis: remove instance_finalize callback

Quoted 2 lines · Paolo Bonzini

It is never used, since ISA device are not hot-unpluggable.

Is it not good design practice though for the uninit to be correctly implemented regardless of whether there is current-day usage? This seems like the kind of patch that would get reverted if anyone finds a reason to un-init a QOM object beyond existing hotplug use-cases.

Regards,
Peter

Quoted 35 lines
---
 hw/tpm/tpm_tis.c | 8 --------
 1 file changed, 8 deletions(-)
hw/tpm/tpm_tis.c +0 -9
index d398c16..82747ee 100644
@@ -896,13 +896,6 @@ static void tpm_tis_initfn(Object *obj)
                                 &s->mmio);
 }
 
-static void tpm_tis_uninitfn(Object *obj)
-{
-    TPMState *s = TPM(obj);
-
-    memory_region_del_subregion(get_system_memory(), &s->mmio);
-}
-
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -918,7 +911,6 @@ static const TypeInfo tpm_tis_info = {
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(TPMState),
     .instance_init = tpm_tis_initfn,
-    .instance_finalize = tpm_tis_uninitfn,
     .class_init  = tpm_tis_class_init,
 };
 
--

1.8.3.1

#21 lore raw

Re: [Qemu-devel] [PATCH 9/9] tpm_tis: remove instance_finalize callback

Il 31/07/2014 14:00, Peter Crosthwaite ha scritto:

Quoted 8 lines · Paolo Bonzini
Quoted 2 lines

It is never used, since ISA device are not hot-unpluggable.

Is it not good design practice though for the uninit to be correctly implemented regardless of whether there is current-day usage? This seems like the kind of patch that would get reverted if anyone finds a reason to un-init a QOM object beyond existing hotplug use-cases.

But even then, it should be an unrealize method, not an instance_finalize, shouldn't it?

Paolo

Quoted 38 lines

Regards,
Peter

Quoted 35 lines
---
 hw/tpm/tpm_tis.c | 8 --------
 1 file changed, 8 deletions(-)
hw/tpm/tpm_tis.c +0 -9
index d398c16..82747ee 100644
@@ -896,13 +896,6 @@ static void tpm_tis_initfn(Object *obj)
                                 &s->mmio);
 }
 
-static void tpm_tis_uninitfn(Object *obj)
-{
-    TPMState *s = TPM(obj);
-
-    memory_region_del_subregion(get_system_memory(), &s->mmio);
-}
-
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -918,7 +911,6 @@ static const TypeInfo tpm_tis_info = {
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(TPMState),
     .instance_init = tpm_tis_initfn,
-    .instance_finalize = tpm_tis_uninitfn,
     .class_init  = tpm_tis_class_init,
 };
 
--

1.8.3.1

Reviewed-by
#22 lore raw

Re: [Qemu-devel] [PATCH 9/9] tpm_tis: remove instance_finalize callback

Quoted 5 lines · Paolo Bonzini

Il 31/07/2014 14:00, Peter Crosthwaite ha scritto:

Quoted 4 lines · Paolo Bonzini
Quoted 2 lines

It is never used, since ISA device are not hot-unpluggable.

Quoted 8 lines
Quoted 4 lines

Is it not good design practice though for the uninit to be correctly implemented regardless of whether there is current-day usage? This seems like the kind of patch that would get reverted if anyone finds a reason to un-init a QOM object beyond existing hotplug use-cases.

But even then, it should be an unrealize method, not an instance_finalize, shouldn't it?

True. I guess this makes your patch half the solution.

Quoted 42 lines

Paolo

Quoted 38 lines

Regards,
Peter

Quoted 35 lines
---
 hw/tpm/tpm_tis.c | 8 --------
 1 file changed, 8 deletions(-)
hw/tpm/tpm_tis.c +0 -9
index d398c16..82747ee 100644
@@ -896,13 +896,6 @@ static void tpm_tis_initfn(Object *obj)
                                 &s->mmio);
 }
 
-static void tpm_tis_uninitfn(Object *obj)
-{
-    TPMState *s = TPM(obj);
-
-    memory_region_del_subregion(get_system_memory(), &s->mmio);
-}
-
 static void tpm_tis_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -918,7 +911,6 @@ static const TypeInfo tpm_tis_info = {
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(TPMState),
     .instance_init = tpm_tis_initfn,
-    .instance_finalize = tpm_tis_uninitfn,
     .class_init  = tpm_tis_class_init,
 };
 
--

1.8.3.1