From: Laszlo Ersek <lersek@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu devel list <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] address order of virtio-mmio devices
Date: Thu, 29 Jan 2015 20:47:03 +0100 [thread overview]
Message-ID: <54CA8E37.8070009@redhat.com> (raw)
In-Reply-To: <54CA8637.2080306@redhat.com>
On 01/29/15 20:12, Laszlo Ersek wrote:
> On 01/29/15 20:01, Peter Maydell wrote:
>> On 29 January 2015 at 18:29, Laszlo Ersek <lersek@redhat.com> wrote:
>>> 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.
>>>
>>>> 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.
>
> 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.
>
>> (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.
>
>>
>>> 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.
>
> 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
next prev parent reply other threads:[~2015-01-29 19:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-29 17:25 [Qemu-devel] address order of virtio-mmio devices Laszlo Ersek
2015-01-29 17:59 ` Paolo Bonzini
2015-01-29 18:15 ` Peter Maydell
2015-01-29 18:29 ` Laszlo Ersek
2015-01-29 19:01 ` Peter Maydell
2015-01-29 19:12 ` Laszlo Ersek
2015-01-29 19:47 ` Laszlo Ersek [this message]
2015-01-29 20:05 ` Peter Maydell
2015-01-30 9:54 ` Daniel P. Berrange
2015-01-30 10:16 ` Laszlo Ersek
2015-01-30 10:29 ` Peter Maydell
2015-01-30 10:48 ` Daniel P. Berrange
2015-01-30 10:54 ` Peter Maydell
2015-01-30 11:32 ` Peter Maydell
2015-01-30 11:39 ` Laszlo Ersek
2015-01-30 11:42 ` Peter Maydell
2015-01-30 11:38 ` Laszlo Ersek
2015-01-30 11:40 ` Peter Maydell
2015-01-30 11:48 ` Laszlo Ersek
2015-01-30 11:50 ` Peter Maydell
2015-01-29 19:09 ` Richard W.M. Jones
2015-01-29 19:28 ` Peter Maydell
2015-01-29 19:35 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54CA8E37.8070009@redhat.com \
--to=lersek@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).