Skip to contentSkip to conversation

virtio-net: spec compatibility fix

PATCH In review Michael S. Tsirkin 5 participants 10 messages Nov 4, 2016 – Nov 7, 2016

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 virtio: allow per-device-class legacy features

In reply to Michael S. Tsirkin

Legacy features are those that transitional devices only expose on the legacy interface.
Allow different ones per device class.

---
 include/hw/virtio/virtio.h | 5 +++++
 hw/s390x/virtio-ccw.c      | 4 +++-
 hw/virtio/virtio-pci.c     | 4 +++-
 hw/virtio/virtio.c         | 2 ++
 4 files changed, 13 insertions(+), 2 deletions(-)
include/hw/virtio/virtio.h +5 -0
index f12a1a8..bdb3c4b 100644
@@ -113,6 +113,11 @@ typedef struct VirtioDeviceClass {
     void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
     void (*reset)(VirtIODevice *vdev);
     void (*set_status)(VirtIODevice *vdev, uint8_t val);
+    /* For transitional devices, this is a bitmap of features
+     * that are only exposed on the legacy interface but not
+     * the modern one.
+     */
+    uint64_t legacy_features;
     /* Test and clear event pending status.
      * Should be called after unmask to avoid losing events.
      * If backend does not support masking,
hw/s390x/virtio-ccw.c +3 -1
index 7d7f8f6..f5c1d98 100644
@@ -303,6 +303,8 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         if (!ccw.cda) {
             ret = -EFAULT;
         } else {
+            VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+
             features.index = address_space_ldub(&address_space_memory,
                                                 ccw.cda
                                                 + sizeof(features.features),
@@ -312,7 +314,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
                 if (dev->revision >= 1) {
                     /* Don't offer legacy features for modern devices. */
                     features.features = (uint32_t)
-                        (vdev->host_features & ~VIRTIO_LEGACY_FEATURES);
+                        (vdev->host_features & ~vdc->legacy_features);
                 } else {
                     features.features = (uint32_t)vdev->host_features;
                 }
hw/virtio/virtio-pci.c +3 -1
index 62001b4..97b32fe 100644
@@ -1175,7 +1175,9 @@ static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
         break;
     case VIRTIO_PCI_COMMON_DF:
         if (proxy->dfselect <= 1) {
-            val = (vdev->host_features & ~VIRTIO_LEGACY_FEATURES) >>
+            VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+
+            val = (vdev->host_features & ~vdc->legacy_features) >>
                 (32 * proxy->dfselect);
         }
         break;
hw/virtio/virtio.c +2 -0
index 1df5f4e..72ee06b 100644
@@ -2214,6 +2214,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
     dc->props = virtio_properties;
     vdc->start_ioeventfd = virtio_device_start_ioeventfd_impl;
     vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
+
+    vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
 }
 
 bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
Signature · 1 line
MST
#4 lore raw

PATCH 2/2 virtio-net: mark VIRTIO_NET_F_GSO as legacy

In reply to Michael S. Tsirkin

virtio 1.0 spec says this is a legacy feature bit, hide it from guests in legacy mode.

Note: for cross-version migration compatibility, we keep the bit set in host_features.
The result will be that a guest migrating cross-version will see host features change under it.
As guests only seem to read it once, this should not be an issue. Meanwhile, will work to fix guests to ignore this bit in virtio1 mode, too.

---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 20aa63e..b68c69d 100644
@@ -1942,6 +1942,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
     vdc->load = virtio_net_load_device;
     vdc->save = virtio_net_save_device;
+    vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO);
 }
 
 static const TypeInfo virtio_net_info = {
Signature · 1 line
MST
#0 lore raw

cover virtio-net: spec compatibility fix

Virtio 1.0 spec lists VIRTIO_NET_F_GSO as a legacy-only flag, by mistake we exposed it on the modern interface too, this is a spec violation.

I decided it's not worth it to implement a compatibility bit here as we already shipped virtio 1.0 support, we want to fix compatibility for old machine types too. While changing feature bits under guest's feet might be surprising, the spec doesn't exactly say it's illegal.

Michael S. Tsirkin (2):
virtio: allow per-device-class legacy features
virtio-net: mark VIRTIO_NET_F_GSO as legacy

 include/hw/virtio/virtio.h | 5 +++++
 hw/net/virtio-net.c        | 1 +
 hw/s390x/virtio-ccw.c      | 4 +++-
 hw/virtio/virtio-pci.c     | 4 +++-
 hw/virtio/virtio.c         | 2 ++
 5 files changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
MST
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] virtio: allow per-device-class legacy features

In reply to Michael S. Tsirkin
Quoted 11 lines · On Fri, 4 Nov 2016 13:01:37 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

Legacy features are those that transitional devices only expose on the legacy interface.
Allow different ones per device class.

---
 include/hw/virtio/virtio.h | 5 +++++
 hw/s390x/virtio-ccw.c      | 4 +++-
 hw/virtio/virtio-pci.c     | 4 +++-
 hw/virtio/virtio.c         | 2 ++
 4 files changed, 13 insertions(+), 2 deletions(-)
Reviewed-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy

In reply to Michael S. Tsirkin
Quoted 10 lines · On Fri, 4 Nov 2016 13:01:40 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

virtio 1.0 spec says this is a legacy feature bit, hide it from guests in legacy mode.

Note: for cross-version migration compatibility, we keep the bit set in host_features.
The result will be that a guest migrating cross-version will see host features change under it.
As guests only seem to read it once, this should not be an issue. Meanwhile, will work to fix guests to ignore this bit in virtio1 mode, too.

This also means that guest may see a different feature set if it is e.g. rebooted after migration. But I agree that this should not be an issue.

Quoted 2 lines

You also need to cc: the previous patch to stable.

Quoted 10 lines
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +0 -0
index 20aa63e..b68c69d 100644

hw/net/virtio-net.c static void virtio_net_class_init(ObjectClass *klass, void *data) · line 1948

Quoted 7 lines
hw/net/virtio-net.c +1 -0
@@ -1942,6 +1942,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
     vdc->load = virtio_net_load_device;
     vdc->save = virtio_net_save_device;
+    vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO);
 }
 
 static const TypeInfo virtio_net_info = {
Acked-by on v1 1/2
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] virtio: allow per-device-class legacy features

In reply to Michael S. Tsirkin
Quoted 70 lines · Michael S. Tsirkin

Legacy features are those that transitional devices only expose on the legacy interface.
Allow different ones per device class.

---
  include/hw/virtio/virtio.h | 5 +++++
  hw/s390x/virtio-ccw.c      | 4 +++-
  hw/virtio/virtio-pci.c     | 4 +++-
  hw/virtio/virtio.c         | 2 ++
  4 files changed, 13 insertions(+), 2 deletions(-)
include/hw/virtio/virtio.h +5 -0
index f12a1a8..bdb3c4b 100644
@@ -113,6 +113,11 @@ typedef struct VirtioDeviceClass {
      void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
      void (*reset)(VirtIODevice *vdev);
      void (*set_status)(VirtIODevice *vdev, uint8_t val);
+    /* For transitional devices, this is a bitmap of features
+     * that are only exposed on the legacy interface but not
+     * the modern one.
+     */
+    uint64_t legacy_features;
      /* Test and clear event pending status.
       * Should be called after unmask to avoid losing events.
       * If backend does not support masking,
hw/s390x/virtio-ccw.c +3 -1
index 7d7f8f6..f5c1d98 100644
@@ -303,6 +303,8 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
          if (!ccw.cda) {
              ret = -EFAULT;
          } else {
+            VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+
              features.index = address_space_ldub(&address_space_memory,
                                                  ccw.cda
                                                  + sizeof(features.features),
@@ -312,7 +314,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
                  if (dev->revision >= 1) {
                      /* Don't offer legacy features for modern devices. */
                      features.features = (uint32_t)
-                        (vdev->host_features & ~VIRTIO_LEGACY_FEATURES);
+                        (vdev->host_features & ~vdc->legacy_features);
                  } else {
                      features.features = (uint32_t)vdev->host_features;
                  }
hw/virtio/virtio-pci.c +3 -1
index 62001b4..97b32fe 100644
@@ -1175,7 +1175,9 @@ static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
          break;
      case VIRTIO_PCI_COMMON_DF:
          if (proxy->dfselect <= 1) {
-            val = (vdev->host_features & ~VIRTIO_LEGACY_FEATURES) >>
+            VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+
+            val = (vdev->host_features & ~vdc->legacy_features) >>
                  (32 * proxy->dfselect);
          }
          break;
hw/virtio/virtio.c +0 -0
index 1df5f4e..72ee06b 100644

hw/virtio/virtio.c static void virtio_device_class_init(ObjectClass *klass, void *data) · line 2221

Quoted 8 lines
hw/virtio/virtio.c +2 -0
@@ -2214,6 +2214,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
      dc->props = virtio_properties;
      vdc->start_ioeventfd = virtio_device_start_ioeventfd_impl;
      vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
+
+    vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
  }
 
  bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
Acked-by on v1 2/2
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy

In reply to Michael S. Tsirkin
Quoted 22 lines · Michael S. Tsirkin

virtio 1.0 spec says this is a legacy feature bit, hide it from guests in legacy mode.

Note: for cross-version migration compatibility, we keep the bit set in host_features.
The result will be that a guest migrating cross-version will see host features change under it.
As guests only seem to read it once, this should not be an issue. Meanwhile, will work to fix guests to ignore this bit in virtio1 mode, too.

---
  hw/net/virtio-net.c | 1 +
  1 file changed, 1 insertion(+)
hw/net/virtio-net.c +0 -0
index 20aa63e..b68c69d 100644

hw/net/virtio-net.c static void virtio_net_class_init(ObjectClass *klass, void *data) · line 1948

Quoted 7 lines
hw/net/virtio-net.c +1 -0
@@ -1942,6 +1942,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
      vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
      vdc->load = virtio_net_load_device;
      vdc->save = virtio_net_save_device;
+    vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO);
  }
 
  static const TypeInfo virtio_net_info = {
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy

In reply to Michael S. Tsirkin
Quoted 10 lines · * Michael S. Tsirkin ([email protected]) wrote:

virtio 1.0 spec says this is a legacy feature bit, hide it from guests in legacy mode.

Note: for cross-version migration compatibility, we keep the bit set in host_features.
The result will be that a guest migrating cross-version will see host features change under it.
As guests only seem to read it once, this should not be an issue. Meanwhile, will work to fix guests to ignore this bit in virtio1 mode, too.

OK, but if they're actually using the feature they'll carry on working ?

Dave

Quoted 21 lines
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 20aa63e..b68c69d 100644
@@ -1942,6 +1942,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
     vdc->load = virtio_net_load_device;
     vdc->save = virtio_net_save_device;
+    vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO);
 }
 
 static const TypeInfo virtio_net_info = {
Signature · 1 line
MST

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy

In reply to Michael S. Tsirkin
Quoted 3 lines · Michael S. Tsirkin

virtio 1.0 spec says this is a legacy feature bit, hide it from guests in legacy mode.

Probably the other way around: since its legacy
it is supposed to be hidden from non-legacy )and
exposed to legacy) or?

Quoted 8 lines

Note: for cross-version migration compatibility, we keep the bit set in host_features.
The result will be that a guest migrating cross-version will see host features change under it.
As guests only seem to read it once, this should not be an issue. Meanwhile, will work to fix guests to ignore this bit in virtio1 mode, too.

Makes sense to me (except for the probably typo).

Regards,
Halil

Quoted 19 lines
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 20aa63e..b68c69d 100644
@@ -1942,6 +1942,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
     vdc->load = virtio_net_load_device;
     vdc->save = virtio_net_save_device;
+    vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO);
 }
 
 static const TypeInfo virtio_net_info = {
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy

In reply to Dr. David Alan Gilbert
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 10 lines

virtio 1.0 spec says this is a legacy feature bit, hide it from guests in legacy mode.

Note: for cross-version migration compatibility, we keep the bit set in host_features.
The result will be that a guest migrating cross-version will see host features change under it.
As guests only seem to read it once, this should not be an issue. Meanwhile, will work to fix guests to ignore this bit in virtio1 mode, too.

Quoted 5 lines

OK, but if they're actually using the feature they'll carry on working ?

Dave

The interesting scenario is when we migrate form older to newer (otherwise the bugous situation can't emerge in the first place). Now the change affects only what the guest sees when it reads host_features, and that should happen only during the feature negotiation (once). That means the change won't have any observable effect unless a reset happens. And if we have a reset, then things are going to work out correctly avoiding the bugous (but still working) state in both host and guest. So yes, both will happily carry on using the feature, and carry on working.

Halil