net: stmmac: DMA address handling fixes
Subsystems (4)
v2 cover net: stmmac: DMA address handling fixes
Update jumbo_frm() (implemented in both "chain_mode.c" and "ring_mode.c") to ensure DMA errors don't get lost due to casting the result to an integer of the wrong size. This was a Sashiko suggestion.
In addition, add explicit calls to lower_32_bits() to DMA addresses before they are passed to cpu_to_le32(), to guarantee the type of the converted value is u32.
Maxime implied that a new version the first patch could handle both fixes, but I thought it better to do them separately.
-Alex
Here is v1 of the series (the patch):
https://lore.kernel.org/lkml/[email protected]/
Alex Elder (2):
net: stmmac: use dma_addr_t for DMA addresses
net: stmmac: convert DMA address to lower 32 before assignment
drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 9 +++++---- drivers/net/ethernet/stmicro/stmmac/ring_mode.c | 15 ++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-)
base-commit: 5e6de6a2b522f659defacb1551d0465ba6ce13cf
Signature · 1 line
2.53.0
PATCH v2 1/2 net: stmmac: use dma_addr_t for DMA addresses
In jumbo_frm() (implemented in both "chain_mode.c" and "ring_mode.c"), an unsigned integer local variable is used to hold the value returned by dma_map_single(). On systems where a dma_addr_t is 64 bits, the subsequent dma_mapping_error() check of the returned value operates only on the low 32 bits (whose high bit won't be sign-extended). In this case, dma_mapping_error() would return 0 (no error) even if there were one.
Fix this in both spots by using a dma_addr_t for the local variable.
--- drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 3 ++- drivers/net/ethernet/stmicro/stmmac/ring_mode.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +2 -1
@@ -20,9 +20,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb,unsigned int nopaged_len =skb_headlen (skb);struct stmmac_priv *priv = tx_q->priv_data;unsigned int entry = tx_q->cur_tx; -unsigned int bmax, buf_len, des2; +unsigned int bmax, buf_len;unsigned int i =1 , len;struct dma_desc *desc; +dma_addr_t des2; desc = tx_q->dma_tx + entry;
drivers/net/ethernet/stmicro/stmmac/ring_mode.c +2 -1
@@ -20,8 +20,9 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb,unsigned int nopaged_len =skb_headlen (skb);struct stmmac_priv *priv = tx_q->priv_data;unsigned int entry = tx_q->cur_tx; -unsigned int bmax, len, des2; +unsigned int bmax, len;struct dma_desc *desc; +dma_addr_t des2;if (priv->extend_desc) desc = (struct dma_desc *)(tx_q->dma_etx + entry);
Signature · 1 line
2.53.0
PATCH v2 2/2 net: stmmac: convert DMA address to lower 32 before assignment
In reply to Alex ElderIn jumbo_frm() (implemented in both "chain_mode.c" and "ring_mode.c"), there are places where a DMA descriptor is converted to little-endian byte order in assignment. The DMA descriptor could be a 64-bit value, which makes the 32-bit byte swapping operation seem a little sketchy.
Explicitly extract the low-order 32 bits of the dma_addr_t value being converted into a u32 so it's crystal clear that we're doing the right thing.
--- drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 6 +++--- drivers/net/ethernet/stmicro/stmmac/ring_mode.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +3 -3
@@ -37,7 +37,7 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, des2 =dma_map_single (priv->device, skb->data, buf_len,DMA_TO_DEVICE ); - desc->des2 =cpu_to_le32 (des2); + desc->des2 =cpu_to_le32 (lower_32_bits (des2));if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2;
@@ -55,7 +55,7 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, des2 =dma_map_single (priv->device, (skb->data + bmax * i), bmax,DMA_TO_DEVICE ); - desc->des2 =cpu_to_le32 (des2); + desc->des2 =cpu_to_le32 (lower_32_bits (des2));if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2;
@@ -68,7 +68,7 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, des2 =dma_map_single (priv->device, (skb->data + bmax * i), len,DMA_TO_DEVICE ); - desc->des2 =cpu_to_le32 (des2); + desc->des2 =cpu_to_le32 (lower_32_bits (des2));if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2;
drivers/net/ethernet/stmicro/stmmac/ring_mode.c +6 -6
@@ -40,7 +40,7 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, des2 =dma_map_single (priv->device, skb->data, bmax,DMA_TO_DEVICE ); - desc->des2 =cpu_to_le32 (des2); + desc->des2 =cpu_to_le32 (lower_32_bits (des2));if (dma_mapping_error (priv->device, des2))return -1 ;
@@ -48,7 +48,7 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, tx_q->tx_skbuff_dma[entry].len = bmax; tx_q->tx_skbuff_dma[entry].is_jumbo = true; - desc->des3 =cpu_to_le32 (des2 + BUF_SIZE_4KiB); + desc->des3 =cpu_to_le32 (lower_32_bits (des2) + BUF_SIZE_4KiB);stmmac_prepare_tx_desc (priv, desc,1 , bmax, csum,STMMAC_RING_MODE ,0 , false, skb->len); tx_q->tx_skbuff[entry] =NULL ;
@@ -61,27 +61,27 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, des2 =dma_map_single (priv->device, skb->data + bmax, len,DMA_TO_DEVICE ); - desc->des2 =cpu_to_le32 (des2); + desc->des2 =cpu_to_le32 (lower_32_bits (des2));if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = len; tx_q->tx_skbuff_dma[entry].is_jumbo = true; - desc->des3 =cpu_to_le32 (des2 + BUF_SIZE_4KiB); + desc->des3 =cpu_to_le32 (lower_32_bits (des2) + BUF_SIZE_4KiB);stmmac_prepare_tx_desc (priv, desc,0 , len, csum,STMMAC_RING_MODE ,1 , !skb_is_nonlinear (skb), skb->len); }else { des2 =dma_map_single (priv->device, skb->data, nopaged_len,DMA_TO_DEVICE ); - desc->des2 =cpu_to_le32 (des2); + desc->des2 =cpu_to_le32 (lower_32_bits (des2));if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = nopaged_len; tx_q->tx_skbuff_dma[entry].is_jumbo = true; - desc->des3 =cpu_to_le32 (des2 + BUF_SIZE_4KiB); + desc->des3 =cpu_to_le32 (lower_32_bits (des2) + BUF_SIZE_4KiB);stmmac_prepare_tx_desc (priv, desc,1 , nopaged_len, csum,STMMAC_RING_MODE ,0 , !skb_is_nonlinear (skb), skb->len);
Signature · 1 line
2.53.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 12 Aug 2026 11:38:29 -0500 you wrote:
Update
jumbo_frm()(implemented in both "chain_mode.c" and "ring_mode.c") to ensure DMA errors don't get lost due to casting the result to an integer of the wrong size. This was a Sashiko suggestion.In addition, add explicit calls to
lower_32_bits()to DMA addresses before they are passed tocpu_to_le32(), to guarantee the type of the converted value is u32.[...]
Here is the summary with links:
- [net-next,v2,1/2] net: stmmac: use dma_addr_t for DMA addresses
https://git.kernel.org/netdev/net-next/c/0c1f9020d2ad - [net-next,v2,2/2] net: stmmac: convert DMA address to lower 32 before assignment https://git.kernel.org/netdev/net-next/c/c11c497af866
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html