mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: sagar.cheluvegowda@oss.qualcomm.com
Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, mcoquelin.stm32@gmail.com,
	alexandre.torgue@foss.st.com, Jose.Abreu@synopsys.com,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	lorenzo.bianconi@oss.qualcomm.com, hongmei.xu@oss.qualcomm.com,
	abhishek.chauhan@oss.qualcomm.com, sarosh.hasan@oss.qualcomm.com
Subject: Re: [PATCH net] net: stmmac: xgmac: fix RX split header length on multi-descriptor frames
Date: Thu, 26 Nov 2026 19:26:20 +0000	[thread overview]
Message-ID: <179572118090.3135.17761933543011019663@kernel.org> (raw)
In-Reply-To: <20261125192531.1940982-1-sagar.cheluvegowda@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] dwxgmac2_get_rx_header_len()
  (drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c:293-304) now…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it can produce
  the same corruption the patch fixes.

--

net: stmmac: xgmac: fix RX split header length on multi-descriptor frames

This patch changes dwxgmac2_get_rx_header_len() so it reads the split
header length from RDES2.HL whenever the first descriptor is not also the
last one. The RDES3.L34T check is kept only for single-descriptor frames.
For descriptors without FD set, the function now returns early.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> index 6719ac6e395bc..ed38aa358642b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> @@ -292,7 +292,14 @@ static int dwxgmac2_get_rx_hash(struct dma_desc *p, u32 *hash,
>  
>  static void dwxgmac2_get_rx_header_len(struct dma_desc *p, unsigned int *len)
>  {
> -	if (le32_to_cpu(p->des3) & XGMAC_RDES3_L34T)
> +	u32 rdes3 = le32_to_cpu(p->des3);
> +
> +	/* HL is only defined on the first descriptor */
> +	if (!(rdes3 & XGMAC_RDES3_FD))
> +		return;
> +
> +	/* L34T is only valid on the last descriptor */
> +	if (!(rdes3 & XGMAC_RDES3_LD) || (rdes3 & XGMAC_RDES3_L34T))

[Severity: Medium]

Can this trust HL for frames the MAC did not actually split?

Commit 96147375d49f added the L34T gate on purpose. Its message says
"Split Header length is only available when L34T ...". After this change,
every FD=1/LD=0 descriptor uses RDES2.HL no matter what L34T says.

Suppose the XGMAC writes a non-zero HL on the first descriptor of a
multi-descriptor frame it did not split, and that HL is smaller than what
buffer 1 really holds. Examples are a large non-IP frame, or a frame whose
headers exceed HDSMS. GPSL=16368 accepts both. stmmac_rx_buf1_len() then
returns hlen without any check:

    if (priv->sph_active && hlen) {
        priv->xstats.rx_split_hdr_pkt_n++;
        return hlen;
    }

Later descriptors count buf1 as 0 and buf2 as dma_buf_sz, so the running
len ends up too low. On the last descriptor, stmmac_rx_buf2_len() has a
floor but no dma_buf_sz cap:

    return plen > len ? plen - len : 0;

stmmac_rx() then uses that value directly:

    dma_sync_single_for_cpu(priv->device, buf->sec_addr,
                            buf2_len, dma_dir);
    skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
                    buf->sec_page, 0, buf2_len,
                    priv->dma_conf.dma_buf_sz);

Could buf2_len then be larger than what the DMA wrote into sec_page? That
would put stale page_pool bytes into the skb. When dma_buf_sz is close to
the page size, it would read past the end of the page.

Before this patch, the FD && !LD case was mostly gated off by L34T. It
fell back to counting buffer 1 as a full dma_buf_sz, which under-counts
but never over-reads.

A stale read-format des2 is a page-aligned DMA address, so it gives HL=0.
That leaves the question of what the hardware writes to HL for frames it
does not split. Does the databook guarantee that HL is either zero or
accurate in that case?

>  		*len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL;
>  }

[Severity: High]

This is a pre-existing issue, but is this des2 read ordered against the
OWN check in stmmac_rx()?

In stmmac_rx(), the only dma_rmb() after the OWN check is behind
extend_desc:

    status = stmmac_rx_status(priv, &priv->xstats, p);
    /* check if managed by the DMA otherwise go ahead */
    if (unlikely(status & dma_own))
        break;
    ...
    if (priv->extend_desc) {
        /* Read the extended status after the own bit */
        dma_rmb();

extend_desc is only set in stmmac_dwmac1_quirks(), for dwmac1 enhanced
descriptors, so XGMAC and GMAC4 never get this barrier. stmmac_rx_zc()
has the same gap.

On weakly ordered CPUs such as arm64, the des2 load in
stmmac_rx()->stmmac_rx_buf1_len()->dwxgmac2_get_rx_header_len() can be
satisfied before the des3 load that saw OWN clear. In that case des2
still holds the read-format value written by stmmac_rx_refill() through
dwxgmac2_set_sec_addr(). That value is a page-aligned address, so HL
reads as 0.

On an FD && !LD descriptor, this gives the same buf1_len = dma_buf_sz
misaccounting that this patch fixes. On a single-descriptor split frame,
buf2_len becomes 0. The skb then carries the header plus stale buffer 1
bytes instead of the payload in buffer 2, and the frame is still marked
CHECKSUM_UNNECESSARY. The RSS hash (des1) and VLAN (des0) reads have the
same exposure.

Documentation/memory-barriers.txt calls for dma_rmb() after checking the
descriptor ownership bit and before reading the other fields. Should
there be an unconditional dma_rmb() after the OWN check for these cores?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125192531.1940982-1-sagar.cheluvegowda%40oss.qualcomm.com

      parent reply	other threads:[~2026-11-26 19:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 19:25 Sagar Cheluvegowda
2026-11-25 19:27 ` netdev-bot+sinfo
2026-11-26 19:26 ` netdev-bot+sashiko [this message]

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=179572118090.3135.17761933543011019663@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Jose.Abreu@synopsys.com \
    --cc=abhishek.chauhan@oss.qualcomm.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hongmei.xu@oss.qualcomm.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=lorenzo.bianconi@oss.qualcomm.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sagar.cheluvegowda@oss.qualcomm.com \
    --cc=sarosh.hasan@oss.qualcomm.com \
    /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

all inboxes | Powered by JetHome®