mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: spacemit: clear TX descriptor on fragment mapping failure
@ 2026-09-19 19:19 Muhammad Bilal
  2026-09-21 11:17 ` Vivian Wang
  2026-09-21 14:00 ` Troy Mitchell
  0 siblings, 2 replies; 3+ messages in thread
From: Muhammad Bilal @ 2026-09-19 19:19 UTC (permalink / raw)
  To: andrew+netdev
  Cc: davem, edumazet, kuba, pabeni, dlan, wangruikang,
	vadim.fedorenko, maxime.chevallier, troy.mitchell, netdev,
	linux-riscv, spacemit, linux-kernel, Muhammad Bilal

emac_tx_mem_map() writes TX_DESC_0_OWN into the ring descriptor for
every slot beyond old_head as soon as that slot's memset()'d local
copy is committed with "*tx_desc_addr = tx_desc", i.e. before the
buffers for that slot have necessarily all been mapped successfully.
If emac_tx_map_frag() then fails on a later fragment, the err_free_skb
path calls emac_free_tx_buf() to unmap and drop the skb, but leaves
the already-written descriptor memory untouched, and tx_ring->head is
never advanced past old_head (the "tx_ring->head = head" store is
skipped by the goto).

So a slot between old_head and the rolled-back head can be left with
TX_DESC_0_OWN set and buffer_addr_{1,2} pointing at DMA mappings that
emac_free_tx_buf() just tore down, while software considers that slot
free again. The next successful emac_tx_mem_map() call only rebuilds
old_head itself; if the DMA engine auto-advances into the following
descriptor once it finishes old_head's packet, it will fetch that
stale, already-unmapped address.

emac_tx_clean_desc() already treats emac_free_tx_buf() and clearing
the descriptor as a pair when reclaiming completed descriptors; do
the same in the mapping failure path.

Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
 drivers/net/ethernet/spacemit/k1_emac.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/spacemit/k1_emac.c b/drivers/net/ethernet/spacemit/k1_emac.c
index f7f16397a2c2..d641ac26a1e8 100644
--- a/drivers/net/ethernet/spacemit/k1_emac.c
+++ b/drivers/net/ethernet/spacemit/k1_emac.c
@@ -803,6 +803,9 @@ static void emac_tx_mem_map(struct emac_priv *priv, struct sk_buff *skb)
 	while (i != head) {
 		emac_free_tx_buf(priv, i);
 
+		tx_desc_addr = &((struct emac_desc *)tx_ring->desc_addr)[i];
+		memset(tx_desc_addr, 0, sizeof(*tx_desc_addr));
+
 		if (++i == tx_ring->total_cnt)
 			i = 0;
 	}
-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: spacemit: clear TX descriptor on fragment mapping failure
  2026-09-19 19:19 [PATCH] net: spacemit: clear TX descriptor on fragment mapping failure Muhammad Bilal
@ 2026-09-21 11:17 ` Vivian Wang
  2026-09-21 14:00 ` Troy Mitchell
  1 sibling, 0 replies; 3+ messages in thread
From: Vivian Wang @ 2026-09-21 11:17 UTC (permalink / raw)
  To: Muhammad Bilal, andrew+netdev
  Cc: davem, edumazet, kuba, pabeni, dlan, vadim.fedorenko,
	maxime.chevallier, troy.mitchell, netdev, linux-riscv, spacemit,
	linux-kernel

On 9/20/26 03:19, Muhammad Bilal wrote:

> emac_tx_mem_map() writes TX_DESC_0_OWN into the ring descriptor for
> every slot beyond old_head as soon as that slot's memset()'d local
> copy is committed with "*tx_desc_addr = tx_desc", i.e. before the
> buffers for that slot have necessarily all been mapped successfully.
> If emac_tx_map_frag() then fails on a later fragment, the err_free_skb
> path calls emac_free_tx_buf() to unmap and drop the skb, but leaves
> the already-written descriptor memory untouched, and tx_ring->head is
> never advanced past old_head (the "tx_ring->head = head" store is
> skipped by the goto).
>
> So a slot between old_head and the rolled-back head can be left with
> TX_DESC_0_OWN set and buffer_addr_{1,2} pointing at DMA mappings that
> emac_free_tx_buf() just tore down, while software considers that slot
> free again. The next successful emac_tx_mem_map() call only rebuilds
> old_head itself; if the DMA engine auto-advances into the following
> descriptor once it finishes old_head's packet, it will fetch that
> stale, already-unmapped address.
>
> emac_tx_clean_desc() already treats emac_free_tx_buf() and clearing
> the descriptor as a pair when reclaiming completed descriptors; do
> the same in the mapping failure path.
>
> Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
> Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
> ---
>  drivers/net/ethernet/spacemit/k1_emac.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Vivian Wang <wangruikang@iscas.ac.cn>

Much appreciated. I indeed did not consider this.

Also, a minor nit, but it should probably be:

Fixes: 86292155bea5 ("net: spacemit: Fix error handling in emac_tx_mem_map()")

Thanks,
Vivian "dramforeve" Wang


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: spacemit: clear TX descriptor on fragment mapping failure
  2026-09-19 19:19 [PATCH] net: spacemit: clear TX descriptor on fragment mapping failure Muhammad Bilal
  2026-09-21 11:17 ` Vivian Wang
@ 2026-09-21 14:00 ` Troy Mitchell
  1 sibling, 0 replies; 3+ messages in thread
From: Troy Mitchell @ 2026-09-21 14:00 UTC (permalink / raw)
  To: Muhammad Bilal, andrew+netdev
  Cc: davem, edumazet, kuba, pabeni, dlan, wangruikang,
	vadim.fedorenko, maxime.chevallier, troy.mitchell, netdev,
	linux-riscv, spacemit, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1517 bytes --]

On Sun Sep 20, 2026 at 3:19 AM +08, Muhammad Bilal wrote:
> emac_tx_mem_map() writes TX_DESC_0_OWN into the ring descriptor for
> every slot beyond old_head as soon as that slot's memset()'d local
> copy is committed with "*tx_desc_addr = tx_desc", i.e. before the
> buffers for that slot have necessarily all been mapped successfully.
> If emac_tx_map_frag() then fails on a later fragment, the err_free_skb
> path calls emac_free_tx_buf() to unmap and drop the skb, but leaves
> the already-written descriptor memory untouched, and tx_ring->head is
> never advanced past old_head (the "tx_ring->head = head" store is
> skipped by the goto).
>
> So a slot between old_head and the rolled-back head can be left with
> TX_DESC_0_OWN set and buffer_addr_{1,2} pointing at DMA mappings that
> emac_free_tx_buf() just tore down, while software considers that slot
> free again. The next successful emac_tx_mem_map() call only rebuilds
> old_head itself; if the DMA engine auto-advances into the following
> descriptor once it finishes old_head's packet, it will fetch that
> stale, already-unmapped address.
>
> emac_tx_clean_desc() already treats emac_free_tx_buf() and clearing
> the descriptor as a pair when reclaiming completed descriptors; do
> the same in the mapping failure path.
>
> Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
> Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>


-- 
Troy Mitchell


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 248 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-21 14:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 19:19 [PATCH] net: spacemit: clear TX descriptor on fragment mapping failure Muhammad Bilal
2026-09-21 11:17 ` Vivian Wang
2026-09-21 14:00 ` Troy Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®