[RFC PATCH] vhost-vsock: SOCK_SEQPACKET feature bit support

Arseny Krasnov posted 1 patch 3 years, 1 month ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210307180736.3467825-1-arseny.krasnov@kaspersky.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
hw/virtio/vhost-vsock.c                       | 16 +++++++++++++++-
include/standard-headers/linux/virtio_vsock.h |  3 +++
2 files changed, 18 insertions(+), 1 deletion(-)
[RFC PATCH] vhost-vsock: SOCK_SEQPACKET feature bit support
Posted by Arseny Krasnov 3 years, 1 month ago
This adds processing of VIRTIO_VSOCK_F_SEQPACKET feature bit. Guest
negotiates it with vhost, thus both will know that SOCK_SEQPACKET
supported by peer.

Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
---
 hw/virtio/vhost-vsock.c                       | 16 +++++++++++++++-
 include/standard-headers/linux/virtio_vsock.h |  3 +++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
index c8f0699b4f..06eb73f086 100644
--- a/hw/virtio/vhost-vsock.c
+++ b/hw/virtio/vhost-vsock.c
@@ -107,10 +107,23 @@ static uint64_t vhost_vsock_get_features(VirtIODevice *vdev,
                                          uint64_t requested_features,
                                          Error **errp)
 {
-    /* No feature bits used yet */
+    VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
+
+    if (vvc->vhost_dev.features & (1ULL << VIRTIO_VSOCK_F_SEQPACKET)) {
+        requested_features |= (1ULL << VIRTIO_VSOCK_F_SEQPACKET);
+    }
+
     return requested_features;
 }
 
+static void vhost_vsock_set_features(VirtIODevice *vdev, uint64_t features)
+{
+    VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
+    const VhostOps *vhost_ops = vvc->vhost_dev.vhost_ops;
+
+    vhost_ops->vhost_set_features(&vvc->vhost_dev, features);
+}
+
 static const VMStateDescription vmstate_virtio_vhost_vsock = {
     .name = "virtio-vhost_vsock",
     .minimum_version_id = VHOST_VSOCK_SAVEVM_VERSION,
@@ -214,6 +227,7 @@ static void vhost_vsock_class_init(ObjectClass *klass, void *data)
     vdc->realize = vhost_vsock_device_realize;
     vdc->unrealize = vhost_vsock_device_unrealize;
     vdc->get_features = vhost_vsock_get_features;
+    vdc->set_features = vhost_vsock_set_features;
     vdc->get_config = vhost_vsock_get_config;
     vdc->set_status = vhost_vsock_set_status;
 }
diff --git a/include/standard-headers/linux/virtio_vsock.h b/include/standard-headers/linux/virtio_vsock.h
index be443211ce..e0d7db4328 100644
--- a/include/standard-headers/linux/virtio_vsock.h
+++ b/include/standard-headers/linux/virtio_vsock.h
@@ -38,6 +38,9 @@
 #include "standard-headers/linux/virtio_ids.h"
 #include "standard-headers/linux/virtio_config.h"
 
+/* The feature bitmap for virtio vsock */
+#define VIRTIO_VSOCK_F_SEQPACKET       0       /* SOCK_SEQPACKET supported */
+
 struct virtio_vsock_config {
 	uint64_t guest_cid;
 } QEMU_PACKED;
-- 
2.25.1