From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Ktb-0004xa-NL for qemu-devel@nongnu.org; Thu, 23 Jan 2014 09:04:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6KtV-0005ql-Nr for qemu-devel@nongnu.org; Thu, 23 Jan 2014 09:04:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6KtV-0005qW-GV for qemu-devel@nongnu.org; Thu, 23 Jan 2014 09:04:33 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0NE4WYn020444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 23 Jan 2014 09:04:32 -0500 Date: Thu, 23 Jan 2014 16:09:18 +0200 From: "Michael S. Tsirkin" Message-ID: <20140123140918.GA21572@redhat.com> References: <1390322271-3310-1-git-send-email-marcel.a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1390322271-3310-1-git-send-email-marcel.a@redhat.com> Subject: Re: [Qemu-devel] [PATCH] hw/pci: fix error flow in pci multifunction init List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum Cc: qemu-devel@nongnu.org, armbru@redhat.com On Tue, Jan 21, 2014 at 06:37:51PM +0200, Marcel Apfelbaum wrote: > Scenario: > - There is a non multifunction pci device A on 00:0X.0. > - Hot-plug another multifunction pci device B at 00:0X.1. > - The operation will fail of course. > - Try to hot-plug the B device 2-3 more times, qemu will crash. > > Reason: The error flow leaves the B's address space into global address spaces > list, but the device object is freed. Fixed that. > > Signed-off-by: Marcel Apfelbaum Thanks, applied. > --- > hw/pci/pci.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c > index aa2a395..5f454dd 100644 > --- a/hw/pci/pci.c > +++ b/hw/pci/pci.c > @@ -793,6 +793,15 @@ static void pci_config_free(PCIDevice *pci_dev) > g_free(pci_dev->used); > } > > +static void do_pci_unregister_device(PCIDevice *pci_dev) > +{ > + pci_dev->bus->devices[pci_dev->devfn] = NULL; > + pci_config_free(pci_dev); > + > + address_space_destroy(&pci_dev->bus_master_as); > + memory_region_destroy(&pci_dev->bus_master_enable_region); > +} > + > /* -1 for devfn means auto assign */ > static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, > const char *name, int devfn) > @@ -858,7 +867,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, > pci_init_mask_bridge(pci_dev); > } > if (pci_init_multifunction(bus, pci_dev)) { > - pci_config_free(pci_dev); > + do_pci_unregister_device(pci_dev); > return NULL; > } > > @@ -873,15 +882,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, > return pci_dev; > } > > -static void do_pci_unregister_device(PCIDevice *pci_dev) > -{ > - pci_dev->bus->devices[pci_dev->devfn] = NULL; > - pci_config_free(pci_dev); > - > - address_space_destroy(&pci_dev->bus_master_as); > - memory_region_destroy(&pci_dev->bus_master_enable_region); > -} > - > static void pci_unregister_io_regions(PCIDevice *pci_dev) > { > PCIIORegion *r; > -- > 1.8.3.1