[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 30/35] hw/pci: fix error flow in pci multifunction
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL v2 30/35] hw/pci: fix error flow in pci multifunction init |
Date: |
Sun, 26 Jan 2014 18:06:58 +0200 |
From: Marcel Apfelbaum <address@hidden>
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 <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
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 2aca8a4..1221f32 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;
--
MST
- [Qemu-devel] [PULL v2 20/35] acpi-build: enable hotplug for PCI bridges, (continued)
- [Qemu-devel] [PULL v2 20/35] acpi-build: enable hotplug for PCI bridges, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 21/35] acpi: factor out common cpu hotplug code for PIIX4/Q35, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 22/35] acpi: ich9: add CPU hotplug handling to Q35 machine, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 23/35] pc: set PRST base in DSDT depending on chipset, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 24/35] pc: PIIX DSDT: exclude CPU/PCI hotplug & GPE0 IO range from PCI bus resources, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 25/35] pc: Q35 DSDT: exclude CPU hotplug IO range from PCI bus resources, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 26/35] pc: ACPI: expose PRST IO range via _CRS, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 27/35] pc: ACPI: unify source of CPU hotplug IO base/len, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 28/35] pc: ACPI: update acpi-dsdt.hex.generated q35-acpi-dsdt.hex.generated, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 29/35] acpi-test: update expected AML since recent changes, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 30/35] hw/pci: fix error flow in pci multifunction init,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL v2 31/35] pc: Save size of RAM below 4GB, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 32/35] acpi: Fix PCI hole handling on build_srat(), Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 33/35] q35: gigabyte alignment for ram, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 34/35] q35: document gigabyte_align, Michael S. Tsirkin, 2014/01/26
- [Qemu-devel] [PULL v2 35/35] MAINTAINERS: add self as virtio co-maintainer, Michael S. Tsirkin, 2014/01/26
- Re: [Qemu-devel] [PULL v2 00/35] acpi, pci, pc, virtio fixes and enhancements, Michael S. Tsirkin, 2014/01/28
- Re: [Qemu-devel] [PULL v2 00/35] acpi, pci, pc, virtio fixes and enhancements, Peter Maydell, 2014/01/29
- Re: [Qemu-devel] [PULL v2 00/35] acpi, pci, pc, virtio fixes and enhancements, Peter Maydell, 2014/01/31