Skip to contentSkip to conversation

Reproducible crash on PCIe hotplug

Qemu-devel Eduardo Habkost 5 participants 11 messages Dec 9, 2016 – Dec 13, 2016

lore
Share & tools
lore
#0 lore raw

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Signature · 1 line
Eduardo
#1 lore raw
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Signature · 2 lines
Sincerely,
Cao jin
#2 lore raw
Quoted 29 lines · Cao jin
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

Stefan

#3 lore raw
Quoted 30 lines · Stefan Hajnoczi
Quoted 29 lines · Cao jin
Quoted 25 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 6 lines
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

The bug went undetected since QEMU 2.5, and the crash happens only on cases where hotplug was already going to return an error. I don't think it should be a release blocker.

Signature · 1 line
Eduardo
#4 lore raw
Quoted 34 lines · Eduardo Habkost
Quoted 33 lines · Stefan Hajnoczi
Quoted 31 lines · Cao jin
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Quoted 7 lines
Quoted 3 lines

Please let me know if this should be considered a release blocker.

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

The bug went undetected since QEMU 2.5, and the crash happens only on cases where hotplug was already going to return an error. I don't think it should be a release blocker.

Excellent, thanks for clarifying.

Stefan

#5 lore raw
In reply to Stefan Hajnoczi
Quoted 30 lines · Stefan Hajnoczi
Quoted 29 lines · Cao jin
Quoted 25 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 8 lines
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

Stefan

I don't see how it's a blocker, it's an illegal configuration. Here's the fix. It's a rather obvious one.
I'll target the fix for 2.9.
Eduardo, I'd appreciate a tested-by tag.

-->

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.

---

hw/pci/pci.c +1 -1
index 24fae16..339c531 100644
@@ -983,7 +983,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         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_get_function_0(pci_dev)->name,
                    name);
 
        return NULL;
Signature · 1 line
MST
#6 lore raw
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Stefan Hajnoczi
Quoted 29 lines · Cao jin
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

Quoted 8 lines
Quoted 3 lines

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

Stefan

I don't see how it's a blocker, it's an illegal configuration. Here's the fix. It's a rather obvious one.
I'll target the fix for 2.9.
Eduardo, I'd appreciate a tested-by tag.

I confirm the patch fixes the crash, but the error message seems
incorrect: the existing e1000e device is on slot 0 function 0, not slot 8.

  $ ./x86-kvm-build/x86_64-softmmu/qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=00
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=08
  PCI: slot 8 function 0 already ocuppied by e1000e, new func e1000e cannot be exposed to guest.
           ^^^
Quoted 39 lines

-->

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.

---

hw/pci/pci.c +1 -1
index 24fae16..339c531 100644
@@ -983,7 +983,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         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_get_function_0(pci_dev)->name,
                    name);
 
        return NULL;
Signature · 2 lines
-- 
MST
Signature · 1 line
Eduardo
#7 lore raw
Quoted 93 lines · Eduardo Habkost
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Stefan Hajnoczi
Quoted 29 lines · Cao jin
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

Quoted 8 lines
Quoted 3 lines

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

Stefan

I don't see how it's a blocker, it's an illegal configuration. Here's the fix. It's a rather obvious one.
I'll target the fix for 2.9.
Eduardo, I'd appreciate a tested-by tag.

I confirm the patch fixes the crash, but the error message seems
incorrect: the existing e1000e device is on slot 0 function 0, not slot 8.

  $ ./x86-kvm-build/x86_64-softmmu/qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=00
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=08
  PCI: slot 8 function 0 already ocuppied by e1000e, new func e1000e cannot be exposed to guest.
           ^^^
Quoted 35 lines

-->

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.

---

hw/pci/pci.c +1 -1
index 24fae16..339c531 100644
@@ -983,7 +983,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         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_get_function_0(pci_dev)->name,
                    name);
 
Quoted 6 lines
Quoted 4 lines
hw/pci/pci.c +0 -0
        return NULL;
Signature · 2 lines
-- 
MST

this then?

hw/pci/pci.c +1 -1
index 339c531..637d545 100644
@@ -982,7 +982,7 @@ 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),
+                   PCI_SLOT(pci_get_function_0(pci_dev)->devfn),
                    pci_get_function_0(pci_dev)->name,
                    name);
 
Tested-by
#8 lore raw
Quoted 111 lines · Michael S. Tsirkin
Quoted 93 lines · Eduardo Habkost
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Stefan Hajnoczi
Quoted 29 lines · Cao jin
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

Quoted 8 lines
Quoted 3 lines

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

Stefan

I don't see how it's a blocker, it's an illegal configuration. Here's the fix. It's a rather obvious one.
I'll target the fix for 2.9.
Eduardo, I'd appreciate a tested-by tag.

I confirm the patch fixes the crash, but the error message seems
incorrect: the existing e1000e device is on slot 0 function 0, not slot 8.

  $ ./x86-kvm-build/x86_64-softmmu/qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=00
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=08
  PCI: slot 8 function 0 already ocuppied by e1000e, new func e1000e cannot be exposed to guest.
           ^^^
Quoted 35 lines

-->

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.

---

hw/pci/pci.c +1 -1
index 24fae16..339c531 100644
@@ -983,7 +983,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         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_get_function_0(pci_dev)->name,
                    name);
 
Quoted 6 lines
Quoted 4 lines
hw/pci/pci.c +0 -0
        return NULL;
Signature · 2 lines
-- 
MST

this then?

hw/pci/pci.c +0 -0
index 339c531..637d545 100644

hw/pci/pci.c static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, · line 988

Quoted 8 lines
hw/pci/pci.c +1 -1
@@ -982,7 +982,7 @@ 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),
+                   PCI_SLOT(pci_get_function_0(pci_dev)->devfn),
                    pci_get_function_0(pci_dev)->name,
                    name);
 

./qemu-system-x86_64 -machine q35 -readconfig ../docs/q35-chipset.cfg -monitor stdio
QEMU 2.7.91 monitor - type 'help' for more information (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=00 (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=08
PCI: slot 0 function 0 already ocuppied by e1000e, new func e1000e cannot be exposed to guest.

Signature · 2 lines
Sincerely,
Cao jin
author Tested-by Reviewed-by
#9 lore raw
In reply to Michael S. Tsirkin
Quoted 111 lines · Michael S. Tsirkin
Quoted 93 lines · Eduardo Habkost
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Stefan Hajnoczi
Quoted 29 lines · Cao jin
Quoted 11 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

It crashes at:

#7 0x000055555598d7dc in do_pci_register_device (errp=0x7fffffffbfd0, devfn=64, name=0x5555565df340 "e1000e", bus=0x555558487380, pci_dev=0x5555589cd000)

Quoted 14 lines
      at /home/ehabkost/rh/proj/virt/qemu/hw/pci/pci.c:983
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  (gdb) l
  978                        PCI_SLOT(devfn), PCI_FUNC(devfn), name,
  979                        bus->devices[devfn]->name);
  980             return NULL;
  981         } else if (dev->hotplugged &&
  982                    pci_get_function_0(pci_dev)) {
  983             error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
  984                        " new func %s cannot be exposed to guest.",
  985                        PCI_SLOT(devfn),
  986                        bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
  987                        name);
Quoted 2 lines

Thanks for informing me. I am kind of busy for now, so I suppose I will investigate it after 2.8 release.

Please let me know if this should be considered a release blocker.

Quoted 8 lines
Quoted 3 lines

The proposed QEMU 2.8 release date is tomorrow (December 13th)!

Stefan

I don't see how it's a blocker, it's an illegal configuration. Here's the fix. It's a rather obvious one.
I'll target the fix for 2.9.
Eduardo, I'd appreciate a tested-by tag.

I confirm the patch fixes the crash, but the error message seems
incorrect: the existing e1000e device is on slot 0 function 0, not slot 8.

  $ ./x86-kvm-build/x86_64-softmmu/qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=00
  (qemu) device_add e1000e,bus=ich9-pcie-port-4,addr=08
  PCI: slot 8 function 0 already ocuppied by e1000e, new func e1000e cannot be exposed to guest.
           ^^^
Quoted 35 lines

-->

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.

---

hw/pci/pci.c +1 -1
index 24fae16..339c531 100644
@@ -983,7 +983,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         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_get_function_0(pci_dev)->name,
                    name);
 
Quoted 6 lines
Quoted 4 lines
hw/pci/pci.c +0 -0
        return NULL;
Signature · 2 lines
-- 
MST

this then?

hw/pci/pci.c +0 -0
index 339c531..637d545 100644

hw/pci/pci.c static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, · line 987

Quoted 7 lines
hw/pci/pci.c +1 -1
@@ -982,7 +982,7 @@ 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),
+                   PCI_SLOT(pci_get_function_0(pci_dev)->devfn),
                    pci_get_function_0(pci_dev)->name,
                    name);

Works for me. Thanks!

Signature · 1 line
Eduardo
Reviewed-by Michael S. Tsirkin
#10 lore raw
In reply to Eduardo Habkost
Quoted 7 lines · Eduardo Habkost

Using latest qemu.git master:

  $ qemu-system-x86_64 -machine q35 -readconfig docs/q35-chipset.cfg -monitor stdio
  QEMU 2.7.93 monitor - type 'help' for more information
  (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)

Bisected to

commit 3f1e1478db2d67098d98f2c3acf5a4946b7fb643

Author: Cao jin <[email protected]>
Date:   Wed Oct 28 14:20:31 2015 +0800

enable multi-function hot-add

Enable PCIe device multi-function hot-add, just ensure function 0 is added last, then driver will get the notification to scan the slot.

It's in v2.5.0, probably no need to hold the release for a fix.