[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <221027d6-a3b1-4608-8952-16ae512e63a5@lunn.ch>
Date: Sat, 23 Aug 2025 21:17:03 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Shenwei Wang <shenwei.wang@....com>
Cc: Wei Fang <wei.fang@....com>, Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
John Fastabend <john.fastabend@...il.com>,
Clark Wang <xiaoning.wang@....com>,
Stanislav Fomichev <sdf@...ichev.me>, imx@...ts.linux.dev,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-imx@....com
Subject: Re: [PATCH v3 net-next 4/5] net: fec: add change_mtu to support
dynamic buffer allocation
> +static int fec_change_mtu(struct net_device *ndev, int new_mtu)
> +{
> + struct fec_enet_private *fep = netdev_priv(ndev);
> + int order, done;
> +
> + order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN);
> + if (fep->pagepool_order == order) {
> + WRITE_ONCE(ndev->mtu, new_mtu);
> + return 0;
> + }
> +
> + fep->pagepool_order = order;
> + fep->rx_frame_size = (PAGE_SIZE << order) - FEC_ENET_XDP_HEADROOM
> + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> + if (!netif_running(ndev)) {
> + WRITE_ONCE(ndev->mtu, new_mtu);
> + return 0;
> + }
> +
> + /* Stop TX/RX and free the buffers */
> + napi_disable(&fep->napi);
> + netif_tx_disable(ndev);
> + read_poll_timeout(fec_enet_rx_napi, done, (done == 0),
> + 10, 1000, false, &fep->napi, 10);
> + fec_stop(ndev);
> + fec_enet_free_buffers(ndev);
> +
> + WRITE_ONCE(ndev->mtu, new_mtu);
> +
> + /* Create the pagepool according the new mtu */
> + if (fec_enet_alloc_buffers(ndev) < 0)
> + return -ENOMEM;
> +
This is the wrong order. You need to first allocate the new buffers
and then free the old ones. If the allocation fails, you still have a
working interface using the smaller buffers, and the MTU change just
returns -ENOMEM. If you free the buffers and the allocation of the new
buffers fail, you interface is dead, because it has no buffers.
Andrew
Powered by blists - more mailing lists