Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3589208pxp; Tue, 15 Mar 2022 01:46:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQPe59dIqYj6iFokHQ37WWQpGyNn9z7i5A1ypkDEPozEfcXvDY6bHQEhQmfl8wRVSr35+a X-Received: by 2002:a63:5945:0:b0:375:799a:281d with SMTP id j5-20020a635945000000b00375799a281dmr23575139pgm.605.1647333977236; Tue, 15 Mar 2022 01:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647333977; cv=none; d=google.com; s=arc-20160816; b=QxMB490l2TLvaI+ihJtZZ+nO0RBBX95x2ozu3T0bi4ukVmbwKeKc/bayJHdvqVkvCy N8xzM9GkQLbhP3bg0aMIH6Suftg4k5vmE+zq34RklYlVREv4EgCrZDsB2FBAZNaqfeeR XToYHxHDa/AJkHLtEdSIKYoMkEn5MzVYVoiYurQeLw1RkK8aH+Jl8HJR9O/Oo2SU9v2W 4rw9P7GSOfT2OUCrF3+bLwfNO+qzF2SEtqJg3yEvq1RtktLbWpVKuqaDgJkAEJScL3Ku zOVUcqVC1UfZhde/GMQl4tWuqKJYOr/WrSXQCTvBJ2kdgw2bBRSyiQnqSmjfzfj8RcXS dxSg== 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=+0ZUqiZ+4TAnoJhaiuv5pf/BdDmguBQBJj5+5SFh0Vc=; b=SfB05Lda4xwUrdb9liWu5610mTXQ32dqgESUi68o4XCtWNwxUQO4AuM2U1EkBYJeD9 K4ZBp0dhO6OoFrDh+lonoQjqydD01cG8mpC7NaahxS5kQxQulmYAbFYB2Btp+2c+PUDR jQrgtKRur0MSm/ZvKorJQ5isXwK7+fLF9r1vvyiveoPbTAi2ROA2h5iesEH6//VKqq9d 6rzQHuTMfSICFbYCHER2/9xynEC1Lro9vnX4m7e9bitxJYkv2QK1KI1SPlZ15tiAfChK 0sKeTXDxSqbXM7DliQZdvb3Qq3tbBmICfXsXv0NBC6DDJz0vBVv/A0dPjuQGMm0WhLij vsAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P22duVXN; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902bb8c00b001530b0d6a23si16541035pls.609.2022.03.15.01.46.05; Tue, 15 Mar 2022 01:46:17 -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=@linuxfoundation.org header.s=korg header.b=P22duVXN; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241459AbiCNMWs (ORCPT + 99 others); Mon, 14 Mar 2022 08:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241216AbiCNMNE (ORCPT ); Mon, 14 Mar 2022 08:13:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE28B366A2; Mon, 14 Mar 2022 05:11:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id 67B8BB80DFB; Mon, 14 Mar 2022 12:11:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B10DBC340E9; Mon, 14 Mar 2022 12:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259862; bh=AOk/3A1maZIhYaKanLu/kz4jEySsk00+Ym/Ql8tG+qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P22duVXNuiildbGMMwt9vqBStlt49nFa3KVxJdyu2ZcQLLAm7JhCfUPZxIgnAiC2Z X3x9IJ5UP5kbEURH0EcRQeTEhaAB6PpkGhUf/AEVwX2YTg8HrhgVrtka7wont0Ehch VGojMM0s97QLQ2FPaqAvvoLcCpK9brKQlxjZmekk= 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.15 079/110] net: macb: Fix lost RX packet wakeup race in NAPI receive Date: Mon, 14 Mar 2022 12:54:21 +0100 Message-Id: <20220314112745.237130901@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112743.029192918@linuxfoundation.org> References: <20220314112743.029192918@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=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 @@ -1606,7 +1606,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) @@ -1614,6 +1621,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); + } } }