linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Jiang Wang <jiang.wang@bytedance.com>
Cc: virtualization@lists.linux-foundation.org, stefanha@redhat.com,
	mst@redhat.com, arseny.krasnov@kaspersky.com,
	jhansen@vmware.comments, cong.wang@bytedance.com,
	duanxiongchun@bytedance.com, xieyongji@bytedance.com,
	chaiwen.cc@bytedance.com, Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	Andra Paraschiv <andraprs@amazon.com>,
	Norbert Slusarek <nslusarek@gmx.net>,
	Colin Ian King <colin.king@canonical.com>,
	Alexander Popov <alex.popov@linux.com>,
	kvm@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC v1 1/6] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit
Date: Fri, 18 Jun 2021 11:39:51 +0200	[thread overview]
Message-ID: <20210618093951.g32htj3rsu2koqi5@steredhat.lan> (raw)
In-Reply-To: <20210609232501.171257-2-jiang.wang@bytedance.com>

On Wed, Jun 09, 2021 at 11:24:53PM +0000, Jiang Wang wrote:
>When this feature is enabled, allocate 5 queues,
>otherwise, allocate 3 queues to be compatible with
>old QEMU versions.
>
>Signed-off-by: Jiang Wang <jiang.wang@bytedance.com>
>---
> drivers/vhost/vsock.c             |  3 +-
> include/linux/virtio_vsock.h      |  9 +++++
> include/uapi/linux/virtio_vsock.h |  3 ++
> net/vmw_vsock/virtio_transport.c  | 73 +++++++++++++++++++++++++++++++++++----
> 4 files changed, 80 insertions(+), 8 deletions(-)
>
>diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>index 5e78fb719602..81d064601093 100644
>--- a/drivers/vhost/vsock.c
>+++ b/drivers/vhost/vsock.c
>@@ -31,7 +31,8 @@
>
> enum {
> 	VHOST_VSOCK_FEATURES = VHOST_FEATURES |
>-			       (1ULL << VIRTIO_F_ACCESS_PLATFORM)
>+			       (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
>+			       (1ULL << VIRTIO_VSOCK_F_DGRAM)
> };
>
> enum {
>diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>index dc636b727179..ba3189ed9345 100644
>--- a/include/linux/virtio_vsock.h
>+++ b/include/linux/virtio_vsock.h
>@@ -18,6 +18,15 @@ enum {
> 	VSOCK_VQ_MAX    = 3,
> };
>
>+enum {
>+	VSOCK_VQ_STREAM_RX     = 0, /* for host to guest data */
>+	VSOCK_VQ_STREAM_TX     = 1, /* for guest to host data */
>+	VSOCK_VQ_DGRAM_RX       = 2,
>+	VSOCK_VQ_DGRAM_TX       = 3,
>+	VSOCK_VQ_EX_EVENT       = 4,
>+	VSOCK_VQ_EX_MAX         = 5,
>+};
>+
> /* Per-socket state (accessed via vsk->trans) */
> struct virtio_vsock_sock {
> 	struct vsock_sock *vsk;
>diff --git a/include/uapi/linux/virtio_vsock.h b/include/uapi/linux/virtio_vsock.h
>index 1d57ed3d84d2..b56614dff1c9 100644
>--- a/include/uapi/linux/virtio_vsock.h
>+++ b/include/uapi/linux/virtio_vsock.h
>@@ -38,6 +38,9 @@
> #include <linux/virtio_ids.h>
> #include <linux/virtio_config.h>
>
>+/* The feature bitmap for virtio net */
>+#define VIRTIO_VSOCK_F_DGRAM	0	/* Host support dgram vsock */
>+
> struct virtio_vsock_config {
> 	__le64 guest_cid;
> } __attribute__((packed));
>diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
>index 2700a63ab095..7dcb8db23305 100644
>--- a/net/vmw_vsock/virtio_transport.c
>+++ b/net/vmw_vsock/virtio_transport.c
>@@ -27,7 +27,8 @@ static DEFINE_MUTEX(the_virtio_vsock_mutex); /* protects the_virtio_vsock */
>
> struct virtio_vsock {
> 	struct virtio_device *vdev;
>-	struct virtqueue *vqs[VSOCK_VQ_MAX];
>+	struct virtqueue **vqs;
>+	bool has_dgram;
>
> 	/* Virtqueue processing is deferred to a workqueue */
> 	struct work_struct tx_work;
>@@ -333,7 +334,10 @@ static int virtio_vsock_event_fill_one(struct virtio_vsock *vsock,
> 	struct scatterlist sg;
> 	struct virtqueue *vq;
>
>-	vq = vsock->vqs[VSOCK_VQ_EVENT];
>+	if (vsock->has_dgram)
>+		vq = vsock->vqs[VSOCK_VQ_EX_EVENT];
>+	else
>+		vq = vsock->vqs[VSOCK_VQ_EVENT];
>
> 	sg_init_one(&sg, event, sizeof(*event));
>
>@@ -351,7 +355,10 @@ static void virtio_vsock_event_fill(struct virtio_vsock *vsock)
> 		virtio_vsock_event_fill_one(vsock, event);
> 	}
>
>-	virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]);
>+	if (vsock->has_dgram)
>+		virtqueue_kick(vsock->vqs[VSOCK_VQ_EX_EVENT]);
>+	else
>+		virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]);
> }
>
> static void virtio_vsock_reset_sock(struct sock *sk)
>@@ -391,7 +398,10 @@ static void virtio_transport_event_work(struct work_struct *work)
> 		container_of(work, struct virtio_vsock, event_work);
> 	struct virtqueue *vq;
>
>-	vq = vsock->vqs[VSOCK_VQ_EVENT];
>+	if (vsock->has_dgram)
>+		vq = vsock->vqs[VSOCK_VQ_EX_EVENT];
>+	else
>+		vq = vsock->vqs[VSOCK_VQ_EVENT];
>
> 	mutex_lock(&vsock->event_lock);
>
>@@ -411,7 +421,10 @@ static void virtio_transport_event_work(struct work_struct *work)
> 		}
> 	} while (!virtqueue_enable_cb(vq));
>
>-	virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]);
>+	if (vsock->has_dgram)
>+		virtqueue_kick(vsock->vqs[VSOCK_VQ_EX_EVENT]);
>+	else
>+		virtqueue_kick(vsock->vqs[VSOCK_VQ_EVENT]);
> out:
> 	mutex_unlock(&vsock->event_lock);
> }
>@@ -434,6 +447,10 @@ static void virtio_vsock_tx_done(struct virtqueue *vq)
> 	queue_work(virtio_vsock_workqueue, &vsock->tx_work);
> }
>
>+static void virtio_vsock_dgram_tx_done(struct virtqueue *vq)
>+{
>+}
>+
> static void virtio_vsock_rx_done(struct virtqueue *vq)
> {
> 	struct virtio_vsock *vsock = vq->vdev->priv;
>@@ -443,6 +460,10 @@ static void virtio_vsock_rx_done(struct virtqueue *vq)
> 	queue_work(virtio_vsock_workqueue, &vsock->rx_work);
> }
>
>+static void virtio_vsock_dgram_rx_done(struct virtqueue *vq)
>+{
>+}
>+
> static struct virtio_transport virtio_transport = {
> 	.transport = {
> 		.module                   = THIS_MODULE,
>@@ -545,13 +566,29 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
> 		virtio_vsock_tx_done,
> 		virtio_vsock_event_done,
> 	};
>+	vq_callback_t *ex_callbacks[] = {

'ex' is not clear, maybe better 'dgram'?

What happen if F_DGRAM is negotiated, but not F_STREAM?

>+		virtio_vsock_rx_done,
>+		virtio_vsock_tx_done,
>+		virtio_vsock_dgram_rx_done,
>+		virtio_vsock_dgram_tx_done,
>+		virtio_vsock_event_done,
>+	};
>+
> 	static const char * const names[] = {
> 		"rx",
> 		"tx",
> 		"event",
> 	};
>+	static const char * const ex_names[] = {
>+		"rx",
>+		"tx",
>+		"dgram_rx",
>+		"dgram_tx",
>+		"event",
>+	};
>+
> 	struct virtio_vsock *vsock = NULL;
>-	int ret;
>+	int ret, max_vq;
>
> 	ret = mutex_lock_interruptible(&the_virtio_vsock_mutex);
> 	if (ret)
>@@ -572,9 +609,30 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>
> 	vsock->vdev = vdev;
>
>-	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
>+	if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_DGRAM))
>+		vsock->has_dgram = true;
>+
>+	if (vsock->has_dgram)
>+		max_vq = VSOCK_VQ_EX_MAX;
>+	else
>+		max_vq = VSOCK_VQ_MAX;
>+
>+	vsock->vqs = kmalloc_array(max_vq, sizeof(struct virtqueue *), GFP_KERNEL);
>+	if (!vsock->vqs) {
>+		ret = -ENOMEM;
>+		goto out;
>+	}
>+
>+	if (vsock->has_dgram) {
>+		ret = virtio_find_vqs(vsock->vdev, max_vq,
>+			      vsock->vqs, ex_callbacks, ex_names,
>+			      NULL);
>+	} else {
>+		ret = virtio_find_vqs(vsock->vdev, max_vq,
> 			      vsock->vqs, callbacks, names,
> 			      NULL);
>+	}
>+
> 	if (ret < 0)
> 		goto out;
>
>@@ -695,6 +753,7 @@ static struct virtio_device_id id_table[] = {
> };
>
> static unsigned int features[] = {
>+	VIRTIO_VSOCK_F_DGRAM,
> };
>
> static struct virtio_driver virtio_vsock_driver = {
>-- 
>2.11.0
>


  reply	other threads:[~2021-06-18  9:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 23:24 [RFC v1 0/6] virtio/vsock: introduce SOCK_DGRAM support Jiang Wang
2021-06-09 23:24 ` [RFC v1 1/6] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit Jiang Wang
2021-06-18  9:39   ` Stefano Garzarella [this message]
2021-06-21 17:24     ` [External] " Jiang Wang .
2021-06-22 10:50       ` Stefano Garzarella
2021-06-09 23:24 ` [RFC v1 2/6] virtio/vsock: add support for virtio datagram Jiang Wang
2021-06-18  9:52   ` Stefano Garzarella
2021-06-18 10:11   ` Stefano Garzarella
2021-06-09 23:24 ` [RFC v1 3/6] vhost/vsock: add support for vhost dgram Jiang Wang
2021-06-18 10:13   ` Stefano Garzarella
2021-06-21 17:32     ` [External] " Jiang Wang .
2021-06-09 23:24 ` [RFC v1 4/6] vsock_test: add tests for vsock dgram Jiang Wang
2021-06-09 23:24 ` [RFC v1 5/6] vhost/vsock: add kconfig for vhost dgram support Jiang Wang
2021-06-18  9:54   ` Stefano Garzarella
2021-06-21 17:25     ` [External] " Jiang Wang .
2021-06-09 23:24 ` [RFC v1 6/6] virtio/vsock: add sysfs for rx buf len for dgram Jiang Wang
2021-06-18 10:04   ` Stefano Garzarella
2021-06-21 17:27     ` [External] " Jiang Wang .
2021-06-10  1:50 ` [RFC v1 0/6] virtio/vsock: introduce SOCK_DGRAM support Jason Wang
2021-06-10  3:43   ` Jiang Wang .
2021-06-10  4:02     ` Jason Wang
2021-06-10  7:23       ` Stefano Garzarella
2021-06-10  7:46         ` Jason Wang
2021-06-10  9:51           ` Stefano Garzarella
2021-06-10 16:44             ` Jiang Wang .
2021-06-18  9:35 ` Stefano Garzarella
2021-06-21 17:21   ` [External] " Jiang Wang .

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210618093951.g32htj3rsu2koqi5@steredhat.lan \
    --to=sgarzare@redhat.com \
    --cc=alex.popov@linux.com \
    --cc=andraprs@amazon.com \
    --cc=arseny.krasnov@kaspersky.com \
    --cc=chaiwen.cc@bytedance.com \
    --cc=colin.king@canonical.com \
    --cc=cong.wang@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=duanxiongchun@bytedance.com \
    --cc=jasowang@redhat.com \
    --cc=jhansen@vmware.comments \
    --cc=jiang.wang@bytedance.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nslusarek@gmx.net \
    --cc=rostedt@goodmis.org \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xieyongji@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).