Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp469477rwe; Thu, 1 Sep 2022 02:39:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR70wvS9hUJfYv/znvdLvt48TOV1RCiCHsl1U59HYERJ1I0CiRpFn9a3jM/9mLJpA2ke9uWU X-Received: by 2002:a17:902:7145:b0:172:fad2:fb71 with SMTP id u5-20020a170902714500b00172fad2fb71mr29743601plm.57.1662025199246; Thu, 01 Sep 2022 02:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662025199; cv=none; d=google.com; s=arc-20160816; b=WR03qidmj/FFAqEXthD76yRrMaB0GhNC3I1warG68rf93CBpwYsPUg1sJQkESdQEdD AzFRvGruaLRVkAifEBSvqHxHEYs55K5ugBQ1SlbIWbO9hcdS3EnEwan3e2eEVc+eP/IA 99Osjx35l8pHSmOtuheH826DWyV+KmgBml5eGW75cFpT3TppVD9hpSWYm4n1CbLcaj70 mtrkaKfDUTNEl6JQchwIAAFiX8gxorml9zDKtvEXqgIXxSmWajqYd5UajRC/z8SxAKH0 Iye3QHDpyIKsc4YN+oL+Q/oy0BNEJINocrl2Cf/e9/TQUz57NKGEouwN/usauofieG0Y QYzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Wlt+f7gBjVGkc0zcQ2pNtyBrX9IrrQuzBjMRXWCKVdg=; b=Hh/TQhgwYbNBqZr84DPRKn0eWltrq73VTXSFYlP95HrcTvC2KV21A2igz1XhsHYhVC gnISfWhQv08wq42c/QmzRm2vDhSw3pJ4q5XyMcaq5CRNdjVyH5t49t76OTsftGn41E/a hJKxdIwFXqLeYsa0Zc0WR/WkfuWUdDn0/COeeV9EG7GNjMZgoHeXbea5/1iolZTLGZWH DoUf0bnRJoX8nWtnfGqhoW3cNHUYwuvSGHxiLqxGRpmoGb81yhUQ0QfXHtErQPZfsRho X4RItI5k6xYrGDPTvsnbxjj07DoVynIlJjo4lXPtAJkA85a1FcfjUswFjIMmKAIbBq7k zJtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Cmpm/rfq"; 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 mj15-20020a17090b368f00b001fae387a66bsi3844850pjb.51.2022.09.01.02.39.47; Thu, 01 Sep 2022 02:39: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="Cmpm/rfq"; 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 S234337AbiIAI4h (ORCPT + 99 others); Thu, 1 Sep 2022 04:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbiIAI4U (ORCPT ); Thu, 1 Sep 2022 04:56:20 -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 814111314FE for ; Thu, 1 Sep 2022 01:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662022576; 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: in-reply-to:in-reply-to:references:references; bh=Wlt+f7gBjVGkc0zcQ2pNtyBrX9IrrQuzBjMRXWCKVdg=; b=Cmpm/rfqf5o2169JdnYIidR7jNgbYmful1YbSCZFNtAFM+/8otHwfwJGWGaupARiD+6oyt qXmBobrMWIZ4uXYb49VEK5dfJJ+mtShowzcJEZDMBh8HR/J/cNC7I5hK0nyKxs0CdKfP/l nvUnuViQ2pMejaRJYMLZedVuUjMC3sQ= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-637-v8dowpQhPbyC-lw3LcZ-XQ-1; Thu, 01 Sep 2022 04:56:15 -0400 X-MC-Unique: v8dowpQhPbyC-lw3LcZ-XQ-1 Received: by mail-qk1-f198.google.com with SMTP id u15-20020a05620a0c4f00b006b8b3f41303so13651583qki.8 for ; Thu, 01 Sep 2022 01:56:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=Wlt+f7gBjVGkc0zcQ2pNtyBrX9IrrQuzBjMRXWCKVdg=; b=B09EiJ0W1JAuFkCqCzHHH4BlQQV1etEvG2dqKD3J+jJt72X3N+K9ypAtRoyEuzbydD XJKX1AWnMsqkvmPRT1JHV7uSTLT+jtgTO0p/jdWP3AEDg9iaUfTJwDHicSW+CyPAXy3I BcjZefTg+7W5HD3ClVLu38+JLVmKEVKdkRe32+QTeMhOToc6MRSCOfA/DgnTnxuUooWI HLbPwxlHKzExkso4/ULpClW4FWd+ViXFmrOPmE/laBDLOoQu6sfXncXEfUGGWTbGRuxs G9LD5XjV9RiZMDoKt7IaB2kStHqmYKuEQY4v6E5QQPXxV61mjf8fFJrvq8jIGLAFkozH khSg== X-Gm-Message-State: ACgBeo2JioAagegSZYtdOCv+NC9gMHmwOFO87aXQcU805qFa6gYayzTr YoGKK/CwPkmYtwlcKHs2WNN48xXd8feIe79LtGd2DWA30/UfT3POGTLzH7VrBU9yBp3xCQNFELz FjOw0RnStRwMPFdPPoE5HWgECca8U/8Z1X/rNoeWC X-Received: by 2002:a05:622a:4204:b0:344:e16c:e597 with SMTP id cp4-20020a05622a420400b00344e16ce597mr22689196qtb.592.1662022574904; Thu, 01 Sep 2022 01:56:14 -0700 (PDT) X-Received: by 2002:a05:622a:4204:b0:344:e16c:e597 with SMTP id cp4-20020a05622a420400b00344e16ce597mr22689189qtb.592.1662022574715; Thu, 01 Sep 2022 01:56:14 -0700 (PDT) MIME-Version: 1.0 References: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn> <20220901055434.824-2-qtxuning1999@sjtu.edu.cn> In-Reply-To: <20220901055434.824-2-qtxuning1999@sjtu.edu.cn> From: Eugenio Perez Martin Date: Thu, 1 Sep 2022 10:55:38 +0200 Message-ID: Subject: Re: [RFC v3 1/7] vhost: expose used buffers To: Guo Zhi Cc: Jason Wang , Stefano Garzarella , Michael Tsirkin , netdev , linux-kernel , kvm list , virtualization Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Thu, Sep 1, 2022 at 7:55 AM Guo Zhi wrote: > > 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]; > + } > 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)); log_used reports to the VMM the modified memory by the device. It iterates over used descriptors translating them to do so. We need to either report here all the descriptors or to modify log_used so it reports all the batch with in_order feature. The latter has an extra advantage: no need to report these non-existent writes to the used ring of the skipped buffers. Although it probably does not make a difference in performance. With the current code, we could iterate the heads[] array too, calling . However, I think it would be a waste. More on that later. Thanks! > } > 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)) { > r = __vhost_add_used_n(vq, heads, n); > if (r < 0) > return r; > -- > 2.17.1 >