Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3267535pxp; Mon, 14 Mar 2022 15:03:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkRFFjF5B3vf/UST1ozzVVblilO8Xz3TYNrQYpQVYMw7zlL53CxHAORFIz91Y5sZKBfBwH X-Received: by 2002:a17:90a:f186:b0:1bf:285a:2731 with SMTP id bv6-20020a17090af18600b001bf285a2731mr1263960pjb.22.1647295389128; Mon, 14 Mar 2022 15:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647295389; cv=none; d=google.com; s=arc-20160816; b=JSEbBuw/MeD6wmnLVPcm+R3pAFutopqs1XZqQVV7pQXK69DstvFVgkcO0D0eoNwPih NeuGB16VMdQFlZgs176ZqwKnMTaNncEZv+LkOvfVjwXQJJlVT9OBlI2K4K0O7mMrZdQa SfB9FFpizIzvQv4ppHghM8oSvr0tEWyB2/SMVlFXPh60M12+w47V8R3vE81SAy10QQGa 9QuzGyKOJrN5SDD7wpEbMLhKSnwXYwqhBA84lmqPhVf/WX2TiZySQXWsiXaIWz/a8X9e jpeM5kVv5mGXZRz4fHf/1yBtX63uy0IXTd4ljjMKKMlfhJpDXFH4Ku7haSjhb9ynZL20 FlqQ== 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=M7bM1j2dDkt4S8Y6Y/n2gRdg19WfhjUj02YiOrDaqLk=; b=f7PDz50LZKJH8LtHSbqIEm/VGKoWoEZBIBcYDaTTJEr6uRqH5+gvdnMGazeqPsyQyl uIrVjsacQhl7DP5ioPKtk2SVOpLQIVXjBw5GYe328HsFgeIoOZtnn2oKaOzbCuTjXxCv 3pwreyev66VY+U4GijE2dmoLBr2ayxShkt01B8Knls4t8JZCE0RKlOGDw4dmLyFpMmsQ Jl7xjw0MM5VmUF2fPgCckYHM1HD0H6Sq5PtAiGeZey/rjPsoVWn7qMDiSs5FZPGLGLJa V8VDuIb0GqVy3TInxA79Ez8HOZTiNdtzQ7yk8m8m/SnKz5S2hwBP5tnd7wl6VyaB6H0M 0jhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1FKTlre9; 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 p8-20020a056a000a0800b004f2a6ab0ce4si19086317pfh.5.2022.03.14.15.02.55; Mon, 14 Mar 2022 15:03:09 -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=1FKTlre9; 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 S240080AbiCNL7R (ORCPT + 99 others); Mon, 14 Mar 2022 07:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240213AbiCNL6c (ORCPT ); Mon, 14 Mar 2022 07:58:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 211519FCB; Mon, 14 Mar 2022 04:57:21 -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 6BF65B80DE2; Mon, 14 Mar 2022 11:57:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0066C340E9; Mon, 14 Mar 2022 11:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259039; bh=B8JxXUMJP+tNVavWWNPa8zbI+2kLLFF+NYvVybtvMdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1FKTlre9OQiZPTE77rWUgSHo45imUkMYjtskrU6uwSoYx8gnyXr01oNAUN7TZXdYc WpgJP/1dWQ9+tlvshYBkiCMcstCBf85Chq2A8ZwqRYYT3+D2U9UZvc+ap1I2dRDd4B hZDRGqeXYdl8T9F7k0ehL/nDhhmUxVgQHdmiCwFg= 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.4 32/43] net: macb: Fix lost RX packet wakeup race in NAPI receive Date: Mon, 14 Mar 2022 12:53:43 +0100 Message-Id: <20220314112735.321761412@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112734.415677317@linuxfoundation.org> References: <20220314112734.415677317@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 @@ -1283,7 +1283,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) @@ -1291,6 +1298,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); + } } }