From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGtcn-0006xI-B9 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 13:15:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGtci-0005wy-6J for qemu-devel@nongnu.org; Thu, 29 Jan 2015 13:15:29 -0500 Received: from mail-lb0-f176.google.com ([209.85.217.176]:58472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGtch-0005wn-Vn for qemu-devel@nongnu.org; Thu, 29 Jan 2015 13:15:24 -0500 Received: by mail-lb0-f176.google.com with SMTP id z12so31054931lbi.7 for ; Thu, 29 Jan 2015 10:15:23 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <54CA6CF6.7090308@redhat.com> References: <54CA6CF6.7090308@redhat.com> From: Peter Maydell Date: Thu, 29 Jan 2015 18:15:02 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] address order of virtio-mmio devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek Cc: qemu devel list On 29 January 2015 at 17:25, Laszlo Ersek wrote: > I find that virtio-mmio devices are assigned highest-to-lowest addresses > as they are found on the command line. IOW, this code (from commit > f5fdcd6e): > > /* Note that we have to create the transports in forwards order > * so that command line devices are inserted lowest address first, > * and then add dtb nodes in reverse order so that they appear in > * the finished device tree lowest address first. > */ > for (i = 0; i < NUM_VIRTIO_TRANSPORTS; i++) { > int irq = vbi->irqmap[VIRT_MMIO] + i; > hwaddr base = vbi->memmap[VIRT_MMIO].base + i * size; > > sysbus_create_simple("virtio-mmio", base, pic[irq]); > } > > works exactly in reverse. Note that you can't rely on device ordering anyway. Guests should be using UUIDs or similar to ensure they mount the right filesystems in the right places, because the kernel makes no guarantee that it will enumerate devices in the device tree in any particular order. > The reason is that qbus_realize() reverses the order of child buses: > > if (bus->parent) { > QLIST_INSERT_HEAD(&bus->parent->child_bus, bus, sibling); > > ie. it inserts at the head, not at the tail. > > Then, when the -device options are processed, qbus_find_recursive() > locates free buses "forwards". > > According to info qtree, for the command line options > > -device virtio-net-device,netdev=netdev0,bootindex=2 > -device virtio-blk-device,drive=hd0,bootindex=0 > -device virtio-scsi-device,id=scsi0 > > (in this order), we end up with the following (partial) tree: > > dev: virtio-mmio, id "" > gpio-out "sysbus-irq" 1 > indirect_desc = true > event_idx = true > mmio 000000000a003e00/0000000000000200 > bus: virtio-mmio-bus.31 What tree is this a dump of? It doesn't look like a device tree dump. Dumping the dtb produces results in the expected order: [run qemu with -machine dumpdtb=/tmp/dump.dtb] dtc -I dtb -O dts /tmp/dump.dtb |less [...] virtio_mmio@a000000 { interrupts = <0x0 0x10 0x1>; reg = <0x0 0xa000000 0x0 0x200>; compatible = "virtio,mmio"; }; virtio_mmio@a000200 { interrupts = <0x0 0x11 0x1>; reg = <0x0 0xa000200 0x0 0x200>; compatible = "virtio,mmio"; }; [etc] Device tree nodes appear in the tree lowest address first, which is exactly what the code above is claiming to do. thanks -- PMM