[PATCH net-next v13 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff

netdev-bot+sashiko at kernel.org netdev-bot+sashiko at kernel.org
Thu Nov 26 06:50:28 PST 2026


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In stmmac_rx()
  (drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:6056), the FCS is…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
  extends it.

--

net: stmmac: rework stmmac_rx to support XDP rx multi-buff

This reworks stmmac_rx() to collect all the descriptors of a frame in an
xdp_buff. XDP programs loaded with BPF_F_XDP_HAS_FRAGS now see the whole
fragmented packet, and the skb is built with xdp_build_skb_from_buff().
The in-progress xdp_buff is saved in rx_q->state across NAPI polls, and
the FCS is stripped with xdp_buff_shrink_tail().

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 7896364c43e95..56355d80ba161 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

[ ... ]

> @@ -5999,120 +6014,79 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)

[ ... ]

> +		n_descs++;
>  
> -drain_data:
>  		if (likely(status & rx_not_ls))
>  			goto read_again;
> -		if (!skb)
> -			goto next;
>  
> -		/* Got entire packet into SKB. Finish it. */
> +		/* ACS is disabled; strip manually. */
> +		len -= ETH_FCS_LEN;
> +		if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) {
> +			if (!error)
> +				rx_dropped++;
> +			error = 1;
> +		}

[Severity: Low]
Is skb->truesize overstated when a frame spans several buffers and the
last buffer holds only FCS bytes (1 to 4 bytes)?

For a fragmented xdp_buff, xdp_buff_shrink_tail() calls
xdp_frags_shrink_tail(). That function returns the FCS-only page to the
pool through xdp_buff_shrink_data(), but it only adjusts nr_frags and
xdp_frags_size:

net/core/xdp.c:xdp_frags_shrink_tail() {
    ...
	sinfo->nr_frags -= n_frags_free;
	sinfo->xdp_frags_size -= len_free;
    ...
}

sinfo->xdp_frags_truesize still counts the xdp->frame_sz that
stmmac_build_xdp_frags() charged for that page through
xdp_buff_add_frag(). If at least one fragment is left,
xdp_build_skb_from_buff() uses that value unchanged:

net/core/xdp.c:xdp_build_skb_from_buff() {
    ...
		tsize = sinfo->xdp_frags_truesize ? : nr_frags * xdp->frame_sz;
    ...
}

As a result, skb->truesize includes a full page_pool allocation
(PAGE_SIZE << order) for a page that has already been released.

In the common case the old code fixed this up. pskb_trim(), removed
below, went through ___pskb_trim()->skb_condense() (skb->sk is NULL on
RX), which pulled small leftover frags into the head and recomputed
truesize.

The commit message says the new truesize "is more accurate". Does that
hold for this case?

>  
> -		/* Remove FCS if needed */
> -		if (!fcs_stripped && pskb_trim(skb, len)) {
> -			dev_kfree_skb_any(skb);
> -			rx_dropped++;
> +		if (unlikely(error))
> +			goto error_free_frag;
> +
> +		ctx.desc = p;
> +		ctx.ndesc = np;
> +
> +		skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
> +		/* For Not XDP_PASS verdict */
> +		if (IS_ERR(skb)) {
> +			unsigned int xdp_res = -PTR_ERR(skb);
> +
> +			if (xdp_res & STMMAC_XDP_CONSUMED) {
> +				__xdp_return_buff(&ctx.xdp, true);
> +				rx_dropped++;
> +			} else if (xdp_res & (STMMAC_XDP_TX |
> +					      STMMAC_XDP_REDIRECT)) {
> +				xdp_status |= xdp_res;
> +			}
>  			goto next;
>  		}

[Severity: High]
This issue was not introduced by this patch, but the patch makes it
wider. With the stmmac_xdp_run_prog() change, programs with
xdp_has_frags can now return XDP_TX on fragmented buffs. Is the direct
recycling done when the TX completes safe here?

stmmac_tx_clean() returns XDP_TX frames like this:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_tx_clean() {
    ...
		if (xdpf &&
		    tx_q->tx_skbuff_dma[entry].buf_type == STMMAC_TXBUF_T_XDP_TX) {
			xdp_return_frame_rx_napi(xdpf);
    ...
}

xdp_return_frame_rx_napi() calls __xdp_return() with napi_direct set to
true. That path ends in page_pool_recycle_in_cache(), which writes
pool->alloc.cache[pool->alloc.count++] with no locking.

stmmac_tx_clean() runs from stmmac_napi_poll_tx() on ch->tx_napi. That
is not the ch->rx_napi which owns and refills rx_q->page_pool.

stmmac_xdp_xmit_back() also picks the TX queue by CPU through
stmmac_xdp_get_tx_queue(priv, smp_processor_id()). The completion can
therefore run on a different channel's tx_napi.

The pool is created without pp_params.napi, so page_pool has no way to
detect the foreign context.

Some setups put the two NAPI contexts on different CPUs:

  - MSI with independent rx/tx IRQ affinity, for example 4 RX and 2 TX
    queues on 4 CPUs
  - irqbalance
  - threaded NAPI
  - busy polling

In those setups rx_napi can pop from pool->alloc.cache while tx_napi
pushes into it from another CPU. With this patch, rx_napi uses that
cache more, through __xdp_return_buff(&ctx.xdp, true) and
page_pool_put_full_page(..., true).

Could the racing alloc.count updates lose a page, so that the pool never
drains? Could they also hand the same page out twice, so that two RX
descriptors DMA into it, or a page is DMA-written while the stack still
owns it?

This race already exists for head pages. With fragmented XDP_TX,
xdp_return_frame_rx_napi() now also direct-recycles every fragment page
from that context.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-stmmac-rx-mb-v13-0-0f6bac53e8d5%40oss.qualcomm.com



More information about the linux-arm-kernel mailing list