Michael S. Tsirkin
2021-Oct-02 18:13 UTC
[RFC PATCH 1/1] virtio: write back features before verify
On Fri, Oct 01, 2021 at 05:18:46PM +0200, Cornelia Huck wrote:> I'd say we need a hack here so that we assume little-endian config space > if VERSION_1 has been offered; if your patch here works, I assume QEMU > does what we expect (assmuming little-endian as well.) I'm mostly > wondering what happens if you use a different VMM; can we expect it to > work similar to QEMU?Hard to say of course ... hopefully other VMMs are actually implementing the spec. E.g. IIUC rust vmm is modern only.> Even if it helps for s390, we should double-check > what happens for other architectures. > > > > >> > >> Anyone have any better suggestions? > >> > > > > There is the conditional compile, as an option but I would not say it is > > better. > > Yes, I agree. > > Anyone else have an idea? This is a nasty regression; we could revert the > patch, which would remove the symptoms and give us some time, but that > doesn't really feel right, I'd do that only as a last resort.Well we have Halil's hack (except I would limit it to only apply to BE, only do devices with validate, and only in modern mode), and we will fix QEMU to be spec compliant. Between these why do we need any conditional compiles? -- MST
Halil Pasic
2021-Oct-04 02:23 UTC
[RFC PATCH 1/1] virtio: write back features before verify
On Sat, 2 Oct 2021 14:13:37 -0400 "Michael S. Tsirkin" <mst at redhat.com> wrote:> > Anyone else have an idea? This is a nasty regression; we could revert the > > patch, which would remove the symptoms and give us some time, but that > > doesn't really feel right, I'd do that only as a last resort. > > Well we have Halil's hack (except I would limit it > to only apply to BE, only do devices with validate, > and only in modern mode), and we will fix QEMU to be spec compliant. > Between these why do we need any conditional compiles?We don't. As I stated before, this hack is flawed because it effectively breaks fencing features by the driver with QEMU. Some features can not be unset after once set, because we tend to try to enable the corresponding functionality whenever we see a write features operation with the feature bit set, and we don't disable, if a subsequent features write operation stores the feature bit as not set. But it looks like VIRTIO_1 is fine to get cleared afterwards. So my hack should actually look like posted below, modulo conditions. Regarding the conditions I guess checking that driver_features has F_VERSION_1 already satisfies "only modern mode", or? For now I've deliberately omitted the has verify and the is big endian conditions so we have a better chance to see if something breaks (i.e. the approach does not work). I can add in those extra conditions later. --------------------------8<--------------------- From: Halil Pasic <pasic at 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. 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. Signed-off-by: Halil Pasic <pasic at linux.ibm.com> Fixes: 82e89ea077b9 ("virtio-blk: Add validation for block size in config space") Reported-by: markver at us.ibm.com --- 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
Cornelia Huck
2021-Oct-04 07:01 UTC
[RFC PATCH 1/1] virtio: write back features before verify
On Sat, Oct 02 2021, "Michael S. Tsirkin" <mst at redhat.com> wrote:> On Fri, Oct 01, 2021 at 05:18:46PM +0200, Cornelia Huck wrote: >> I'd say we need a hack here so that we assume little-endian config space >> if VERSION_1 has been offered; if your patch here works, I assume QEMU >> does what we expect (assmuming little-endian as well.) I'm mostly >> wondering what happens if you use a different VMM; can we expect it to >> work similar to QEMU? > > Hard to say of course ... hopefully other VMMs are actually > implementing the spec. E.g. IIUC rust vmm is modern only.Yes, I kind of hope they are simply doing LE config space accesses. Are there any other VMMs that are actually supported on s390x (or other BE architectures)?