From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36953 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5gDy-00030c-Gm for qemu-devel@nongnu.org; Tue, 12 Oct 2010 10:53:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5gDx-00086N-Bo for qemu-devel@nongnu.org; Tue, 12 Oct 2010 10:53:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5gDx-000861-5k for qemu-devel@nongnu.org; Tue, 12 Oct 2010 10:53:05 -0400 Message-ID: <4CB47649.6020104@redhat.com> Date: Tue, 12 Oct 2010 16:52:57 +0200 From: Gerd Hoffmann MIME-Version: 1.0 References: <3D29523C-48CB-41B3-BCBE-901EAEE2779E@suse.de> In-Reply-To: <3D29523C-48CB-41B3-BCBE-901EAEE2779E@suse.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: qdev: Some ISA devices don't handle second instantiation gracefully List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: qemu-devel@nongnu.org, "H. Peter Anvin" , Markus Armbruster , "Richard W. M. Jones" Hi, >> 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. >> >> 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. > > There can be multiple of these devices on different ports, but a > single PIO port can still only be managed by a single device. By > creating the same device twice without giving it a PIO option, you > put two devices on the same PIO port which can't work. > > As this is a configuration error, I'd guess the best way to deal with > it is to return an error for register_ioport which makes the qdev > init fail. Then the respective instantiator can do what is fit. If > the device is passed in on the cmdline, it'd refuse to create the > machine and exit. If it's a hotplug event, it would fail to hotplug. ISA isn't hotpluggable anyway, so just exiting unconditionally here isn't a big issue IMHO as effectively only ISA devices are affected by this. register_ioport_write() should exit with a more useful error message here instead of calling hw_error() though. We could also make register_ioport_write() pass up an error and have all callers check that. Not sure this is worth the trouble though. An "at most one" flag might make sense. But on a PC all ISA devices which exist only once at a fixed address (keyboard, floppy, ...) are automagically created so no_user does the trick here. The other ones (serial, ne2k_isa, ...) actually can be created multiple times if you configure different iobases using properties. Dunno what kind of device apple-smc is ... cheers, Gerd