Skip to contentSkip to conversation

net: stmmac: Apply new page pool parameters when SPH is enabled

PATCH Applied Furong Xu 5 participants 5 messages Feb 7, 2025 – Feb 11, 2025

Subsystems (5)
lore
Share & tools
lore

Furong Xu

author
#0 lore raw

PATCH 1/1 net: stmmac: Apply new page pool parameters when SPH is enabled

Commit df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path") makes DMA write received frame into buffer at offset of NET_SKB_PAD and sets page pool parameters to sync from offset of NET_SKB_PAD. But when Header Payload Split is enabled, the header is written at offset of NET_SKB_PAD, while the payload is written at offset of zero. Uncorrect offset parameter for the payload breaks dma coherence [1] since both CPU and DMA touch the page buffer from offset of zero which is not handled by the page pool sync parameter.

And in case the DMA cannot split the received frame, for example, a large L2 frame, pp_params.max_len should grow to match the tail of entire frame.

[1] https://lore.kernel.org/netdev/[email protected]/

Fixes df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -0
index b34ebb916b89..c0ae7db96f46 100644
@@ -2094,6 +2094,11 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
 	pp_params.offset = stmmac_rx_offset(priv);
 	pp_params.max_len = dma_conf->dma_buf_sz;
 
+	if (priv->sph) {
+		pp_params.offset = 0;
+		pp_params.max_len += stmmac_rx_offset(priv);
+	}
+
 	rx_q->page_pool = page_pool_create(&pp_params);
 	if (IS_ERR(rx_q->page_pool)) {
 		ret = PTR_ERR(rx_q->page_pool);
Signature · 1 line
2.34.1
maintainer Tested-by on v1 1/1
#1 lore raw

Hi Furong,

Quoted 30 lines · Furong Xu

Commit df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path") makes DMA write received frame into buffer at offset of NET_SKB_PAD and sets page pool parameters to sync from offset of NET_SKB_PAD. But when Header Payload Split is enabled, the header is written at offset of NET_SKB_PAD, while the payload is written at offset of zero. Uncorrect offset parameter for the payload breaks dma coherence [1] since both CPU and DMA touch the page buffer from offset of zero which is not handled by the page pool sync parameter.

And in case the DMA cannot split the received frame, for example, a large L2 frame, pp_params.max_len should grow to match the tail of entire frame.

[1] https://lore.kernel.org/netdev/[email protected]/

Fixes df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path")
---
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index b34ebb916b89..c0ae7db96f46 100644
@@ -2094,6 +2094,11 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
  	pp_params.offset = stmmac_rx_offset(priv);

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, · line 2104

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -0
  	pp_params.max_len = dma_conf->dma_buf_sz;
 
+	if (priv->sph) {
+		pp_params.offset = 0;
+		pp_params.max_len += stmmac_rx_offset(priv);
+	}
+
  	rx_q->page_pool = page_pool_create(&pp_params);
  	if (IS_ERR(rx_q->page_pool)) {
  		ret = PTR_ERR(rx_q->page_pool);

Thanks for sending this. I can confirm that it fixes the issue we are seeing and so ...

Cheers
Jon

Signature · 1 line
nvpublic
Tested-by
#2 lore raw
Quoted 47 lines · Jon Hunter

Hi Furong,

Quoted 29 lines · Furong Xu

Commit df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path") makes DMA write received frame into buffer at offset of NET_SKB_PAD and sets page pool parameters to sync from offset of NET_SKB_PAD. But when Header Payload Split is enabled, the header is written at offset of NET_SKB_PAD, while the payload is written at offset of zero. Uncorrect offset parameter for the payload breaks dma coherence [1] since both CPU and DMA touch the page buffer from offset of zero which is not handled by the page pool sync parameter.

And in case the DMA cannot split the received frame, for example, a large L2 frame, pp_params.max_len should grow to match the tail of entire frame.

[1] https://lore.kernel.org/netdev/[email protected]/

Fixes df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path")
---
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index b34ebb916b89..c0ae7db96f46 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, · line 2103

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -0
@@ -2094,6 +2094,11 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
  	pp_params.offset = stmmac_rx_offset(priv);
  	pp_params.max_len = dma_conf->dma_buf_sz;
+	if (priv->sph) {
+		pp_params.offset = 0;
+		pp_params.max_len += stmmac_rx_offset(priv);
+	}
+
  	rx_q->page_pool = page_pool_create(&pp_params);
  	if (IS_ERR(rx_q->page_pool)) {
  		ret = PTR_ERR(rx_q->page_pool);

Thanks for sending this. I can confirm that it fixes the issue we are seeing and so ...

Quoted 1 line

Yes, I can confirm as well. I've tested based on the discussion in the earlier thread and had the equivalent of this patch (modulo the ->sph check, but that's always true on this system), so:

Reviewed-by on v1 1/1
#3 lore raw
In reply to Furong Xu
Quoted 13 lines · Furong Xu

Commit df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path") makes DMA write received frame into buffer at offset of NET_SKB_PAD and sets page pool parameters to sync from offset of NET_SKB_PAD. But when Header Payload Split is enabled, the header is written at offset of NET_SKB_PAD, while the payload is written at offset of zero. Uncorrect offset parameter for the payload breaks dma coherence [1] since both CPU and DMA touch the page buffer from offset of zero which is not handled by the page pool sync parameter.

And in case the DMA cannot split the received frame, for example, a large L2 frame, pp_params.max_len should grow to match the tail of entire frame.

Quoted 7 lines

[1] https://lore.kernel.org/netdev/[email protected]/

Fixes df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path")
#4 lore raw
In reply to Furong Xu
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Fri, 7 Feb 2025 16:56:39 +0800 you wrote:

Commit df542f669307 ("net: stmmac: Switch to zero-copy in non-XDP RX path") makes DMA write received frame into buffer at offset of NET_SKB_PAD and sets page pool parameters to sync from offset of NET_SKB_PAD. But when Header Payload Split is enabled, the header is written at offset of NET_SKB_PAD, while the payload is written at offset of zero. Uncorrect offset parameter for the payload breaks dma coherence [1] since both CPU and DMA touch the page buffer from offset of zero which is not handled by the page pool sync parameter.

[...]

Here is the summary with links:
- [net,v1] net: stmmac: Apply new page pool parameters when SPH is enabled

    https://git.kernel.org/netdev/net/c/cb6cc8ed7717

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html