Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp910000rwl; Wed, 29 Mar 2023 09:58:04 -0700 (PDT) X-Google-Smtp-Source: AKy350a4/X8PSk3062dw2O/QEAv0KkG0AnLq9+Cg10J4aGYu5sZ+RNptFA9zU0P2iLQ8hqMUBjBF X-Received: by 2002:a05:6402:8c4:b0:4fc:725:e670 with SMTP id d4-20020a05640208c400b004fc0725e670mr19562565edz.11.1680109084229; Wed, 29 Mar 2023 09:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680109084; cv=none; d=google.com; s=arc-20160816; b=TJYYJOCh01fO2D236EfLuCye9FM3F368tSSbrUdnQNpMUjgsRpWTscdVn1pP2kVVJT y3h4tk1enxfyFq8DZK3M8Xlq8eUdeyzkJ33Vs56YqAFZb2xyKSB3E7l/RwcVBxFdHWdx uyhuI+UBWn+sRRipp3EIFtVNWEMolvaLG/bR4WMbB0EjFcFGqbU2Lq/+WxYVW8G9Qs5u 92Yz3MjW47bU4TlGzep9emWO9WlPnbntCL9h4mnvffyIVnkaVKhoXfsl505tFpfIRoiT gSmI1lyPWhBD0/qkm9ZTG9rtlhgXjG3ybHbu1isaIxj4vkodLxq/+QNtXsjmoI9On8yL f1cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=b9R4dQgGGlVY8zkY31lqs8u3LNDE0nvPHRAHirYjox8=; b=xgJFLypd3mgv9wgXImYuDNJvJYYxH8X+8gSDfqpU66In7Dl7A7TtYHMm07d+PIm2KX PnXkUnXrkVVY36c7Q+iiF6/fIfs5rHzTXbANmMyEJQJWNa5CweQFG2lr6pp49lIS5dfO g4bD86nGJDlzzTymxd8uzTDgJhQRvZwmKRdov68Gc1fSajHrJIQG/dAjr6okQU0txSxL Ucji6Ufr0+zIibuDD7eofl2zagU8ICu8bo0xnar++3UbHFXgsK5ITr+VbK0fS6Ynw1ZZ tFI3ojHB1z4H3pNwGnzWA40Ati+bh1R3OBap4z0o9nlX24m7bAntau8g0rTkvfqZe5xN 04ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V6cH//IE"; 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 bb12-20020a1709070a0c00b0093dd4c98938si15092840ejc.817.2023.03.29.09.57.38; Wed, 29 Mar 2023 09:58:04 -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="V6cH//IE"; 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 S230147AbjC2QlP (ORCPT + 99 others); Wed, 29 Mar 2023 12:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjC2QlN (ORCPT ); Wed, 29 Mar 2023 12:41:13 -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 8E65F10F for ; Wed, 29 Mar 2023 09:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680108028; 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=b9R4dQgGGlVY8zkY31lqs8u3LNDE0nvPHRAHirYjox8=; b=V6cH//IEpVRCkJWf2N1lIz9QFCP52xZeJBM7DCr2a7r5udp4KUUO9YbD6mkZb06xK2tiRj 9ajZdc3EpwN9b78aA7FfjQaBf6Nel0AYQhApC3SeQIGJ2MJZhkIU5/adNUlRtQIKjHn9Hw KJ0g9ad5JiZhkDlSqjGePAKO1Y2mzB4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-IvkzhK8GNUOFM7PsEOonrg-1; Wed, 29 Mar 2023 12:40:25 -0400 X-MC-Unique: IvkzhK8GNUOFM7PsEOonrg-1 Received: by mail-wm1-f71.google.com with SMTP id bi7-20020a05600c3d8700b003edecc610abso9068957wmb.7 for ; Wed, 29 Mar 2023 09:40:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680108021; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=b9R4dQgGGlVY8zkY31lqs8u3LNDE0nvPHRAHirYjox8=; b=davRV26U9yjS+GbWzNlBWRFoVXIl0+FsXZgaarUWUCRPk0Niip4WwymXEFPywyvlVn 0YLwUT9LK3/G8+pxwCMFQIDWzEUbTMlO2g8HH8jD3nBl6WeYlPcGwVVJw4zFBih7wKSp JCBtLm3w+xlVlp201CegKFpyxzdscncwds44SXPk/bDhXIetovOt/oRhCvX4YHdfdP02 dhbiNmUFHfGpJKFUR+TGSezJc2qRQV0zJapuloUZ1dKmyZjb5HX3Aoc0mH+ThbLP6juX IitEACa6UHLJsX+/0NgvtVkbi1kr2+qtYNHSp/SvYQ9UCL3hRV3GQGNoZ4PsVvQu4FDO ag+Q== X-Gm-Message-State: AAQBX9fdqcn16PyNPGWb+vkcjPJBMkIS5qudYt2mMFD3qED6qqVKzKOa +CHSaW2Ms8Fotfj3NJi4ajMvhwnDwRppOkAUjq8HFlaoFe2a6P338Wq6eJCK7D6vQf9urj5ehcj dS5qjtJtbeXmv9EGcSX4eatNGET55EoRo X-Received: by 2002:adf:d845:0:b0:2d1:a818:6c23 with SMTP id k5-20020adfd845000000b002d1a8186c23mr17410923wrl.39.1680108021732; Wed, 29 Mar 2023 09:40:21 -0700 (PDT) X-Received: by 2002:adf:d845:0:b0:2d1:a818:6c23 with SMTP id k5-20020adfd845000000b002d1a8186c23mr17410911wrl.39.1680108021447; Wed, 29 Mar 2023 09:40:21 -0700 (PDT) Received: from redhat.com ([2.52.18.165]) by smtp.gmail.com with ESMTPSA id a4-20020adffb84000000b002d322b9a7f5sm30550080wrr.88.2023.03.29.09.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 09:40:21 -0700 (PDT) Date: Wed, 29 Mar 2023 12:40:17 -0400 From: "Michael S. Tsirkin" To: Albert Huang Cc: Jason Wang , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] virtio_ring: interrupt disable flag updated to vq even with event_triggered is set Message-ID: <20230329123959-mutt-send-email-mst@kernel.org> References: <20230329102300.61000-1-huangjie.albert@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230329102300.61000-1-huangjie.albert@bytedance.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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, Mar 29, 2023 at 06:23:00PM +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") > Signed-off-by: huangjie.albert > Signed-off-by: Michael S. Tsirkin > Signed-off-by: Jason Wang Can you confirm you tested 9p and it still works fine? > --- > 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