From: Cornelia Huck <cohuck@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, Halil Pasic <pasic@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, markver@us.ibm.com,
Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-devel@nongnu.org, Jason Wang <jasowang@redhat.com>,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
Xie Yongji <xieyongji@bytedance.com>,
stefanha@redhat.com,
Raphael Norwitz <raphael.norwitz@nutanix.com>
Subject: Re: [RFC PATCH 1/1] virtio: write back features before verify
Date: Tue, 05 Oct 2021 12:06:57 +0200 [thread overview]
Message-ID: <87o88323b2.fsf@redhat.com> (raw)
In-Reply-To: <20211004040937-mutt-send-email-mst@kernel.org>
On Mon, Oct 04 2021, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Mon, Oct 04, 2021 at 04:23:23AM +0200, Halil Pasic wrote:
>> --------------------------8<---------------------
>>
>> From: Halil Pasic <pasic@linux.ibm.com>
>> Date: Thu, 30 Sep 2021 02:38:47 +0200
>> Subject: [PATCH] virtio: write back feature VERSION_1 before verify
>>
>> This patch fixes a regression introduced by commit 82e89ea077b9
>> ("virtio-blk: Add validation for block size in config space") and
>> enables similar checks in verify() on big endian platforms.
>>
>> The problem with checking multi-byte config fields in the verify
>> callback, on big endian platforms, and with a possibly transitional
>> device is the following. The verify() callback is called between
>> config->get_features() and virtio_finalize_features(). That we have a
>> device that offered F_VERSION_1 then we have the following options
>> either the device is transitional, and then it has to present the legacy
>> interface, i.e. a big endian config space until F_VERSION_1 is
>> negotiated, or we have a non-transitional device, which makes
>> F_VERSION_1 mandatory, and only implements the non-legacy interface and
>> thus presents a little endian config space. Because at this point we
>> can't know if the device is transitional or non-transitional, we can't
>> know do we need to byte swap or not.
>
> Well we established that we can know. Here's an alternative explanation:
>
> The virtio specification virtio-v1.1-cs01 states:
>
> Transitional devices MUST detect Legacy drivers by detecting that
> VIRTIO_F_VERSION_1 has not been acknowledged by the driver.
> This is exactly what QEMU as of 6.1 has done relying solely
> on VIRTIO_F_VERSION_1 for detecting that.
>
> However, the specification also says:
> driver MAY read (but MUST NOT write) the device-specific
> configuration fields to check that it can support the device before
> accepting it.
>
> In that case, any device relying solely on VIRTIO_F_VERSION_1
> for detecting legacy drivers will return data in legacy format.
> In particular, this implies that it is in big endian format
> for big endian guests. This naturally confuses the driver
> which expects little endian in the modern mode.
>
> It is probably a good idea to amend the spec to clarify that
> VIRTIO_F_VERSION_1 can only be relied on after the feature negotiation
> is complete. However, we already have regression so let's
> try to address it.
I prefer that explanation.
>
>
>>
>> The virtio spec explicitly states that the driver MAY read config
>> between reading and writing the features so saying that first accessing
>> the config before feature negotiation is done is not an option. The
>> specification ain't clear about setting the features multiple times
>> before FEATURES_OK, so I guess that should be fine to set F_VERSION_1
>> since at this point we already know that we are about to negotiate
>> F_VERSION_1.
>>
>> I don't consider this patch super clean, but frankly I don't think we
>> have a ton of options. Another option that may or man not be cleaner,
>> but is also IMHO much uglier is to figure out whether the device is
>> transitional by rejecting _F_VERSION_1, then resetting it and proceeding
>> according tho what we have figured out, hoping that the characteristics
>> of the device didn't change.
>
> An empty line before tags.
>
>> Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
>> Fixes: 82e89ea077b9 ("virtio-blk: Add validation for block size in config space")
>> Reported-by: markver@us.ibm.com
>
> Let's add more commits that are affected. E.g. virtio-net with MTU
> feature bit set is affected too.
>
> So let's add Fixes tag for:
> commit 14de9d114a82a564b94388c95af79a701dc93134
> Author: Aaron Conole <aconole@redhat.com>
> Date: Fri Jun 3 16:57:12 2016 -0400
>
> virtio-net: Add initial MTU advice feature
>
> I think that's all, but pls double check me.
I could not find anything else after a quick check.
>
>
>> ---
>> drivers/virtio/virtio.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
>> index 0a5b54034d4b..2b9358f2e22a 100644
>> --- a/drivers/virtio/virtio.c
>> +++ b/drivers/virtio/virtio.c
>> @@ -239,6 +239,12 @@ static int virtio_dev_probe(struct device *_d)
>> driver_features_legacy = driver_features;
>> }
>>
>> + /* Write F_VERSION_1 feature to pin down endianness */
>> + if (device_features & (1ULL << VIRTIO_F_VERSION_1) & driver_features) {
>> + dev->features = (1ULL << VIRTIO_F_VERSION_1);
>> + dev->config->finalize_features(dev);
>> + }
>> +
>> if (device_features & (1ULL << VIRTIO_F_VERSION_1))
>> dev->features = driver_features & device_features;
>> else
>> --
>> 2.31.1
I think we should go with this just to fix the nasty regression for now.
next prev parent reply other threads:[~2021-10-05 10:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210930012049.3780865-1-pasic@linux.ibm.com>
[not found] ` <87r1d64dl4.fsf@redhat.com>
[not found] ` <20210930130350.0cdc7c65.pasic@linux.ibm.com>
[not found] ` <87ilyi47wn.fsf@redhat.com>
[not found] ` <20211001162213.18d7375e.pasic@linux.ibm.com>
[not found] ` <87v92g3h9l.fsf@redhat.com>
[not found] ` <20211002082128-mutt-send-email-mst@kernel.org>
[not found] ` <20211004042323.730c6a5e.pasic@linux.ibm.com>
2021-10-04 9:07 ` [RFC PATCH 1/1] virtio: write back features before verify Michael S. Tsirkin
2021-10-05 10:06 ` Cornelia Huck [this message]
2021-10-05 10:43 ` Halil Pasic
2021-10-05 11:11 ` Michael S. Tsirkin
2021-10-05 11:13 ` Cornelia Huck
2021-10-05 11:20 ` Michael S. Tsirkin
2021-10-05 11:59 ` Halil Pasic
2021-10-05 15:25 ` Cornelia Huck
[not found] ` <20210930070444-mutt-send-email-mst@kernel.org>
[not found] ` <20211001092125.64fef348.pasic@linux.ibm.com>
[not found] ` <20211002055605-mutt-send-email-mst@kernel.org>
2021-10-04 12:19 ` Cornelia Huck
2021-10-04 13:11 ` Michael S. Tsirkin
2021-10-04 14:33 ` Cornelia Huck
2021-10-04 15:07 ` Michael S. Tsirkin
2021-10-04 15:50 ` Cornelia Huck
2021-10-04 19:17 ` Michael S. Tsirkin
2021-10-06 10:13 ` Cornelia Huck
2021-10-06 12:15 ` Michael S. Tsirkin
2021-10-05 7:25 ` Halil Pasic
2021-10-05 7:53 ` Michael S. Tsirkin
2021-10-05 10:46 ` Halil Pasic
2021-10-05 11:11 ` Michael S. Tsirkin
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=87o88323b2.fsf@redhat.com \
--to=cohuck@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=markver@us.ibm.com \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=raphael.norwitz@nutanix.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xieyongji@bytedance.com \
/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).