From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHLPk-0005gn-50 for qemu-devel@nongnu.org; Fri, 30 Jan 2015 18:55:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHLPe-0005RC-54 for qemu-devel@nongnu.org; Fri, 30 Jan 2015 18:55:52 -0500 From: Alex Williamson Date: Fri, 30 Jan 2015 16:55:43 -0700 Message-ID: <20150130235443.14915.89419.stgit@gimli.home> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] vfio-pci: unparent BAR subregions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alex Williamson , qemu-stable@nongnu.org Commit d8d95814609e replaced a number of memory_region_destroy() calls with object_unparent() calls. The logic appears to be that subregions need to be unparented, but the base region is destroyed with the device object. Doing hotplug testing with vfio-pci I occasionally get a segfault from object_finalize_child_property() due to completely bogus class pointers on the child Object. Adding the explicit object_unparent() for these subregions resolves the problem, however I question the sanity of the Memory API now where we sometimes need to destroy MemoryRegions, but the rules aren't clear and there's no longer a memory_region_destroy() function, so we need to reach over to some other random QEMU API and unparent an object that we barely know about and certainly didn't explicitly parent previously. Signed-off-by: Alex Williamson Cc: Paolo Bonzini Cc: qemu-stable@nongnu.org --- hw/vfio/pci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 014a92c..c71499e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2294,10 +2294,12 @@ static void vfio_unmap_bar(VFIOPCIDevice *vdev, int nr) memory_region_del_subregion(&bar->region.mem, &bar->region.mmap_mem); munmap(bar->region.mmap, memory_region_size(&bar->region.mmap_mem)); + object_unparent(OBJECT(&bar->region.mmap_mem)); if (vdev->msix && vdev->msix->table_bar == nr) { memory_region_del_subregion(&bar->region.mem, &vdev->msix->mmap_mem); munmap(vdev->msix->mmap, memory_region_size(&vdev->msix->mmap_mem)); + object_unparent(OBJECT(&vdev->msix->mmap_mem)); } }