Received: from eggs.gnu.org ([2001:4830:134:3::10]:34439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0Ovq-0002Iu-CO for qemu-devel@nongnu.org; Wed, 11 May 2016 03:51:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0Ovn-0004Is-3f for qemu-devel@nongnu.org; Wed, 11 May 2016 03:51:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0Ovm-0004IV-RE for qemu-devel@nongnu.org; Wed, 11 May 2016 03:51:43 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 249B57F6A7 for ; Wed, 11 May 2016 07:51:42 +0000 (UTC) From: Markus Armbruster References: <1462816056-17463-1-git-send-email-marcel@redhat.com> <8737pqfhac.fsf@dusky.pond.sub.org> <5731C070.2010709@redhat.com> Date: Wed, 11 May 2016 09:51:39 +0200 In-Reply-To: <5731C070.2010709@redhat.com> (Marcel Apfelbaum's message of "Tue, 10 May 2016 14:05:20 +0300") Message-ID: <87y47hhw1g.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC 0/3] qdev: order devices by priority before creating them List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, mst@redhat.com Marcel Apfelbaum writes: > On 05/10/2016 11:28 AM, Markus Armbruster wrote: >> Marcel Apfelbaum writes: >> >>> This series aims to allow more devices to be used with '-device' >>> by sorting the devices based on a predefined creation order flag >>> before creating them. >>> >>> Devices like IOMMU need to be created before others, so they can leverage >>> the DeviceCreationPriority flag introduced by the first patch to DeviceClass. >>> >>> The second patch sorts the devices by their DeviceCreationPriority >>> before creating them. >>> >>> Finally, the last patch demonstrates how it can be used to ensure >>> the creation of host-bridges before the pci-bridges and pci-bridges before >>> the others. >>> >>> I preferred to combine all the priorities into a single enum >>> to better manage the creation order. >>> >>> This is an RFC because I only wanted to know if it seems like the right way to go. >>> Comments are appreciated, >> > > Hi Markus, > Thanks for looking into this. > > >> Can you explain why requiring the user to specify -device in a sane >> order isn't good enough? >> > > Point taken, the truth is I didn't like the 'order' restriction in the > first place. > > If the device creation depends on the id of some other devices (e.g we > need the bus id to plug a device into it), for IOMMU devices it gets a > little tricky. You can add the IOMMU device before other PCI devices > but it will not work (because some internal implementation). This is > why we added using -machine pc,iommu=on. I suppose we have other > examples as well. This is not user friendly IMO. > > To solve the specific IOMMU problem we can check that there are no PCI > devices created yet, but I am not sure is a better approach and is > strictly related to this device. > > The goal is to be able to add more devices with -device and I thought > this kind of creation in steps may help. In my opinion, there are two sane ways to do command line options. One is to make order relevant, and process them strictly left to right. The other is to do the right thing regardless of order. This requires some kind of dependency tracking if there are any. QEMU, of course, does neither: we process them in left to right unless we don't, and users juggle them until the errors go away. I'm afraid this patch adds to "unless we don't" without covering much ground towards "do the right thing regardless of order". Static priorities are a rather crude approximation of dependencies. Is it the best we can do for user now?