* [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types @ 2017-10-06 15:09 Greg Kurz 2017-10-06 20:30 ` [Qemu-devel] [Qemu-ppc] " Daniel Henrique Barboza 2017-10-07 5:19 ` [Qemu-devel] " David Gibson 0 siblings, 2 replies; 7+ messages in thread From: Greg Kurz @ 2017-10-06 15:09 UTC (permalink / raw) To: qemu-devel; +Cc: qemu-ppc, David Gibson 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; + } + if (sphb->index != (uint32_t)-1) { sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); Error *local_err = NULL; ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr_pci: fail gracefully with non-pseries machine types 2017-10-06 15:09 [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types Greg Kurz @ 2017-10-06 20:30 ` Daniel Henrique Barboza 2017-10-07 5:19 ` [Qemu-devel] " David Gibson 1 sibling, 0 replies; 7+ messages in thread From: Daniel Henrique Barboza @ 2017-10-06 20:30 UTC (permalink / raw) To: Greg Kurz, qemu-devel; +Cc: qemu-ppc, David Gibson 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 <groug@kaod.org> > --- Reviewed-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> > 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; > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types 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 2017-10-07 8:06 ` Greg Kurz 2017-10-11 7:29 ` [Qemu-devel] " Greg Kurz 1 sibling, 2 replies; 7+ messages in thread From: David Gibson @ 2017-10-07 5:19 UTC (permalink / raw) To: Greg Kurz; +Cc: qemu-devel, qemu-ppc [-- 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 --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types 2017-10-07 5:19 ` [Qemu-devel] " David Gibson @ 2017-10-07 8:06 ` Greg Kurz 2017-10-07 16:08 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz 2017-10-11 7:29 ` [Qemu-devel] " Greg Kurz 1 sibling, 1 reply; 7+ messages in thread From: Greg Kurz @ 2017-10-07 8:06 UTC (permalink / raw) To: David Gibson; +Cc: qemu-devel, qemu-ppc [-- Attachment #1: Type: text/plain, Size: 2454 bytes --] On Sat, 7 Oct 2017 16:19:25 +1100 David Gibson <david@gibson.dropbear.id.au> wrote: > 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. > Unless I'm missing something, OBJECT_CHECK() is precisely what we're removing with this patch to avoid the runtime assert... #define SPAPR_MACHINE(obj) \ OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE) > > + > > if (sphb->index != (uint32_t)-1) { > > sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); > > Error *local_err = NULL; > > > > [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr_pci: fail gracefully with non-pseries machine types 2017-10-07 8:06 ` Greg Kurz @ 2017-10-07 16:08 ` Greg Kurz 0 siblings, 0 replies; 7+ messages in thread From: Greg Kurz @ 2017-10-07 16:08 UTC (permalink / raw) To: David Gibson; +Cc: qemu-ppc, qemu-devel [-- Attachment #1: Type: text/plain, Size: 2795 bytes --] On Sat, 7 Oct 2017 10:06:00 +0200 Greg Kurz <groug@kaod.org> wrote: > On Sat, 7 Oct 2017 16:19:25 +1100 > David Gibson <david@gibson.dropbear.id.au> wrote: > > > 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. > > > > Unless I'm missing something, OBJECT_CHECK() is precisely what we're > removing with this patch to avoid the runtime assert... > > #define SPAPR_MACHINE(obj) \ > OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE) > Since we already do this in spapr-cpu-core, I guess I'll hide the ugliness in some macro. I'll send another patch. > > > + > > > if (sphb->index != (uint32_t)-1) { > > > sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); > > > Error *local_err = NULL; > > > > > > > > [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types 2017-10-07 5:19 ` [Qemu-devel] " David Gibson 2017-10-07 8:06 ` Greg Kurz @ 2017-10-11 7:29 ` Greg Kurz 2017-10-11 10:26 ` David Gibson 1 sibling, 1 reply; 7+ messages in thread From: Greg Kurz @ 2017-10-11 7:29 UTC (permalink / raw) To: David Gibson; +Cc: qemu-devel, qemu-ppc [-- Attachment #1: Type: text/plain, Size: 3382 bytes --] On Sat, 7 Oct 2017 16:19:25 +1100 David Gibson <david@gibson.dropbear.id.au> wrote: > 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. > The negative review on v2 seem to indicate we have an agreement on using object_dynamic_cast() explicitly. So we have two possibilities, either the "clunky" v1, or possibly: - 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 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); char *namebuf; int i; PCIBus *bus; uint64_t msi_window_size = 4096; sPAPRTCETable *tcet; 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; + } + Which one do you prefer ? I'll also change spapr_cpu_core_realize() if needed. > > + > > if (sphb->index != (uint32_t)-1) { > > sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); > > Error *local_err = NULL; > > > > [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types 2017-10-11 7:29 ` [Qemu-devel] " Greg Kurz @ 2017-10-11 10:26 ` David Gibson 0 siblings, 0 replies; 7+ messages in thread From: David Gibson @ 2017-10-11 10:26 UTC (permalink / raw) To: Greg Kurz; +Cc: qemu-devel, qemu-ppc [-- Attachment #1: Type: text/plain, Size: 3858 bytes --] On Wed, Oct 11, 2017 at 09:29:08AM +0200, Greg Kurz wrote: > On Sat, 7 Oct 2017 16:19:25 +1100 > David Gibson <david@gibson.dropbear.id.au> wrote: > > > 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. > > > > The negative review on v2 seem to indicate we have an agreement on using > object_dynamic_cast() explicitly. So we have two possibilities, either > the "clunky" v1, or possibly: > > - 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 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); > char *namebuf; > int i; > PCIBus *bus; > uint64_t msi_window_size = 4096; > sPAPRTCETable *tcet; > 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; > + } > + > > Which one do you prefer ? I'll also change spapr_cpu_core_realize() > if needed. Second one looks good to me. > > > > + > > > 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 --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-10-11 10:27 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 ` [Qemu-devel] " David Gibson 2017-10-07 8:06 ` 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
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.