From mboxrd@z Thu Jan 1 00:00:00 1970 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 DB326C6498F for ; Thu, 25 Aug 2022 07:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236775AbiHYHBt (ORCPT ); Thu, 25 Aug 2022 03:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236578AbiHYHBm (ORCPT ); Thu, 25 Aug 2022 03:01:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533B59F752 for ; Thu, 25 Aug 2022 00:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661410900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+7Q/XXN1Xt6SZJFciYXpFS6HHcnYgr65n/puG7GgfQY=; b=Oo7FmtoPw8Cnm3lmDdaM2xF+wAoMJsVOqwspXH6KAmZUwqVUDOAIr37WZs8eJn77yvPoxG 9mn2hjQ0ke74YXEwLGEaJbcq1kJrkvwsoLnurzjza6rIdVB7pNvSBPIVo0xQulNmjZ5bGB bmhFw4iwABQ/WT3yHeXQcb+EYTLvJiM= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-404-pSDyt1JQMQOhCbzIknXM4g-1; Thu, 25 Aug 2022 03:01:39 -0400 X-MC-Unique: pSDyt1JQMQOhCbzIknXM4g-1 Received: by mail-pj1-f70.google.com with SMTP id lw13-20020a17090b180d00b001fb2be14a3dso2401491pjb.8 for ; Thu, 25 Aug 2022 00:01:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=+7Q/XXN1Xt6SZJFciYXpFS6HHcnYgr65n/puG7GgfQY=; b=Zl71xE4CzHcY8TWu6nJPaKXH+PCgf5HYI/mMIK9u74TtkpjHG9NL8f21+vfHDe0/ey /erlKRMniskxzwX/2TDD2FedhwwavDMyf2OuZXu7DiU11GUbnOtSY/5eIIRG7X9xbzN5 zBJ+KcWZtonY8T+8wTsoqhSL3gS99Bk64kyFsQQc4KQVX1KaL9RoagrJqdvGZLF88KS8 MEOGi+HU53880fWI69RMrAsUfGG1p2WO5bJF0pB5r9EmLngO8g7j/gTsPUh9+1QgXGGp T2Ro4qDCqD0ZpYnUZvdcoWgCqLCCFldfc4jmPHNGOWj+bedw9y+F+uj7xBVl03CgWA+G IJjA== X-Gm-Message-State: ACgBeo0iIs8cjYW4wbCltuPlOpJcVIZCTl6LESDQLa5I2M3QLZ6kIfzw chc5c7waToQPxDg4L5wU6dN0kFYAfQ+MyXhxFMhAZOZsZHZ7OP6BiYluz/kKuaIxQVSg3MYaqR5 H/1BxJVUnyyJgDqNHMpwogGHp X-Received: by 2002:a17:90a:1b69:b0:1fa:f9de:fbcf with SMTP id q96-20020a17090a1b6900b001faf9defbcfmr11990632pjq.201.1661410898296; Thu, 25 Aug 2022 00:01:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4fQhngR98Oeq2+dGcVYZV3kfTv/ZlLWB36qK/slHkYNTgX2VUISGCAUCdxzL/7nf+paX9Aow== X-Received: by 2002:a17:90a:1b69:b0:1fa:f9de:fbcf with SMTP id q96-20020a17090a1b6900b001faf9defbcfmr11990595pjq.201.1661410897994; Thu, 25 Aug 2022 00:01:37 -0700 (PDT) Received: from [10.72.12.107] ([119.254.120.70]) by smtp.gmail.com with ESMTPSA id 12-20020a17090a034c00b001fb438fb772sm2609158pjf.56.2022.08.25.00.01.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Aug 2022 00:01:37 -0700 (PDT) Message-ID: <3a184162-afdc-9103-e786-66d796389e3a@redhat.com> Date: Thu, 25 Aug 2022 15:01:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [RFC v2 1/7] vhost: expose used buffers Content-Language: en-US To: Guo Zhi , eperezma@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 References: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> <20220817135718.2553-2-qtxuning1999@sjtu.edu.cn> From: Jason Wang In-Reply-To: <20220817135718.2553-2-qtxuning1999@sjtu.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/8/17 21:57, Guo Zhi 写道: > 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]; Do we need to check whether or not the buffer is fully used before doing this? > + } > 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) | Are we sure all vhost devices can support in-order (especially the SCSI)? It looks better to start from a device specific one. Thanks > (1ULL << VIRTIO_F_ANY_LAYOUT) | > (1ULL << VIRTIO_F_VERSION_1)