From nobody Mon Apr 29 01:22:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149132025391557.47071485789127; Tue, 4 Apr 2017 08:37:33 -0700 (PDT) Received: from localhost ([::1]:36280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvQWS-0007L8-Ay for importer@patchew.org; Tue, 04 Apr 2017 11:37:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvQUQ-0005iG-DK for qemu-devel@nongnu.org; Tue, 04 Apr 2017 11:35:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvQUP-0006rl-9g for qemu-devel@nongnu.org; Tue, 04 Apr 2017 11:35:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48170) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvQUP-0006rA-4U for qemu-devel@nongnu.org; Tue, 04 Apr 2017 11:35:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07C5580478; Tue, 4 Apr 2017 15:35:24 +0000 (UTC) Received: from redhat.com (ovpn-123-243.rdu2.redhat.com [10.10.123.243]) by smtp.corp.redhat.com (Postfix) with SMTP id 6AACF7DB23; Tue, 4 Apr 2017 15:35:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 07C5580478 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mst@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 07C5580478 Date: Tue, 4 Apr 2017 18:35:18 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1491320063-12719-2-git-send-email-mst@redhat.com> References: <1491320063-12719-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1491320063-12719-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 04 Apr 2017 15:35:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] pci: Only unmap bus_master_enabled_region if was added previously X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Alexey Kardashevskiy , jcody@redhat.com, Max Reitz , Marcel Apfelbaum , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexey Kardashevskiy Normally pci_init_bus_master() would be called either via bus->machine_done.notify or directly from do_pci_register_device(). However if a device's realize() failed, pci_init_bus_master() is not called, and do_pci_unregister_device() fails on memory_region_del_subregion() as it was not mapped. This adds a check that subregion was mapped before unmapping it. Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference") Signed-off-by: Alexey Kardashevskiy Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Max Reitz Reviewed-by: Marcel Apfelbaum Acked-by: Paolo Bonzini Tested-by: John Snow --- hw/pci/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index bd8043c..259483b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_de= v) pci_dev->bus->devices[pci_dev->devfn] =3D NULL; pci_config_free(pci_dev); =20 - memory_region_del_subregion(&pci_dev->bus_master_container_region, - &pci_dev->bus_master_enable_region); + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) { + memory_region_del_subregion(&pci_dev->bus_master_container_region, + &pci_dev->bus_master_enable_region); + } address_space_destroy(&pci_dev->bus_master_as); } =20 --=20 MST