๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Sandeep Haemoon Sun, 22 Nov 2026 23:13
[PATCH net-next v8 1/3] net: ethernet: mtk_eth_soc: reset dma_addr
#20569
Author: Sandeep Haemoon
Date: Sun, 22 Nov 2026 23:13
68 lines
11662 bytes
mtk_poll_rx() keeps one dma_addr_t across the whole poll loop and only
refreshes it when a replacement buffer was mapped for the descriptor
being processed.  The paths that jump straight to release_desc (no
netdev for the source port, MTK_RESETTING set, or a refill allocation
failure) re-arm the descriptor with the buffer it still holds.  The
address written back must therefore come from the descriptor's own
rxd2, and the release path relies on dma_addr being DMA_MAPPING_ERROR
to select those bits.

The declaration was moved to function scope and initialised to
DMA_MAPPING_ERROR by commit e10a35abb3da ("net: ethernet: mtk_eth_soc:
fix uninitialized variable"), which also added the first check for
that sentinel on the release path.  The check was later replaced with
the FIELD_GET(rxd2) fallback below by commit 6e0490fc36cd ("net:
ethernet: mtk_eth_soc: fix SER panic with 4GB+ RAM").  Because the
sentinel is only still true before the first mapping, that fallback
has only ever been taken for the first descriptor of a poll.  From the
second iteration on, the previous descriptor's high address bits are
combined with the current descriptor's low bits in rxd1.  With
MTK_36BIT_DMA and DRAM above 4 GiB the hardware then DMAs the next
frame to an address that is neither buffer, and the driver passes the
stale contents of the untouched buffer up the stack.  mtk_rx_clean()
unmaps the same mismatched address during a SER, which is the panic
that commit was fixing.

Reset dma_addr to DMA_MAPPING_ERROR at the start of every iteration,
so a descriptor that is released without a new mapping keeps its own
address bits.

This change depends on the FIELD_GET(rxd2) fallback, so that commit or
its stable backport has to be present: on a tree without it the
release path would clear the high bits instead of preserving them.

Fixes: 2d75891ebc09 ("net: ethernet: mtk_eth_soc: support 36-bit DMA addressing on MT7988")
Signed-off-by: Sandeep Haemoon <sandeeph@loljews.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 21abeccfe0..6c8b039fad 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2210,7 +2210,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 	u8 *data, *new_data;
 	struct mtk_rx_dma_v2 *rxd, trxd;
 	int done = 0, bytes = 0;
-	dma_addr_t dma_addr = DMA_MAPPING_ERROR;
+	dma_addr_t dma_addr;
 	int ppe_idx = 0;
 
 	while (done < budget) {
@@ -2219,6 +2219,12 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 		u32 hash, reason;
 		int mac = 0;
 
+		/* The release paths below hand the descriptor back with the
+		 * buffer it still holds, so only overwrite its address when
+		 * a new buffer was actually mapped for it.
+		 */
+		dma_addr = DMA_MAPPING_ERROR;
+
 		ring = mtk_get_rx_ring(eth);
 		if (unlikely(!ring))
 			goto rx_done;
-- 
2.53.0
Re: [PATCH net-next v8 1/3] net: ethernet: mtk_eth_soc: reset dma_addr
#21365
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 23:15
62 lines
10286 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message of "net: ethernet: mtk_eth_soc: reset
  dma_addr" describes the mechanism correctly but undersells the impact.

--

net: ethernet: mtk_eth_soc: reset dma_addr

This patch resets dma_addr to DMA_MAPPING_ERROR at the start of every
iteration of the mtk_poll_rx() loop. A descriptor that goes to
release_desc without a new mapping then keeps its own high address
bits in rxd2, instead of picking up the previous descriptor's bits.

> With
> MTK_36BIT_DMA and DRAM above 4 GiB the hardware then DMAs the next
> frame to an address that is neither buffer, and the driver passes the
> stale contents of the untouched buffer up the stack.

[Severity: Low]
The code change looks correct. Could the commit message say more plainly
what this means in practice?

Before this patch, once one descriptor had been refilled, a later
descriptor that jumped to release_desc kept its own low bits in rxd1.
Its rxd2 was then rebuilt from the previous descriptor's mapping:

drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_poll_rx() {
    ...
release_desc:
	if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA)) {
		if (unlikely(dma_addr == DMA_MAPPING_ERROR))
			addr64 = FIELD_GET(RX_DMA_ADDR64_MASK,
					   rxd->rxd2);
		else
			addr64 = RX_DMA_PREP_ADDR64(dma_addr);
	}
    ...
		rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size) | addr64;
    ...
}

The release paths are: no netdev for the source port, MTK_RESETTING
set, or mtk_page_pool_get_buff()/napi_alloc_frag() failing under
GFP_ATOMIC.

In that case the NIC writes the next received frame, up to
ring->buf_size bytes, to (prev_hi << 32) | cur_lo. The driver does not
own that memory. So ordinary inbound traffic can cause the device to
silently corrupt arbitrary kernel memory.

The current wording ("an address that is neither buffer") describes
the mechanism, but it never calls this memory corruption. Would it
help stable and security triage to state that directly?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/patch-51fa5ed3bc801edb3f29b61ca7888382%40loljews.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads