net: lan966x: return an error for XDP frames that are not queued
Subsystems (4)
PATCH 1/1 net: lan966x: return an error for XDP frames that are not queued
lan966x_xdp_xmit() counts a frame as transmitted when lan966x_fdma_xmit_xdpf() returns 0, and its caller only returns the frames that were not counted.
Before this patch, lan966x_fdma_xmit_xdpf() returns NETDEV_TX_OK, which is 0, when an xdp_frame has less headroom than the IFH or when its DMA mapping fails, without queueing the frame. The frame is then counted as transmitted and never freed. An xdp_frame can have less headroom than the IFH when an XDP program grows the head of a frame with bpf_xdp_adjust_head() before redirecting it to a lan966x port.
Return -EINVAL and -ENOMEM in these cases, so that lan966x_xdp_xmit() stops and the frames that were not queued are returned to the caller.
Found by an AI code review agent. Reproduced on a lan9668 board with an XDP program that grows the head of each frame and redirects it to another lan966x port. With the fix the frames are returned to the caller.
--- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2 -2
@@ -636,7 +636,7 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len) xdpf = ptr;if (xdpf->headroom <IFH_LEN_BYTES ) { - ret =NETDEV_TX_OK ; + ret = -EINVAL ; goto out; }
@@ -650,7 +650,7 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len) xdpf->len +IFH_LEN_BYTES , DMA_TO_DEVICE);if (dma_mapping_error (lan966x->dma_dev, dma_addr)) { - ret =NETDEV_TX_OK ; + ret = -ENOMEM ; goto out; }
---
base-commit: af6737b9066832a2017c281159950ba92385ce00
change-id: 20261123-lan966x-xdp-xmit-errors-ed70befc70de
Best regards,
Signature · 1 line
Daniel Machon <[email protected]>
Paolo Abeni
maintainerQuoted 14 lines · Daniel Machon
lan966x_xdp_xmit()counts a frame as transmitted whenlan966x_fdma_xmit_xdpf()returns 0, and its caller only returns the frames that were not counted.Before this patch,
lan966x_fdma_xmit_xdpf()returnsNETDEV_TX_OK, which is 0, when anxdp_framehas less headroom than the IFH or when its DMA mapping fails, without queueing the frame. The frame is then counted as transmitted and never freed. Anxdp_framecan have less headroom than the IFH when an XDP program grows the head of a frame withbpf_xdp_adjust_head()before redirecting it to a lan966x port.Return
-EINVALand-ENOMEMin these cases, so thatlan966x_xdp_xmit()stops and the frames that were not queued are returned to the caller.
Quoted 7 lines
Found by an AI code review agent. Reproduced on a lan9668 board with an XDP program that grows the head of each frame and redirects it to another lan966x port. With the fix the frames are returned to the caller.
Fixes a825b611c7c1 ("net: lan966x: Add support for XDP_REDIRECT")Signed-off-by Daniel Machon <[email protected]>
It's not clear to me if the issue addressed here is stats miscount (should target net-next) or deterministic memory leak per packet.
Could you please clarify?
Thanks!
Paolo
Quoted 20 lines · Daniel Machon
Quoted 19 lines
lan966x_xdp_xmit()counts a frame as transmitted whenlan966x_fdma_xmit_xdpf()returns 0, and its caller only returns the frames that were not counted.Before this patch,
lan966x_fdma_xmit_xdpf()returnsNETDEV_TX_OK, which is 0, when anxdp_framehas less headroom than the IFH or when its DMA mapping fails, without queueing the frame. The frame is then counted as transmitted and never freed. Anxdp_framecan have less headroom than the IFH when an XDP program grows the head of a frame withbpf_xdp_adjust_head()before redirecting it to a lan966x port.Return
-EINVALand-ENOMEMin these cases, so thatlan966x_xdp_xmit()stops and the frames that were not queued are returned to the caller.Found by an AI code review agent. Reproduced on a lan9668 board with an XDP program that grows the head of each frame and redirects it to another lan966x port. With the fix the frames are returned to the caller.
Quoted 6 lines
Quoted 2 lines
Fixes a825b611c7c1 ("net: lan966x: Add support for XDP_REDIRECT")Signed-off-by Daniel Machon <[email protected]>It's not clear to me if the issue addressed here is stats miscount (should target net-next) or deterministic memory leak per packet.
Could you please clarify?
The commit message could have explain that better, sorry. It's the latter - per frame memory leak.
Quoted 5 lines
Thanks!
Paolo
/Daniel
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 4 lines · On Mon, 23 Nov 2026 15:54:36 +0100 you wrote:
lan966x_xdp_xmit()counts a frame as transmitted whenlan966x_fdma_xmit_xdpf()returns 0, and its caller only returns the frames that were not counted.
Quoted 8 lines
Before this patch,
lan966x_fdma_xmit_xdpf()returnsNETDEV_TX_OK, which is 0, when anxdp_framehas less headroom than the IFH or when its DMA mapping fails, without queueing the frame. The frame is then counted as transmitted and never freed. Anxdp_framecan have less headroom than the IFH when an XDP program grows the head of a frame withbpf_xdp_adjust_head()before redirecting it to a lan966x port.[...]
Here is the summary with links:
- [net] net: lan966x: return an error for XDP frames that are not queued
https://git.kernel.org/netdev/net/c/0651cae60e84
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html