From: Michael S. Tsirkin Date: Mon, 12 Dec 2016 18:42:03 +0000 (+0200) Subject: pci: fix error message for express slots X-Git-Tag: v2.8.1~71 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fqemu.git;a=commitdiff_plain;h=620a65dc44e120b4b3530dfd546434f494c81a44 pci: fix error message for express slots PCI Express downstream slot has a single PCI slot behind it, using PCI_DEVFN(PCI_SLOT(devfn), 0) does not give you function 0 in cases such as ARI as well as some error cases. This is exactly what we are hitting: $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=00 (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=08 Segmentation fault (core dumped) The fix is to use the pci_get_function_0 API. Cc: qemu-stable@nongnu.org Signed-off-by: Michael S. Tsirkin Reported-by: Eduardo Habkost Tested-by: Cao jin Tested-by: Eduardo Habkost Reviewed-by: Eduardo Habkost (cherry picked from commit d93ddfb1f8fb72a7c175a8cf1028c639f769d105) Signed-off-by: Michael Roth --- diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 24fae1689d5..637d54549e4 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -982,8 +982,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_get_function_0(pci_dev)) { error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s," " new func %s cannot be exposed to guest.", - PCI_SLOT(devfn), - bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name, + PCI_SLOT(pci_get_function_0(pci_dev)->devfn), + pci_get_function_0(pci_dev)->name, name); return NULL;