* [PATCH 5.10.y v2] net: mvpp2: refill RX buffers before XDP or skb use
@ 2026-11-26 6:02 Dickson Wu via B4 Relay
2026-11-27 17:01 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-26 6:02 UTC (permalink / raw)
To: stable; +Cc: Til Kaiser, Paolo Abeni, netdev
From: Til Kaiser <mail@tk154.de>
commit 5e8e2a9624df72fca7c736b2966b2cbf6c9c3ff6 upstream.
The RX error path returns the current descriptor buffer to the hardware
BM pool. That is only valid while the driver still owns the buffer.
mvpp2_rx_refill() can fail after the current buffer has been handed to
XDP or attached to an skb. In those cases mvpp2_run_xdp() may have
recycled, redirected, or queued the page for XDP_TX, and an skb free also
retires the data buffer. Returning such a buffer to BM lets hardware DMA
into memory that is no longer owned by the RX ring.
Refill the BM pool before handing the current buffer to XDP or to the
skb. If the allocation fails there, drop the packet and return the
still-owned current buffer to BM, preserving the pool depth. Once the
refill succeeds, later local drops retire/free the current buffer instead
of returning it to BM.
Fixes: 07dd0a7aae7f ("mvpp2: add basic XDP support")
Fixes: d6526926de73 ("net: mvpp2: fix memory leak in mvpp2_rx")
Signed-off-by: Til Kaiser <mail@tk154.de>
Link: https://patch.msgid.link/20260607134943.21996-4-mail@tk154.de
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
[ adapted to 5.10: page_pool_release_page() in place of skb_mark_for_recycle() ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
.../net/ethernet/marvell/mvpp2/mvpp2_main.c | 43 +++++++++++--------
1 file changed, 24 insertions(+), 19 deletions(-)
Changes in v2
v2: resent through a whitespace-safe path; v1 <CAFaZ9eob6Kg4WDo_m203vhom-XtsNN1kFUKgyUs3DcCTev5msQ@mail.gmail.com> was damaged by my mail client and does not apply.
The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
5.15.y and newer already have this. 5.10 has no skb_mark_for_recycle();
mvpp2_rx() there hands the page over with page_pool_release_page()
instead, so that call moves up to right after build_skb() succeeds,
where the 5.15.y backport has skb_mark_for_recycle(). Everything else
matches 5.15.y.
It goes with f3c6aa078927 ("net: mvpp2: limit XDP frame size to the RX
buffer") that I sent for 5.10.y earlier. The two don't depend on each
other.
Tested on v5.10.275:
- x86_64 allmodconfig (CONFIG_MVPP2=m) W=1 build of mvpp2_main.o, base
vs patched, no new warnings
- x86_64 defconfig with CONFIG_MVPP2=y builds and boots under QEMU/KVM
- I don't have mvpp2 hardware, so the RX refill path itself is untested
here.
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 3e60d40b3f6f..5915a8cdeddd 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -3613,6 +3613,12 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
else
frag_size = bm_pool->frag_size;
+ err = mvpp2_rx_refill(port, bm_pool, pp, pool);
+ if (err) {
+ netdev_err(port->dev, "failed to refill BM pools\n");
+ goto err_drop_frame;
+ }
+
if (xdp_prog) {
xdp.data_hard_start = data;
xdp.data = data + MVPP2_MH_SIZE + MVPP2_SKB_HEADROOM;
@@ -3630,12 +3636,6 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
if (ret) {
xdp_ret |= ret;
- err = mvpp2_rx_refill(port, bm_pool, pp, pool);
- if (err) {
- netdev_err(port->dev, "failed to refill BM pools\n");
- goto err_drop_frame;
- }
-
ps.rx_packets++;
ps.rx_bytes += rx_bytes;
continue;
@@ -3645,8 +3645,21 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
skb = build_skb(data, frag_size);
if (!skb) {
netdev_warn(port->dev, "skb build failed\n");
- goto err_drop_frame;
+ if (pp) {
+ page_pool_put_page(pp, virt_to_head_page(data),
+ rx_bytes + MVPP2_MH_SIZE,
+ true);
+ } else {
+ dma_unmap_single_attrs(dev->dev.parent, dma_addr,
+ bm_pool->buf_size,
+ DMA_FROM_DEVICE,
+ DMA_ATTR_SKIP_CPU_SYNC);
+ mvpp2_frag_free(bm_pool, pp, data);
+ }
+ goto err_drop_frame_retired;
}
+ if (pp)
+ page_pool_release_page(pp, virt_to_page(data));
/* If we have RX hardware timestamping enabled, grab the
* timestamp from the queue and convert.
@@ -3657,16 +3670,7 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
skb_hwtstamps(skb));
}
- err = mvpp2_rx_refill(port, bm_pool, pp, pool);
- if (err) {
- netdev_err(port->dev, "failed to refill BM pools\n");
- dev_kfree_skb_any(skb);
- goto err_drop_frame;
- }
-
- if (pp)
- page_pool_release_page(pp, virt_to_page(data));
- else
+ if (!pp)
dma_unmap_single_attrs(dev->dev.parent, dma_addr,
bm_pool->buf_size, DMA_FROM_DEVICE,
DMA_ATTR_SKIP_CPU_SYNC);
@@ -3683,13 +3687,14 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
continue;
err_drop_frame:
- dev->stats.rx_errors++;
- mvpp2_rx_error(port, rx_desc);
/* Return the buffer to the pool */
if (rx_status & MVPP2_RXD_BUF_HDR)
mvpp2_buff_hdr_pool_put(port, rx_desc, pool, rx_status);
else
mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr);
+err_drop_frame_retired:
+ dev->stats.rx_errors++;
+ mvpp2_rx_error(port, rx_desc);
}
rcu_read_unlock();
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 5.10.y v2] net: mvpp2: refill RX buffers before XDP or skb use
2026-11-26 6:02 [PATCH 5.10.y v2] net: mvpp2: refill RX buffers before XDP or skb use Dickson Wu via B4 Relay
@ 2026-11-27 17:01 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-11-27 17:01 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Til Kaiser, Paolo Abeni, netdev,
Dickson Wu via B4 Relay, Dickson Wu
> Refill the BM pool before handing the current buffer to XDP or to the
> skb. If the allocation fails there, drop the packet and return the
> still-owned current buffer to BM, preserving the pool depth.
Queued for 5.10, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 17:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 6:02 [PATCH 5.10.y v2] net: mvpp2: refill RX buffers before XDP or skb use Dickson Wu via B4 Relay
2026-11-27 17:01 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox