From nobody Wed May 1 22:29:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507302608048930.3006390690985; Fri, 6 Oct 2017 08:10:08 -0700 (PDT) Received: from localhost ([::1]:45402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0UGN-0000V7-Cs for importer@patchew.org; Fri, 06 Oct 2017 11:10:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0UFX-00009E-Jj for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:09:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0UFT-0001LI-GP for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:09:15 -0400 Received: from 1.mo4.mail-out.ovh.net ([178.33.248.196]:60540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e0UFT-0001Ka-9m for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:09:11 -0400 Received: from player772.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo4.mail-out.ovh.net (Postfix) with ESMTP id D778FC9BAA for ; Fri, 6 Oct 2017 17:09:08 +0200 (CEST) Received: from [192.168.0.243] (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player772.ha.ovh.net (Postfix) with ESMTPA id 4F382740086; Fri, 6 Oct 2017 17:09:05 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 06 Oct 2017 17:09:04 +0200 Message-ID: <150730254473.16260.6484345241358746630.stgit@bahia> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 11282642969775413587 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrleefgdekhecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.248.196 Subject: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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=3D1 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 Reviewed-by: Daniel Henrique Barboza --- 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, =20 static void spapr_phb_realize(DeviceState *dev, Error **errp) { - sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); + sPAPRMachineState *spapr; SysBusDevice *s =3D SYS_BUS_DEVICE(dev); sPAPRPHBState *sphb =3D SPAPR_PCI_HOST_BRIDGE(s); PCIHostState *phb =3D PCI_HOST_BRIDGE(s); @@ -1519,6 +1519,12 @@ static void spapr_phb_realize(DeviceState *dev, Erro= r **errp) const unsigned windows_supported =3D sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1; =20 + spapr =3D (sPAPRMachineState *) qdev_get_machine(); + if (!object_dynamic_cast((Object *) spapr, TYPE_SPAPR_MACHINE)) { + error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries mach= ine"); + return; + } + if (sphb->index !=3D (uint32_t)-1) { sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); Error *local_err =3D NULL;