Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4842094rwb; Wed, 17 Aug 2022 07:02:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR7wlxJq4+SAIaMBV2KAgd9VzaMuGy4Vvs3MaxavK33gQRnOd3cCijOE3K8ZMKHT/chBDpG2 X-Received: by 2002:aa7:d59a:0:b0:441:ecc9:f33e with SMTP id r26-20020aa7d59a000000b00441ecc9f33emr23903508edq.173.1660744923279; Wed, 17 Aug 2022 07:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660744923; cv=none; d=google.com; s=arc-20160816; b=k2HIjBperuUNKica+pPqjJJV06aw7+ku8+yzsoC2AgGamfBwmnpAcS8UextaOdMUsW OctmZF0K3fZjYbOvQ3+lluyEzF06ZSfuBw7I9hfoXhwN0P+DB9DKTrjJqbeyrjsIc8MP aIXBGA2+J3RW1FH7xlrDUXmnAZgGllzxdFAiMhQSDjZG1bAOMGEjSCuBQFNicGuAsOCd /N3wV3JhFf+4WB0Q/Jqg+DK39O9eV4Fue85vfiMO0mPLxYkdT61c+uV17jWUp2sDFjwB DHXWsjLyj7VS0xMQLNq8cZKsSEfzJb/w92h9MJOPpL3CXe2ReXxNsH412CT56T1Uidxh pDRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=XQCL7HLKUXkDxKYdX7tNsrcqHwGOhY4bBro6gCOB43I=; b=CWpolLLPvm91biSLUSqlDgU+sENrG2frjapG57I4QVG7GAug3pmAEgZpq1WtQonAB/ pk2IL4ikw/PSF0ApQUxKioZaAcmmLhBETvdvjJ6Gwzuk8Z7t4dQplaO8150wXsXsoKEi 5hzAZ51WtQecMKFGzeSaNJ2PIjmxX1Lg/jNNHX3Fe1ptaENe9dz7e+yeLUbT4OKYKl5Z egakQef+OsKEPNKGlZ+EG8L/1eIdJEKYRrpupcXufXZsZj7/nlI0vAr/Vg+MQDOnbUqE JJDlRiGx0AFdU2jAx0y0xQ18cQnhtqd6RtUV42VpXA3er+mFc3cTtgUHjVITYC3PKQ2e igqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx2-20020a170907760200b00726e142a88esi10431770ejc.983.2022.08.17.07.01.37; Wed, 17 Aug 2022 07:02:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239736AbiHQN6G (ORCPT + 99 others); Wed, 17 Aug 2022 09:58:06 -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> X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,RCVD_IN_SORBS_WEB, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_virtqueue *vq, vring_used_elem_t __user *used; u16 old, new; int start; + int copy_n = count; + /** + * 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 corresponding + * to the head entry of the descriptor chain describing the last buffer in the batch. + */ + if (vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) { + copy_n = 1; + heads = &heads[count - 1]; + } start = vq->last_used_idx & (vq->num - 1); used = 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, struct vring_used_elem *heads, start = vq->last_used_idx & (vq->num - 1); n = vq->num - start; - if (n < count) { + if (n < count && !vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) { r = __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 = (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) -- 2.17.1