Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3967803pxj; Mon, 21 Jun 2021 10:25:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmBvEfY8g+EpiTilI+t7ZGp6f4sEh+0r7wNU071/5vG41d5ALr/JEzID3CK9VCVdz89AOq X-Received: by 2002:a6b:fc11:: with SMTP id r17mr10368556ioh.93.1624296342871; Mon, 21 Jun 2021 10:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624296342; cv=none; d=google.com; s=arc-20160816; b=N1hTPHWaVgdRfM7QlN6R3FFmczCDolL6pcaaSzm4LXPlL005gZn/dtLPXTixu0LEq4 EbjXZ2Uf6L279QoG3tTLa9CTl0ByprGDUuRqpk2J9lI9ngBks8TCwOV9EVNMpwrbQ3fv 21G2lMzQNlIUX4G2Mq2HGSwlNj4OWwWlgfgeQhnhg5qoElLmz2nZwlgjZ36X3MQKux1o xG34CFFauBy9zJtGt7bU+X8WB69zUydNa1sIc2ayh2GXcJbmAizyI0oxBGyVmvFdmhwe AwfnS/nHeweBvoMCIvfpgOOXVxxY7xSOLzOiKoiJMe6xyMkelMAMdqJGtDQXVP9+n5Dk PAkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xKmGjgLsgWsFBaBePs7cjUDuoclC/CKZFAJTnQ9AJMs=; b=cQYL8hyVarvAusayvRt+MUjxUhweByLzUp48qDW279INWQq5cVmHWSBd8KGkArVEDz 8tjfm61tSnsHcyDxBgul3ewMYwgqD3Eu1XqEGYht7khd1JN32c6DQl/qMfKMWiThho5w pW4UoeCGRQM2sfkudSuyZJiEg1rbbd9F4NrREF+T+7GTAdX0DzjR5ymq5l6EZ9RE2/Lx eCneufW5QxZ9pxX+YIXHY4kJ9nZgvoqe+Q9/D9TXoSjuwIwS6YPTDwtAf+psx312nXk1 p9mCRct7Vgjn6t4efsMeC9CKD+XljEojCEly7ofndxai2w7Thf+qA7UWXKAcc1/kx9cY sftg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=JlwDd3p+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j1si14060885ila.160.2021.06.21.10.25.20; Mon, 21 Jun 2021 10:25:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=JlwDd3p+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbhFUR0s (ORCPT + 99 others); Mon, 21 Jun 2021 13:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbhFUR0r (ORCPT ); Mon, 21 Jun 2021 13:26:47 -0400 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4A0C061756 for ; Mon, 21 Jun 2021 10:24:31 -0700 (PDT) Received: by mail-oi1-x22a.google.com with SMTP id w1so7487889oie.13 for ; Mon, 21 Jun 2021 10:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xKmGjgLsgWsFBaBePs7cjUDuoclC/CKZFAJTnQ9AJMs=; b=JlwDd3p+9HGTZoM82mSEcGnLlu8sxR3GFo+ou3kNhT/FgSBJWjVVZksAYHD9snLqOW t4C02M5/JrwhTMk0Ev8rvYIabC2Kk6bjAVy059EXiCL2dezvvxDtrmkWTkGi4vCDbWf9 10M+9Rvbtotts+rFzzKWY3IdBrJcr3HgL6eIb2GLAnjpqwz7X6bKHUWsDLSykTY/APoy GOJfjWZqf5htG0uaZNLWmE56Sbo4iGBftsw6p6kURUVn2AaOcKkjBpADwWPqaN1VoU1l d6j9JDM00UGUKbyIhm34TdmSz7EmZ733coZcUYgYB3DhkA2ErfjYDiAm4Ta/fblght9t cE8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xKmGjgLsgWsFBaBePs7cjUDuoclC/CKZFAJTnQ9AJMs=; b=UXdchLB97u9mmDeZoIjJC3Gg9+XjrqtzlzNjOMD1G3BslhHkpfWk+Jjv4Qf3KQ/eu8 wl/FPKpKUTMgXGNyz0VRClFThZjtwTBqe53E0uHRs+W4QW8LqaFDz77L22qgLL0y7tpq k9FC9kZY/JBOLPDPQnwUK0uJ6Jwi9rQgO6nk4+cFBsW1GhDJ/6VUMWZNWtqvlV3Cnmwo sVHdZP+2LUNMohTszDYAmOSKegBokB3gzycxoWUiWBigtTuTxWrT43JdjY+MKxEEZmq/ VntlcWcu+wyg4L15XdOfbdl9Dl3PnE9Qb4YH1S/i1ZffqTViMpOsrCm3GhtoiIG/k98J VDzg== X-Gm-Message-State: AOAM532ni1JKvDYvMzbybkn/zrpki8qZvyDuESpmKoQQnXXcO0hF8Zz4 9RN7Opluo7gbyLr+OhsaP48Tp1puWsvyOjqD6NNEXg== X-Received: by 2002:aca:e0d6:: with SMTP id x205mr17923656oig.109.1624296271029; Mon, 21 Jun 2021 10:24:31 -0700 (PDT) MIME-Version: 1.0 References: <20210609232501.171257-1-jiang.wang@bytedance.com> <20210609232501.171257-2-jiang.wang@bytedance.com> <20210618093951.g32htj3rsu2koqi5@steredhat.lan> In-Reply-To: <20210618093951.g32htj3rsu2koqi5@steredhat.lan> From: "Jiang Wang ." Date: Mon, 21 Jun 2021 10:24:20 -0700 Message-ID: Subject: Re: [External] Re: [RFC v1 1/6] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit To: Stefano Garzarella Cc: virtualization@lists.linux-foundation.org, Stefan Hajnoczi , "Michael S. Tsirkin" , Arseny Krasnov , cong.wang@bytedance.com, Xiongchun Duan , Yongji Xie , =?UTF-8?B?5p+056iz?= , Jason Wang , "David S. Miller" , Jakub Kicinski , Steven Rostedt , Ingo Molnar , Andra Paraschiv , Norbert Slusarek , Colin Ian King , Alexander Popov , kvm@vger.kernel.org, Networking , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 18, 2021 at 2:40 AM Stefano Garzarella wrote: > > 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 > >--- > > 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 > > #include > > > >+/* 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'? > sure. > What happen if F_DGRAM is negotiated, but not F_STREAM? > Hmm. In my mind, F_STREAM is always negotiated. Do we want to add support when F_STREAM is not negotiated? > >+ 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 > > >