Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4205938rwb; Mon, 16 Jan 2023 20:07:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXv56DsAHoFAGERdQJb+BVOgIAff225sAwHXnYz2nMbiI73Y5woT7qn6FEQ8VLcoLgAhB3Om X-Received: by 2002:a17:902:b702:b0:186:8568:be7e with SMTP id d2-20020a170902b70200b001868568be7emr2234060pls.15.1673928460134; Mon, 16 Jan 2023 20:07:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673928460; cv=none; d=google.com; s=arc-20160816; b=uGaPE6HfWxh5ctMAqICzrbdPJbhMLbdWEqhVAX7wH8aRimDVgke8bTV9SyT5u/o63t NekyTsfphFseMoXW3gXQ8aZDKs4QPlL5NPZ54ucuJ5/ofBzm5SIsApCQJ9lhldHFnf/e eIFmuOGVmflOP5GaLAM/IitIctYOrZWDaM0Kuebmu2h/yYgvhAa1OXn67zcSiDRrsaAH do9vTOeHLlXOQcbeq1GY04pdSH+Of9q8GmIP5bcIQFcoU2DeyW1OZU0RT+P55ljxRYtd zGtTSYt5nMBUCOZ2gGeJXYILDzhC5z/wkcZtWsMjM9qW6DHkWEcPHCAIQ+Uvu9G61HHB fuoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=90WVwCZHiyeI3L+ZIDFVaep8HNaYc9xGptfBX2i+B+U=; b=n59FnONgUHEsFCyemrP5Z9cY8ZQoBY6d7ALhoFlRe7KCyvT2t8U4nmHUhcdtZ3fLpX NmFr/enRocW154c3pD3aYchG/YhzUpFKw8wQdZyvRmh6JDzwP0YEpLGtOSx/nSH63ZIh ZBiD4ihJhmsQxQfcBpDc7ZYEucWsRE14/78374pWpktvdpjZDIY51B//AzHsL6a5Wkom Dhj7Yo8j95J7MwlPZGB8w72rleUMLcdAEUH1IwDbCD6KSDTV8asERaJPpmWXSlIxGIyv Mg/do7ZWnlEjfOjFaShCZX0qae6utgRSmCRgNJuKVIidXJc+GPX3RTq8XTvKV/S0v0U2 n+bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U8flMJLa; 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 ix18-20020a170902f81200b0019471f1dee8si11720040plb.492.2023.01.16.20.07.33; Mon, 16 Jan 2023 20:07:40 -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=U8flMJLa; 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 S235447AbjAQDsS (ORCPT + 50 others); Mon, 16 Jan 2023 22:48:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235451AbjAQDsL (ORCPT ); Mon, 16 Jan 2023 22:48:11 -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 3F4DF21A2F for ; Mon, 16 Jan 2023 19:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673927247; 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; bh=90WVwCZHiyeI3L+ZIDFVaep8HNaYc9xGptfBX2i+B+U=; b=U8flMJLaM8v04ZBr3YlsiBu7j1/ra/EY2YBOb7A6Roj3SWcA/lG+oR24cnf2UWDTLnRbsk TuV8ekThbXqjEiFEbb1EuV+He9GV6Ox4disz8Y5S5vAfOnczfzEPb/lw5VL/QrM5EaR6r0 Sm9GU0k7D2QjF85nzCkyLs/9Dh8uxwo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-308-Xfu7N253NMu8rBvYODjSUw-1; Mon, 16 Jan 2023 22:47:17 -0500 X-MC-Unique: Xfu7N253NMu8rBvYODjSUw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4452B858F09; Tue, 17 Jan 2023 03:47:17 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-215.pek2.redhat.com [10.72.13.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 571522166B26; Tue, 17 Jan 2023 03:47:09 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com 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, lvivier@redhat.com Subject: [PATCH net V3] virtio-net: correctly enable callback during start_xmit Date: Tue, 17 Jan 2023 11:47:07 +0800 Message-Id: <20230117034707.52356-1-jasowang@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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 Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement: do { if (use_napi) virtqueue_disable_cb(sq->vq); free_old_xmit_skbs(sq, false); } 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. TO be consistent with the logic that tries to disable cb only for NAPI, fixing this by trying to enable delayed callback only when NAPI is enabled when the queue is about to be full. Fixes: a7766ef18b33 ("virtio_net: disable cb aggressively") Signed-off-by: Jason Wang --- The patch is needed for -stable. Changes since V2: - try to enabled delayed callback and schedule NAPI instead of try to poll as when TX NAPI is disabled Changes since V1: - enable tx interrupt after we disable TX --- drivers/net/virtio_net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7723b2a49d8e..18b3de854aeb 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1877,8 +1877,10 @@ 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 && - unlikely(!virtqueue_enable_cb_delayed(sq->vq))) { + if (use_napi) { + if (unlikely(!virtqueue_enable_cb_delayed(sq->vq))) + virtqueue_napi_schedule(&sq->napi, sq->vq); + } else if (unlikely(!virtqueue_enable_cb_delayed(sq->vq))) { /* More just got used, free them then recheck. */ free_old_xmit_skbs(sq, false); if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) { -- 2.25.1