From patchwork Fri Jan 30 23:55:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 435065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D3DE91402B3 for ; Sat, 31 Jan 2015 10:56:12 +1100 (AEDT) Received: from localhost ([::1]:39163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHLQ1-00063W-98 for incoming@patchwork.ozlabs.org; Fri, 30 Jan 2015 18:56:09 -0500 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 Received: from mx1.redhat.com ([209.132.183.28]:50893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHLPd-0005Qz-UG; Fri, 30 Jan 2015 18:55:46 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0UNtigs009503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 30 Jan 2015 18:55:44 -0500 Received: from gimli.home (ovpn-113-68.phx2.redhat.com [10.3.113.68]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0UNthw5009372; Fri, 30 Jan 2015 18:55:44 -0500 From: Alex Williamson To: qemu-devel@nongnu.org Date: Fri, 30 Jan 2015 16:55:43 -0700 Message-ID: <20150130235443.14915.89419.stgit@gimli.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Alex Williamson , qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH] vfio-pci: unparent BAR subregions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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)); } }