Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: sandeeph@loljews.com
Cc: netdev@vger.kernel.org, nbd@nbd.name, lorenzo@kernel.org,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, linux@armlinux.org.uk,
	daniel@makrotopia.org, mason-cw.chang@mediatek.com,
	frank-w@public-files.de, linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v9 2/2] net: ethernet: mtk_eth_soc: add 9K jumbo
Date: Thu, 03 Dec 2026 14:18:30 +0000	[thread overview]
Message-ID: <179630751086.3146.15182958236912809367@kernel.org> (raw)
In-Reply-To: <patch-cd5d32f0108811f44a891aacdaac4881@loljews.com>

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

Critical: 1 · High: 0 · Medium: 3 · Low: 3

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).

- [Critical] In mtk_poll_rx(),
  drivers/net/ethernet/mediatek/mtk_eth_soc.c, `dma_addr` is set to…
- [Medium] On MT7988, GMAC1 (phy-mode internal, the built-in switch port)
  gets max_mtu = MTK_MAX_RX_LENGTH_9K - MTK_RX_ETH_HLEN - VLAN_HLEN =…
- [Medium] mtk_pdma_set_sdl() is called at the end of every
  mtk_dma_init() and is gated only on mtk_is_netsys_v3_or_greater(), not…
- [Medium] The only Author/Signed-off-by is 'Sandeep Haemoon
  <sandeeph@loljews.com>', and the domain reads as a deliberately…
- [Low] On MT7988 the MAC receive limit no longer follows each netdev's
  MTU.
- [Low] The MT7988 jumbo-frame feature commit also carries several
  behaviour changes for every SoC the driver supports, with no Fixes:…
- [Low] The commit describes itself as a forward-port of MediaTek
  downstream patches (Mason Chang's 999-eth-30/31) plus a fix by Frank…

--

net: ethernet: mtk_eth_soc: add 9K jumbo

This commit adds an MTK_NETSYS_RX_9K capability for MT7988. It advertises
a 9194-byte max_mtu on the XGMII MACs and sizes the shared RX rings from
the largest MTU of any MAC. It also programs the MAC limits and
ADMA_RX_CFG from the shared buffer length, drops over-long RX
descriptors, changes rx_errors accounting and reports the real
allocation size in skb->truesize.

Link: https://github.com/frank-w/BPI-Router-Linux/commit/b4c6cb1d5532
Link: https://github.com/mediatek/mtk-openwrt-feeds

> This is a forward-port of the MediaTek downstream jumbo work: Mason
> Chang's "change default rx buffer length" and "add 9k jumbo frame
> support" (MediaTek OpenWrt feed 999-eth-30/31, carried in
> frank-w/BPI-Router-Linux), plus Frank Wunderlich's "try to fix crash
> the right way".

[ ... ]

> The code is credited by reference rather than with
> co-author tags, which need the original authors' own Signed-off-by
> lines;

[Severity: Low]
Patches carried in the MediaTek feed and in frank-w's tree usually already
have their authors' Signed-off-by lines. If these do, could those lines be
kept, together with Co-developed-by (or with From: for the original
author)?

As it stands, the vendor-derived code is credited only through Link:
tags. Its provenance rests only on the submitter's DCO (b)
certification.

> Signed-off-by: Sandeep Haemoon <sandeeph@loljews.com>

[Severity: Medium]
The DCO depends on a real, contactable identity. This is the only
Signed-off-by on the patch. The domain in the address reads as offensive
and does not look like an accountable identity.

Could the submitter confirm their identity and resend from a real
address? This matters more here because the patch forward-ports
third-party code without the original authors' sign-offs.

> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index cb05a8e43e301..5affaf7fc4c14 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c

[ ... ]

> @@ -554,6 +555,112 @@ static int mtk_mac_prepare(struct phylink_config *config, unsigned int mode,
>  	return 0;
>  }
>  

[ ... ]

> +static void mtk_set_mcr_max_rx(struct mtk_mac *mac, phy_interface_t interface,
> +			       u32 val)
> +{

[ ... ]

> +		/* The bucket encodes at most 2048; the SoCs with the 9K
> +		 * capability need the jumbo field, in 1024-byte units, for
> +		 * anything larger.  The MT7988A reference manual defines
> +		 * only 4'h2 (2 Kbytes) for that field and marks the rest
> +		 * reserved, and the MT7988 downstream 9K patch does not
> +		 * raise it for GMAC1 at all; the field is the encoding the

[ ... ]

> +		if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K)) {
> +			u32 jumbo = DIV_ROUND_UP(val, MTK_MAX_RX_LENGTH_UNIT);
> +
> +			jumbo = min(jumbo, MTK_MAX_RX_LENGTH_9K /
> +					   MTK_MAX_RX_LENGTH_UNIT);
> +
> +			mcr_new &= ~MAC_MCR_MAX_RX_JUMBO_MASK;
> +
> +			if (val > 1552) {
> +				if (mac->id != MTK_GMAC1_ID)
> +					jumbo = 2;
> +				mcr_new |= MAC_MCR_MAX_RX_JUMBO(jumbo);
> +			}
> +		}

[Severity: Medium]
Does GMAC1 actually accept frames above 2048 bytes with this encoding?

For GMAC1, jumbo is DIV_ROUND_UP(rx_buf_len, 1024), so values 3 through 9
are written to MCR[31:28]. The comment above says the reference manual
defines only 4'h2 and marks the other encodings reserved. It also says
the downstream MT7988 9K patch never raises the field for GMAC1.

Even so, mtk_add_mac() advertises max_mtu 9194 for GMAC1, because
PHY_INTERFACE_MODE_INTERNAL counts as xgmii:

	else if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K) &&
		 mtk_interface_mode_is_xgmii(eth, phy_mode))
		eth->netdev[id]->max_mtu =
			MTK_MAX_RX_LENGTH_9K - MTK_RX_ETH_HLEN - VLAN_HLEN;

Suppose the hardware ignores or misdecodes the reserved values. A user
could then raise the GMAC1/DSA conduit MTU to 9194 and get 16 KiB
GFP_ATOMIC ring buffers (about 32 MiB pinned). Wouldn't the MAC still
drop every frame above 2048 bytes?

Is it safe to write reserved encodings into this register at all?

[ ... ]

> @@ -1231,37 +1371,51 @@ static void mtk_get_stats64(struct net_device *dev,
>  		storage->collisions = hw_stats->tx_collisions;
>  		storage->rx_length_errors = hw_stats->rx_short_errors +
>  			hw_stats->rx_long_errors;
> +		storage->rx_errors = hw_stats->rx_checksum_errors +
> +				     hw_stats->rx_fcs_errors +
> +				     storage->rx_length_errors;
>  		storage->rx_over_errors = hw_stats->rx_overflow;
>  		storage->rx_crc_errors = hw_stats->rx_fcs_errors;
> -		storage->rx_errors = hw_stats->rx_checksum_errors;
>  		storage->tx_aborted_errors = hw_stats->tx_skip;
>  	} while (u64_stats_fetch_retry(&hw_stats->syncp, start));

[Severity: Low]
This isn't a bug, but this rx_errors change affects every SoC the driver
supports, not only MT7988. It is described as an if_link.h conformance
fix.

Other parts of this feature patch also reach the other SoCs:

- build_skb(data, alloc_size) in mtk_poll_rx() raises skb->truesize on
  the HW-LRO rings of mt2701, mt7622, mt7623 and mt7629 from about
  12.6 KiB to 16 KiB.
- The new PLEN0 > buf_size drop runs on all SoCs.
- The mtk_set_mcr_max_rx() refactor touches every SoC.

Could these be split into separate patches, with Fixes: tags where they
correct existing behaviour? They could then be backported or reverted
without the jumbo feature.

[ ... ]

> @@ -2262,6 +2424,16 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
>  
>  		pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
>  
> +		/* Never pass a descriptor longer than the posted buffer up
> +		 * the stack: the refill below gives build_skb() the whole
> +		 * allocation as tailroom, so such a length would expose
> +		 * uninitialised memory instead of tripping skb_over_panic().
> +		 */
> +		if (unlikely(pktlen > ring->buf_size)) {
> +			netdev->stats.rx_length_errors++;
> +			goto release_desc;
> +		}

[Severity: Critical]
On MTK_36BIT_DMA SoCs such as MT7988, can this goto give the PDMA a
descriptor with a mismatched address?

mtk_poll_rx() initialises dma_addr once per call, not once per
descriptor:

	dma_addr_t dma_addr = DMA_MAPPING_ERROR;

If an earlier descriptor in the same poll was refilled, dma_addr still
holds that new buffer's address when this goto runs. release_desc then
does:

release_desc:
	if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA)) {
		if (unlikely(dma_addr == DMA_MAPPING_ERROR))
			addr64 = FIELD_GET(RX_DMA_ADDR64_MASK,
					   rxd->rxd2);
		else
			addr64 = RX_DMA_PREP_ADDR64(dma_addr);
	}
	...
		rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size) | addr64;

rxd1 still holds the low 32 bits of the buffer kept in this slot. Bits
35:32, however, now come from the previous descriptor's buffer.

MT7988 DRAM starts at 0x40000000, so on boards with 4 GiB or more the
two buffers can sit in different 4 GiB windows. Would the next frame
(now up to about 9 KiB) then be DMA'd into a page the driver does not
own? Would the kept buffer later be unmapped with the wrong address and
passed up the stack with stale contents?

The other direct goto release_desc paths use the same stale value:
invalid MAC, MTK_RESETTING, and page_pool or frag refill failure. This
patch adds a new path. It also makes the normal-ring refill an order-1
or order-2 GFP_ATOMIC allocation once any MTU reaches about 3051, so
this failure path should be hit much more often:

	new_data = mtk_max_buf_alloc(ring->frag_size, GFP_ATOMIC);
	...
	if (unlikely(!new_data)) {
		netdev->stats.rx_dropped++;
		goto release_desc;
	}

Would resetting dma_addr to DMA_MAPPING_ERROR at the start of each loop
iteration avoid this?

[ ... ]

> @@ -3253,6 +3443,75 @@ static int mtk_dma_busy_wait(struct mtk_eth *eth)

[ ... ]

> +/* Program ADMA_RX_CFG[31:16] from the shared RX buffer length on netsys
> + * v3+.  The MT7988A reference manual names the field "ADMA LRO free
> + * buffer SDL": the size of a buffer handed to the LRO engine, which its
> + * LRO chapter requires to be at least the largest frame the MAC accepts.
> + * The MediaTek downstream driver encodes it as MTK_PDMA_LRO_SDL plus the
> + * frame area, and that is what is written here.  It is a buffer size, not
> + * a DMA length, so the per-descriptor PLEN0 still bounds every transfer;
> + * MT7988 does not use the LRO rings, and the write matches the downstream
> + * driver rather than gating the jumbo path.
> + */
> +static void mtk_pdma_set_sdl(struct mtk_eth *eth)
> +{
> +	const struct mtk_reg_map *reg_map = eth->soc->reg_map;
> +	u32 val;
> +
> +	if (!mtk_is_netsys_v3_or_greater(eth))
> +		return;
> +
> +	val = mtk_r32(eth, reg_map->pdma.rx_cfg);
> +	val &= ~MTK_RX_CFG_SDL_MASK;
> +	val |= FIELD_PREP(MTK_RX_CFG_SDL_MASK,
> +			  MTK_PDMA_LRO_SDL + eth->rx_buf_len);
> +	mtk_w32(eth, val, reg_map->pdma.rx_cfg);
> +}

[Severity: Medium]
Is it safe to write this register on every MT7988 configuration?

mtk_dma_init() calls mtk_pdma_set_sdl() on every netsys v3+ DMA
bring-up. The call does not depend on MTK_NETSYS_RX_9K, hwlro or the
MTU. At the default MTU it writes 0x3000 + 2048 = 0x3800 (14336 bytes)
into ADMA_RX_CFG[31:16]. That is about seven times the buffer size
mtk_rx_alloc() actually posts. Before this patch the driver never wrote
this field.

The comment calls the field the LRO free buffer size and says MT7988
does not use the LRO rings. It also says PLEN0 still bounds every
transfer, but nothing in the tree supports that.

What happens if the ADMA engine uses this size for non-LRO rings, for
example with MTK_RESV_BUF set in glo_cfg? Could it DMA past the posted
buffers? The pktlen > ring->buf_size check in mtk_poll_rx() runs only
after the transfer, so it cannot prevent an overrun.

[ ... ]

> @@ -4207,13 +4459,25 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)
>  	 */
>  	for (i = 0; i < MTK_MAX_DEVS; i++) {
>  		struct net_device *dev = eth->netdev[i];
> +		struct mtk_mac *mac;
>  
>  		if (!dev)
>  			continue;
>  
> +		mac = netdev_priv(dev);
>  		mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
> -		mtk_set_mcr_max_rx(netdev_priv(dev),
> -				   dev->mtu + MTK_RX_ETH_HLEN);
> +		if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K)) {
> +			mtk_set_mcr_max_rx(mac, mac->interface,
> +					   dev->mtu + MTK_RX_ETH_HLEN);
> +		} else if (mac->interface != PHY_INTERFACE_MODE_NA) {
> +			/* Before the first mac_config() the interface mode
> +			 * is unknown and the limit would land in the MCR
> +			 * register of an XGMII MAC; that open programs each
> +			 * MAC from its own mac_config() anyway.
> +			 */
> +			mtk_set_mcr_max_rx(mac, mac->interface,
> +					   eth->rx_buf_len);
> +		}
>  	}

[Severity: Low]
On MT7988 the MAC receive limit no longer follows each netdev's MTU.
mtk_hw_init(), mtk_mac_config(), both link-up paths and
mtk_set_all_macs_max_rx() all program every MAC from the shared
eth->rx_buf_len.

mtk_rx_buf_len_from_mtu() never returns less than 2048:

	if (max_mtu + MTK_RX_ETH_HLEN <= MTK_MAX_RX_LENGTH_2K)
		return MTK_MAX_RX_LENGTH_2K;

At the default MTU of 1500, GMAC1 and the non-XGMII GDM MACs therefore
move from the 1518 bucket to the 2048 bucket, with MCR[31:28] = 2.

An XGMII MAC that stays at MTU 1500 (GMAC2) is affected as well. Once
another MAC's MTU is raised, mtk_set_all_macs_max_rx() sets its
XMAC_RX_CFG2 limit as high as 9216.

The hardware used to reject frames longer than the MTU and count them in
rx_long_errors. Those frames now reach the stack. Is that intended?

The commit message says the limits are "a property of the shared rings",
but it does not say that MACs now accept frames larger than their MTU
even at default settings.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/patch-957a473dc4caca415acb95d2d6cfa1ab%40loljews.com

  reply	other threads:[~2026-12-03 14:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 23:16 [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support Sandeep Haemoon
2026-11-30 23:16 ` [PATCH net-next v9 2/2] net: ethernet: mtk_eth_soc: add 9K jumbo Sandeep Haemoon
2026-12-03 14:18   ` netdev-bot+sashiko [this message]
2026-11-30 23:16 ` [PATCH net-next v9 1/2] net: ethernet: mtk_eth_soc: skip page_pool Sandeep Haemoon
2026-12-01  7:12 ` [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support Frank Wunderlich
2026-12-02 19:15   ` Sandeep Haemoon

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=179630751086.3146.15182958236912809367@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=frank-w@public-files.de \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=lorenzo@kernel.org \
    --cc=mason-cw.chang@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sandeeph@loljews.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