From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56528 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5fJw-0000CL-O2 for qemu-devel@nongnu.org; Tue, 12 Oct 2010 09:56:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5fJp-0005o5-Pi for qemu-devel@nongnu.org; Tue, 12 Oct 2010 09:55:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26187) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5fJp-0005o1-JJ for qemu-devel@nongnu.org; Tue, 12 Oct 2010 09:55:05 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] qdev: Some ISA devices don't handle second instantiation gracefully References: <4CB46239.60500@codemonkey.ws> Date: Tue, 12 Oct 2010 15:54:59 +0200 In-Reply-To: <4CB46239.60500@codemonkey.ws> (Anthony Liguori's message of "Tue, 12 Oct 2010 08:27:21 -0500") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, "H. Peter Anvin" , Gerd Hoffmann , Alexander Graf , "Richard W. M. Jones" Anthony Liguori writes: > On 10/12/2010 08:00 AM, Markus Armbruster wrote: >> Markus Armbruster writes: >> >> >>> When I try -device isa-applesmc -device isa-applesmc, I get >>> >>> WARNING: Using AppleSMC with invalid key >>> qemu: hardware error: register_ioport_read: invalid opaque >>> [...] >>> >>> and a core dump. >>> >>> I know nothing about this device. Instantiating twice may well make no >>> sense. But hw_error() is not a nice way to reject a command line >>> option. >>> >> Actually, ib700 and isa-debugcon fail the same way. >> >> They call register_ioport_write(), which aborts via hw_error() when the >> port is already in use. This is okay for non-configurable parts of a >> board emulation, but not okay for a qdev device, unless it has no_user >> set. >> > > It's definitely right to fail but I agree, it's better to propagate > the error. > >> Related: when isa_init_irq() finds the requested IRQ already in use, it >> fails with exit(1). Maybe register_ioport_write()& friends should do >> that as well. >> >> Or maybe qdev device models should have an "at most one" flag. >> > > I think the proper thing to do is remove all exit(1)s and propagate > errors instead. exit() is good enough during startup, i.e. -device. It's wrong for hot plug; anything to be used in a hot plug path must propagate errors. We could keep exiting in code that's only used by non-hotpluggable devices. > A simple approach would be to make register_ioport_{read,write}() > return an int, then do a query-replace on the source tree to make all > invocations of it simply check the return value and exit if it's > non-zero. In similar cases, we've used a simple FOO_nofail() wrapper in places that want to exit. I'll see what I can do.