Skip to contentSkip to conversation

address order of virtio-mmio devices

Qemu-devel Laszlo Ersek 5 participants 23 messages Jan 29, 2015 – Jan 30, 2015

lore
Share & tools
lore
#0 lore raw

Hi,

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.

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
type virtio-mmio-bus
dev: virtio-net-device, id ""
mac = "52:54:00:12:34:56"
vlan = <null>
netdev = "netdev0"
x-txtimer = 150000 (0x249f0)
x-txburst = 256 (0x100)
tx = ""
dev: virtio-mmio, id ""

    gpio-out "sysbus-irq" 1
    indirect_desc = true
    event_idx = true
    mmio 000000000a003c00/0000000000000200
    bus: virtio-mmio-bus.30
      type virtio-mmio-bus
      dev: virtio-blk-device, id ""
        drive = "hd0"
        logical_block_size = 512 (0x200)
        physical_block_size = 512 (0x200)
        min_io_size = 0 (0x0)
        opt_io_size = 0 (0x0)
        discard_granularity = 4294967295 (0xffffffff)
        cyls = 16383 (0x3fff)
        heads = 16 (0x10)
        secs = 63 (0x3f)
        serial = ""
        config-wce = true
        scsi = true
        x-data-plane = false
  dev: virtio-mmio, id ""
    gpio-out "sysbus-irq" 1
    indirect_desc = true
    event_idx = true
    mmio 000000000a003a00/0000000000000200
    bus: virtio-mmio-bus.29
      type virtio-mmio-bus
      dev: virtio-scsi-device, id "scsi0"
        num_queues = 1 (0x1)
        max_sectors = 65535 (0xffff)
        cmd_per_lun = 128 (0x80)
        bus: scsi0.0
          type SCSI
          [snip]

Notice that the first device listed ends at 0xa000000 + 0x20 * 0x200 = 0xa004000, and further devices are located at decreasing addresses.

So, my questions are:
- has anyone actually tested the placement?
- would you take a patch that reverses the loop?

----------------

hw/arm/virt.c +0 -0
index 2353440..705e623 100644
@@ -441,23 +441,17 @@ static void create_virtio_devices(const

VirtBoardInfo *vbi, qemu_irq *pic)

     int i;
     hwaddr size = vbi->memmap[VIRT_MMIO].size;

- /* Note that we have to create the transports in forwards order
+ /* Note that we have to create the transports in backwards order
* so that command line devices are inserted lowest address first,
- * and then add dtb nodes in reverse order so that they appear in
+ * and then add dtb nodes in reverse order too 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]);
- }
-

     for (i = NUM_VIRTIO_TRANSPORTS - 1; i >= 0; i--) {
         char *nodename;
         int irq = vbi->irqmap[VIRT_MMIO] + i;
         hwaddr base = vbi->memmap[VIRT_MMIO].base + i * size;
+        sysbus_create_simple("virtio-mmio", base, pic[irq]);
         nodename = g_strdup_printf("/virtio_mmio@%" PRIx64, base);
         qemu_fdt_add_subnode(vbi->fdt, nodename);
         qemu_fdt_setprop_string(vbi->fdt, nodename,

----------------

With the patch, the info qtree output is as follows:

dev: virtio-mmio, id ""
gpio-out "sysbus-irq" 1
indirect_desc = true
event_idx = true
mmio 000000000a000000/0000000000000200
bus: virtio-mmio-bus.31
type virtio-mmio-bus
dev: virtio-net-device, id ""
mac = "52:54:00:12:34:56"
vlan = <null>
netdev = "netdev0"
x-txtimer = 150000 (0x249f0)
x-txburst = 256 (0x100)
tx = ""
dev: virtio-mmio, id ""

    gpio-out "sysbus-irq" 1
    indirect_desc = true
    event_idx = true
    mmio 000000000a000200/0000000000000200
    bus: virtio-mmio-bus.30
      type virtio-mmio-bus
      dev: virtio-blk-device, id ""
        drive = "hd0"
        logical_block_size = 512 (0x200)
        physical_block_size = 512 (0x200)
        min_io_size = 0 (0x0)
        opt_io_size = 0 (0x0)
        discard_granularity = 4294967295 (0xffffffff)
        cyls = 16383 (0x3fff)
        heads = 16 (0x10)
        secs = 63 (0x3f)
        serial = ""
        config-wce = true
        scsi = true
        x-data-plane = false
  dev: virtio-mmio, id ""
    gpio-out "sysbus-irq" 1
    indirect_desc = true
    event_idx = true
    mmio 000000000a000400/0000000000000200
    bus: virtio-mmio-bus.29
      type virtio-mmio-bus
      dev: virtio-scsi-device, id "scsi0"
        num_queues = 1 (0x1)
        max_sectors = 65535 (0xffff)
        cmd_per_lun = 128 (0x80)
        bus: scsi0.0
          type SCSI
          [snip]

There's nothing to do about the decreasing "virtio-mmio-bus.N" naming -- see the "automatic_ids++" in qbus_realize(), which, paired with QLIST_INSERT_HEAD() just below it, leads to the decrasing IDs. However, the addresses do reflect the command line order.

Another possibility would be to replace QLIST_INSERT_HEAD() with QTAILQ_INSERT_TAIL() in qbus_realize(), but compared to the virt board code, that could very easily regress stuff.

Thanks
Laszlo

#1 lore raw
Quoted 3 lines · Laszlo Ersek

Another possibility would be to replace QLIST_INSERT_HEAD() with QTAILQ_INSERT_TAIL() in qbus_realize(), but compared to the virt board code, that could very easily regress stuff.

Yes, this would be an ABI change.

Paolo

#2 lore raw
In reply to Laszlo Ersek
Quoted 16 lines · Laszlo Ersek

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]);
    }
Quoted 1 line

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.

Quoted 16 lines

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

Quoted 8 lines

(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

#3 lore raw
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Laszlo Ersek

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]);
    }
Quoted 7 lines
Quoted 1 line

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.

Understood. Then we'll probably have to address this in libguestfs.

Quoted 26 lines
Quoted 17 lines

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

Quoted 8 lines

(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

Quoted 2 lines

What tree is this a dump of? It doesn't look like a device tree dump.

No, it is the output of "info qtree", as I said above.

Quoted 18 lines

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";
        };
Quoted 1 line

[etc]

Yes. The DTB is 100% fine. However, we're talking two independent mappings here. The lower level mapping is the DTB, and that's completely fine. It's handled by the second loop in create_virtio_devices(). But, that mapping in the DTB doesn't know about actual virtio devices at all, it only describes virtio-mmio transports.

The bug is in the other mapping, ie. how devices specified with the -device options are mapped onto the (then already existing) virtio-mmio transports. The processing of -device is fine, it goes forward. The issue is that qbus_find_recursive(), in response to each -device option, finds the next free transport in decreasing address order, *because* qbus_realize() *prepended* each transport, not appended it, when create_virtio_devices() called sysbus_create_simple() in increasing address order at startup.

Quoted 3 lines

Device tree nodes appear in the tree lowest address first, which is exactly what the code above is claiming to do.

The comment makes two statements, and two loops follow it.

The first statement in the comment is wrong:

/* Note that we have to create the transports in forwards order
* so that command line devices are inserted lowest address first,

The first loop matches the first statement in the comment, hence the first loop is also wrong.

The second statement in the comment is correct:

* and then add dtb nodes in reverse order so that they appear in
* the finished device tree lowest address first.

hence the second loop (which matches the second statement) is also correct.

Thanks
Laszlo

#4 lore raw
Quoted 15 lines · Laszlo Ersek

Yes. The DTB is 100% fine. However, we're talking two independent mappings here. The lower level mapping is the DTB, and that's completely fine. It's handled by the second loop in create_virtio_devices(). But, that mapping in the DTB doesn't know about actual virtio devices at all, it only describes virtio-mmio transports.

The bug is in the other mapping, ie. how devices specified with the -device options are mapped onto the (then already existing) virtio-mmio transports. The processing of -device is fine, it goes forward. The issue is that qbus_find_recursive(), in response to each -device option, finds the next free transport in decreasing address order, *because* qbus_realize() *prepended* each transport, not appended it, when create_virtio_devices() called sysbus_create_simple() in increasing address order at startup.

Quoted 5 lines
Quoted 3 lines

Device tree nodes appear in the tree lowest address first, which is exactly what the code above is claiming to do.

The comment makes two statements, and two loops follow it.

I see what you mean now.

Does the ordering we have result in the guest kernel (usually) allocating vda to the first command line device, vdb to the second, and so on? I'm pretty sure I recall testing at the time and that that's why we have the funny ordering.

(Looking back through the archives, when we last looked at this I think it turned out that the kernel probes the mmio devices in one order and then assigns them vda/vdb/etc in the opposite order.)

Quoted 7 lines

The first statement in the comment is wrong:

/* Note that we have to create the transports in forwards order
* so that command line devices are inserted lowest address first,

The first loop matches the first statement in the comment, hence the first loop is also wrong.

Regardless, we can't change the ordering now without breaking existing command lines (I'm sure there are people out there who aren't using UUIDs).

We could fix the comment, though.

-- PMM

#5 lore raw
Quoted 20 lines · Peter Maydell
Quoted 19 lines · Laszlo Ersek

Yes. The DTB is 100% fine. However, we're talking two independent mappings here. The lower level mapping is the DTB, and that's completely fine. It's handled by the second loop in create_virtio_devices(). But, that mapping in the DTB doesn't know about actual virtio devices at all, it only describes virtio-mmio transports.

The bug is in the other mapping, ie. how devices specified with the -device options are mapped onto the (then already existing) virtio-mmio transports. The processing of -device is fine, it goes forward. The issue is that qbus_find_recursive(), in response to each -device option, finds the next free transport in decreasing address order, *because* qbus_realize() *prepended* each transport, not appended it, when create_virtio_devices() called sysbus_create_simple() in increasing address order at startup.

Quoted 3 lines

Device tree nodes appear in the tree lowest address first, which is exactly what the code above is claiming to do.

Quoted 8 lines
Quoted 1 line

The comment makes two statements, and two loops follow it.

I see what you mean now.

Does the ordering we have result in the guest kernel (usually) allocating vda to the first command line device, vdb to the second, and so on? I'm pretty sure I recall testing at the time and that that's why we have the funny ordering.

That's exactly what we're seeing. The first virtio-blk-device on the qemu command line ends up getting the highest /dev/vdX in the guest, and the last one on the qemu cmdline becomes /dev/vda in the guest. Libguestfs expects the last cmdline option to become the highest /dev/vdX.

Quoted 4 lines

(Looking back through the archives, when we last looked at this I think it turned out that the kernel probes the mmio devices in one order and then assigns them vda/vdb/etc in the opposite order.)

Ugh! That would be the perfect explanation for the current qemu code.

Quoted 6 lines
Quoted 6 lines

The first statement in the comment is wrong:

/* Note that we have to create the transports in forwards order
* so that command line devices are inserted lowest address first,

Quoted 8 lines
Quoted 2 lines

The first loop matches the first statement in the comment, hence the first loop is also wrong.

Regardless, we can't change the ordering now without breaking existing command lines (I'm sure there are people out there who aren't using UUIDs).

We could fix the comment, though.

If the guest kernel changed its "assignment strategy" at some point, but earlier it used to match the comment (and the code), then whichever way we shape the comment will be wrong for the other kernel strategy. :) So, in that case this code is probably best left undisturbed.

I'll try to dig out some kernel commit for more evidence.

Thanks!
Laszlo

#6 lore raw
Quoted 55 lines · Laszlo Ersek
Quoted 20 lines · Peter Maydell
Quoted 19 lines · Laszlo Ersek

Yes. The DTB is 100% fine. However, we're talking two independent mappings here. The lower level mapping is the DTB, and that's completely fine. It's handled by the second loop in create_virtio_devices(). But, that mapping in the DTB doesn't know about actual virtio devices at all, it only describes virtio-mmio transports.

The bug is in the other mapping, ie. how devices specified with the -device options are mapped onto the (then already existing) virtio-mmio transports. The processing of -device is fine, it goes forward. The issue is that qbus_find_recursive(), in response to each -device option, finds the next free transport in decreasing address order, *because* qbus_realize() *prepended* each transport, not appended it, when create_virtio_devices() called sysbus_create_simple() in increasing address order at startup.

Quoted 3 lines

Device tree nodes appear in the tree lowest address first, which is exactly what the code above is claiming to do.

Quoted 8 lines
Quoted 1 line

The comment makes two statements, and two loops follow it.

I see what you mean now.

Does the ordering we have result in the guest kernel (usually) allocating vda to the first command line device, vdb to the second, and so on? I'm pretty sure I recall testing at the time and that that's why we have the funny ordering.

That's exactly what we're seeing. The first virtio-blk-device on the qemu command line ends up getting the highest /dev/vdX in the guest, and the last one on the qemu cmdline becomes /dev/vda in the guest. Libguestfs expects the last cmdline option to become the highest /dev/vdX.

Quoted 4 lines

(Looking back through the archives, when we last looked at this I think it turned out that the kernel probes the mmio devices in one order and then assigns them vda/vdb/etc in the opposite order.)

Ugh! That would be the perfect explanation for the current qemu code.

Quoted 13 lines
Quoted 8 lines

The first statement in the comment is wrong:

/* Note that we have to create the transports in forwards order
* so that command line devices are inserted lowest address first,

The first loop matches the first statement in the comment, hence the first loop is also wrong.

Regardless, we can't change the ordering now without breaking existing command lines (I'm sure there are people out there who aren't using UUIDs).

Quoted 8 lines
Quoted 1 line

We could fix the comment, though.

If the guest kernel changed its "assignment strategy" at some point, but earlier it used to match the comment (and the code), then whichever way we shape the comment will be wrong for the other kernel strategy. :) So, in that case this code is probably best left undisturbed.

I'll try to dig out some kernel commit for more evidence.

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=70161ff3

Laszlo

#7 lore raw
Quoted 9 lines · Laszlo Ersek
Quoted 6 lines · Laszlo Ersek

If the guest kernel changed its "assignment strategy" at some point, but earlier it used to match the comment (and the code), then whichever way we shape the comment will be wrong for the other kernel strategy. :) So, in that case this code is probably best left undisturbed.

I'll try to dig out some kernel commit for more evidence.

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=70161ff3

Thanks for digging that up -- I was half-thinking we might just have got it wrong two years ago when we wrote the code :-)

We should probably update the comment to say (a) what we were trying to do (b) that we don't want to change it now because it would break existing setups.

-- PMM

#8 lore raw
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Laszlo Ersek
Quoted 6 lines · Laszlo Ersek

If the guest kernel changed its "assignment strategy" at some point, but earlier it used to match the comment (and the code), then whichever way we shape the comment will be wrong for the other kernel strategy. :) So, in that case this code is probably best left undisturbed.

I'll try to dig out some kernel commit for more evidence.

Quoted 8 lines
Quoted 1 line

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=70161ff3

Thanks for digging that up -- I was half-thinking we might just have got it wrong two years ago when we wrote the code :-)

We should probably update the comment to say (a) what we were trying to do (b) that we don't want to change it now because it would break existing setups.

While it is clear there is no solution that works correctly with all kernels, I hate to think that we're going to stick with an ordering that is clearly wrong for modern kernels, forever going forward. The aarch64 world is only just starting out, so on balance I think we should optimize for the future rather than the past, since that gives right behaviour for orders of magnitude more people in the long term.

Also can we start using a versioned machine type for ARM, and make the new machine type have the correct ordering for current kernels.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#9 lore raw
Quoted 26 lines · Daniel P. Berrange
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Laszlo Ersek
Quoted 6 lines · Laszlo Ersek

If the guest kernel changed its "assignment strategy" at some point, but earlier it used to match the comment (and the code), then whichever way we shape the comment will be wrong for the other kernel strategy. :) So, in that case this code is probably best left undisturbed.

I'll try to dig out some kernel commit for more evidence.

Quoted 8 lines
Quoted 1 line

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=70161ff3

Thanks for digging that up -- I was half-thinking we might just have got it wrong two years ago when we wrote the code :-)

We should probably update the comment to say (a) what we were trying to do (b) that we don't want to change it now because it would break existing setups.

While it is clear there is no solution that works correctly with all kernels, I hate to think that we're going to stick with an ordering that is clearly wrong for modern kernels, forever going forward. The aarch64 world is only just starting out, so on balance I think we should optimize for the future rather than the past, since that gives right behaviour for orders of magnitude more people in the long term.

Quoted 2 lines

Also can we start using a versioned machine type for ARM, and make the new machine type have the correct ordering for current kernels.

Wei recently posted a patch that introduced versioning for machvirt. (I didn't see the patch, only know about it.) If Peter agrees, I guess both Wei's patch and mine could be applied. (Although, mine should be reworked so that it affect only the new machtype.)

Thanks
Laszlo

#10 lore raw
In reply to Daniel P. Berrange
Quoted 6 lines · Daniel P. Berrange

While it is clear there is no solution that works correctly with all kernels, I hate to think that we're going to stick with an ordering that is clearly wrong for modern kernels, forever going forward. The aarch64 world is only just starting out, so on balance I think we should optimize for the future rather than the past, since that gives right behaviour for orders of magnitude more people in the long term.

Yeah, I agree it's awkward. But I hate breaking people's working setups, and we have no guarantee the kernel won't change again in the future.

You could try asking the kernel folk to revert that patch on the basis that it breaks things...

Quoted 2 lines

Also can we start using a versioned machine type for ARM, and make the new machine type have the correct ordering for current kernels.

No, not yet. We are miles and miles and miles away from being able to do cross-version migration correctly, and adding version machine types is accepting a huge maintenance burden from now extending indefinitely into the future. (It only works for x86, as I understand it, because RedHat do a lot of testing of various migration scenarios including cross-version, and even then we miss things. Nobody has as yet suggested they're doing or even planning to do that level of testing on the ARM boards. I'm not going to add versioned boards until it becomes absolutely required. Having working within-version migration would be a start.

-- PMM

#11 lore raw
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Daniel P. Berrange

While it is clear there is no solution that works correctly with all kernels, I hate to think that we're going to stick with an ordering that is clearly wrong for modern kernels, forever going forward. The aarch64 world is only just starting out, so on balance I think we should optimize for the future rather than the past, since that gives right behaviour for orders of magnitude more people in the long term.

Quoted 6 lines

Yeah, I agree it's awkward. But I hate breaking people's working setups, and we have no guarantee the kernel won't change again in the future.

You could try asking the kernel folk to revert that patch on the basis that it breaks things...

Might be worth a shot - the patch is only a month old. Or at least do a followup patch to put the ordering back the way it was, rather than plain revert

Long term though it will be much better of AArch64 would just do PCI instead of MMIO bus. Then we have proper device addressing which we can control in a predictable manner that will be stable across hotplug and unplug and migration. I hear there's work on PCI for AArch64 but is there a near term ETA yet ?

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#12 lore raw
Quoted 5 lines · Daniel P. Berrange

Long term though it will be much better of AArch64 would just do PCI instead of MMIO bus. Then we have proper device addressing which we can control in a predictable manner that will be stable across hotplug and unplug and migration. I hear there's work on PCI for AArch64 but is there a near term ETA yet ?

I need to review Alex's v3 patchset; if it doesn't have any issues it'll probably go into target-arm.next next week and hit mainline shortly after that.

-- PMM

#13 lore raw
Quoted 10 lines · Peter Maydell
Quoted 5 lines · Daniel P. Berrange

Long term though it will be much better of AArch64 would just do PCI instead of MMIO bus. Then we have proper device addressing which we can control in a predictable manner that will be stable across hotplug and unplug and migration. I hear there's work on PCI for AArch64 but is there a near term ETA yet ?

I need to review Alex's v3 patchset; if it doesn't have any issues it'll probably go into target-arm.next next week and hit mainline shortly after that.

Incidentally if you have opinions about sensible minimum sizes of PCI ECAM and MMIO windows in the address space now would be a good time to air them.

-- PMM

#14 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell
Quoted 5 lines · Daniel P. Berrange

Long term though it will be much better of AArch64 would just do PCI instead of MMIO bus. Then we have proper device addressing which we can control in a predictable manner that will be stable across hotplug and unplug and migration. I hear there's work on PCI for AArch64 but is there a near term ETA yet ?

I need to review Alex's v3 patchset; if it doesn't have any issues it'll probably go into target-arm.next next week and hit mainline shortly after that.

(And then a root bridge driver for it will be necessary in edk2. (I'm unsure if the guest kernel driver is already being worked on.))

Thanks
Laszlo

#15 lore raw
Quoted 8 lines · Laszlo Ersek
Quoted 7 lines · Peter Maydell
Quoted 5 lines · Daniel P. Berrange

Long term though it will be much better of AArch64 would just do PCI instead of MMIO bus. Then we have proper device addressing which we can control in a predictable manner that will be stable across hotplug and unplug and migration. I hear there's work on PCI for AArch64 but is there a near term ETA yet ?

Quoted 6 lines
Quoted 3 lines

I need to review Alex's v3 patchset; if it doesn't have any issues it'll probably go into target-arm.next next week and hit mainline shortly after that.

(And then a root bridge driver for it will be necessary in edk2. (I'm unsure if the guest kernel driver is already being worked on.))

Guest kernel doesn't need any particular support because it uses the generic pcie-driven-by-device-tree. For 64-bit ARM there's some minor missing kernel cleanup/patch, but for 32-bit it works as is. [see Alex's notes in patch 3/4 for detail.]

-- PMM

#16 lore raw
In reply to Daniel P. Berrange
Quoted 13 lines · Daniel P. Berrange
Quoted 12 lines · Peter Maydell
Quoted 6 lines · Daniel P. Berrange

While it is clear there is no solution that works correctly with all kernels, I hate to think that we're going to stick with an ordering that is clearly wrong for modern kernels, forever going forward. The aarch64 world is only just starting out, so on balance I think we should optimize for the future rather than the past, since that gives right behaviour for orders of magnitude more people in the long term.

Yeah, I agree it's awkward. But I hate breaking people's working setups, and we have no guarantee the kernel won't change again in the future.

Quoted 6 lines
Quoted 2 lines

You could try asking the kernel folk to revert that patch on the basis that it breaks things...

Might be worth a shot - the patch is only a month old. Or at least do a followup patch to put the ordering back the way it was, rather than plain revert

Please note that (as far as I understand) the patch that I referenced is indeed very new, it's not part of v3.18, but the reversal can easily be seen with v3.18. In other words, the kernel patch I referenced introduces no functional change, it just reorganizes stuff in the kernel (AIUI), with the benefit of killing a superfluous field.

The reason I referenced it because its *commit message* gives good background. If we really wanted to find the kernel change that reversed the traversal, we'd have to talk to Grant and/or bisect the kernel.

Thanks
Laszlo

Quoted 9 lines

Long term though it will be much better of AArch64 would just do PCI instead of MMIO bus. Then we have proper device addressing which we can control in a predictable manner that will be stable across hotplug and unplug and migration. I hear there's work on PCI for AArch64 but is there a near term ETA yet ?

Regards,
Daniel

#17 lore raw
Quoted 9 lines · Laszlo Ersek

Please note that (as far as I understand) the patch that I referenced is indeed very new, it's not part of v3.18, but the reversal can easily be seen with v3.18. In other words, the kernel patch I referenced introduces no functional change, it just reorganizes stuff in the kernel (AIUI), with the benefit of killing a superfluous field.

The reason I referenced it because its *commit message* gives good background. If we really wanted to find the kernel change that reversed the traversal, we'd have to talk to Grant and/or bisect the kernel.

Just as a sanity check, do we actually have an old kernel that enumerates in the opposite order (as opposed to my two-year-old "I'm sure this used to be right" memories...) ?

-- PMM

#18 lore raw
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Laszlo Ersek

Please note that (as far as I understand) the patch that I referenced is indeed very new, it's not part of v3.18, but the reversal can easily be seen with v3.18. In other words, the kernel patch I referenced introduces no functional change, it just reorganizes stuff in the kernel (AIUI), with the benefit of killing a superfluous field.

Quoted 7 lines
Quoted 3 lines

The reason I referenced it because its *commit message* gives good background. If we really wanted to find the kernel change that reversed the traversal, we'd have to talk to Grant and/or bisect the kernel.

Just as a sanity check, do we actually have an old kernel that enumerates in the opposite order (as opposed to my two-year-old "I'm sure this used to be right" memories...) ?

I never saw one. :) That's why I asked in my first message if anyone had actually tested that loop / comment.

Thanks,
Laszlo

#19 lore raw
Quoted 7 lines · Laszlo Ersek
Quoted 3 lines · Peter Maydell

Just as a sanity check, do we actually have an old kernel that enumerates in the opposite order (as opposed to my two-year-old "I'm sure this used to be right" memories...) ?

I never saw one. :) That's why I asked in my first message if anyone had actually tested that loop / comment.

Well, I *think* I did, because I remember the go-round about it and I wouldn't have written weird code like that without a reason. But it's two years ago now...

-- PMM

#20 lore raw
In reply to Laszlo Ersek
Quoted 20 lines · Laszlo Ersek
Quoted 19 lines · Peter Maydell
Quoted 17 lines · Laszlo Ersek

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.

Quoted 7 lines
Quoted 5 lines

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.

Understood. Then we'll probably have to address this in libguestfs.

That's pretty much impossible. If we can't fix qemu, then libguestfs will need to add the drives in reverse order on the command line (for this case virtio-blk && -M virt).

I should note that we're only trying to use virtio-blk because virtio-scsi is broken ... Laszlo: is there a public bug for that?

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
#21 lore raw
Quoted 8 lines · Richard W.M. Jones
Quoted 7 lines · Laszlo Ersek
Quoted 5 lines · Peter Maydell

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.

Quoted 5 lines
Quoted 1 line

Understood. Then we'll probably have to address this in libguestfs.

That's pretty much impossible. If we can't fix qemu, then libguestfs will need to add the drives in reverse order on the command line (for this case virtio-blk && -M virt).

This is still wrong, because the kernel doesn't guarantee the device ordering. It could break tomorrow with a new kernel version.

Quoted 2 lines

I should note that we're only trying to use virtio-blk because virtio-scsi is broken ... Laszlo: is there a public bug for that?

I don't think the kernel guarantees device order for *anything*.

-- PMM

#22 lore raw
In reply to Richard W.M. Jones
Quoted 27 lines · Richard W.M. Jones
Quoted 26 lines · Laszlo Ersek
Quoted 24 lines · Peter Maydell
Quoted 16 lines · Laszlo Ersek

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]);
    }
Quoted 1 line

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.

Quoted 5 lines
Quoted 1 line

Understood. Then we'll probably have to address this in libguestfs.

That's pretty much impossible. If we can't fix qemu, then libguestfs will need to add the drives in reverse order on the command line (for this case virtio-blk && -M virt).

That's precisely what I meant by "addressing it in libguestfs". My idea wasn't reversing the drives but to fixup the root=.... kernel cmdline parameter. But I didn't look into it at all; I certainly defer to you.

Quoted 2 lines

I should note that we're only trying to use virtio-blk because virtio-scsi is broken

It's not directly virtio-scsi that's broken; something in the thread pool breaks on aarch64 KVM, and only virtio-scsi exposes it, virtio-blk doesn't (although it uses the same thread pool, just with fewer middle layers).

Quoted 1 line

... Laszlo: is there a public bug for that?

There isn't.

I requested permission on the appropriate internal list to open up bug 1184405. I didn't get permission. I disagree with that to this day (given the actual contents of the bug).

Paolo had suggested to use Launchpad, but I resisted (for good reason; Launchpad is possibly the worst bug tracker imaginable. I have specific reasons.)

Working 12+ hours per day I don't feel the slightest inclination to screw around with substandard bug trackers during the original research, nor to shovel over 30+ carefully edited comments and about 10 attachments after their initial record in the RHBZ. The way forward is to open up 1184405, if we'd like it to be public.

Thanks
Laszlo