Re: [PATCH net] net: stmmac: xgmac: fix RX split header length on multi-descriptor frames
From: Maxime Chevallier
Date: Wed Dec 02 2026 - 13:40:59 EST
Hi,
On 11/25/26 20:25, Sagar Cheluvegowda wrote:
> 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")
> Co-developed-by: Abhishek Chauhan <abhishek.chauhan@xxxxxxxxxxxxxxxx>
> Signed-off-by: Abhishek Chauhan <abhishek.chauhan@xxxxxxxxxxxxxxxx>
> Co-developed-by: Sarosh Hasan <sarosh.hasan@xxxxxxxxxxxxxxxx>
> Signed-off-by: Sarosh Hasan <sarosh.hasan@xxxxxxxxxxxxxxxx>
> Signed-off-by: Sagar Cheluvegowda <sagar.cheluvegowda@xxxxxxxxxxxxxxxx>
Reviewed-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx>
Thanks for addressing this,
Maxime
> ---
> 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/20261120005243.3724402-1-sagar.cheluvegowda@xxxxxxxxxxxxxxxx/
> Review comment:
> https://lore.kernel.org/netdev/179548403438.3135.1804854034587814346@xxxxxxxxxx/
>
> drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h | 1 +
> drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c | 9 ++++++++-
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
> index f8ab347f7b5b..0cdc0bc695c2 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
> @@ -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)
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
> index 6719ac6e395b..ed38aa358642 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))
> *len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL;
> }
>