* [PATCH net] net: lan966x: return an error for XDP frames that are not queued
@ 2026-11-23 14:54 Daniel Machon
2026-11-27 9:06 ` Paolo Abeni
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Machon @ 2026-11-23 14:54 UTC (permalink / raw)
To: Horatiu Vultur, UNGLinuxDriver, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: netdev, bpf
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.
Fixes: a825b611c7c1 ("net: lan966x: Add support for XDP_REDIRECT")
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
index 1fbe910c5ec38..f1b6638d5668d 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
@@ -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,
--
Daniel Machon <daniel.machon@microchip.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: lan966x: return an error for XDP frames that are not queued
2026-11-23 14:54 [PATCH net] net: lan966x: return an error for XDP frames that are not queued Daniel Machon
@ 2026-11-27 9:06 ` Paolo Abeni
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Abeni @ 2026-11-27 9:06 UTC (permalink / raw)
To: Daniel Machon, Horatiu Vultur, UNGLinuxDriver, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: netdev, bpf
On 11/23/26 15:54, Daniel Machon wrote:
> 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.
>
> Fixes: a825b611c7c1 ("net: lan966x: Add support for XDP_REDIRECT")
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 9:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:54 [PATCH net] net: lan966x: return an error for XDP frames that are not queued Daniel Machon
2026-11-27 9:06 ` Paolo Abeni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox