qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr_pci: fail gracefully with non-


From: Daniel Henrique Barboza
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr_pci: fail gracefully with non-pseries machine types
Date: Fri, 6 Oct 2017 17:30:34 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0



On 10/06/2017 12:09 PM, Greg Kurz wrote:
QEMU currently crashes when the user tries to add a spapr-pci-host-bridge
on a non-pseries machine:

$ qemu-system-ppc64 -M ppce500 -device spapr-pci-host-bridge,index=1
hw/ppc/spapr_pci.c:1535:spapr_phb_realize:
Object 0x1003dacae60 is not an instance of type spapr-machine
Aborted (core dumped)

The same thing happens with the deprecated but still available child type
spapr-pci-vfio-host-bridge.

Fix both by checking the machine type with object_dynamic_cast().

Signed-off-by: Greg Kurz <address@hidden>
---
Reviewed-by: Daniel Henrique Barboza <address@hidden>

  hw/ppc/spapr_pci.c |    8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 5049ced4e8b4..9e85106f51f8 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1507,7 +1507,7 @@ static void spapr_pci_unplug_request(HotplugHandler 
*plug_handler,

  static void spapr_phb_realize(DeviceState *dev, Error **errp)
  {
-    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+    sPAPRMachineState *spapr;
      SysBusDevice *s = SYS_BUS_DEVICE(dev);
      sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
      PCIHostState *phb = PCI_HOST_BRIDGE(s);
@@ -1519,6 +1519,12 @@ static void spapr_phb_realize(DeviceState *dev, Error 
**errp)
      const unsigned windows_supported =
          sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1;

+    spapr = (sPAPRMachineState *) qdev_get_machine();
+    if (!object_dynamic_cast((Object *) spapr, TYPE_SPAPR_MACHINE)) {
+        error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries 
machine");
+        return;
+    }
+
      if (sphb->index != (uint32_t)-1) {
          sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
          Error *local_err = NULL;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]