virtio-net: spec compatibility fix
PATCH 1/2 virtio: allow per-device-class legacy features
In reply to Michael S. TsirkinLegacy 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 2/2 virtio-net: mark VIRTIO_NET_F_GSO as legacy
In reply to Michael S. Tsirkinvirtio 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
@@ -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
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
Re: [Qemu-devel] [PATCH 1/2] virtio: allow per-device-class legacy features
In reply to Michael S. TsirkinQuoted 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.Signed-off-by Michael S. Tsirkin <[email protected]>--- 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(-)
Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy
In reply to Michael S. TsirkinQuoted 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
Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)hw/net/virtio-net.c +0
-0
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 = {
Re: [Qemu-devel] [PATCH 1/2] virtio: allow per-device-class legacy features
In reply to Michael S. TsirkinQuoted 70 lines · Michael S. Tsirkin
Legacy features are those that transitional devices only expose on the legacy interface.
Allow different ones per device class.Signed-off-by Michael S. Tsirkin <[email protected]>--- 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@@ -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@@ -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@@ -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
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)
Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy
In reply to Michael S. TsirkinQuoted 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.Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)hw/net/virtio-net.c +0
-0
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 = {
Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy
In reply to Michael S. TsirkinQuoted 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
Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)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 = {Signature · 1 line
MST
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy
In reply to Michael S. TsirkinQuoted 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
Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)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 = {
Re: [Qemu-devel] [PATCH 2/2] virtio-net: mark VIRTIO_NET_F_GSO as legacy
In reply to Dr. David Alan GilbertQuoted 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