[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/42] virtio: disallow late feature changes for virt
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 05/42] virtio: disallow late feature changes for virtio-1 |
Date: |
Thu, 11 Jun 2015 13:58:19 +0200 |
From: Cornelia Huck <address@hidden>
For virtio-1 devices, the driver must not attempt to set feature bits
after it set FEATURES_OK in the device status. Simply reject it in
that case.
Signed-off-by: Cornelia Huck <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
---
hw/virtio/virtio.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index c27e975..3367100 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1021,7 +1021,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
vmstate_save_state(f, &vmstate_virtio, vdev, NULL);
}
-int virtio_set_features(VirtIODevice *vdev, uint64_t val)
+static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
{
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
bool bad = (val & ~(vdev->host_features)) != 0;
@@ -1034,6 +1034,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)
return bad ? -1 : 0;
}
+int virtio_set_features(VirtIODevice *vdev, uint64_t val)
+{
+ /*
+ * The driver must not attempt to set features after feature negotiation
+ * has finished.
+ */
+ if (vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) {
+ return -EINVAL;
+ }
+ return virtio_set_features_nocheck(vdev, val);
+}
+
int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
{
int i, ret;
@@ -1137,14 +1149,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int
version_id)
* host_features.
*/
uint64_t features64 = vdev->guest_features;
- if (virtio_set_features(vdev, features64) < 0) {
+ if (virtio_set_features_nocheck(vdev, features64) < 0) {
error_report("Features 0x%" PRIx64 " unsupported. "
"Allowed features: 0x%" PRIx64,
features64, vdev->host_features);
return -1;
}
} else {
- if (virtio_set_features(vdev, features) < 0) {
+ if (virtio_set_features_nocheck(vdev, features) < 0) {
error_report("Features 0x%x unsupported. "
"Allowed features: 0x%" PRIx64,
features, vdev->host_features);
--
MST
- [Qemu-devel] [PULL 00/42] pc, acpi, virtio, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 01/42] vhost: put log correctly in vhost_dev_start(), Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 02/42] virtio: endianness checks for virtio 1.0 devices, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 03/42] virtio: allow virtio-1 queue layout, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 05/42] virtio: disallow late feature changes for virtio-1,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 04/42] dataplane: allow virtio-1 devices, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 06/42] virtio: allow to fail setting status, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 07/42] virtio-net: no writeable mac for virtio-1, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 08/42] virtio-net: support longer header, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 10/42] vhost_net: add version_1 feature, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 09/42] virtio-net: enable virtio 1.0, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 12/42] linux-headers: add virtio_pci, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 14/42] virtio: generation counter support, Michael S. Tsirkin, 2015/06/11
- [Qemu-devel] [PULL 13/42] virtio-pci: initial virtio 1.0 support, Michael S. Tsirkin, 2015/06/11