Legacy vs modern should be detected via transport specific means. We can't wait till feature negotiation is done. Let us introduce virtio_force_modern() as a means for the transport code to signal that the device should operate in modern mode (because a modern driver was detected).
A new callback is added for the situations where the device needs to do more than just setting the VIRTIO_F_VERSION_1 feature bit. For example, when vhost is involved, we may need to propagate the features to the vhost device. Signed-off-by: Halil Pasic <pa...@linux.ibm.com> --- I'm still struggling with how to deal with vhost-user and co. The problem is that I'm not very familiar with the life-cycle of, let us say, a vhost_user device. Looks to me like the vhost part might be just an implementation detail, and could even become a hot swappable thing. Another thing is, that vhost processes set_features differently. It might or might not be a good idea to change this. Does anybody know why don't we propagate the features on features_set, but under a set of different conditions, one of which is the vhost device is started? --- hw/virtio/virtio.c | 13 +++++++++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3a1f6c520c..26db1b31e6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3281,6 +3281,19 @@ void virtio_init(VirtIODevice *vdev, const char *name, vdev->use_guest_notifier_mask = true; } +void virtio_force_modern(VirtIODevice *vdev) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + + virtio_add_feature(&vdev->guest_features, VIRTIO_F_VERSION_1); + /* Let the device do it's normal thing. */ + virtio_set_features(vdev, vdev->guest_features); + /* For example for vhost-user we have to propagate to the vhost dev. */ + if (k->force_modern) { + k->force_modern(vdev); + } +} + /* * Only devices that have already been around prior to defining the virtio * standard support legacy mode; this includes devices not specified in the diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8bab9cfb75..1bb1551865 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -126,6 +126,7 @@ struct VirtioDeviceClass { int (*validate_features)(VirtIODevice *vdev); void (*get_config)(VirtIODevice *vdev, uint8_t *config); void (*set_config)(VirtIODevice *vdev, const uint8_t *config); + void (*force_modern)(VirtIODevice *vdev); void (*reset)(VirtIODevice *vdev); void (*set_status)(VirtIODevice *vdev, uint8_t val); /* For transitional devices, this is a bitmap of features @@ -394,6 +395,7 @@ static inline bool virtio_device_disabled(VirtIODevice *vdev) return unlikely(vdev->disabled || vdev->broken); } +void virtio_force_modern(VirtIODevice *vdev); bool virtio_legacy_allowed(VirtIODevice *vdev); bool virtio_legacy_check_disabled(VirtIODevice *vdev); -- 2.25.1