From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9YoP-0007oD-Rs for qemu-devel@nongnu.org; Thu, 17 Dec 2015 08:41:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9YoL-0000vQ-Pr for qemu-devel@nongnu.org; Thu, 17 Dec 2015 08:41:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9YoL-0000vM-Hq for qemu-devel@nongnu.org; Thu, 17 Dec 2015 08:41:37 -0500 Date: Thu, 17 Dec 2015 15:41:32 +0200 From: "Michael S. Tsirkin" Message-ID: <20151217154105-mutt-send-email-mst@redhat.com> References: <1450354795-31608-1-git-send-email-armbru@redhat.com> <1450354795-31608-11-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1450354795-31608-11-git-send-email-armbru@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 10/13] isa: Clean up error handling around isa_bus_new() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Markus Armbruster , Mark Cave-Ayland , qemu-devel@nongnu.org, =?iso-8859-1?Q?Herv=E9?= Poussineau , Aurelien Jarno , Richard Henderson On Thu, Dec 17, 2015 at 01:19:52PM +0100, Markus Armbruster wrote: > We can have at most one ISA bus. If you try to create another one, > isa_bus_new() complains to stderr and returns null. >=20 > isa_bus_new() is called in two contexts, machine's init() and device's > realize() methods. Since complaining to stderr is not proper in the > latter context, convert isa_bus_new() to Error. >=20 > Machine's init(): >=20 > * mips_jazz_init(), called from the init() methods of machines > "magnum" and "pica" >=20 > * mips_r4k_init(), the init() method of machine "mips" >=20 > * pc_init1() called from the init() methods of non-q35 PC machines >=20 > * typhoon_init(), called from clipper_init(), the init() method of > machine "clipper" >=20 > These callers always create the first ISA bus, hence isa_bus_new() > can't fail. Simply pass &error_abort. >=20 > Device's realize(): >=20 > * i82378_realize(), of PCI device "i82378" >=20 > * ich9_lpc_realize(), of PCI device "ICH9-LPC" >=20 > * pci_ebus_realize(), of PCI device "ebus" >=20 > * piix3_realize(), of PCI device "pci-piix3", abstract parent of > "PIIX3" and "PIIX3-xen" >=20 > * piix4_realize(), of PCI device "PIIX4" >=20 > * vt82c686b_realize(), of PCI device "VT82C686B" >=20 > Propagate the error. Note that these devices are typically created > only by machine init() methods with qdev_init_nofail() or similar. If > we screwed up and created an ISA bus before that call, we now give up > right away. Before, we'd hobble on, and typically die in > isa_bus_irqs(). Similar if someone finds a way to hot-plug one of > these critters. >=20 > Cc: Richard Henderson > Cc: "Michael S. Tsirkin" > Cc: "Herv=E9 Poussineau" > Cc: Aurelien Jarno > Cc: Mark Cave-Ayland > Signed-off-by: Markus Armbruster > Reviewed-by: Marcel Apfelbaum > Reviewed-by: Herv=E9 Poussineau Reviewed-by: Michael S. Tsirkin > --- > hw/alpha/typhoon.c | 3 ++- > hw/i386/pc_piix.c | 3 ++- > hw/isa/i82378.c | 5 ++++- > hw/isa/isa-bus.c | 4 ++-- > hw/isa/lpc_ich9.c | 6 +++++- > hw/isa/piix4.c | 6 ++++-- > hw/isa/vt82c686.c | 5 ++++- > hw/mips/mips_jazz.c | 2 +- > hw/mips/mips_r4k.c | 2 +- > hw/pci-host/piix.c | 6 ++++-- > hw/sparc64/sun4u.c | 6 ++++-- > include/hw/isa/isa.h | 2 +- > 12 files changed, 34 insertions(+), 16 deletions(-) >=20 > diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c > index 421162e..35dc8a5 100644 > --- a/hw/alpha/typhoon.c > +++ b/hw/alpha/typhoon.c > @@ -920,7 +920,8 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **= isa_bus, > { > qemu_irq *isa_irqs; > =20 > - *isa_bus =3D isa_bus_new(NULL, get_system_memory(), &s->pchip.= reg_io); > + *isa_bus =3D isa_bus_new(NULL, get_system_memory(), &s->pchip.= reg_io, > + &error_abort); > isa_irqs =3D i8259_init(*isa_bus, > qemu_allocate_irq(typhoon_set_isa_irq, s= , 0)); > isa_bus_irqs(*isa_bus, isa_irqs); > diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c > index 2e41efe..48fdad4 100644 > --- a/hw/i386/pc_piix.c > +++ b/hw/i386/pc_piix.c > @@ -200,7 +200,8 @@ static void pc_init1(MachineState *machine, > } else { > pci_bus =3D NULL; > i440fx_state =3D NULL; > - isa_bus =3D isa_bus_new(NULL, get_system_memory(), system_io); > + isa_bus =3D isa_bus_new(NULL, get_system_memory(), system_io, > + &error_abort); > no_hpet =3D 1; > } > isa_bus_irqs(isa_bus, gsi); > diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c > index d4c8306..3793c6f 100644 > --- a/hw/isa/i82378.c > +++ b/hw/isa/i82378.c > @@ -75,7 +75,10 @@ static void i82378_realize(PCIDevice *pci, Error **e= rrp) > pci_config_set_interrupt_pin(pci_conf, 1); /* interrupt pin 0 */ > =20 > isabus =3D isa_bus_new(dev, get_system_memory(), > - pci_address_space_io(pci)); > + pci_address_space_io(pci), errp); > + if (!isabus) { > + return; > + } > =20 > /* This device has: > 2 82C59 (irq) > diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c > index 43e0cd8..af6ffd6 100644 > --- a/hw/isa/isa-bus.c > +++ b/hw/isa/isa-bus.c > @@ -44,10 +44,10 @@ static const TypeInfo isa_bus_info =3D { > }; > =20 > ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space, > - MemoryRegion *address_space_io) > + MemoryRegion *address_space_io, Error **errp) > { > if (isabus) { > - fprintf(stderr, "Can't create a second ISA bus\n"); > + error_setg(errp, "Can't create a second ISA bus"); > return NULL; > } > if (!dev) { > diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c > index 8e58449..ed9907d 100644 > --- a/hw/isa/lpc_ich9.c > +++ b/hw/isa/lpc_ich9.c > @@ -607,7 +607,11 @@ static void ich9_lpc_realize(PCIDevice *d, Error *= *errp) > ICH9LPCState *lpc =3D ICH9_LPC_DEVICE(d); > ISABus *isa_bus; > =20 > - isa_bus =3D isa_bus_new(DEVICE(d), get_system_memory(), get_system= _io()); > + isa_bus =3D isa_bus_new(DEVICE(d), get_system_memory(), get_system= _io(), > + errp); > + if (!isa_bus) { > + return; > + } > =20 > pci_set_long(d->wmask + ICH9_LPC_PMBASE, > ICH9_LPC_PMBASE_BASE_ADDRESS_MASK); > diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c > index 2c59e91..644cfd9 100644 > --- a/hw/isa/piix4.c > +++ b/hw/isa/piix4.c > @@ -90,8 +90,10 @@ static void piix4_realize(PCIDevice *dev, Error **er= rp) > { > PIIX4State *d =3D PIIX4_PCI_DEVICE(dev); > =20 > - isa_bus_new(DEVICE(d), pci_address_space(dev), > - pci_address_space_io(dev)); > + if (!isa_bus_new(DEVICE(d), pci_address_space(dev), > + pci_address_space_io(dev), errp)) { > + return; > + } > piix4_dev =3D &d->dev; > qemu_register_reset(piix4_reset, d); > } > diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c > index 252e1d7..6c2190b 100644 > --- a/hw/isa/vt82c686.c > +++ b/hw/isa/vt82c686.c > @@ -440,7 +440,10 @@ static void vt82c686b_realize(PCIDevice *d, Error = **errp) > int i; > =20 > isa_bus =3D isa_bus_new(DEVICE(d), get_system_memory(), > - pci_address_space_io(d)); > + pci_address_space_io(d), errp); > + if (!isa_bus) { > + return; > + } > =20 > pci_conf =3D d->config; > pci_config_set_prog_interface(pci_conf, 0x0); > diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c > index 1ab885b..1cfbaa6 100644 > --- a/hw/mips/mips_jazz.c > +++ b/hw/mips/mips_jazz.c > @@ -219,7 +219,7 @@ static void mips_jazz_init(MachineState *machine, > memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000); > memory_region_add_subregion(address_space, 0x90000000, isa_io); > memory_region_add_subregion(address_space, 0x91000000, isa_mem); > - isa_bus =3D isa_bus_new(NULL, isa_mem, isa_io); > + isa_bus =3D isa_bus_new(NULL, isa_mem, isa_io, &error_abort); > =20 > /* ISA devices */ > i8259 =3D i8259_init(isa_bus, env->irq[4]); > diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c > index af10da1..2d4e038 100644 > --- a/hw/mips/mips_r4k.c > +++ b/hw/mips/mips_r4k.c > @@ -272,7 +272,7 @@ void mips_r4k_init(MachineState *machine) > memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000); > memory_region_add_subregion(get_system_memory(), 0x14000000, isa_i= o); > memory_region_add_subregion(get_system_memory(), 0x10000000, isa_m= em); > - isa_bus =3D isa_bus_new(NULL, isa_mem, get_system_io()); > + isa_bus =3D isa_bus_new(NULL, isa_mem, get_system_io(), &error_abo= rt); > =20 > /* The PIC is attached to the MIPS CPU INT0 pin */ > i8259 =3D i8259_init(isa_bus, env->irq[2]); > diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c > index 715208b..775b4bd 100644 > --- a/hw/pci-host/piix.c > +++ b/hw/pci-host/piix.c > @@ -651,8 +651,10 @@ static void piix3_realize(PCIDevice *dev, Error **= errp) > { > PIIX3State *d =3D PIIX3_PCI_DEVICE(dev); > =20 > - isa_bus_new(DEVICE(d), get_system_memory(), > - pci_address_space_io(dev)); > + if (!isa_bus_new(DEVICE(d), get_system_memory(), > + pci_address_space_io(dev), errp)) { > + return; > + } > =20 > memory_region_init_io(&d->rcr_mem, OBJECT(dev), &rcr_ops, d, > "piix3-reset-control", 1); > diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c > index c37e8b0..6c7596b 100644 > --- a/hw/sparc64/sun4u.c > +++ b/hw/sparc64/sun4u.c > @@ -597,8 +597,10 @@ static void pci_ebus_realize(PCIDevice *pci_dev, E= rror **errp) > { > EbusState *s =3D DO_UPCAST(EbusState, pci_dev, pci_dev); > =20 > - isa_bus_new(DEVICE(pci_dev), get_system_memory(), > - pci_address_space_io(pci_dev)); > + if (!isa_bus_new(DEVICE(pci_dev), get_system_memory(), > + pci_address_space_io(pci_dev), errp)) { > + return; > + } > =20 > pci_dev->config[0x04] =3D 0x06; // command =3D bus master, pci mem > pci_dev->config[0x05] =3D 0x00; > diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h > index d758b39..de3cd3d 100644 > --- a/include/hw/isa/isa.h > +++ b/include/hw/isa/isa.h > @@ -59,7 +59,7 @@ struct ISADevice { > }; > =20 > ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space, > - MemoryRegion *address_space_io); > + MemoryRegion *address_space_io, Error **errp); > void isa_bus_irqs(ISABus *bus, qemu_irq *irqs); > qemu_irq isa_get_irq(ISADevice *dev, int isairq); > void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq); > --=20 > 2.4.3