From nobody Sat Apr 11 00:48:18 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 B707FC25B08 for ; Wed, 17 Aug 2022 13:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236762AbiHQN6J (ORCPT ); Wed, 17 Aug 2022 09:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239702AbiHQN5z (ORCPT ); Wed, 17 Aug 2022 09:57:55 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F2096751; Wed, 17 Aug 2022 06:57:52 -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 38CFD1008B38F; Wed, 17 Aug 2022 21:57:44 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 0FF992009BEA0; Wed, 17 Aug 2022 21:57:44 +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 IDVIL2_B6a_l; Wed, 17 Aug 2022 21:57:43 +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 DD9B32009BEAD; Wed, 17 Aug 2022 21:57:31 +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 v2 1/7] vhost: expose used buffers Date: Wed, 17 Aug 2022 21:57:12 +0800 Message-Id: <20220817135718.2553-2-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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 | 14 ++++++++++++-- drivers/vhost/vhost.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 40097826cff0..7b20fa5a46c3 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; } @@ -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; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index d9109107af08..0d5c49a30421 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -236,6 +236,7 @@ enum { VHOST_FEATURES =3D (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | (1ULL << VIRTIO_RING_F_EVENT_IDX) | + (1ULL << VIRTIO_F_IN_ORDER) | (1ULL << VHOST_F_LOG_ALL) | (1ULL << VIRTIO_F_ANY_LAYOUT) | (1ULL << VIRTIO_F_VERSION_1) --=20 2.17.1 From nobody Sat Apr 11 00:48:18 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 10788C28B2B for ; Wed, 17 Aug 2022 13:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239765AbiHQN6W (ORCPT ); Wed, 17 Aug 2022 09:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239482AbiHQN6H (ORCPT ); Wed, 17 Aug 2022 09:58:07 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB3D9675B; Wed, 17 Aug 2022 06:58:05 -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 9F4331008B38F; Wed, 17 Aug 2022 21:57:59 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 8D49D2032D489; Wed, 17 Aug 2022 21:57:56 +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 SFMeObJ2TNmb; Wed, 17 Aug 2022 21:57:56 +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 E48B92009BEAD; Wed, 17 Aug 2022 21:57:44 +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 v2 2/7] vhost_test: batch used buffer Date: Wed, 17 Aug 2022 21:57:13 +0800 Message-Id: <20220817135718.2553-3-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c index bc8e7fb1e635..57cdb3a3edf6 100644 --- a/drivers/vhost/test.c +++ b/drivers/vhost/test.c @@ -43,6 +43,9 @@ struct vhost_test { static void handle_vq(struct vhost_test *n) { struct vhost_virtqueue *vq =3D &n->vqs[VHOST_TEST_VQ]; + struct vring_used_elem *heads =3D kmalloc(sizeof(*heads) + * vq->num, GFP_KERNEL); + int batch_idx =3D 0; unsigned out, in; int head; size_t len, total_len =3D 0; @@ -84,11 +87,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); + heads[batch_idx].id =3D cpu_to_vhost32(vq, head); + heads[batch_idx++].len =3D cpu_to_vhost32(vq, len); total_len +=3D len; if (unlikely(vhost_exceeds_weight(vq, 0, total_len))) break; } + if (batch_idx) + vhost_add_used_and_signal_n(&n->dev, vq, heads, batch_idx); =20 mutex_unlock(&vq->mutex); } --=20 2.17.1 From nobody Sat Apr 11 00:48:18 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 5696AC32771 for ; Wed, 17 Aug 2022 13:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234589AbiHQN6h (ORCPT ); Wed, 17 Aug 2022 09:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239788AbiHQN62 (ORCPT ); Wed, 17 Aug 2022 09:58:28 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE332240BB; Wed, 17 Aug 2022 06:58:19 -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 7CE131008B38F; Wed, 17 Aug 2022 21:58:17 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id D36002009BEAD; Wed, 17 Aug 2022 21:58:10 +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 BeLQLT-bhQHC; Wed, 17 Aug 2022 21:58:10 +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 36ED6200BFDA8; Wed, 17 Aug 2022 21:57:56 +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 v2 3/7] vsock: batch buffers in tx Date: Wed, 17 Aug 2022 21:57:14 +0800 Message-Id: <20220817135718.2553-4-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 368330417bde..b0108009c39a 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -500,6 +500,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_wor= k *work) int head, pkts =3D 0, total_len =3D 0; unsigned int out, in; bool added =3D false; + int last_head =3D -1; =20 mutex_lock(&vq->mutex); =20 @@ -551,10 +552,16 @@ 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 + last_head =3D head; 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) && last_head !=3D -1) + vhost_add_used(vq, last_head, 0); no_more_replies: if (added) vhost_signal(&vsock->dev, vq); --=20 2.17.1 From nobody Sat Apr 11 00:48:18 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 64B34C25B08 for ; Wed, 17 Aug 2022 13:59:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239811AbiHQN7N (ORCPT ); Wed, 17 Aug 2022 09:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239536AbiHQN6p (ORCPT ); Wed, 17 Aug 2022 09:58:45 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F126A75CDC; Wed, 17 Aug 2022 06:58:33 -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 8BD1F1008B392; Wed, 17 Aug 2022 21:58:29 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 602EB2009BEA0; Wed, 17 Aug 2022 21:58:24 +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 M2sepWPQLjQx; Wed, 17 Aug 2022 21:58:24 +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 C0A792009BEB4; Wed, 17 Aug 2022 21:58:10 +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 v2 4/7] vsock: announce VIRTIO_F_IN_ORDER in vsock Date: Wed, 17 Aug 2022 21:57:15 +0800 Message-Id: <20220817135718.2553-5-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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 b0108009c39a..3dd3a2a27d27 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:48:18 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 43070C25B08 for ; Wed, 17 Aug 2022 13:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239945AbiHQN7f (ORCPT ); Wed, 17 Aug 2022 09:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239912AbiHQN7E (ORCPT ); Wed, 17 Aug 2022 09:59:04 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 053AC96FE8; Wed, 17 Aug 2022 06:58:57 -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 C9DE21008B389; Wed, 17 Aug 2022 21:58:35 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id AEB792009BEA0; Wed, 17 Aug 2022 21:58:35 +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 hlbN_24HEFDA; Wed, 17 Aug 2022 21:58:35 +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 A1B4E2009BEB0; Wed, 17 Aug 2022 21:58:24 +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 v2 5/7] virtio: unmask F_NEXT flag in desc_extra Date: Wed, 17 Aug 2022 21:57:16 +0800 Message-Id: <20220817135718.2553-6-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index a5ec724c01d8..1c1b3fa376a2 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. */ @@ -693,7 +695,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 & nextflag) { 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:48:18 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 6E576C28B2B for ; Wed, 17 Aug 2022 13:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236634AbiHQN7t (ORCPT ); Wed, 17 Aug 2022 09:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239884AbiHQN7V (ORCPT ); Wed, 17 Aug 2022 09:59:21 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6527589917; Wed, 17 Aug 2022 06:59:11 -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 9A62A1008B38F; Wed, 17 Aug 2022 21:58:48 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 052AA2009BEAD; Wed, 17 Aug 2022 21:58: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 9ZmfqEkD5H1c; Wed, 17 Aug 2022 21:58:47 +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 EB8352009BEA0; Wed, 17 Aug 2022 21:58:35 +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 v2 6/7] virtio: in order support for virtio_ring Date: Wed, 17 Aug 2022 21:57:17 +0800 Message-Id: <20220817135718.2553-7-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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. Signed-off-by: Guo Zhi --- drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 1c1b3fa376a2..143184ebb5a1 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -144,6 +144,9 @@ struct vring_virtqueue { /* DMA address and size information */ dma_addr_t queue_dma_addr; size_t queue_size_in_bytes; + + /* In order feature batch begin here */ + u16 next_desc_begin; } split; =20 /* Available for packed ring */ @@ -702,8 +705,13 @@ 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; + /* In order feature use desc in order, + * that means, the next desc will always be free + */ + if (!virtio_has_feature(vq->vq.vdev, VIRTIO_F_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++; @@ -745,7 +753,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); @@ -764,11 +772,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 (virtio_has_feature(_vq->vdev, VIRTIO_F_IN_ORDER)) { + /* Skip used ring and get used desc in order*/ + 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; + /* 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; + if (!vq->indirect) { + *len =3D vq->split.desc_extra[i].len; + } else { + struct vring_desc *indir_desc =3D + vq->split.desc_state[i].indir_desc; + u32 indir_num =3D vq->split.desc_extra[i].len, buffer_len =3D 0; + + if (indir_desc) { + for (j =3D 0; j < indir_num / sizeof(struct vring_desc); j++) + buffer_len +=3D indir_desc[j].len; + } + + *len =3D buffer_len; + } + } 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); @@ -2236,6 +2271,8 @@ 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; + /* 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:48:18 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 36F8CC28B2B for ; Wed, 17 Aug 2022 14:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239957AbiHQOAG (ORCPT ); Wed, 17 Aug 2022 10:00:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239776AbiHQN7c (ORCPT ); Wed, 17 Aug 2022 09:59:32 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34F9E98585; Wed, 17 Aug 2022 06:59:27 -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 6A93C1008B393; Wed, 17 Aug 2022 21:59:00 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 4D4982032D480; Wed, 17 Aug 2022 21:59: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 HhqxGr9Oea1E; Wed, 17 Aug 2022 21:59: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 D7C482009BEA0; Wed, 17 Aug 2022 21:58:47 +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 v2 7/7] virtio: annouce VIRTIO_F_IN_ORDER support Date: Wed, 17 Aug 2022 21:57:18 +0800 Message-Id: <20220817135718.2553-8-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> References: <20220817135718.2553-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 143184ebb5a1..50aa361abd65 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2416,6 +2416,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