This allows it to test if the guest has acknowledged an invalid
transport feature for SVQ. This will include packed vq layout or
event_idx, where the VirtIO device needs help from SVQ.
It is not needed at this moment, but since SVQ will not re-negotiate
features again with the guest, a failure to acknowledge them is fatal
for SVQ.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.h | 1 +
hw/virtio/vhost-shadow-virtqueue.c | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
index d963867a04..1aae6a2297 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -16,6 +16,7 @@
typedef struct VhostShadowVirtqueue VhostShadowVirtqueue;
bool vhost_svq_valid_device_features(uint64_t *features);
+bool vhost_svq_valid_guest_features(uint64_t *features);
void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call_fd);
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 51442b3dbf..f70160d7ca 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -89,6 +89,30 @@ bool vhost_svq_valid_device_features(uint64_t *dev_features)
return r;
}
+/**
+ * Offers SVQ valid transport features to the guest.
+ *
+ * @guest_features The device's supported features. Return SVQ's if success.
+ *
+ * Returns true if SVQ can handle them, false otherwise.
+ */
+bool vhost_svq_valid_guest_features(uint64_t *guest_features)
+{
+ static const uint64_t transport = MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START,
+ VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_START);
+
+ /* These transport features are handled by VirtQueue */
+ static const uint64_t valid = BIT_ULL(VIRTIO_RING_F_INDIRECT_DESC) |
+ BIT_ULL(VIRTIO_F_VERSION_1) |
+ BIT_ULL(VIRTIO_F_IOMMU_PLATFORM);
+
+ /* We are only interested in transport-related feature bits */
+ uint64_t guest_transport_features = (*guest_features) & transport;
+
+ *guest_features &= (valid | ~transport);
+ return !(guest_transport_features & (transport ^ valid));
+}
+
/* Forward guest notifications */
static void vhost_handle_guest_kick(EventNotifier *n)
{
--
2.27.0