Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2349121rwl; Sun, 26 Mar 2023 21:37:06 -0700 (PDT) X-Google-Smtp-Source: AKy350aCandH0W5qEpQ5AlJmraRUZB4iPtf7YtWaqBaykBR76gr/ZvUVZpJniRQU78osYvxrADlz X-Received: by 2002:a17:903:1c6:b0:1a1:cb18:7f99 with SMTP id e6-20020a17090301c600b001a1cb187f99mr8840137plh.30.1679891825757; Sun, 26 Mar 2023 21:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679891825; cv=none; d=google.com; s=arc-20160816; b=m8Gj297OeJRdCF7QwWSxLAJ7z65eWlGFVjy4axWSQD+yMLkjZKIW302k0jEJvEel/q TsfqAqC/DmKGwlHMr3k6+2geGXKHR+YNjoGiMsU+YumfHEpnftk/I7tiKNQEt0PeEQ8U oMVBW0XanoJBnpdPYgyVSj3hOlRe8lZLXnvlpsNZZgQ2mopQ7mWbadXzYcV0Bwp4Qojw kWkkFgtaAlpxp6Kj3RQMuk5D75oZIb1ex03evXGp83JjoW2CnBUR17Vc7XyKki8Fd0/J gpVeeHeuc4IkTX2MaZ6VIv37evjl5fIcbrxnDEddvY/q7hPnTNgu97sBPevT0pekhAwG JogA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:cc:to:from:date:subject :message-id; bh=ezMduVn7r8mLPJ/7m4a1RLIjl2cxgdu9Dr4oSBNXTWE=; b=KYeppYKPlxi57EwBOSICFnBUIZEKeycLCbQaUKxJ1njJB9uIewllEkCzRjd5VAkw1p n5ou38SutS8VWW44s476R8l3tG/QuAh+X4gagmKf//47JVfcE/HxtfXa3WjoeEwygrDw psdDABqQkLJePaVbryfdYbgQQPK613mkLX2XaJ7qP5kPoaikIAThN1vykQh8mHMTYZs3 pMSoXFoepPbf182jBSKAvnkO4z/mkk7WBI9Mx5V+pkc217ikBR07XEhBwMNk8M2EXNGE XmFA5jhPqqyzwyMSOO/wYgPHXmrIAwLuMCStbE2/Lxz5O7fwYE/Tnk2pdkIZ7Xhacg0E j2eg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jw20-20020a170903279400b0019c354055d0si25499023plb.304.2023.03.26.21.36.54; Sun, 26 Mar 2023 21:37:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbjC0EDK (ORCPT + 99 others); Mon, 27 Mar 2023 00:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229967AbjC0EDI (ORCPT ); Mon, 27 Mar 2023 00:03:08 -0400 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7D554499 for ; Sun, 26 Mar 2023 21:03:05 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0Vef4MtJ_1679889782; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0Vef4MtJ_1679889782) by smtp.aliyun-inc.com; Mon, 27 Mar 2023 12:03:02 +0800 Message-ID: <1679889763.914955-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH v2] virtio_ring: don't update event idx on get_buf Date: Mon, 27 Mar 2023 12:02:43 +0800 From: Xuan Zhuo To: Albert Huang Cc: Albert Huang , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" References: <20230325105633.58592-1-huangjie.albert@bytedance.com> In-Reply-To: <20230325105633.58592-1-huangjie.albert@bytedance.com> X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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 Sat, 25 Mar 2023 18:56:33 +0800, Albert Huang wrote: > in virtio_net, if we disable the napi_tx, when we triger a tx interrupt, > the vq->event_triggered will be set to true. It will no longer be set to > false. Unless we explicitly call virtqueue_enable_cb_delayed or > virtqueue_enable_cb_prepare. > > If we disable the napi_tx, it will only be called when the tx ring > buffer is relatively small. > > Because event_triggered is true. Therefore, VRING_AVAIL_F_NO_INTERRUPT or > VRING_PACKED_EVENT_FLAG_DISABLE will not be set. So we update > vring_used_event(&vq->split.vring) or vq->packed.vring.driver->off_wrap > every time we call virtqueue_get_buf_ctx. This will bring more interruptions. > > To summarize: > 1) event_triggered was set to true in vring_interrupt() > 2) after this nothing will happen for virtqueue_disable_cb() so > VRING_AVAIL_F_NO_INTERRUPT is not set in avail_flags_shadow > 3) virtqueue_get_buf_ctx_split() will still think the cb is enabled > then it tries to publish new event > > To fix, if event_triggered is set to true, do not update > vring_used_event(&vq->split.vring) or vq->packed.vring.driver->off_wrap > > Tested with iperf: > iperf3 tcp stream: > vm1 -----------------> vm2 > vm2 just receives tcp data stream from vm1, and sends the ack to vm1, > there are many tx interrupts in vm2. > but without event_triggered there are just a few tx interrupts. > > Fixes: 8d622d21d248 ("virtio: fix up virtio_disable_cb") > Signed-off-by: Albert Huang > Message-Id: <20230321085953.24949-1-huangjie.albert@bytedance.com> > Signed-off-by: Michael S. Tsirkin Reviewed-by: Xuan Zhuo > --- > drivers/virtio/virtio_ring.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index cbeeea1b0439..1c36fa477966 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -914,7 +914,8 @@ static void *virtqueue_get_buf_ctx_split(struct virtqueue *_vq, > /* If we expect an interrupt for the next entry, tell host > * by writing event index and flush out the write before > * the read in the next get_buf call. */ > - if (!(vq->split.avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT)) > + if (unlikely(!(vq->split.avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) && > + !vq->event_triggered)) > virtio_store_mb(vq->weak_barriers, > &vring_used_event(&vq->split.vring), > cpu_to_virtio16(_vq->vdev, vq->last_used_idx)); > @@ -1744,7 +1745,8 @@ static void *virtqueue_get_buf_ctx_packed(struct virtqueue *_vq, > * by writing event index and flush out the write before > * the read in the next get_buf call. > */ > - if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DESC) > + if (unlikely(vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DESC && > + !vq->event_triggered)) > virtio_store_mb(vq->weak_barriers, > &vq->packed.vring.driver->off_wrap, > cpu_to_le16(vq->last_used_idx)); > -- > 2.37.0 (Apple Git-136) >