net: stmmac: TSO: Fix unaligned DMA unmap for non-paged SKB data
Subsystems (5)
PATCH 1/1 net: stmmac: TSO: Fix unaligned DMA unmap for non-paged SKB data
Commit 66600fac7a98 ("net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data") assigns a wrong DMA buffer address that is added an offset of proto_hdr_len to tx_q->tx_skbuff_dma[entry].buf on a certain platform that the DMA AXI address width is configured to 40-bit/48-bit, stmmac_tx_clean() will try to unmap this illegal DMA buffer address and many crashes are reported: [1] [2].
This patch guarantees that DMA address is passed to stmmac_tx_clean() unmodified and without offset.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/klkzp5yn5kq5efgtrow6wbvnc46bcqfxs65nz3qy77ujr5turc@bwwhelz2l4dw/
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -2
@@ -4192,8 +4192,8 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)struct stmmac_txq_stats *txq_stats;struct stmmac_tx_queue *tx_q;u32 pay_len, mss, queue; +dma_addr_t tso_hdr, des;u8 proto_hdr_len, hdr; -dma_addr_t des;bool set_ic;int i;
@@ -4279,6 +4279,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) DMA_TO_DEVICE);if (dma_mapping_error (priv->device, des)) goto dma_map_err; + tso_hdr = des;if (priv->dma_cap.addr64 <=32 ) { first->des0 =cpu_to_le32 (des);
@@ -4310,7 +4311,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)* this DMA buffer right after the DMA engine completely finishes the * full buffer transmission. */ - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; + tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = tso_hdr; tx_q->tx_skbuff_dma[tx_q->cur_tx].len =skb_headlen (skb); tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = false; tx_q->tx_skbuff_dma[tx_q->cur_tx].buf_type =STMMAC_TXBUF_T_SKB ;
Signature · 1 line
2.34.1
Quoted 4 lines · Furong Xu
Commit
66600fac7a98("net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data") assigns a wrong DMA buffer address that is added an offset ofproto_hdr_lento tx_q->tx_skbuff_dma[entry].buf on a certain platform that the DMA AXI address width is configured to 40-bit/48-bit,
In our case it is 40/40 ...
dwc-eth-dwmac 2490000.ethernet: Using 40/40 bits DMA host/device width
Quoted 41 lines
stmmac_tx_clean()will try to unmap this illegal DMA buffer address and many crashes are reported: [1] [2].This patch guarantees that DMA address is passed to
stmmac_tx_clean()unmodified and without offset.[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/klkzp5yn5kq5efgtrow6wbvnc46bcqfxs65nz3qy77ujr5turc@bwwhelz2l4dw/Reported-by Jon Hunter <[email protected]>Reported-by Thierry Reding <[email protected]>Suggested-by Russell King (Oracle) <[email protected]>Fixes 66600fac7a98 ("net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data")Signed-off-by Furong Xu <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2
-1@@ -4192,8 +4192,8 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)struct stmmac_txq_stats *txq_stats;struct stmmac_tx_queue *tx_q;u32 pay_len, mss, queue; +dma_addr_t tso_hdr, des;u8 proto_hdr_len, hdr; -dma_addr_t des;bool set_ic;int i;@@ -4279,6 +4279,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) DMA_TO_DEVICE);if (dma_mapping_error (priv->device, des)) goto dma_map_err; + tso_hdr = des;if (priv->dma_cap.addr64 <=32 ) { first->des0 =cpu_to_le32 (des);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) · line 4317
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1
-1@@ -4310,7 +4311,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)* this DMA buffer right after the DMA engine completely finishes the * full buffer transmission. */ - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; + tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = tso_hdr; tx_q->tx_skbuff_dma[tx_q->cur_tx].len =skb_headlen (skb); tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = false; tx_q->tx_skbuff_dma[tx_q->cur_tx].buf_type =STMMAC_TXBUF_T_SKB ;
Otherwise ...
Jon
Signature · 1 line
nvpublic
I'm slightly disappointed to have my patch turned into a commit under someone else's authorship before I've had a chance to do that myself. Next time I won't send a patch out until I've done that.
Quoted 6 lines · Furong Xu
Commit
66600fac7a98("net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data") assigns a wrong DMA buffer address that is added an offset ofproto_hdr_lento tx_q->tx_skbuff_dma[entry].buf on a certain platform that the DMA AXI address width is configured to 40-bit/48-bit,stmmac_tx_clean()will try to unmap this illegal DMA buffer address and many crashes are reported: [1] [2].
This should mention that the DMA mapping API requires the cookie that is returned from dma_map_single() be passed in unaltered to dma_unmap_single(), and this driver does not do that when the DMA address width is greater than 32-bit.
Quoted 10 lines
This patch guarantees that DMA address is passed to
stmmac_tx_clean()unmodified and without offset.[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/klkzp5yn5kq5efgtrow6wbvnc46bcqfxs65nz3qy77ujr5turc@bwwhelz2l4dw/Reported-by Jon Hunter <[email protected]>Reported-by Thierry Reding <[email protected]>Suggested-by Russell King (Oracle) <[email protected]>
Please use [email protected] there.
Quoted 41 lines
Fixes 66600fac7a98 ("net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data")Signed-off-by Furong Xu <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-2@@ -4192,8 +4192,8 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)struct stmmac_txq_stats *txq_stats;struct stmmac_tx_queue *tx_q;u32 pay_len, mss, queue; +dma_addr_t tso_hdr, des;u8 proto_hdr_len, hdr; -dma_addr_t des;bool set_ic;int i;@@ -4279,6 +4279,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) DMA_TO_DEVICE);if (dma_mapping_error (priv->device, des)) goto dma_map_err; + tso_hdr = des;if (priv->dma_cap.addr64 <=32 ) { first->des0 =cpu_to_le32 (des);@@ -4310,7 +4311,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)* this DMA buffer right after the DMA engine completely finishes the * full buffer transmission. */ - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; + tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = tso_hdr; tx_q->tx_skbuff_dma[tx_q->cur_tx].len =skb_headlen (skb); tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = false; tx_q->tx_skbuff_dma[tx_q->cur_tx].buf_type =STMMAC_TXBUF_T_SKB ;Signature · 1 line
2.34.1
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Jakub Kicinski
maintainerQuoted 3 lines · On Thu, 5 Dec 2024 16:43:22 +0000 Russell King (Oracle) wrote:
I'm slightly disappointed to have my patch turned into a commit under someone else's authorship before I've had a chance to do that myself. Next time I won't send a patch out until I've done that.
Yes, this is definitely not okay. LMK if you dropped this from your TODO already, otherwise I'm tossing this patch and expecting the fix from the real author.
Side rant - the Suggested-by tag is completely meaningless, maybe we should stop using it. The usage ranges from crediting people pointing out issues in basic code review, to crediting authors when stealing their code. What is the point.
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Thu, 5 Dec 2024 16:43:22 +0000 Russell King (Oracle) wrote:
I'm slightly disappointed to have my patch turned into a commit under someone else's authorship before I've had a chance to do that myself. Next time I won't send a patch out until I've done that.
Yes, this is definitely not okay. LMK if you dropped this from your TODO already, otherwise I'm tossing this patch and expecting the fix from the real author.
See https://lore.kernel.org/r/[email protected]/
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Hi Russell,
Quoted 4 lines · Russell King (Oracle)
I'm slightly disappointed to have my patch turned into a commit under someone else's authorship before I've had a chance to do that myself. Next time I won't send a patch out until I've done that.
I am really sorry for this, I should have requested your permission first.
Quoted 3 lines
Please use [email protected] there.
So another iteration is required here.
Would you mind me send the v2 of this fix?
I will not send v2 without your permission.
Thanks.