[net,v2,1/2] net: stmmac: Limit the MTU of normal descriptors to one buffer

Message ID 20261122-sun8i-emac-mtu-limit-v2-1-c4081e5b83cf@gmail.com (mailing list archive)
State New
Headers
Series net: stmmac: Limit the MTU of normal descriptors to one buffer |

Commit Message

Arun Iyengar via B4 Relay Nov. 22, 2026, 9:13 a.m. UTC
From: Arun Iyengar <aiyengar1990@gmail.com>

Russell King noted in [1] that max_mtu for normal descriptors,
SKB_MAX_HEAD() (3712 on arm64), does not match the hardware. Their
buffer sizes are 11 bits, and stmmac neither splits TX frames nor joins
RX descriptors for them, so a frame must fit one 2047-byte buffer.

Limit max_mtu so that a frame with two VLAN tags and the FCS fits.

Link: https://lore.kernel.org/r/E1vLJcL-0000000ExBL-0GFe@rmk-PC.armlinux.org.uk [1]
Fixes: 48febf7e6476 ("stmmac: allow mtu bigger than 1500 in case of normal desc (V4)")
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Nicolai Buchwitz Nov. 22, 2026, 4:27 p.m. UTC | #1
On 22.11.2026 10:13, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> Russell King noted in [1] that max_mtu for normal descriptors,
> SKB_MAX_HEAD() (3712 on arm64), does not match the hardware. Their
> buffer sizes are 11 bits, and stmmac neither splits TX frames nor joins
> RX descriptors for them, so a frame must fit one 2047-byte buffer.

AFAIU TX does split (jumbo_frm() in chain_mode.c).

This makes RX the real limit as ndesc_get_rx_status() drops a frame that
spans more than one descriptor. Please say that instead, it should also
answer Chen-Yu's question about hardware vs driver?

> 
> Limit max_mtu so that a frame with two VLAN tags and the FCS fits.
> 
> Link: 
> https://lore.kernel.org/r/E1vLJcL-0000000ExBL-0GFe@rmk-PC.armlinux.org.uk 
> [1]
> Fixes: 48febf7e6476 ("stmmac: allow mtu bigger than 1500 in case of 
> normal desc (V4)")
> Cc: Russell King <rmk+kernel@armlinux.org.uk>
> Cc: stable@vger.kernel.org
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>

> [...]

Thanks,
Nicolai
  
Chen-Yu Tsai Nov. 22, 2026, 4:56 p.m. UTC | #2
On Mon, Nov 23, 2026 at 12:27 AM Nicolai Buchwitz <nb@tipi-net.de> wrote:
>
> On 22.11.2026 10:13, Arun Iyengar via B4 Relay wrote:
> > From: Arun Iyengar <aiyengar1990@gmail.com>
> >
> > Russell King noted in [1] that max_mtu for normal descriptors,
> > SKB_MAX_HEAD() (3712 on arm64), does not match the hardware. Their
> > buffer sizes are 11 bits, and stmmac neither splits TX frames nor joins
> > RX descriptors for them, so a frame must fit one 2047-byte buffer.
>
> AFAIU TX does split (jumbo_frm() in chain_mode.c).

Yes. But it also assumes each buffer is 2KB or 8KB, which this series
already says is not correct. (I do wonder why the size field is not
size - 1.)

And also, if I'm reading this correctly, the jumbo frame conditional
is only ever true if enhanced descriptors are available:


    /* To program the descriptors according to the size of the frame */
    if (enh_desc)
            is_jumbo = stmmac_is_jumbo_frm(priv, skb->len, enh_desc);

    csum_insertion = skb->ip_summed == CHECKSUM_PARTIAL;

    if (unlikely(is_jumbo)) {
            entry = stmmac_jumbo_frm(priv, tx_q, skb, csum_insertion);
            if (unlikely(entry < 0) && (entry != -EINVAL))


I might have pointed this out in a reply to Arun's other patch, but here
it is again. This seems to have been broke since 2014 by

    29896a674c8e stmmac: fix chained mode

> This makes RX the real limit as ndesc_get_rx_status() drops a frame that
> spans more than one descriptor. Please say that instead, it should also
> answer Chen-Yu's question about hardware vs driver?

It's great that we have interest in getting this working again, and tools
to help us get there.


FWIW the the new "GMAC200" cores in the latest Allwinner SoCs, and the GMAC
in Rockchip SoCs would also benefit. As far as I can tell they don't support
enhanced descriptors, based on DMA cap values reported in debugfs.


ChenYu

> >
> > Limit max_mtu so that a frame with two VLAN tags and the FCS fits.
> >
> > Link:
> > https://lore.kernel.org/r/E1vLJcL-0000000ExBL-0GFe@rmk-PC.armlinux.org.uk
> > [1]
> > Fixes: 48febf7e6476 ("stmmac: allow mtu bigger than 1500 in case of
> > normal desc (V4)")
> > Cc: Russell King <rmk+kernel@armlinux.org.uk>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
>
> > [...]
>
> Thanks,
> Nicolai
>
  

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a685ce4638f6..2a27e1e7f9b9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -8247,6 +8247,9 @@  static int __stmmac_dvr_probe(struct device *device,
 		ndev->max_mtu = XGMAC_JUMBO_LEN;
 	else if (priv->plat->enh_desc || priv->synopsys_id >= DWMAC_CORE_4_00)
 		ndev->max_mtu = JUMBO_LEN;
+	else if (priv->hw->desc == &ndesc_ops)
+		ndev->max_mtu = BUF_SIZE_2KiB - 1 - ETH_HLEN - 2 * VLAN_HLEN -
+				ETH_FCS_LEN;
 	else
 		ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);