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 08EA2ECAAD3 for ; Wed, 7 Sep 2022 04:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229480AbiIGEV1 (ORCPT ); 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-Google-Smtp-Source: AA6agR7FdPkXihchbJtJv8Jd83bDgPxk3tYbsa2yRZ4rh/+Tyemh4rXUJmUXF5h6WyCU3XNVQ3nufA== 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 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;