BPF List
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff
Date: Sat, 5 Dec 2026 20:11:36 +0100	[thread overview]
Message-ID: <axRh6CuU7xg-aXnr@lore-desk> (raw)
In-Reply-To: <sashiko-outbox-251407@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 5325 bytes --]

On Dec 05, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Low] net: stmmac: stmmac_rx() copies uninitialized ctx.xdp to
>   state.xdp
> - [Low] net: stmmac: stale xdp_frags_truesize after
>   xdp_buff_shrink_tail()
> --
> 
> commit 60febdab2a5f659e2de10ff9559c6cfd968ef63a
> Author: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
> 
> net: stmmac: rework stmmac_rx to support XDP rx multi-buff
> 
> This commit reworks stmmac_rx() to accumulate multi-descriptor and
> second-buffer frames into an xdp_buff before running the XDP program and
> building the skb with xdp_build_skb_from_buff().  It also stores the
> in-progress xdp_buff in rx_q->state across NAPI poll boundaries.
> 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index c429cb9e1ccbe..0edc92d5fb306 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> 
> [ ... ]
> 
> > @@ -5879,6 +5883,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
> >  	return failure ? limit : (int)count;
> >  }
> >  
> > +static bool stmmac_build_xdp_frags(struct stmmac_priv *priv,
> > +				   struct stmmac_rx_queue *rx_q,
> > +				   unsigned int len, struct page *page,
> > +				   unsigned int offset,
> > +				   enum dma_data_direction dma_dir,
> > +				   struct xdp_buff *xdp)
> > +{
> > +	dma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;
> > +
> > +	dma_sync_single_for_cpu(priv->device, dma_addr, len, dma_dir);
> > +	if (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,
> > +			       xdp->frame_sz)) {
> > +		page_pool_put_full_page(rx_q->page_pool, page, true);
> > +		return false;
> > +	}
> > +
> > +	return true;
> > +}
> 
> [Severity: Low]
> Can passing xdp->frame_sz to xdp_buff_add_frag() leave skb->truesize
> overstated after FCS stripping?
> 
> xdp_buff_add_frag() accumulates xdp->frame_sz into sinfo->xdp_frags_truesize
> for every attached fragment.  When a frame with two or more fragments has 1
> to 4 trailing FCS bytes in its final fragment, stmmac_rx() calls
> xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN) -> xdp_frags_shrink_tail(),
> which frees that fragment and updates sinfo->nr_frags and
> sinfo->xdp_frags_size, but leaves sinfo->xdp_frags_truesize unchanged.
> 
> xdp_build_skb_from_buff() then prefers the stale non-zero
> sinfo->xdp_frags_truesize over nr_frags * xdp->frame_sz, overcharging
> skb->truesize by a full xdp->frame_sz allocation and slightly reducing
> effective socket receive buffer accounting.  Passing 0 for truesize here
> would let xdp_build_skb_from_buff() compute nr_frags * xdp->frame_sz from
> the post-shrink fragment count, or xdp_frags_shrink_tail() could adjust
> sinfo->xdp_frags_truesize.

As pointed out before, this is a latent issue for bpf_xdp_adjust_tail() and we
should have a dedicated fix for it.

> 
> [ ... ]
> 
> > @@ -6138,21 +6110,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
> >  		if (!stmmac_get_rx_hash(priv, p, &hash, &hash_type))
> >  			skb_set_hash(skb, hash, hash_type);
> >  
> > -		skb_record_rx_queue(skb, queue);
> >  		napi_gro_receive(&ch->rx_napi, skb);
> >  		rx_packets++;
> >  		rx_bytes += len;
> >  next:
> >  		in_progress = false;
> > -		skb = NULL;
> > +		n_descs = 0;
> > +		count++;
> > +		continue;
> > +error_free_frag:
> > +		if (n_descs)
> > +			__xdp_return_buff(&ctx.xdp, true);
> > +		in_progress = false;
> > +		n_descs = 0;
> >  		count++;
> >  	}
> >  
> > -	if (in_progress || skb) {
> > -		rx_q->state_saved = true;
> > -		rx_q->state.skb = skb;
> > +	if (in_progress || n_descs) {
> > +		rx_q->state.xdp = ctx.xdp;
> > +		rx_q->state.n_descs = n_descs;
> >  		rx_q->state.error = error;
> >  		rx_q->state.len = len;
> > +		rx_q->state_saved = true;
> >  	}
> 
> [Severity: Low]
> Can this copy uninitialized stack memory from ctx.xdp into rx_q->state.xdp?
> 
> ctx is declared uninitialized on the stack in stmmac_rx().  On cores using
> enh_desc_get_rx_status() or ndesc_get_rx_status(), a first descriptor
> without RDES0_LAST_DESCRIPTOR returns discard_frame | rx_not_ls, so
> stmmac_rx() sets in_progress and error and jumps to read_again without
> initializing ctx.xdp, leaving n_descs at 0.  If the next descriptor is still
> owned by DMA and the loop breaks, rx_q->state.xdp = ctx.xdp copies the
> uninitialized struct (and the next poll copies it back).
> 
> Even when n_descs is non-zero, xdp_init_buff() and xdp_prepare_buff() leave
> ctx.xdp.txq uninitialized, so copying ctx.xdp by value still reads an
> uninitialized field.  This can trigger KMSAN uninit-value reports or
> -Wmaybe-uninitialized warnings.  Guarding the xdp save and restore with
> n_descs and zero-initializing ctx (or ctx.xdp.txq) would avoid both.

I do not think this is harmful since ndesc is 0 between two different
stmmac_rx() runs and we do not use the uninitialized memory.

Regards,
Lorenzo

> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e@oss.qualcomm.com?part=5

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-12-05 19:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 10:44 [PATCH net-next v14 0/5] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 1/5] net: stmmac: selftests: Prevent RXC from being disabled in LPI Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping Lorenzo Bianconi
2026-12-05 10:45   ` sashiko-bot
2026-12-05 17:35     ` Lorenzo Bianconi
2026-12-05 10:51   ` netdev-bot+sashiko
2026-12-05 11:48     ` Lorenzo Bianconi
2026-12-05 17:33       ` Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 3/5] net: xdp: add xdp_buff_shrink_tail() helper Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 4/5] net: xdp: add __xdp_return_buff() helper Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Lorenzo Bianconi
2026-12-05 10:45   ` sashiko-bot
2026-12-05 19:11     ` Lorenzo Bianconi [this message]
2026-12-05 10:51   ` netdev-bot+sashiko
2026-12-05 18:40     ` Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axRh6CuU7xg-aXnr@lore-desk \
    --to=lorenzo.bianconi@oss.qualcomm.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox