Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795041683; b=Aj5FJJSLNoNfvlCysbmvDX2RJO9uxZ2RB85TcULCRm8JwzxjdwkyGBR6suswFcJL1SN2 8aekUL/ZNA8UDf3WLMECPSPfJQYaH25u23QM9HfGB450FhmCaOB537XNiuxunQqFwLmOg 0hHG5FYiJ1pgBA7HJsD/LLnlDWsXbwfHGZFLrbxQL1fSUaJC1wlewogDIHUnd2Fnk4phB 2BJv50ytZHiUf+hKBa5FL3sPsLhsB50ELxuBCZSsdaN5N7j2v6b2LF2jswONuq2Rz25vn Ds9mCiRmkIqBBU4bkenBNoDuqdhAS/aIcb2tmyItnh+iJHsHFsaatKPmGwGCmQaHoZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795041683; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=65OB7ZDFwgqcR7PpEQSJnUFjbJwrFzO+pl9DEPG7WfE=; b=kCZJ6iJT2B5wWDEp5QCwnJq/oqie0Z+pxZVALcx4U6Wgu9sh+5F7OpgnUQg2/uICd5OY g0NvAxtwsaprlapjAbfjxucFEk7pfVUcoRYGUGKKA7+zYufBuEy9DN5817ake1L2jH+7S E/0l90UZRc79nKlKfQLGBv36AR8j3AcgFHFrm5KDTHHTVHZ60xKExLdOM4JoDCjARc9co zvtwlp7WdjB73fVyEzd/Ma5qENyZEV/BQdfra2RdjTGIzmpg5gNtIVlo0UzAb7UA7s5sz aX+01H492FLrrByA+HCQzrFc1GjZRKUcIMjQ0NGJZjcq/Y90JqqyewAMT7hLyONg3gQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=cUkiTIqV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23B38606A325; Wed, 18 Nov 2026 22:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=cUkiTIqV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31E001F000C6; Wed, 18 Nov 2026 22:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795041682; bh=65OB7ZDFwgqcR7PpEQSJnUFjbJwrFzO+pl9DEPG7WfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cUkiTIqVutv1+thzJiaGQ07N6iXUy06v2OY4oNcqMkP+kyeSYRGR9J5h40zY5KSa9 PsJN1RUYzDej7gmJzoMw+aVsWgtP37dB8VVDj0oFqiOFI/pKrgS0xUSKJwNqB6mamH VD29J7ibIEH2elTbtIuwOSDBI/6gPndUXPI46Ht0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joe Damato , Sagi Maimon , Simon Horman , Paolo Abeni , Sasha Levin Subject: [PATCH 6.6 2902/3318] net: axienet: free outstanding TX buffers in axienet_dma_bd_release() Date: Wed, 18 Nov 2026 15:58:44 +0100 Message-ID: <20261118150447.537072990@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sagi Maimon [ Upstream commit 0c20cb4cfb40cf270d6c4c2c2ff5e5d72322644a ] axienet_dma_bd_release() walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring with dma_free_coherent() alone. Any descriptor that axienet_free_tx_chain() had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost. axienet_stop() disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up to lp->tx_bd_num skbs and mappings each time. axienet_dma_err_handler() already walks the TX ring this way before it restarts the DMA engine: it unmaps every descriptor whose cntrl is still set - axienet_free_tx_chain() clears it on reclaim - frees any skb still attached, and clears the descriptor. Move that loop into a helper, axienet_free_tx_bufs(), and call it from axienet_dma_bd_release() too. This relies on axienet_stop() having stopped the DMA engine first, as the RX walk in the same function already does. The helper frees the skbs with dev_kfree_skb_any(), as drops: in the error handler, which runs from a workqueue, that frees them directly rather than deferring them to softirq as dev_kfree_skb_irq() did. The walk must not run on a ring that is not there. axienet_open() does not check the result of the reset that runs axienet_dma_bd_init(), so when that reset fails tx_bd_v is either still NULL or, after an earlier close, points at the ring that close freed. Clear tx_bd_v and rx_bd_v once their rings are freed, and skip the walk when tx_bd_v is NULL. That also ends the second dma_free_coherent() of a stale ring which the same path already did. On the axienet_dma_bd_init() error path the TX ring has just been allocated zeroed, so the walk does nothing. This was reported by the Sashiko AI review bot. Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and neither the failed-reset paths nor axienet_dma_err_handler() were exercised. Fixes: 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver") Reviewed-by: Joe Damato Assisted-by: LLM sparse Signed-off-by: Sagi Maimon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261007034620.1360542-1-maimon.sagi@gmail.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- .../net/ethernet/xilinx/xilinx_axienet_main.c | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 3517a2275821f..e6f313414262d 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -153,6 +153,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, return ret; } +/** + * axienet_free_tx_bufs - Release the buffers still held by the TX ring + * @lp: Pointer to the axienet_local structure + * + * Unmap every descriptor whose mapping is still live, free any skb still + * attached, and clear the descriptor for reuse. axienet_free_tx_chain() + * clears cntrl when it reclaims a descriptor, so a non-zero value means + * the mapping is live. The DMA engine must be stopped. + */ +static void axienet_free_tx_bufs(struct axienet_local *lp) +{ + struct axidma_bd *cur_p; + u32 i; + + for (i = 0; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i]; + if (cur_p->cntrl) { + dma_addr_t addr = desc_get_phys_addr(lp, cur_p); + + dma_unmap_single(lp->dev, addr, + (cur_p->cntrl & + XAXIDMA_BD_CTRL_LENGTH_MASK), + DMA_TO_DEVICE); + } + /* not reclaimed by axienet_free_tx_chain(), so a drop */ + if (cur_p->skb) + dev_kfree_skb_any(cur_p->skb); + cur_p->phys = 0; + cur_p->phys_msb = 0; + cur_p->cntrl = 0; + cur_p->status = 0; + cur_p->app0 = 0; + cur_p->app1 = 0; + cur_p->app2 = 0; + cur_p->app3 = 0; + cur_p->app4 = 0; + cur_p->skb = NULL; + } +} + /** * axienet_dma_bd_release - Release buffer descriptor rings * @ndev: Pointer to the net_device structure @@ -166,11 +206,18 @@ static void axienet_dma_bd_release(struct net_device *ndev) int i; struct axienet_local *lp = netdev_priv(ndev); - /* If we end up here, tx_bd_v must have been DMA allocated. */ + /* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as + * allocating it, and is cleared below once the ring is freed; + * dma_free_coherent() accepts NULL. + */ + if (lp->tx_bd_v) + axienet_free_tx_bufs(lp); + dma_free_coherent(lp->dev, sizeof(*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v = NULL; if (!lp->rx_bd_v) return; @@ -201,6 +248,7 @@ static void axienet_dma_bd_release(struct net_device *ndev) sizeof(*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v = NULL; } /** @@ -1792,29 +1840,7 @@ static void axienet_dma_err_handler(struct work_struct *work) axienet_dma_stop(lp); - for (i = 0; i < lp->tx_bd_num; i++) { - cur_p = &lp->tx_bd_v[i]; - if (cur_p->cntrl) { - dma_addr_t addr = desc_get_phys_addr(lp, cur_p); - - dma_unmap_single(lp->dev, addr, - (cur_p->cntrl & - XAXIDMA_BD_CTRL_LENGTH_MASK), - DMA_TO_DEVICE); - } - if (cur_p->skb) - dev_kfree_skb_irq(cur_p->skb); - cur_p->phys = 0; - cur_p->phys_msb = 0; - cur_p->cntrl = 0; - cur_p->status = 0; - cur_p->app0 = 0; - cur_p->app1 = 0; - cur_p->app2 = 0; - cur_p->app3 = 0; - cur_p->app4 = 0; - cur_p->skb = NULL; - } + axienet_free_tx_bufs(lp); for (i = 0; i < lp->rx_bd_num; i++) { cur_p = &lp->rx_bd_v[i]; -- 2.53.0