linux-stable/drivers/virtio
Michael S. Tsirkin cbb726e6c6 virtio: acknowledge all features before access
commit 4fa59ede95 upstream.

The feature negotiation was designed in a way that
makes it possible for devices to know which config
fields will be accessed by drivers.

This is broken since commit 404123c2db ("virtio: allow drivers to
validate features") with fallout in at least block and net.  We have a
partial work-around in commit 2f9a174f91 ("virtio: write back
F_VERSION_1 before validate") which at least lets devices find out which
format should config space have, but this is a partial fix: guests
should not access config space without acknowledging features since
otherwise we'll never be able to change the config space format.

To fix, split finalize_features from virtio_finalize_features and
call finalize_features with all feature bits before validation,
and then - if validation changed any bits - once again after.

Since virtio_finalize_features no longer writes out features
rename it to virtio_features_ok - since that is what it does:
checks that features are ok with the device.

As a side effect, this also reduces the amount of hypervisor accesses -
we now only acknowledge features once unless we are clearing any
features when validating (which is uncommon).

IRC I think that this was more or less always the intent in the spec but
unfortunately the way the spec is worded does not say this explicitly, I
plan to address this at the spec level, too.

Acked-by: Jason Wang <jasowang@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 404123c2db ("virtio: allow drivers to validate features")
Fixes: 2f9a174f91 ("virtio: write back F_VERSION_1 before validate")
Cc: "Halil Pasic" <pasic@linux.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-03-16 14:23:43 +01:00
..
Kconfig virtio-pci: introduce modern device module 2021-02-23 07:52:58 -05:00
Makefile virtio-pci: introduce modern device module 2021-02-23 07:52:58 -05:00
virtio.c virtio: acknowledge all features before access 2022-03-16 14:23:43 +01:00
virtio_balloon.c virtio-balloon: Use virtio_find_vqs() helper 2021-09-06 07:20:56 -04:00
virtio_dma_buf.c virtio: fix build for configs without dma-bufs 2020-08-19 06:43:28 +02:00
virtio_input.c virtio-input: add multi-touch support 2021-02-23 07:52:59 -05:00
virtio_mem.c virtio/virtio_mem: handle a possible NULL as a memcpy parameter 2022-01-27 11:02:59 +01:00
virtio_mmio.c virtio-mmio: Use to_virtio_mmio_device() to simply code 2021-03-14 04:37:35 -04:00
virtio_pci_common.c virtio_pci: Support surprise removal of virtio pci device 2021-08-10 11:50:55 -04:00
virtio_pci_common.h virtio-pci: introduce modern device module 2021-02-23 07:52:58 -05:00
virtio_pci_legacy.c
virtio_pci_modern.c virtio_pci_modern: __force cast the notify mapping 2021-05-04 04:19:58 -04:00
virtio_pci_modern_dev.c virtio-pci library: introduce vp_modern_get_driver_features() 2021-07-08 07:49:01 -04:00
virtio_ring.c virtio_ring: mark ring unused on error 2022-01-27 11:05:35 +01:00
virtio_vdpa.c virtio_vdpa: reject invalid vq indices 2021-08-11 06:44:23 -04:00