qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <groug@kaod.org>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types
Date: Sat, 7 Oct 2017 16:19:25 +1100	[thread overview]
Message-ID: <20171007051925.GJ10050@umbus.fritz.box> (raw)
In-Reply-To: <150730254473.16260.6484345241358746630.stgit@bahia>

[-- Attachment #1: Type: text/plain, Size: 2215 bytes --]

On Fri, Oct 06, 2017 at 05:09:04PM +0200, 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 <groug@kaod.org>



> ---
>  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;
> +    }

This is slightly clunky.  You could instead use OBJECT_CHECK in the
initializer, then just if (!spapr) here.

> +
>      if (sphb->index != (uint32_t)-1) {
>          sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
>          Error *local_err = NULL;
> 


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-10-07  5:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 15:09 [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types Greg Kurz
2017-10-06 20:30 ` [Qemu-devel] [Qemu-ppc] " Daniel Henrique Barboza
2017-10-07  5:19 ` David Gibson [this message]
2017-10-07  8:06   ` [Qemu-devel] " Greg Kurz
2017-10-07 16:08     ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2017-10-11  7:29   ` [Qemu-devel] " Greg Kurz
2017-10-11 10:26     ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171007051925.GJ10050@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).