net: moxa: clear TX descriptor length bits
Subsystems (2)
PATCH v4 1/2 net: moxa: clear TX descriptor length bits
TX buffer length is not cleared on ndo_start_xmit(). Failing to do so can bug/hang the controller and cause TX interrupts to stop altogether.
Add TX_DESC1_BUF_SIZE_MASK to bits that are cleared, before the TX buffer length is set.
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69031
---
Notes:
Changes since v3:
1. commit message reworded
Applies to next-20140818
drivers/net/ethernet/moxa/moxart_ether.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/moxa/moxart_ether.c +2 -1
@@ -348,7 +348,8 @@ static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) txdes1 =readl (desc +TX_REG_OFFSET_DESC1 ); txdes1 |=TX_DESC1_LTS |TX_DESC1_FTS ; - txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE ); + txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE | +TX_DESC1_BUF_SIZE_MASK ); txdes1 |= (len &TX_DESC1_BUF_SIZE_MASK );writel (txdes1, desc +TX_REG_OFFSET_DESC1 );writel (TX_DESC0_DMA_OWN , desc +TX_REG_OFFSET_DESC0 );
Signature · 1 line
1.8.2.1
PATCH v4 2/2 net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
build_skb() is used to make skbs out of existing RX ring memory which is bad because the RX ring is allocated only once, on probe. Memory corruption occur because said memory is reclaimed, i.e. __kfree_skb() (and eventually put_page()).
Replace build_skb() with netdev_alloc_skb_ip_align() and use memcpy(). Also, synchronize DMA memory before passing skb to napi_gro_receive().
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69041
---
Notes:
The original motivation was to avoid memcpy(), since the memory is already allocated, why make a copy.
Maybe the copy can be avoided updating RX ring descriptor addresses; new memory must be allocated just the same, the only difference that the controller could write directly to it.
This fixes errors due to memory corruption, such as the following, seen on wget download (or ncftp):
"read error: Bad address"
On receiving error, wget exits without resuming (busybox default).
Changes since v3:
1. commit message reworded
Applies to next-20140818
drivers/net/ethernet/moxa/moxart_ether.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +10 -3
@@ -226,14 +226,21 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget)if (len >RX_BUF_SIZE ) len =RX_BUF_SIZE ; - skb =build_skb (priv->rx_buf[rx_head], priv->rx_buf_size); +dma_sync_single_for_cpu (&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size,DMA_FROM_DEVICE ); + skb =netdev_alloc_skb_ip_align (ndev, len);if (unlikely (!skb)) { -net_dbg_ratelimited ("build_skb failed\n" ); +net_dbg_ratelimited ("netdev_alloc_skb_ip_align failed\n" ); priv->stats.rx_dropped++; priv->stats.rx_errors++; } - +memcpy (skb->data, priv->rx_buf[rx_head], len);skb_put (skb, len); +dma_sync_single_for_device (&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size,DMA_FROM_DEVICE ); + skb->protocol =eth_type_trans (skb, ndev);napi_gro_receive (&priv->napi, skb); rx++;
Signature · 1 line
1.8.2.1
Re: [PATCH v4 2/2] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
Quoted 9 lines · Jonas Jensen
build_skb()is used to make skbs out of existing RX ring memory which is bad because the RX ring is allocated only once, on probe. Memory corruption occur because said memory is reclaimed, i.e.__kfree_skb()(and eventuallyput_page()).Replace
build_skb()withnetdev_alloc_skb_ip_align()and usememcpy(). Also, synchronize DMA memory before passing skb tonapi_gro_receive().
Wow, this driver was really buggy.
Patch is not complete.
Instead of :
priv->rx_buf_size = RX_BUF_SIZE +
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
I think rx_buf_size can now be RX_BUF_SIZE
Another point is that priv->stats seems not needed, as ndev->stats could be used instead (and remove moxart_mac_get_stats())
PATCH v5 1/2 net: moxa: clear TX descriptor length bits
In reply to Jonas JensenTX buffer length is not cleared on ndo_start_xmit(). Failing to do so can bug/hang the controller and cause TX interrupts to stop altogether.
Add TX_DESC1_BUF_SIZE_MASK to bits that are cleared, before the TX buffer length is set.
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69031
---
Notes:
No changes since v4.
Applies to next-20140820
drivers/net/ethernet/moxa/moxart_ether.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/moxa/moxart_ether.c +2 -1
@@ -348,7 +348,8 @@ static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) txdes1 =readl (desc +TX_REG_OFFSET_DESC1 ); txdes1 |=TX_DESC1_LTS |TX_DESC1_FTS ; - txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE ); + txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE | +TX_DESC1_BUF_SIZE_MASK ); txdes1 |= (len &TX_DESC1_BUF_SIZE_MASK );writel (txdes1, desc +TX_REG_OFFSET_DESC1 );writel (TX_DESC0_DMA_OWN , desc +TX_REG_OFFSET_DESC0 );
Signature · 1 line
1.8.2.1
PATCH v5 2/2 net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Jonas Jensenbuild_skb() is used to make skbs out of existing RX ring memory which is bad because the RX ring is allocated only once, on probe. Memory corruption occur because said memory is reclaimed, i.e. __kfree_skb() (and eventually put_page()).
Replace build_skb() with netdev_alloc_skb_ip_align(), use memcpy(), and synchronize DMA memory before passing skb to napi_gro_receive().
Remove SKB_DATA_ALIGN() from RX buffer size while we're at it.
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69041
---
Notes:
Changes since v4:
1. remove SKB_DATA_ALIGN() from RX buffer size
Applies to next-20140820
drivers/net/ethernet/moxa/moxart_ether.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +11 -5
@@ -226,14 +226,21 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget)if (len >RX_BUF_SIZE ) len =RX_BUF_SIZE ; - skb =build_skb (priv->rx_buf[rx_head], priv->rx_buf_size); +dma_sync_single_for_cpu (&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size,DMA_FROM_DEVICE ); + skb =netdev_alloc_skb_ip_align (ndev, len);if (unlikely (!skb)) { -net_dbg_ratelimited ("build_skb failed\n" ); +net_dbg_ratelimited ("netdev_alloc_skb_ip_align failed\n" ); priv->stats.rx_dropped++; priv->stats.rx_errors++; } - +memcpy (skb->data, priv->rx_buf[rx_head], len);skb_put (skb, len); +dma_sync_single_for_device (&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size,DMA_FROM_DEVICE ); + skb->protocol =eth_type_trans (skb, ndev);napi_gro_receive (&priv->napi, skb); rx++;
@@ -466,8 +473,7 @@ static int moxart_mac_probe(struct platform_device *pdev)spin_lock_init (&priv->txlock); priv->tx_buf_size =TX_BUF_SIZE ; - priv->rx_buf_size =RX_BUF_SIZE + -SKB_DATA_ALIGN (sizeof (struct skb_shared_info )); + priv->rx_buf_size =RX_BUF_SIZE ; priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE * TX_DESC_NUM, &priv->tx_base,
Signature · 1 line
1.8.2.1
Re: [PATCH v4 2/2] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Eric DumazetQuoted 6 lines · Eric Dumazet
Instead of :
priv->rx_buf_size=RX_BUF_SIZE+SKB_DATA_ALIGN(sizeof(struct skb_shared_info));I think
rx_buf_sizecan now beRX_BUF_SIZE
You're right, that's now a remnant, see update in v5.
Quoted 2 lines
Another point is that
priv->statsseems not needed, asndev->statscould be used instead (and removemoxart_mac_get_stats())
I will fix that. I can add it to patches adding support for ethtool / stats and PHY.
I think I'm supposed to post those closer to the merge window, which would keep this set about bug fixes only.
Regards,
Jonas
Quoted 10 lines · Jonas Jensen
TX buffer length is not cleared on
ndo_start_xmit(). Failing to do so can bug/hang the controller and cause TX interrupts to stop altogether.drivers/net/ethernet/moxa/moxart_ether.c +0
-0
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) · line 355
Quoted 9 lines
drivers/net/ethernet/moxa/moxart_ether.c +2
-1@@ -348,7 +348,8 @@ static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) txdes1 =readl (desc +TX_REG_OFFSET_DESC1 ); txdes1 |=TX_DESC1_LTS |TX_DESC1_FTS ; - txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE ); + txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE | +TX_DESC1_BUF_SIZE_MASK ); txdes1 |= (len &TX_DESC1_BUF_SIZE_MASK );writel (txdes1, desc +TX_REG_OFFSET_DESC1 );writel (TX_DESC0_DMA_OWN , desc +TX_REG_OFFSET_DESC0 );
Wouldnt it be faster to not use readl() at all here ?
readl() is only used to get TX_DESC1_END bit.
It seems you could replace the thing by :
txdes1 = TX_DESC1_LTS | TX_DESC1_FTS | (len & TX_DESC1_BUF_SIZE_MASK); if (tx_head == TX_DESC_NUM_MASK)
txdes1 |= TX_DESC1_END;
Re: [PATCH v4 2/2] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Jonas Jensen2014-08-19 16:49 GMT+02:00 Jonas Jensen <[email protected]>:
[...]
Quoted 11 lines
drivers/net/ethernet/moxa/moxart_ether.c +2
-1@@ -226,14 +226,21 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget)if (len >RX_BUF_SIZE ) len =RX_BUF_SIZE ; - skb =build_skb (priv->rx_buf[rx_head], priv->rx_buf_size); + dma_sync_single_for_cpu(&ndev->dev, + priv->rx_mapping[rx_head],
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_rx_poll(struct napi_struct *napi, int budget) · line 238
Quoted 10 lines
drivers/net/ethernet/moxa/moxart_ether.c +4
-2+ priv->rx_buf_size, DMA_FROM_DEVICE); + skb =netdev_alloc_skb_ip_align (ndev, len);if (unlikely (!skb)) { -net_dbg_ratelimited ("build_skb failed\n" ); +net_dbg_ratelimited ("netdev_alloc_skb_ip_align failed\n" ); priv->stats.rx_dropped++; priv->stats.rx_errors++; } - +memcpy (skb->data, priv->rx_buf[rx_head], len);
This has implicit: if (!skb) BUG(); There should probably be a return or continue inside the if (!skb).
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_rx_poll(struct napi_struct *napi, int budget) · line 243
Quoted 5 lines
drivers/net/ethernet/moxa/moxart_ether.c +4
-0skb_put (skb, len); +dma_sync_single_for_device (&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size,DMA_FROM_DEVICE ); +
dma_sync_single_for_device() is not needed here as CPU does not and should not write to the DMA_FROM_DEVICE mapping.
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_rx_poll(struct napi_struct *napi, int budget) · line 246
Quoted 3 lines
drivers/net/ethernet/moxa/moxart_ether.c +0
-0skb->protocol =eth_type_trans (skb, ndev);napi_gro_receive (&priv->napi, skb); rx++;
Best Regards,
Micha? Miros?aw
David Miller
maintainerFrom: Jonas Jensen <[email protected]>
Date: Wed, 20 Aug 2014 16:18:42 +0200
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) · line 355
Quoted 10 lines
drivers/net/ethernet/moxa/moxart_ether.c +2
-1@@ -348,7 +348,8 @@ static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) txdes1 =readl (desc +TX_REG_OFFSET_DESC1 ); txdes1 |=TX_DESC1_LTS |TX_DESC1_FTS ; - txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE ); + txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE | +TX_DESC1_BUF_SIZE_MASK ); txdes1 |= (len &TX_DESC1_BUF_SIZE_MASK );writel (txdes1, desc +TX_REG_OFFSET_DESC1 );writel (TX_DESC0_DMA_OWN , desc +TX_REG_OFFSET_DESC0 );
Like others I wonder why the existing descriptor value is being read at all.
It's inefficient and completely unnecessary, you can just compute a new value from scratch, and that way all of these "uncleared field" issues just automatically disappear.
PATCH v6 1/4 net: moxa: clear DESC1 on ndo_start_xmit()
In reply to Jonas JensenTX buffer length is not cleared on ndo_start_xmit(). Failing to do so can bug/hang the controller and cause TX interrupts to stop altogether.
Remove the readl() and compute a new value for DESC1.
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69031
---
Notes:
Changes since v5:
1. remove readl(desc + TX_REG_OFFSET_DESC1) in moxart_mac_start_xmit()
2. compute entirely new values for DESC1
3. set TX_DESC1_END if (tx_head == TX_DESC_NUM_MASK)
Applies to next-20140825
drivers/net/ethernet/moxa/moxart_ether.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +3 -4
@@ -346,10 +346,9 @@ static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) len =ETH_ZLEN ; } - txdes1 =readl (desc +TX_REG_OFFSET_DESC1 ); - txdes1 |=TX_DESC1_LTS |TX_DESC1_FTS ; - txdes1 &= ~(TX_DESC1_FIFO_COMPLETE |TX_DESC1_INTR_COMPLETE ); - txdes1 |= (len &TX_DESC1_BUF_SIZE_MASK ); + txdes1 =TX_DESC1_LTS |TX_DESC1_FTS | (len &TX_DESC1_BUF_SIZE_MASK ); +if (tx_head ==TX_DESC_NUM_MASK ) + txdes1 |=TX_DESC1_END ;writel (txdes1, desc +TX_REG_OFFSET_DESC1 );writel (TX_DESC0_DMA_OWN , desc +TX_REG_OFFSET_DESC0 );
Signature · 1 line
1.8.2.1
PATCH v6 2/4 net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Jonas Jensenbuild_skb() is used to make skbs out of existing RX ring memory which is bad because the RX ring is allocated only once, on probe. Memory corruption occur because said memory is reclaimed, i.e. __kfree_skb() (and eventually put_page()).
Replace build_skb() with netdev_alloc_skb_ip_align() and use memcpy().
Remove SKB_DATA_ALIGN() from RX buffer size while we're at it.
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69041
---
Notes:
Changes since v5:
1. broke out DMA synchronization to separate patch
Applies to next-20140825
drivers/net/ethernet/moxa/moxart_ether.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +5 -4
@@ -226,13 +226,15 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget)if (len >RX_BUF_SIZE ) len =RX_BUF_SIZE ; - skb =build_skb (priv->rx_buf[rx_head], priv->rx_buf_size); + skb =netdev_alloc_skb_ip_align (ndev, len); +if (unlikely (!skb)) { -net_dbg_ratelimited ("build_skb failed\n" ); +net_dbg_ratelimited ("netdev_alloc_skb_ip_align failed\n" ); priv->stats.rx_dropped++; priv->stats.rx_errors++; } +memcpy (skb->data, priv->rx_buf[rx_head], len);skb_put (skb, len); skb->protocol =eth_type_trans (skb, ndev);napi_gro_receive (&priv->napi, skb);
@@ -464,8 +466,7 @@ static int moxart_mac_probe(struct platform_device *pdev)spin_lock_init (&priv->txlock); priv->tx_buf_size =TX_BUF_SIZE ; - priv->rx_buf_size =RX_BUF_SIZE + -SKB_DATA_ALIGN (sizeof (struct skb_shared_info )); + priv->rx_buf_size =RX_BUF_SIZE ; priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE * TX_DESC_NUM, &priv->tx_base,
Signature · 1 line
1.8.2.1
Re: [PATCH v4 2/2] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Michał MirosławThanks for giving feedback.
Quoted 2 lines · Micha? Miros?aw
This has implicit: if (!skb)
BUG(); There should probably be a return or continue inside the if (!skb).
Fixed, see v6 update (broken out to separate patch) which now includes increment to RX head counter
Quoted 2 lines
dma_sync_single_for_device()is not needed here as CPU does not and should not write to theDMA_FROM_DEVICEmapping.
Fixed, this was also broken out, dma_sync_single_for_device() moved to TX path. Maybe someone can verify this is the correct thing to do.
Regards,
Jonas
Thanks for giving feedback.
Quoted 1 line · Eric Dumazet
Wouldnt it be faster to not use
readl()at all here ?
Quoted 2 lines · David Miller
Like others I wonder why the existing descriptor value is being read at all.
It makes sense and I have verified, transfers continue to work clearing the whole thing, see update in v6.
Regards,
Jonas
Re: [PATCH v6 1/4] net: moxa: clear DESC1 on ndo_start_xmit()
In reply to Jonas JensenFrom: Jonas Jensen <[email protected]>
Date: Mon, 25 Aug 2014 16:22:11 +0200
Quoted 9 lines
TX buffer length is not cleared on
ndo_start_xmit(). Failing to do so can bug/hang the controller and cause TX interrupts to stop altogether.Remove the
readl()and compute a new value for DESC1.Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69031
Signed-off-by Jonas Jensen <[email protected]>
Applied.
Re: [PATCH v6 2/4] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Jonas JensenFrom: Jonas Jensen <[email protected]>
Date: Mon, 25 Aug 2014 16:22:22 +0200
Quoted 5 lines
build_skb()is used to make skbs out of existing RX ring memory which is bad because the RX ring is allocated only once, on probe. Memory corruption occur because said memory is reclaimed, i.e.__kfree_skb()(and eventuallyput_page()).
Quoted 7 lines
Replace
build_skb()withnetdev_alloc_skb_ip_align()and usememcpy().Remove
SKB_DATA_ALIGN()from RX buffer size while we're at it.Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69041
Signed-off-by Jonas Jensen <[email protected]>
Applied.
Re: [PATCH v6 2/4] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
In reply to Jonas JensenQuoted 8 lines · On Monday 25 August 2014 16:22:22 Jonas Jensen wrote:
drivers/net/ethernet/moxa/moxart_ether.c +2
-1@@ -226,13 +226,15 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget)if (len >RX_BUF_SIZE ) len =RX_BUF_SIZE ; - skb =build_skb (priv->rx_buf[rx_head], priv->rx_buf_size); + skb =netdev_alloc_skb_ip_align (ndev, len); +if (unlikely (!skb)) {
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_rx_poll(struct napi_struct *napi, int budget) · line 240
Quoted 10 lines
drivers/net/ethernet/moxa/moxart_ether.c +2
-1-net_dbg_ratelimited ("build_skb failed\n" ); +net_dbg_ratelimited ("netdev_alloc_skb_ip_align failed\n" ); priv->stats.rx_dropped++; priv->stats.rx_errors++; } +memcpy (skb->data, priv->rx_buf[rx_head], len);skb_put (skb, len); skb->protocol =eth_type_trans (skb, ndev);napi_gro_receive (&priv->napi, skb);
While this seems correct, I wonder why you don't do the normal approach of dequeuing the skb from the chain and adding a newly allocated skb to it to save the memcpy.
Arnd
RE: [PATCH v6 2/4] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
From: Arnd Bergmann
Quoted 15 lines · On Monday 25 August 2014 16:22:22 Jonas Jensen wrote:
Quoted 14 lines
drivers/net/ethernet/moxa/moxart_ether.c +3
-2@@ -226,13 +226,15 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget)if (len >RX_BUF_SIZE ) len =RX_BUF_SIZE ; - skb =build_skb (priv->rx_buf[rx_head], priv->rx_buf_size); + skb =netdev_alloc_skb_ip_align (ndev, len); +if (unlikely (!skb)) { -net_dbg_ratelimited ("build_skb failed\n" ); +net_dbg_ratelimited ("netdev_alloc_skb_ip_align failed\n" ); priv->stats.rx_dropped++; priv->stats.rx_errors++; }
Quoted 1 line
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_rx_poll(struct napi_struct *napi, int budget) · line 237
Quoted 1 line
drivers/net/ethernet/moxa/moxart_ether.c +1
-0+memcpy (skb->data, priv->rx_buf[rx_head], len);
Is this memcpy() aligned?
If the hardware can receive to a 4n+2 offset it is probably better to copy the two bytes before the frame data and to round the length of to a whole number of words.
Quoted 7 lines
drivers/net/ethernet/moxa/moxart_ether.c static int moxart_rx_poll(struct napi_struct *napi, int budget) · line 240
Quoted 3 lines
drivers/net/ethernet/moxa/moxart_ether.c +0
-0skb_put (skb, len); skb->protocol =eth_type_trans (skb, ndev);napi_gro_receive (&priv->napi, skb);While this seems correct, I wonder why you don't do the normal approach of dequeuing the skb from the chain and adding a newly allocated skb to it to save the memcpy.
Because the receive buffer area isn't made of skbs. Post-allocating the skb also reduces the 'true size' of the skb.
David
RE: [PATCH v6 2/4] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy()
Quoted 8 lines · David Laight
From: Arnd Bergmann
Quoted 3 lines
While this seems correct, I wonder why you don't do the normal approach of dequeuing the skb from the chain and adding a newly allocated skb to it to save the memcpy.
Because the receive buffer area isn't made of skbs. Post-allocating the skb also reduces the 'true size' of the skb.
This strategy assumes this is not a 10Gbe NIC.
We try to avoid copies because they are generally not needed.
Wifi devices are usually slow, and packet losses are more frequent, so the copybreak gives better chance to not doing the collapses [1] later in the TCP stack.
[1] collapses : reducing skb overhead (skb->len / skb->truesize ratio)