From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6JuE-0004QN-NG for qemu-devel@nongnu.org; Thu, 23 Jan 2014 08:01:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6Ju6-0003Lm-5S for qemu-devel@nongnu.org; Thu, 23 Jan 2014 08:01:14 -0500 Received: from mail-ee0-x233.google.com ([2a00:1450:4013:c00::233]:33764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Ju5-0003LR-VS for qemu-devel@nongnu.org; Thu, 23 Jan 2014 08:01:06 -0500 Received: by mail-ee0-f51.google.com with SMTP id b57so393411eek.24 for ; Thu, 23 Jan 2014 05:01:04 -0800 (PST) Message-ID: <1390482064.2533.8.camel@localhost.localdomain> From: Marcel Apfelbaum Date: Thu, 23 Jan 2014 15:01:04 +0200 In-Reply-To: <1390322271-3310-1-git-send-email-marcel.a@redhat.com> References: <1390322271-3310-1-git-send-email-marcel.a@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] hw/pci: fix error flow in pci multifunction init Reply-To: marcel.a@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, mst@redhat.com On Tue, 2014-01-21 at 18:37 +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. Ping Thanks, Marcel > > Signed-off-by: Marcel Apfelbaum > --- > 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;