[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 33/34] spapr_pci: fail gracefully with non-pseries ma
From: |
David Gibson |
Subject: |
[Qemu-devel] [PULL 33/34] spapr_pci: fail gracefully with non-pseries machine types |
Date: |
Tue, 17 Oct 2017 15:21:51 +1100 |
From: Greg Kurz <address@hidden>
QEMU currently crashes when the user tries to add an 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().
Reviewed-by: Daniel Henrique Barboza <address@hidden>
Signed-off-by: Greg Kurz <address@hidden>
Signed-off-by: David Gibson <address@hidden>
---
hw/ppc/spapr_pci.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 5049ced4e8..5a3122a9f9 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1507,7 +1507,12 @@ 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());
+ /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user
+ * tries to add a sPAPR PHB to a non-pseries machine.
+ */
+ sPAPRMachineState *spapr =
+ (sPAPRMachineState *) object_dynamic_cast(qdev_get_machine(),
+ TYPE_SPAPR_MACHINE);
SysBusDevice *s = SYS_BUS_DEVICE(dev);
sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
PCIHostState *phb = PCI_HOST_BRIDGE(s);
@@ -1519,6 +1524,11 @@ static void spapr_phb_realize(DeviceState *dev, Error
**errp)
const unsigned windows_supported =
sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1;
+ if (!spapr) {
+ 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;
--
2.13.6
- [Qemu-devel] [PULL 06/34] target/ppc: Add POWER9 DD2.0 model information, (continued)
- [Qemu-devel] [PULL 06/34] target/ppc: Add POWER9 DD2.0 model information, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 34/34] spapr_cpu_core: rewrite machine type sanity check, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 18/34] ppc: spapr: replace ppc_cpu_parse_features() with cpu_parse_cpu_model(), David Gibson, 2017/10/17
- [Qemu-devel] [PULL 20/34] ppc: spapr: define core types statically, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 28/34] ppc: pnv: drop PnvCoreClass::cpu_oc field, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 21/34] ppc: spapr: use cpu type name directly, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 19/34] ppc: move '-cpu foo, compat=xxx' parsing into ppc_cpu_parse_featurestr(), David Gibson, 2017/10/17
- [Qemu-devel] [PULL 27/34] ppc: pnv: normalize core/chip type names, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 31/34] ppc: pnv: consolidate type definitions and batch register them, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 29/34] ppc: pnv: define core types statically, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 33/34] spapr_pci: fail gracefully with non-pseries machine types,
David Gibson <=
- [Qemu-devel] [PULL 17/34] ppc: 40p/prep: replace cpu_model with cpu_type, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 32/34] spapr: Correct RAM size calculation for HPT resizing, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 30/34] ppc: pnv: drop PnvChipClass::cpu_model field, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 26/34] ppc: pnv: use generic cpu_model parsing, David Gibson, 2017/10/17
- [Qemu-devel] [PULL 25/34] ppc: spapr: use generic cpu_model parsing, David Gibson, 2017/10/17
- Re: [Qemu-devel] [PULL 00/34] ppc-for-2.11 queue 20171017, Peter Maydell, 2017/10/19