From f9315cde1c5a8785b2d1a0159bf505e7dac6e73f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 21 Feb 2018 11:10:30 -0500 Subject: [PATCH] memory: do not add a reference to the owner of aliased regions Very often the owner of the aliased region is the same as the owner of the alias region itself. When this happens, the reference count can never go back to 0 and the owner is leaked. This is for example breaking hot-unplug of virtio-pci devices (the device cannot be plugged back again with the same id). Another common use for alias is to transform the system I/O address space into an MMIO regions; in this case the aliased region never dies, so there is no problem. Otherwise the owner is always the same for aliasing and aliased region. I checked all calls to memory_region_init_alias introduced after commit dfde4e6 (memory: add ref/unref calls, 2013-05-06) and they do not need the reference in order to keep the owner of the aliased region alive. Backports commit 52c91dac6bd891656f297dab76da51fc8bc61309 from qemu --- qemu/memory.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/qemu/memory.c b/qemu/memory.c index 7871f97d..a0abdf03 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -819,11 +819,6 @@ static void memory_region_destructor_ram(MemoryRegion *mr) qemu_ram_free(mr->uc, memory_region_get_ram_addr(mr)); } -static void memory_region_destructor_alias(MemoryRegion *mr) -{ - memory_region_unref(mr->alias); -} - static bool memory_region_need_escape(char c) { return c == '/' || c == '[' || c == '\\' || c == ']'; @@ -1226,8 +1221,6 @@ void memory_region_init_alias(struct uc_struct *uc, MemoryRegion *mr, uint64_t size) { memory_region_init(uc, mr, owner, name, size); - memory_region_ref(orig); - mr->destructor = memory_region_destructor_alias; mr->alias = orig; mr->alias_offset = offset; }