Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp483370rwl; Wed, 29 Mar 2023 04:55:20 -0700 (PDT) X-Google-Smtp-Source: AKy350YpqqcOIkaRXlS/7VfecbsjEerLraT+4pPBrHjo3dVKepUkqGsMs+j/jzWP6iVEZCfKkWx6 X-Received: by 2002:a17:903:28c8:b0:1a2:19c1:a974 with SMTP id kv8-20020a17090328c800b001a219c1a974mr14888429plb.68.1680090920698; Wed, 29 Mar 2023 04:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680090920; cv=none; d=google.com; s=arc-20160816; b=voWwwf+bFxXVQk72+fwJZ/ECm7Hdl4GYBqWAb4MxvWkn/Ca+DPnGW3X42XFjIfLB0Q WpTHC3UKZKiagYWkw4eQ2mPHVPLA8vtjIckLhQrgErzGSECk/5wMGDLPnHDA8N0Cv6Y3 RbcdylY1Jor3vHuDXfYEGMFDyeTqp+S7Ks5v7uch3LWCKxBoezKUblPHq8o1j5tbVUFi ZM4gWQWxKNkXqorOEt/yKWVk8PLx92SBQ6Vj+KYIDjBiOUlgI2wX57bRjFo5crUJka1h IMkgL7ikHGaFBH5MjsWc71CN4y1VPabT9cEQyvXn+FSB7LeE9eWYBV1KJtFgTmTTsTwN REZA== 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=fgol6Fl/JLIFzKQanwwd+qH3MgaKqj7aHk5Im6Mjago=; b=Ckw0pLZlAGu6EcuVmNX8KbHDeYFdky8x/IO5YO9VRsAlEosMehpGvSx0t1b7aJHHZI 1PrrkDgct1S8PShyj5YpreufZE2TcJkZhm0Wv2VwWMT8yXI2MFYgpgXcLR+GFzZgfe6w edWffZa8UeSrKxI9harGpZIjZqwGB7O7Mm3N3UJufEXl4XL0XD/MVc7Bb1DfqJpRV54d JzsO0rifshtMsXr+E4qicERHsuSvTV3opNdifT/JSJCdGCi2MdRafrn8WXnbL2954Ur0 bE2UoA1coifNhL01ucvpQ+dDvWU9xlHcY2VVXbOq8sh5L1SP0qXNlg6qgGikgvDJ3tPv ARqw== 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 c20-20020a6566d4000000b005006397721fsi27750541pgw.859.2023.03.29.04.55.09; Wed, 29 Mar 2023 04:55:20 -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 S229933AbjC2Lru (ORCPT + 99 others); Wed, 29 Mar 2023 07:47:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjC2Lrt (ORCPT ); Wed, 29 Mar 2023 07:47:49 -0400 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDFFD4690 for ; Wed, 29 Mar 2023 04:47:30 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R371e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VewkDRj_1680090447; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0VewkDRj_1680090447) by smtp.aliyun-inc.com; Wed, 29 Mar 2023 19:47:28 +0800 Message-ID: <1680090301.6450636-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH v4] virtio_ring: interrupt disable flag updated to vq even with event_triggered is set Date: Wed, 29 Mar 2023 19:45:01 +0800 From: Xuan Zhuo To: Albert Huang Cc: "huangjie.albert" , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Jason Wang , "Michael S . Tsirkin" References: <20230329102300.61000-1-huangjie.albert@bytedance.com> In-Reply-To: <20230329102300.61000-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,RCVD_IN_MSPIKE_H2,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 Wed, 29 Mar 2023 18:23:00 +0800, Albert Huang wrote: > From: "huangjie.albert" > > 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 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: > update VRING_AVAIL_F_NO_INTERRUPT or VRING_PACKED_EVENT_FLAG_DISABLE to vq > when we call virtqueue_disable_cb even the event_triggered is set to true. > > 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. > > v2->v3: > -update the interrupt disable flag even with the event_triggered is set, > -instead of checking whether event_triggered is set in > -virtqueue_get_buf_ctx_{packed/split}, will cause the drivers which have > -not called virtqueue_{enable/disable}_cb to miss notifications. > > v3->v4: > -remove change for > -"if (vq->packed.event_flags_shadow != VRING_PACKED_EVENT_FLAG_DISABLE)" > -in virtqueue_disable_cb_packed > > Fixes: 8d622d21d248 ("virtio: fix up virtio_disable_cb") Hi Michael, I want to know what the purpose of this patch("virtio: fix up virtio_disable_cb") is. I re-review this patch. I didn't understand what the purpose of this patches. Does it reduce one write to vring_used_event(&vq->split.vring) ? Thanks. > Signed-off-by: huangjie.albert > Signed-off-by: Michael S. Tsirkin > Signed-off-by: Jason Wang > --- > drivers/virtio/virtio_ring.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index cbeeea1b0439..ec7ab8e04846 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -931,6 +931,14 @@ static void virtqueue_disable_cb_split(struct virtqueue *_vq) > > if (!(vq->split.avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT)) { > vq->split.avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT; > + > + /* > + * If device triggered an event already it won't trigger one again: > + * no need to disable. > + */ > + if (vq->event_triggered) > + return; > + > if (vq->event) > /* TODO: this is a hack. Figure out a cleaner value to write. */ > vring_used_event(&vq->split.vring) = 0x0; > @@ -1761,6 +1769,14 @@ static void virtqueue_disable_cb_packed(struct virtqueue *_vq) > > if (vq->packed.event_flags_shadow != VRING_PACKED_EVENT_FLAG_DISABLE) { > vq->packed.event_flags_shadow = VRING_PACKED_EVENT_FLAG_DISABLE; > + > + /* > + * If device triggered an event already it won't trigger one again: > + * no need to disable. > + */ > + if (vq->event_triggered) > + return; > + > vq->packed.vring.driver->flags = > cpu_to_le16(vq->packed.event_flags_shadow); > } > @@ -2462,12 +2478,6 @@ void virtqueue_disable_cb(struct virtqueue *_vq) > { > struct vring_virtqueue *vq = to_vvq(_vq); > > - /* If device triggered an event already it won't trigger one again: > - * no need to disable. > - */ > - if (vq->event_triggered) > - return; > - > if (vq->packed_ring) > virtqueue_disable_cb_packed(_vq); > else > -- > 2.20.1 >