Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12895639rwl; Tue, 3 Jan 2023 23:55:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXtV787OnMnG3bYzyU8hYCO80nyZd2FOc9KJU8ZA6SjXsjf1B9njFFsHFKs2pgsxlW+cM/8q X-Received: by 2002:a17:906:d217:b0:7af:1139:de77 with SMTP id w23-20020a170906d21700b007af1139de77mr39518190ejz.4.1672818916439; Tue, 03 Jan 2023 23:55:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672818916; cv=none; d=google.com; s=arc-20160816; b=mWefIHGXr8bmnL1fi1uRfoJqSgZd2tKshWGdBtEOPbgneH9Q3nSRT8Xv46+jop/GT8 YKZJlmLK8lJd0L1keXPZJ4C0sJKi6ahZkY6D4nK/eVIbTt8g1enAti+WR1hHrSdTCs5I 7z7bUUCtqLn3TL2sAWlJWHvzAmyBk2ZVJps3TYlF2KXOj+8HakFGS4Wn2nPIIU+OSAl3 ERvxnUYMD9/LcJMc+gcQZ9llG/rCYJEg3WWLx3RZTstqWqQNiFliytmXdGlqmjaxK4lw AOMaU5qumruMueQvU9fgDOeE4/vJ+NCvu6oxkqGzm7BH1MwtAHIECIqfdoM5UPI26Djg wpgg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=dZlFWtxiRkDtk+thRF9nVuLB+b4oL2TYgzK5e9wk6bs=; b=ncvtd+DLtkv6oUZjLl2neTPL6jxI2WCTKOEeFADs5GlG8r2dZ1WfZFfdKHDmwhPiAb W2Oob+nlS1uIPBu/6oz5wOkuduEm7TbbPhxl91ZolkRY4eFpX3PKf/866pF0TP/t/eul j8Q4n7/9gAKCEbufJTG+ycPhgaUJOZn53M42vcw4ZM2y+ApiMAhDUrPAtUTzNr6VMNWK ssLmx1Zrj1nKd+kdG4mMRRoWMdQqpy+2hRaOanLHtEJWvj+JncgPbdkFHVYqp0IVZlfI ml83VO/U8kO/7uK4FUNeXmuKiC41Lc0EH5ZI0v+Mm3Ycso3HVnH0HG/lOCcOCHJlBN6H aj0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SOOS8aI8; 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 oz8-20020a1709077d8800b007c0c9bd6206si32205726ejc.553.2023.01.03.23.55.03; Tue, 03 Jan 2023 23:55:16 -0800 (PST) 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=SOOS8aI8; 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 S233738AbjADGse (ORCPT + 57 others); Wed, 4 Jan 2023 01:48:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233798AbjADGrc (ORCPT ); Wed, 4 Jan 2023 01:47:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4369186F1 for ; Tue, 3 Jan 2023 22:46:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672814776; 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=dZlFWtxiRkDtk+thRF9nVuLB+b4oL2TYgzK5e9wk6bs=; b=SOOS8aI83cGhGdG2ckdETkO+AvAKw6/I1mzXh0cWm2ObnR3Oc0hTOR6dvkiwyxLtu+/KY0 McwH5kTcpX/O1e8umacApWemFGXdRoSTCzhogLjB9kgQ6N07DCtDesJ4tqaFQNCcxYXS91 RQCE/C7oLa5zLszqrNRdjFIItVgsKoo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-552-fhAv2q2nPLOAt5fC20D_EA-1; Wed, 04 Jan 2023 01:46:14 -0500 X-MC-Unique: fhAv2q2nPLOAt5fC20D_EA-1 Received: by mail-wm1-f72.google.com with SMTP id l17-20020a05600c1d1100b003d9a145366cso7539908wms.4 for ; Tue, 03 Jan 2023 22:46:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding: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=dZlFWtxiRkDtk+thRF9nVuLB+b4oL2TYgzK5e9wk6bs=; b=o0OdJPjHJHLFp5AKg6+3mzZV2wc1zJl4wPRcyroiKHxIgrl5El5IfbIfkhNfZPCLBb XRoeXDfvGvAGHbADFORwwQd5JNNXhsHpxOnURDA7V1o+muX6Twju26h28YlbfjODP5K6 U/hYwJS0lKQKfHSL5ne9CrJEfmwoBVIQKf9MkdRiAZXRFtRor6fKGwo9x4ZaVU3wbyQu P/E3NrizFe91+OSsNVXojAHXiINWyOf1Z6uUANoFeb1+AIa81JOfmVi/ZQuwpSmJBonA JP55w+ujG1Cn9y0EEg7F8WMCXEt+leh6ydedryODpUFXXT5lGv/aJKckMdancUy/RCXL jtOA== X-Gm-Message-State: AFqh2krG+7viEl+I94tnW2eIyhdW44DDEBiZn37Iwu4Ikly1LzfTNHg+ vCxl8MtPnFA6nWWbWDZzk0/DsZD79i2GFTWwmRQ2xo84Kr2R6uf8554RwjIfGGUfYmMlKNfExUW WE848/BHmXiZ618YULUWZa/1I X-Received: by 2002:a05:600c:3ba7:b0:3d3:4dac:aa69 with SMTP id n39-20020a05600c3ba700b003d34dacaa69mr32523077wms.36.1672814773591; Tue, 03 Jan 2023 22:46:13 -0800 (PST) X-Received: by 2002:a05:600c:3ba7:b0:3d3:4dac:aa69 with SMTP id n39-20020a05600c3ba700b003d34dacaa69mr32523066wms.36.1672814773307; Tue, 03 Jan 2023 22:46:13 -0800 (PST) Received: from redhat.com ([2.52.151.85]) by smtp.gmail.com with ESMTPSA id x7-20020a05600c188700b003d9aa76dc6asm17424241wmp.0.2023.01.03.22.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 22:46:12 -0800 (PST) Date: Wed, 4 Jan 2023 01:46:09 -0500 From: "Michael S. Tsirkin" To: Jason Wang Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xuanzhuo@linux.alibaba.com Subject: Re: [PATCH net V2] virtio-net: correctly enable callback during start_xmit Message-ID: <20230104014256-mutt-send-email-mst@kernel.org> References: <20221215032719.72294-1-jasowang@redhat.com> <20221215034740-mutt-send-email-mst@kernel.org> <20221215042918-mutt-send-email-mst@kernel.org> <50eb0df0-89fe-a5df-f89f-07bf69bd00ae@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <50eb0df0-89fe-a5df-f89f-07bf69bd00ae@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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=ham 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, Jan 04, 2023 at 12:23:07PM +0800, Jason Wang wrote: > > 在 2022/12/23 14:29, Jason Wang 写道: > > On Fri, Dec 16, 2022 at 11:43 AM Jason Wang wrote: > > > On Thu, Dec 15, 2022 at 5:35 PM Michael S. Tsirkin wrote: > > > > On Thu, Dec 15, 2022 at 05:15:43PM +0800, Jason Wang wrote: > > > > > On Thu, Dec 15, 2022 at 5:02 PM Michael S. Tsirkin wrote: > > > > > > On Thu, Dec 15, 2022 at 11:27:19AM +0800, Jason Wang wrote: > > > > > > > Commit a7766ef18b33("virtio_net: disable cb aggressively") enables > > > > > > > virtqueue callback via the following statement: > > > > > > > > > > > > > > do { > > > > > > > ...... > > > > > > > } while (use_napi && kick && > > > > > > > unlikely(!virtqueue_enable_cb_delayed(sq->vq))); > > > > > > > > > > > > > > When NAPI is used and kick is false, the callback won't be enabled > > > > > > > here. And when the virtqueue is about to be full, the tx will be > > > > > > > disabled, but we still don't enable tx interrupt which will cause a TX > > > > > > > hang. This could be observed when using pktgen with burst enabled. > > > > > > > > > > > > > > Fixing this by trying to enable tx interrupt after we disable TX when > > > > > > > we're not using napi or kick is false. > > > > > > > > > > > > > > Fixes: a7766ef18b33 ("virtio_net: disable cb aggressively") > > > > > > > Signed-off-by: Jason Wang > > > > > > > --- > > > > > > > The patch is needed for -stable. > > > > > > > Changes since V1: > > > > > > > - enable tx interrupt after we disable tx > > > > > > > --- > > > > > > > drivers/net/virtio_net.c | 2 +- > > > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > > > > > index 86e52454b5b5..dcf3a536d78a 100644 > > > > > > > --- a/drivers/net/virtio_net.c > > > > > > > +++ b/drivers/net/virtio_net.c > > > > > > > @@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) > > > > > > > */ > > > > > > > if (sq->vq->num_free < 2+MAX_SKB_FRAGS) { > > > > > > > netif_stop_subqueue(dev, qnum); > > > > > > > - if (!use_napi && > > > > > > > + if ((!use_napi || !kick) && > > > > > > > unlikely(!virtqueue_enable_cb_delayed(sq->vq))) { > > > > > > > /* More just got used, free them then recheck. */ > > > > > > > free_old_xmit_skbs(sq, false); > > > > > > This will work but the following lines are: > > > > > > > > > > > > if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) { > > > > > > netif_start_subqueue(dev, qnum); > > > > > > virtqueue_disable_cb(sq->vq); > > > > > > } > > > > > > > > > > > > > > > > > > and I thought we are supposed to keep callbacks enabled with napi? > > > > > This seems to be the opposite logic of commit a7766ef18b33 that > > > > > disables callbacks for NAPI. > > > > > > > > > > It said: > > > > > > > > > > There are currently two cases where we poll TX vq not in response to a > > > > > callback: start xmit and rx napi. We currently do this with callbacks > > > > > enabled which can cause extra interrupts from the card. Used not to be > > > > > a big issue as we run with interrupts disabled but that is no longer the > > > > > case, and in some cases the rate of spurious interrupts is so high > > > > > linux detects this and actually kills the interrupt. > > > > > > > > > > My undersatnding is that it tries to disable callbacks on TX. > > > > I think we want to disable callbacks while polling, yes. here we are not > > > > polling, and I think we want a callback because otherwise nothing will > > > > orphan skbs and a socket can be blocked, not transmitting anything - a > > > > deadlock. > > > I'm not sure how I got here, did you mean a partial revert of > > > a7766ef18b33 (the part that disables TX callbacks on start_xmit)? > > Michael, any idea on this? > > > > Thanks > > > Michael, any comment? > > Thanks Sorry I don't understand the question. What does "how I got here" mean? To repeat my suggestion: I think it is easier to just do a separate branch here. Along the lines of: if (use_napi) { if (unlikely(!virtqueue_enable_cb_delayed(sq->vq))) virtqueue_napi_schedule(napi, vq); } else { ... old code ... } we can also backport this minimal safe fix, any refactorings can be done on top. -- MST