Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5195748rwb; Tue, 6 Sep 2022 21:28:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR45B/+3mnmKotEZUD+xMINwYrV89/PBPxD5ZfoaWpi4/ax6DQP/Kch1+V8piTjnlBX/9+Vy X-Received: by 2002:a17:906:9bf0:b0:741:362a:3ff1 with SMTP id de48-20020a1709069bf000b00741362a3ff1mr1009952ejc.275.1662524939198; Tue, 06 Sep 2022 21:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662524939; cv=none; d=google.com; s=arc-20160816; b=jLQitNjakrwA/d1x3BvqCNEoqfZlSTtUVECwmjm2Yl5++8rpHnNdhmD3CVwFmZCc0Z R3BEEgOoG0JAAfX0Onn2D8lZ5hisKec2p8x+Dhcq0TrjT6AXvEKJmuVwuO7+I/5FnR0s w9OqPYgkR+QRSok5enXAPM2kqPy3Ro84UAlkHpQvnjF2qKIIhi2lORVKfY05/PjFhomB EJJ/YxDZFv3JkLswSCDtb5XP+8vEQR1/QBqx2x15do4nmCmIh5pwNroqcRmCR1145Uj3 nfbwzb1yIdELFGvZIY8biWnOFO/dDGrRHzNwJCXpNpB1RHZ0avMwW57Cn5BbWoN75BP0 C9hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=S+P+z8TSJ/Zyfj7d1c5azECG0cOYl08GFb3K30xN3HE=; b=s8mboWQI3wpazpIGDW1PFFhECZJYCg1NzWKUCYN/dpRoEGWzSgKk+TSw7WDHiI8nfD Q45BWpsmyV71o+vszJcLwIrAQBcdFYdbpQDbxH6Zmw1e/mhKgwt5KpVYt1jPMpXaVdfZ u4Ojw6Cicv8I5zBo28bc86aYWxkup9nbBtgT5XhcXrqemB/0lZW2JklWouQdn7ZEXZ73 9RdJ851Remq2jCOJdu/6uhySfH82mBN5HcGOiy3RyQnNQGCgaThb+0f7EvW2HTTNQwPs MjcOP+g21Qxl9JMMNNdyJqUSA7/xgBgFCe5xYjEcDrqLXJY0XocJ/4RHBqiyx4FSCHkM fivg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Lpu79Qs4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020aa7db44000000b0044efaa88731si1219189edt.289.2022.09.06.21.28.34; Tue, 06 Sep 2022 21:28:59 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Lpu79Qs4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229449AbiIGEV1 (ORCPT + 99 others); Wed, 7 Sep 2022 00:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiIGEVZ (ORCPT ); Wed, 7 Sep 2022 00:21:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00F024D278 for ; Tue, 6 Sep 2022 21:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662524481; 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=S+P+z8TSJ/Zyfj7d1c5azECG0cOYl08GFb3K30xN3HE=; b=Lpu79Qs4LxRlTr9nFiLQt8z3VqN1+EVqRtq9cv6L9TIFgnCJ8GNHQdijAMYVh+YHPMxLPp hYWm22hAlZdg7toFaJlgGO9zSV+x+/SnrjCTGC7O6CF0kQ8ogZFHtkLbHCb7na8mWB2dEO 9OL8y22bLnAr5j8riMYXsQJtvtxGYHU= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-379-nDHV4y4MMTCjBDX8XZhevA-1; Wed, 07 Sep 2022 00:21:20 -0400 X-MC-Unique: nDHV4y4MMTCjBDX8XZhevA-1 Received: by mail-pf1-f199.google.com with SMTP id cj15-20020a056a00298f00b0053a700f1178so6832197pfb.14 for ; Tue, 06 Sep 2022 21:21:19 -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:subject:date; bh=S+P+z8TSJ/Zyfj7d1c5azECG0cOYl08GFb3K30xN3HE=; b=2ztQW85mMSUlsfAse4IlW496QmYwE/67z1Uprlw7da6Ztuj8W0Bn/HR2UtmNteaoQb yHC32SX8/v0Jv/uF2ckCJxIixj6e/i+Sdlq7AUVBL5muN0BgpzrGYNDFDdyX73KQHAke fwLQtoEwEzLY4dfTqQVTitbtay+OiXfEQy1rfJeP0vgAfyy1Ckrm/sX5doTIyxfd5rHy H4mKzenmhJs2f9EimHaVX10LvIjFJX1AR6u00If2SUoo6RQ3H1qTceauvZZGiYs+wHSe 7ii32Ysn/3PWRkPtE9HFq+hK9H0/C3YEVq3/HU/Ta1yDh2dBFo2mNKhPzYOa/RJrHj79 jdPw== X-Gm-Message-State: ACgBeo0QHiiRqsmZMleI4V5cuiAyJCXLu2gjuoLetKLUR4sufql9x7cG DsZ/05Os2DktYXjvhQ40HELFrhxZF+win+Y51IEIS907u5wiKXW60SJmvxgerqjMU/J7s66Sn22 njZwzf6w47dFKfqCMvjEdx+eJ X-Received: by 2002:a05:6a00:22c7:b0:53a:bea5:9abd with SMTP id f7-20020a056a0022c700b0053abea59abdmr1770319pfj.3.1662524479099; Tue, 06 Sep 2022 21:21:19 -0700 (PDT) X-Received: by 2002:a05:6a00:22c7:b0:53a:bea5:9abd with SMTP id f7-20020a056a0022c700b0053abea59abdmr1770291pfj.3.1662524478842; Tue, 06 Sep 2022 21:21:18 -0700 (PDT) Received: from [10.72.13.171] ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b28-20020aa78edc000000b0053ae6a3c51asm11172533pfr.186.2022.09.06.21.21.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Sep 2022 21:21:18 -0700 (PDT) Message-ID: Date: Wed, 7 Sep 2022 12:21:06 +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 v3 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: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> <20220901055434.824-2-qtxuning1999@sjtu.edu.cn> From: Jason Wang In-Reply-To: <20220901055434.824-2-qtxuning1999@sjtu.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 在 2022/9/1 13:54, 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 | 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_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]; > + } Would it better to have a dedicated helper like vhost_add_used_in_order() here? > 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; > } > @@ -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 = vq->last_used_idx; > new = (vq->last_used_idx += count); > @@ -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)) { This seems strange, any reason for this? (Actually if we support in-order we only need one used slot which fit for the case here) Thanks > r = __vhost_add_used_n(vq, heads, n); > if (r < 0) > return r;