Skip to contentSkip to conversation

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

PATCH New Sagar Cheluvegowda 3 participants 3 messages Nov 25 – Nov 26

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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

dwxgmac2_get_rx_header_len() only reads the split header length (HL) from RDES2 when RDES3.L34T is non-zero. L34T, like all RDES3 status fields other than bits [31:28], is only valid on the last descriptor (LD set). HL, on the other hand, is only valid on the first descriptor (FD set), and the databook's "Header Length Availability in RDES2" table states that HL is available in RDES2[9:0] when FD=1 and LD=0, without any dependency on L34T.

A frame spans multiple descriptors when it is larger than the RX buffer size. This can happen at any MTU, as XGMAC_CORE_INIT_RX sets GPSLCE and WD with GPSL = XGMAC_JUMBO_LEN (16368), so the MAC accepts frames up to 16368 bytes while dma_buf_sz is only 1536 at an MTU of 1500.

For such a frame, the first descriptor has FD set and LD clear, and L34T is not valid there. When it reads as zero, hlen stays 0 and stmmac_rx_buf1_len() falls through to the rx_not_ls path, which counts buffer 1 as a full dma_buf_sz although it only holds the split header. The frame length accounting is then wrong and the skb is built with the wrong data.

Read HL whenever the first descriptor is not also the last one, and keep the L34T check for single-descriptor frames. Also return early when FD is not set, as HL is not defined there. The caller already ignores the header length for non-first descriptors, so this part does not change the current behaviour.

Fixes 96147375d49f ("net: stmmac: xgmac: Only get SPH header len if available")

---
This fix was split out of the net-next L2 split header series after review of v5, where the multi-descriptor case was pointed out to be reachable with the current GPSL setting and to need a separate fix. The net-next patch will be reposted on top of this once it is in net-next.

v5 of the net-next patch:
https://lore.kernel.org/netdev/[email protected]/
Review comment:
https://lore.kernel.org/netdev/[email protected]/

 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h       | 1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +1 -0
index f8ab347f7b5b..0cdc0bc695c2 100644
@@ -437,6 +437,7 @@
 #define XGMAC_RDES3_OWN			BIT(31)
 #define XGMAC_RDES3_CTXT		BIT(30)
 #define XGMAC_RDES3_IOC			BIT(30)
+#define XGMAC_RDES3_FD			BIT(29)
 #define XGMAC_RDES3_LD			BIT(28)
 #define XGMAC_RDES3_CDA			BIT(27)
 #define XGMAC_RDES3_RSV			BIT(26)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +8 -1
index 6719ac6e395b..ed38aa358642 100644
@@ -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))
 		*len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL;
 }
 
Signature · 1 line
2.34.1
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#2 lore raw
In reply to Sagar Cheluvegowda
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

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.

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +0 -0
index 6719ac6e395bc..ed38aa358642b 100644
@@ -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)

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c static int dwxgmac2_get_rx_hash(struct dma_desc *p, u32 *hash, · line 302

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +8 -1
 {
-	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?

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c static int dwxgmac2_get_rx_hash(struct dma_desc *p, u32 *hash, · line 304

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +0 -0
 		*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?

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