From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B8F5ECAAD1 for ; Thu, 1 Sep 2022 05:55:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233205AbiIAFzY (ORCPT ); Thu, 1 Sep 2022 01:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232629AbiIAFzU (ORCPT ); Thu, 1 Sep 2022 01:55:20 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 714FD2B241; Wed, 31 Aug 2022 22:55:13 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 75EE01008B39A; Thu, 1 Sep 2022 13:55:00 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 609CA2020B0F0; Thu, 1 Sep 2022 13:55:00 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hp0m2z9P8C9H; Thu, 1 Sep 2022 13:55:00 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id D71342009BEAF; Thu, 1 Sep 2022 13:54:46 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 1/7] vhost: expose used buffers Date: Thu, 1 Sep 2022 13:54:28 +0800 Message-Id: <20220901055434.824-2-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Follow VIRTIO 1.1 spec, only writing out a single used ring for a batch of descriptors. Signed-off-by: Guo Zhi --- drivers/vhost/vhost.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 40097826cff0..26862c8bf751 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2376,10 +2376,20 @@ static int __vhost_add_used_n(struct vhost_virtqueu= e *vq, vring_used_elem_t __user *used; u16 old, new; int start; + int copy_n =3D count; =20 + /** + * If in order feature negotiated, devices can notify the use of a batch = of buffers to + * the driver by only writing out a single used ring entry with the id co= rresponding + * to the head entry of the descriptor chain describing the last buffer i= n the batch. + */ + if (vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) { + copy_n =3D 1; + heads =3D &heads[count - 1]; + } start =3D vq->last_used_idx & (vq->num - 1); used =3D vq->used->ring + start; - if (vhost_put_used(vq, heads, start, count)) { + if (vhost_put_used(vq, heads, start, copy_n)) { vq_err(vq, "Failed to write used"); return -EFAULT; } @@ -2388,7 +2398,7 @@ static int __vhost_add_used_n(struct vhost_virtqueue = *vq, smp_wmb(); /* Log used ring entry write. */ log_used(vq, ((void __user *)used - (void __user *)vq->used), - count * sizeof *used); + copy_n * sizeof(*used)); } old =3D vq->last_used_idx; new =3D (vq->last_used_idx +=3D count); @@ -2410,7 +2420,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, stru= ct vring_used_elem *heads, =20 start =3D vq->last_used_idx & (vq->num - 1); n =3D vq->num - start; - if (n < count) { + if (n < count && !vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) { r =3D __vhost_add_used_n(vq, heads, n); if (r < 0) return r; --=20 2.17.1 From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0C63ECAAD2 for ; Thu, 1 Sep 2022 05:55:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233216AbiIAFzh (ORCPT ); Thu, 1 Sep 2022 01:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233189AbiIAFzf (ORCPT ); Thu, 1 Sep 2022 01:55:35 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170F348EA7; Wed, 31 Aug 2022 22:55:32 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 986E71008B399; Thu, 1 Sep 2022 13:55:12 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 7B5CB2020B0ED; Thu, 1 Sep 2022 13:55:11 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tZFLs25QOxNr; Thu, 1 Sep 2022 13:55:11 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id AEA1F200BFDA8; Thu, 1 Sep 2022 13:55:00 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 2/7] vhost_test: batch used buffer Date: Thu, 1 Sep 2022 13:54:29 +0800 Message-Id: <20220901055434.824-3-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Only add to used ring when a batch of buffer have all been used. And if in order feature negotiated, only add the last used descriptor for a batch of buffer. Signed-off-by: Guo Zhi --- drivers/vhost/test.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c index bc8e7fb1e635..20548a5eb3de 100644 --- a/drivers/vhost/test.c +++ b/drivers/vhost/test.c @@ -28,6 +28,11 @@ */ #define VHOST_TEST_PKT_WEIGHT 256 =20 +enum { + VHOST_TEST_FEATURES =3D VHOST_FEATURES | + (1ULL << VIRTIO_F_IN_ORDER) +}; + enum { VHOST_TEST_VQ =3D 0, VHOST_TEST_VQ_MAX =3D 1, @@ -44,7 +49,7 @@ static void handle_vq(struct vhost_test *n) { struct vhost_virtqueue *vq =3D &n->vqs[VHOST_TEST_VQ]; unsigned out, in; - int head; + int head, add =3D 0; size_t len, total_len =3D 0; void *private; =20 @@ -84,11 +89,14 @@ static void handle_vq(struct vhost_test *n) vq_err(vq, "Unexpected 0 len for TX\n"); break; } - vhost_add_used_and_signal(&n->dev, vq, head, 0); + vq->heads[add].id =3D cpu_to_vhost32(vq, head); + vq->heads[add++].len =3D cpu_to_vhost32(vq, len); total_len +=3D len; if (unlikely(vhost_exceeds_weight(vq, 0, total_len))) break; } + if (add) + vhost_add_used_and_signal_n(&n->dev, vq, vq->heads, add); =20 mutex_unlock(&vq->mutex); } @@ -328,7 +336,7 @@ static long vhost_test_ioctl(struct file *f, unsigned i= nt ioctl, return -EFAULT; return vhost_test_set_backend(n, backend.index, backend.fd); case VHOST_GET_FEATURES: - features =3D VHOST_FEATURES; + features =3D VHOST_TEST_FEATURES; if (copy_to_user(featurep, &features, sizeof features)) return -EFAULT; return 0; @@ -337,7 +345,7 @@ static long vhost_test_ioctl(struct file *f, unsigned i= nt ioctl, if (copy_from_user(&features, featurep, sizeof features)) return -EFAULT; printk(KERN_ERR "2\n"); - if (features & ~VHOST_FEATURES) + if (features & ~VHOST_TEST_FEATURES) return -EOPNOTSUPP; printk(KERN_ERR "3\n"); return vhost_test_set_features(n, features); --=20 2.17.1 From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03065ECAAD8 for ; Thu, 1 Sep 2022 05:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233230AbiIAFzy (ORCPT ); Thu, 1 Sep 2022 01:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233215AbiIAFzt (ORCPT ); Thu, 1 Sep 2022 01:55:49 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84D0A5F208; Wed, 31 Aug 2022 22:55:47 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id E3C5A1008B396; Thu, 1 Sep 2022 13:55:22 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id CA7AE200C0822; Thu, 1 Sep 2022 13:55:22 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id MMn6qdJgaft3; Thu, 1 Sep 2022 13:55:22 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 755BB200A5BFF; Thu, 1 Sep 2022 13:55:11 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 3/7] vsock: batch buffers in tx Date: Thu, 1 Sep 2022 13:54:30 +0800 Message-Id: <20220901055434.824-4-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Vsock uses buffers in order, and for tx driver doesn't have to know the length of the buffer. So we can do a batch for vsock if in order negotiated, only write one used ring for a batch of buffers Signed-off-by: Guo Zhi --- drivers/vhost/vsock.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 368330417bde..e08fbbb5439e 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -497,7 +497,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_wor= k *work) struct vhost_vsock *vsock =3D container_of(vq->dev, struct vhost_vsock, dev); struct virtio_vsock_pkt *pkt; - int head, pkts =3D 0, total_len =3D 0; + int head, pkts =3D 0, total_len =3D 0, add =3D 0; unsigned int out, in; bool added =3D false; =20 @@ -551,10 +551,18 @@ static void vhost_vsock_handle_tx_kick(struct vhost_w= ork *work) else virtio_transport_free_pkt(pkt); =20 - vhost_add_used(vq, head, 0); + if (!vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) { + vhost_add_used(vq, head, 0); + } else { + vq->heads[add].id =3D head; + vq->heads[add++].len =3D 0; + } added =3D true; } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len))); =20 + /* If in order feature negotiaged, we can do a batch to increase performa= nce */ + if (vhost_has_feature(vq, VIRTIO_F_IN_ORDER) && added) + vhost_add_used_n(vq, vq->heads, add); no_more_replies: if (added) vhost_signal(&vsock->dev, vq); --=20 2.17.1 From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7088EC54EE9 for ; Thu, 1 Sep 2022 05:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233218AbiIAF4J (ORCPT ); Thu, 1 Sep 2022 01:56:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbiIAF4D (ORCPT ); Thu, 1 Sep 2022 01:56:03 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1997A5F992; Wed, 31 Aug 2022 22:56:01 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 72F5D1008B399; Thu, 1 Sep 2022 13:55:36 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 3C8542009BEA0; Thu, 1 Sep 2022 13:55:36 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id byLToQIaCGBV; Thu, 1 Sep 2022 13:55:36 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 23565200C0822; Thu, 1 Sep 2022 13:55:22 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 4/7] vsock: announce VIRTIO_F_IN_ORDER in vsock Date: Thu, 1 Sep 2022 13:54:31 +0800 Message-Id: <20220901055434.824-5-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In order feature is used by vsock now, since vsock already use buffer in order. Signed-off-by: Guo Zhi --- drivers/vhost/vsock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index e08fbbb5439e..fcf649cbfb02 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -32,6 +32,7 @@ enum { VHOST_VSOCK_FEATURES =3D VHOST_FEATURES | (1ULL << VIRTIO_F_ACCESS_PLATFORM) | + (1ULL << VIRTIO_F_IN_ORDER) | (1ULL << VIRTIO_VSOCK_F_SEQPACKET) }; =20 --=20 2.17.1 From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CB39ECAAD2 for ; Thu, 1 Sep 2022 05:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231668AbiIAF4W (ORCPT ); Thu, 1 Sep 2022 01:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233219AbiIAF4S (ORCPT ); Thu, 1 Sep 2022 01:56:18 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C33BCC36; Wed, 31 Aug 2022 22:56:15 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id C83A01008B38F; Thu, 1 Sep 2022 13:55:48 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id B499F2009BEAD; Thu, 1 Sep 2022 13:55:48 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id SIB7hdKllpuC; Thu, 1 Sep 2022 13:55:48 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 78BC72009BEB0; Thu, 1 Sep 2022 13:55:36 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 5/7] virtio: unmask F_NEXT flag in desc_extra Date: Thu, 1 Sep 2022 13:54:32 +0800 Message-Id: <20220901055434.824-6-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We didn't unmask F_NEXT flag in desc_extra in the end of a chain, unmask it so that we can access desc_extra to get next information. Signed-off-by: Guo Zhi --- drivers/virtio/virtio_ring.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index a5ec724c01d8..00aa4b7a49c2 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -567,7 +567,7 @@ static inline int virtqueue_add_split(struct virtqueue = *_vq, } /* Last one doesn't continue. */ desc[prev].flags &=3D cpu_to_virtio16(_vq->vdev, ~VRING_DESC_F_NEXT); - if (!indirect && vq->use_dma_api) + if (!indirect) vq->split.desc_extra[prev & (vq->split.vring.num - 1)].flags &=3D ~VRING_DESC_F_NEXT; =20 @@ -584,6 +584,8 @@ static inline int virtqueue_add_split(struct virtqueue = *_vq, total_sg * sizeof(struct vring_desc), VRING_DESC_F_INDIRECT, false); + vq->split.desc_extra[head & (vq->split.vring.num - 1)].flags &=3D + ~VRING_DESC_F_NEXT; } =20 /* We're using some buffers from the free list. */ @@ -685,7 +687,6 @@ static void detach_buf_split(struct vring_virtqueue *vq= , unsigned int head, void **ctx) { unsigned int i, j; - __virtio16 nextflag =3D cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT); =20 /* Clear data ptr. */ vq->split.desc_state[head].data =3D NULL; @@ -693,7 +694,7 @@ static void detach_buf_split(struct vring_virtqueue *vq= , unsigned int head, /* Put back on free list: unmap first-level descriptors and find end */ i =3D head; =20 - while (vq->split.vring.desc[i].flags & nextflag) { + while (vq->split.desc_extra[i].flags & VRING_DESC_F_NEXT) { vring_unmap_one_split(vq, i); i =3D vq->split.desc_extra[i].next; vq->vq.num_free++; --=20 2.17.1 From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32953ECAAD8 for ; Thu, 1 Sep 2022 05:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233273AbiIAF4j (ORCPT ); Thu, 1 Sep 2022 01:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233269AbiIAF4d (ORCPT ); Thu, 1 Sep 2022 01:56:33 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9760114C45; Wed, 31 Aug 2022 22:56:29 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id CDBB01008B396; Thu, 1 Sep 2022 13:56:03 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 59CBA2020B0ED; Thu, 1 Sep 2022 13:56:02 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id YxKukzGCCgZD; Thu, 1 Sep 2022 13:56:02 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id EE3492009BEAF; Thu, 1 Sep 2022 13:55:48 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 6/7] virtio: in order support for virtio_ring Date: Thu, 1 Sep 2022 13:54:33 +0800 Message-Id: <20220901055434.824-7-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If in order feature negotiated, we can skip the used ring to get buffer's desc id sequentially. For skipped buffers in the batch, the used ring doesn't contain the buffer length, actually there is not need to get skipped buffers' length as they are tx buffer. Signed-off-by: Guo Zhi --- drivers/virtio/virtio_ring.c | 74 +++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 00aa4b7a49c2..d52624179b43 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -103,6 +103,9 @@ struct vring_virtqueue { /* Host supports indirect buffers */ bool indirect; =20 + /* Host supports in order feature */ + bool in_order; + /* Host publishes avail event idx */ bool event; =20 @@ -144,6 +147,19 @@ struct vring_virtqueue { /* DMA address and size information */ dma_addr_t queue_dma_addr; size_t queue_size_in_bytes; + + /* If in_order feature is negotiated, here is the next head to consume = */ + u16 next_desc_begin; + /* + * If in_order feature is negotiated, + * here is the last descriptor's id in the batch + */ + u16 last_desc_in_batch; + /* + * If in_order feature is negotiated, + * buffers except last buffer in the batch are skipped buffer + */ + bool is_skipped_buffer; } split; =20 /* Available for packed ring */ @@ -584,8 +600,6 @@ static inline int virtqueue_add_split(struct virtqueue = *_vq, total_sg * sizeof(struct vring_desc), VRING_DESC_F_INDIRECT, false); - vq->split.desc_extra[head & (vq->split.vring.num - 1)].flags &=3D - ~VRING_DESC_F_NEXT; } =20 /* We're using some buffers from the free list. */ @@ -701,8 +715,16 @@ static void detach_buf_split(struct vring_virtqueue *v= q, unsigned int head, } =20 vring_unmap_one_split(vq, i); - vq->split.desc_extra[i].next =3D vq->free_head; - vq->free_head =3D head; + /* + * If in_order feature is negotiated, + * the descriptors are made available in order. + * Since the free_head is already a circular list, + * it must consume it sequentially. + */ + if (!vq->in_order) { + vq->split.desc_extra[i].next =3D vq->free_head; + vq->free_head =3D head; + } =20 /* Plus final descriptor */ vq->vq.num_free++; @@ -744,7 +766,7 @@ static void *virtqueue_get_buf_ctx_split(struct virtque= ue *_vq, { struct vring_virtqueue *vq =3D to_vvq(_vq); void *ret; - unsigned int i; + unsigned int i, j; u16 last_used; =20 START_USE(vq); @@ -763,11 +785,38 @@ static void *virtqueue_get_buf_ctx_split(struct virtq= ueue *_vq, /* Only get used array entries after they have been exposed by host. */ virtio_rmb(vq->weak_barriers); =20 - last_used =3D (vq->last_used_idx & (vq->split.vring.num - 1)); - i =3D virtio32_to_cpu(_vq->vdev, - vq->split.vring.used->ring[last_used].id); - *len =3D virtio32_to_cpu(_vq->vdev, - vq->split.vring.used->ring[last_used].len); + if (vq->in_order) { + last_used =3D (vq->last_used_idx & (vq->split.vring.num - 1)); + if (!vq->split.is_skipped_buffer) { + vq->split.last_desc_in_batch =3D + virtio32_to_cpu(_vq->vdev, + vq->split.vring.used->ring[last_used].id); + vq->split.is_skipped_buffer =3D true; + } + /* For skipped buffers in batch, we can ignore the len info, simply set = len as 0 */ + if (vq->split.next_desc_begin !=3D vq->split.last_desc_in_batch) { + *len =3D 0; + } else { + *len =3D virtio32_to_cpu(_vq->vdev, + vq->split.vring.used->ring[last_used].len); + vq->split.is_skipped_buffer =3D false; + } + i =3D vq->split.next_desc_begin; + j =3D i; + /* Indirect only takes one descriptor in descriptor table */ + while (!vq->indirect && (vq->split.desc_extra[j].flags & VRING_DESC_F_NE= XT)) + j =3D (j + 1) & (vq->split.vring.num - 1); + /* move to next */ + j =3D (j + 1) % vq->split.vring.num; + /* Next buffer will use this descriptor in order */ + vq->split.next_desc_begin =3D j; + } else { + last_used =3D (vq->last_used_idx & (vq->split.vring.num - 1)); + i =3D virtio32_to_cpu(_vq->vdev, + vq->split.vring.used->ring[last_used].id); + *len =3D virtio32_to_cpu(_vq->vdev, + vq->split.vring.used->ring[last_used].len); + } =20 if (unlikely(i >=3D vq->split.vring.num)) { BAD_RING(vq, "id %u out of range\n", i); @@ -2223,6 +2272,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int = index, =20 vq->indirect =3D virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) && !context; + vq->in_order =3D virtio_has_feature(vdev, VIRTIO_F_IN_ORDER); vq->event =3D virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX); =20 if (virtio_has_feature(vdev, VIRTIO_F_ORDER_PLATFORM)) @@ -2235,6 +2285,10 @@ struct virtqueue *__vring_new_virtqueue(unsigned int= index, vq->split.avail_flags_shadow =3D 0; vq->split.avail_idx_shadow =3D 0; =20 + vq->split.next_desc_begin =3D 0; + vq->split.last_desc_in_batch =3D 0; + vq->split.is_skipped_buffer =3D false; + /* No callback? Tell other side not to bother us. */ if (!callback) { vq->split.avail_flags_shadow |=3D VRING_AVAIL_F_NO_INTERRUPT; --=20 2.17.1 From nobody Sat Apr 11 00:44:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F68AECAAD2 for ; Thu, 1 Sep 2022 05:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233346AbiIAF5E (ORCPT ); Thu, 1 Sep 2022 01:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbiIAF4w (ORCPT ); Thu, 1 Sep 2022 01:56:52 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E043118234; Wed, 31 Aug 2022 22:56:43 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 227C81008B399; Thu, 1 Sep 2022 13:56:15 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 9D9CA2009BEAF; Thu, 1 Sep 2022 13:56:14 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id dsRbT5RbWGbv; Thu, 1 Sep 2022 13:56:14 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 1498E200A5BFF; Thu, 1 Sep 2022 13:56:02 +0800 (CST) From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Guo Zhi Subject: [RFC v3 7/7] virtio: announce VIRTIO_F_IN_ORDER support Date: Thu, 1 Sep 2022 13:54:34 +0800 Message-Id: <20220901055434.824-8-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In order feature is supported by default in virtio. Signed-off-by: Guo Zhi --- drivers/virtio/virtio_ring.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index d52624179b43..63a6381913a5 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2432,6 +2432,8 @@ void vring_transport_features(struct virtio_device *v= dev) break; case VIRTIO_F_ORDER_PLATFORM: break; + case VIRTIO_F_IN_ORDER: + break; default: /* We don't understand this bit. */ __virtio_clear_bit(vdev, i); --=20 2.17.1