The virtio specifications allows for up to 128 bits for the device features. Soon we are going to use some of the 'extended' bits features (above 64) for the virtio net driver.
Add support to allow extended features negotiation on a per devices basis. Devices willing to negotiated extended features need to implemented a new pair of features getter/setter, the core will conditionally use them instead of the basic one. Note that 'bad_features' don't need to be extended, as they are bound to the 64 bits limit. No functional changes intended for host without 128 bit support. Signed-off-by: Paolo Abeni <pab...@redhat.com> --- hw/virtio/virtio-bus.c | 15 ++++++++++++--- hw/virtio/virtio.c | 23 +++++++++++++++++------ include/hw/virtio/virtio.h | 8 +++++++- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 9b84ead831..40948fca39 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -62,9 +62,18 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) } /* Get the features of the plugged device. */ - assert(vdc->get_features != NULL); - vdev->host_features_ex = vdc->get_features(vdev, vdev->host_features, - &local_err); +#ifdef CONFIG_INT128 + if (vdc->get_features_ex) + vdev->host_features_ex = vdc->get_features_ex(vdev, + vdev->host_features_ex, + &local_err); + else +#endif + { + assert(vdc->get_features != NULL); + vdev->host_features_ex = vdc->get_features(vdev, vdev->host_features, + &local_err); + } if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ef15a1835e..90822e54f8 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3114,13 +3114,24 @@ static int virtio_set_features_nocheck(VirtIODevice *vdev, virtio_features_t val) { VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - bool bad = (val & ~(vdev->host_features)) != 0; + bool bad = (val & ~(vdev->host_features_ex)) != 0; - val &= vdev->host_features; - if (k->set_features) { - k->set_features(vdev, val); + val &= vdev->host_features_ex; +#ifdef CONFIG_INT128 + if (!k->set_features_ex) { + val = (uint64_t)val; + } + + if (k->set_features_ex) { + k->set_features_ex(vdev, val); + } else +#endif + { + if (k->set_features) { + k->set_features(vdev, val); + } } - vdev->guest_features = val; + vdev->guest_features_ex = val; return bad ? -1 : 0; } @@ -3193,7 +3204,7 @@ virtio_set_features_ex_nocheck_maybe_co(VirtIODevice *vdev, __uint128_t val) #endif -int virtio_set_features(VirtIODevice *vdev, uint64_t val) +int virtio_set_features(VirtIODevice *vdev, virtio_features_t val) { int ret; /* diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 82ff6c1630..e98fd76e7f 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -178,6 +178,12 @@ struct VirtioDeviceClass { /* This is what a VirtioDevice must implement */ DeviceRealize realize; DeviceUnrealize unrealize; +#ifdef CONFIG_INT128 + virtio_features_t (*get_features_ex)(VirtIODevice *vdev, + virtio_features_t requested_features, + Error **errp); + void (*set_features_ex)(VirtIODevice *vdev, virtio_features_t val); +#endif uint64_t (*get_features)(VirtIODevice *vdev, uint64_t requested_features, Error **errp); @@ -366,7 +372,7 @@ void virtio_reset(void *opaque); void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index); void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index); void virtio_update_irq(VirtIODevice *vdev); -int virtio_set_features(VirtIODevice *vdev, uint64_t val); +int virtio_set_features(VirtIODevice *vdev, virtio_features_t val); /* Base devices. */ typedef struct VirtIOBlkConf VirtIOBlkConf; -- 2.49.0