Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp917125pxp; Wed, 16 Mar 2022 21:13:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC6KCbR4qkNX7vTVy0KDf/9ua+7JPiJ6PHhkPeOa9rqDhXQK3Cpmo6AG61K4qbKarH16Ev X-Received: by 2002:a17:902:e844:b0:151:f805:30ee with SMTP id t4-20020a170902e84400b00151f80530eemr2800067plg.33.1647490432538; Wed, 16 Mar 2022 21:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647490432; cv=none; d=google.com; s=arc-20160816; b=ld/miGbg6QTcOuTG1k+GTlcDOyn2TrDbu55FjdPsDIzojhSquRMiNJ/udAAdh2eG0G l0nWNnX4x6T2pRfGLnsEnfcNriILbUFn5Cp0yRA3CkOcIw7iL87IcoX8GZsOBAl7idhl cbH2Virrhm/Cm7Xo3azg2B1e0nvcQ1xeZaQc0e/OlhlKjoDojGW+wvgWDnrSq0rIYF9O 41qXBFtB3tLOQxCdYmjNQLPDX4G4/irSUhQDc1SXdoM0jq7ntxfFX+5BHlY7+x/letzl N8upEBXiYGGe+DZEA/G4scz8j4tUu1YZTJh2bNCLHmKCQpuii4GG0bfFuYuDjeR1Kh6x JTkA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bOuP9zSlBa64tJLAXJ0r5PHrFkzYBdYdZGZCYxo+s7M=; b=eI2MhZ0ecStGzWuoiFqb2+1KxADSxR3Ke2d0+De5GysvRCkPbAnjE1wSc828oFA9zX wzvU0eW67dOdim56iWvR6ihWhPo1bgbEb0INzHp0CHGuhih9ZUtbtb1eYtTY7/lOkyDy rFq/qKTFdr5XGvPnXfhsb+ifKTvZL0egNp8EuVaWdSocftZfX+Qx2C1mb/zD5xfzZXeM pPYzW8PztJ6BV90E0VugOD6o2QfQSpprYkeEMqFTO5Ft62taI4SOPvurjiJ4v6lZva2d zgSFF8iSlhl4QF+E5ZxABVhTAfprlFrrVSjZ+/ykAnbgvnLVrV67b1b0T/tMTVxgBZoP FycQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pQdtL5sG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y2-20020a62f242000000b004f2765d1575si3588637pfl.193.2022.03.16.21.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:13:52 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pQdtL5sG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9763FBAB9D; Wed, 16 Mar 2022 20:51:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240492AbiCNMGG (ORCPT + 99 others); Mon, 14 Mar 2022 08:06:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240421AbiCNMFP (ORCPT ); Mon, 14 Mar 2022 08:05:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2942149241; Mon, 14 Mar 2022 05:02:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5C0061260; Mon, 14 Mar 2022 12:02:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40FC7C340E9; Mon, 14 Mar 2022 12:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259324; bh=UyCtQWl67fX8xmmCx85LQ2WETmjPJSDy8cN0/Tj/lPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQdtL5sGfvE2kE1vLsfDJRX2jJ7vK+k6yiF6tEyA0Roy8CGPcPpoxDTWULiMeTsns 2BO5VB7dHxOCX1o8+Ots/Jb+JwmJHpnvAeweFc1GLs+QTDt6Jr6jrV4/a45ly+X0rJ 7fVuBweUcQmH8sj7rsJiEzaJe6e9WGvEChePSXhY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Scott McNutt , Robert Hancock , Claudiu Beznea , "David S. Miller" Subject: [PATCH 5.10 53/71] net: macb: Fix lost RX packet wakeup race in NAPI receive Date: Mon, 14 Mar 2022 12:53:46 +0100 Message-Id: <20220314112739.414191650@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112737.929694832@linuxfoundation.org> References: <20220314112737.929694832@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Robert Hancock commit 0bf476fc3624e3a72af4ba7340d430a91c18cd67 upstream. There is an oddity in the way the RSR register flags propagate to the ISR register (and the actual interrupt output) on this hardware: it appears that RSR register bits only result in ISR being asserted if the interrupt was actually enabled at the time, so enabling interrupts with RSR bits already set doesn't trigger an interrupt to be raised. There was already a partial fix for this race in the macb_poll function where it checked for RSR bits being set and re-triggered NAPI receive. However, there was a still a race window between checking RSR and actually enabling interrupts, where a lost wakeup could happen. It's necessary to check again after enabling interrupts to see if RSR was set just prior to the interrupt being enabled, and re-trigger receive in that case. This issue was noticed in a point-to-point UDP request-response protocol which periodically saw timeouts or abnormally high response times due to received packets not being processed in a timely fashion. In many applications, more packets arriving, including TCP retransmissions, would cause the original packet to be processed, thus masking the issue. Fixes: 02f7a34f34e3 ("net: macb: Re-enable RX interrupt only when RX is done") Cc: stable@vger.kernel.org Co-developed-by: Scott McNutt Signed-off-by: Scott McNutt Signed-off-by: Robert Hancock Tested-by: Claudiu Beznea Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/cadence/macb_main.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1448,7 +1448,14 @@ static int macb_poll(struct napi_struct if (work_done < budget) { napi_complete_done(napi, work_done); - /* Packets received while interrupts were disabled */ + /* RSR bits only seem to propagate to raise interrupts when + * interrupts are enabled at the time, so if bits are already + * set due to packets received while interrupts were disabled, + * they will not cause another interrupt to be generated when + * interrupts are re-enabled. + * Check for this case here. This has been seen to happen + * around 30% of the time under heavy network load. + */ status = macb_readl(bp, RSR); if (status) { if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) @@ -1456,6 +1463,22 @@ static int macb_poll(struct napi_struct napi_reschedule(napi); } else { queue_writel(queue, IER, bp->rx_intr_mask); + + /* In rare cases, packets could have been received in + * the window between the check above and re-enabling + * interrupts. Therefore, a double-check is required + * to avoid losing a wakeup. This can potentially race + * with the interrupt handler doing the same actions + * if an interrupt is raised just after enabling them, + * but this should be harmless. + */ + status = macb_readl(bp, RSR); + if (unlikely(status)) { + queue_writel(queue, IDR, bp->rx_intr_mask); + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) + queue_writel(queue, ISR, MACB_BIT(RCOMP)); + napi_schedule(napi); + } } }