From patchwork Mon Nov 13 17:42:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 13454275 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAA1D224ED for ; Mon, 13 Nov 2023 17:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="Wb0g/zz9" Received: from mail.tkos.co.il (mail.tkos.co.il [84.110.109.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7FE310F4 for ; Mon, 13 Nov 2023 09:49:32 -0800 (PST) Received: from tarshish.tkos.co.il (unknown [10.0.8.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 0143844064C; Mon, 13 Nov 2023 19:41:52 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1699897313; bh=RLd7CYtbOxJsDnFRd7kaDxKZyPo0aj/FzvTE9nAfQmU=; h=From:To:Cc:Subject:Date:From; b=Wb0g/zz9WwdVDaGM5a1dhHMrBJ8097vMj2KraGTyzlTY3lIHs9rG8Tt7pWx69zRyG c8U5IujyC1oIPJUpBaTP4+hKTQl0ZA2gxZcEwSLO4ZyAnkldQbk7hOHKXIgPj7sgbm HRNp6M6Olib4Re0CzZ9lc8jOOFV7pzKM32fXFTupHjM84t8PeuLr8pXkVCxoAGOuZ0 xoXXhLVuIZ4BF7Q2FMxJn4XUQnso7pVNVXGjL2C1heI+6tEOoeynTtxePNo79KY9M/ GtCKp+J2v9zy/E3itMXx5Gy2tASdu/DPR2AADj1DWCvtZua0onVdWUMU6Sk0hly83y aUJhnpbu8r81w== From: Baruch Siach To: Alexandre Torgue , Jose Abreu Cc: netdev@vger.kernel.org, Baruch Siach Subject: [PATCH net 1/2] net: stmmac: fix rx budget limit check Date: Mon, 13 Nov 2023 19:42:49 +0200 Message-ID: X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The while loop condition verifies 'count < limit'. Neither value change before the 'count >= limit' check. As is this check is dead code. But code inspection reveals a code path that modifies 'count' and then goto 'drain_data' and back to 'read_again'. So there is a need to verify count value sanity after 'read_again'. Move 'read_again' up to fix the count limit check. Fixes: ec222003bd94 ("net: stmmac: Prepare to add Split Header support") Signed-off-by: Baruch Siach Reviewed-by: Serge Semin --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 3e50fd53a617..f28838c8cdb3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5328,10 +5328,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) len = 0; } +read_again: if (count >= limit) break; -read_again: buf1_len = 0; buf2_len = 0; entry = next_entry; From patchwork Mon Nov 13 17:42:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 13454274 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C69D2224EA for ; Mon, 13 Nov 2023 17:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="h4Svy6gl" Received: from mail.tkos.co.il (mail.tkos.co.il [84.110.109.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4AA410EC for ; Mon, 13 Nov 2023 09:49:32 -0800 (PST) Received: from tarshish.tkos.co.il (unknown [10.0.8.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 3F44D4406F7; Mon, 13 Nov 2023 19:41:53 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1699897313; bh=rsN6ONrmXmjveXdLExCyq9Ko3XW2Kuct8gTVNvQv1Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4Svy6glaao3UeOsYqVpyLldJOjSdH3PiiA6BWKQlLbUUZ6QfeHGq9JIVid+XiCAu e0xbf4ANGF7eIVh2Z7mJXMS7iixqqw/aJVe10ujnrZInqs1HiUXiL2FP4B1ucdtBPA 24eAAhEV6KYK+GM+ZXF6275IQ9xkgOa2YZg1hNXINedEd47HzKHzZC/sfxM6X775x2 imG1rES1nT4oCO+uZ+W6VFRlL/2Uiobgpnf9ZCgCWfZaVeApbruxl4j7uDNWGVfSlQ 1PjlVoG8mw32T7Og1DOCdxR1xJAK9V1tln4TTanlc1bDU3DH5zxt3XjnB/TWsD8u1J sID0eyUC7VKTQ== From: Baruch Siach To: Alexandre Torgue , Jose Abreu Cc: netdev@vger.kernel.org, Baruch Siach Subject: [PATCH net 2/2] net: stmmac: avoid rx queue overrun Date: Mon, 13 Nov 2023 19:42:50 +0200 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org dma_rx_size can be set as low as 64. Rx budget might be higher than that. Make sure to not overrun allocated rx buffers when budget is larger. Leave one descriptor unused to avoid wrap around of 'dirty_rx' vs 'cur_rx'. Signed-off-by: Baruch Siach Reviewed-by: Serge Semin --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f28838c8cdb3..2afb2bd25977 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5293,6 +5293,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) dma_dir = page_pool_get_dma_dir(rx_q->page_pool); buf_sz = DIV_ROUND_UP(priv->dma_conf.dma_buf_sz, PAGE_SIZE) * PAGE_SIZE; + limit = min(priv->dma_conf.dma_rx_size - 1, (unsigned int)limit); if (netif_msg_rx_status(priv)) { void *rx_head;