Re: [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed

From: netdev-bot+sashiko

Date: Sat Nov 28 2026 - 06:26:28 EST


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

Critical: 0 · High: 0 · 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] In bcmgenet_change_mtu(), if the DMA engine will not halt, the
driver frees RX buffers and page pools that the hardware descriptors…

--

net: bcmgenet: allow the MTU to be changed

This commit sets dev->max_mtu on GENET v5 from the packet ready threshold
and adds bcmgenet_change_mtu(). On a running interface it stops the
datapath, reprograms the MTU registers and restarts DMA while the PHY
keeps running. When the new MTU maps to the same rx_buf_len, the existing
rings are reused.

Link: https://github.com/raspberrypi/linux/issues/5561

> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index fc8b8400fcbb5..1307faf135bd4 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c

[ ... ]

> @@ -3997,6 +4023,97 @@ static int bcmgenet_change_carrier(struct net_device *dev, bool new_carrier)
> return 0;
> }
>
> +static int bcmgenet_change_mtu(struct net_device *dev, int new_mtu)
> +{

[ ... ]

> + /* The threshold is quantised, so a band of MTUs shares one buffer
> + * length and the running rings can serve the new MTU as they are.
> + */
> + reuse = buf_len == priv->rx_buf_len;
> + if (!reuse) {
> + ret = bcmgenet_alloc_dma(priv, buf_len, &set);
> + if (ret)
> + return ret;
> + }
> +
> + /* The watchdog trips on an idle queue once the rings are gone */
> + netif_device_detach(dev);
> +
> + /* The PHY stays up, hold its lock. A link event would otherwise take
> + * the MAC out of reset and enable it mid rewrite.
> + */
> + mutex_lock(&dev->phydev->lock);
> + bcmgenet_netif_stop(dev, false, reuse ? &set : NULL);
> +
> + WRITE_ONCE(dev->mtu, new_mtu);
> + priv->rx_buf_len = buf_len;
> + bcmgenet_set_mtu_regs(priv, new_mtu);
> +
> + ret = bcmgenet_init_dma(priv, true, &set);
> + if (ret) {

[Severity: Medium]
What happens to the RX buffers here if the DMA engine does not halt?

bcmgenet_netif_stop() ignores the return value of bcmgenet_dma_teardown():

bcmgenet_netif_stop() {
...
bcmgenet_dma_teardown(priv);
...
bcmgenet_tx_reclaim_all(dev);
bcmgenet_fini_dma(priv, keep);
}

On the reuse path, bcmgenet_fini_dma() moves the live rx_cbs, tx_cbs and
page pools into set. The RDMA descriptors still hold the DMA addresses of
those pages.

bcmgenet_init_dma() then checks the halt again with
bcmgenet_tdma_disable() and bcmgenet_rdma_disable(). On a timeout it
jumps to err before it rewrites any descriptor:

err:
bcmgenet_free_dma_set(priv, set);

bcmgenet_free_dma_set() is documented as:

/* Hand back a set that was never installed */

Here the set is the one the hardware is armed with. The helper returns
every page to its pool and calls page_pool_destroy(), which unmaps the
pages and hands them back to the page allocator.

After that, netif_close() runs bcmgenet_close(). Because tx_cbs is NULL,
bcmgenet_close() skips bcmgenet_netif_stop(), and nothing resets RDMA,
UMAC or RBUF. Can an RX engine that never reported halted then write into
pages that have been freed and reused?

The non-reuse path looks similar. bcmgenet_fini_dma(priv, NULL) frees the
old, still-armed rings regardless of what bcmgenet_dma_teardown()
returned. bcmgenet_close() and the resume path already have the same
"teardown failed, free anyway" pattern, but this patch makes it reachable
at runtime through an MTU change on a running v5 interface.

The commit message only says:

Only a DMA that refuses to halt still takes the interface down, because
nothing is left to run on.

It does not cover the hardware still referencing the freed buffers.

On a halt failure, would it be safer to WARN and leak the set rather than
free it? Another option is to reset the block before releasing the
buffers.

As far as I can tell, the later patch "net: bcmgenet: reassemble jumbo
frames from status block fragments" does not change this error path in
bcmgenet_init_dma() or bcmgenet_change_mtu(), so the issue remains at the
end of the series.

> + /* The datapath is gone, do not leave the interface up */
> + netdev_err(dev, "failed to initialize DMA, closing\n");
> + WRITE_ONCE(dev->mtu, old_mtu);
> + priv->rx_buf_len = bcmgenet_rx_buf_len(old_mtu);
> + mutex_unlock(&dev->phydev->lock);
> + /* bcmgenet_close() attaches the device again */
> + netif_close(dev);
> + return ret;
> + }

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de