Received: from eggs.gnu.org ([2001:4830:134:3::10]:60644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJzso-0000Yj-Rz for qemu-devel@nongnu.org; Tue, 28 Jul 2015 04:05:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJzsm-0008Ra-9u for qemu-devel@nongnu.org; Tue, 28 Jul 2015 04:05:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59756) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJzsm-0008P7-4m for qemu-devel@nongnu.org; Tue, 28 Jul 2015 04:05:04 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 8B0178EA3F for ; Tue, 28 Jul 2015 08:05:03 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-40.ams2.redhat.com [10.36.112.40]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6S84tc4024621 for ; Tue, 28 Jul 2015 04:05:02 -0400 From: Paolo Bonzini Date: Tue, 28 Jul 2015 10:04:55 +0200 Message-Id: <1438070695-24889-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1438070695-24889-1-git-send-email-pbonzini@redhat.com> References: <1438070695-24889-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 4/4] memory: do not add a reference to the owner of aliased regions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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. Reported-by: Michael S. Tsirkin Tested-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini --- memory.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/memory.c b/memory.c index 5e5f325..4eb138a 100644 --- a/memory.c +++ b/memory.c @@ -859,11 +859,6 @@ static void memory_region_destructor_ram(MemoryRegion *mr) qemu_ram_free(mr->ram_addr); } -static void memory_region_destructor_alias(MemoryRegion *mr) -{ - memory_region_unref(mr->alias); -} - static void memory_region_destructor_ram_from_ptr(MemoryRegion *mr) { qemu_ram_free_from_ptr(mr->ram_addr); @@ -1272,8 +1267,6 @@ void memory_region_init_alias(MemoryRegion *mr, uint64_t size) { memory_region_init(mr, owner, name, size); - memory_region_ref(orig); - mr->destructor = memory_region_destructor_alias; mr->alias = orig; mr->alias_offset = offset; } -- 2.4.3