lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
 <PAXPR04MB9185F42CDE16107E3A29FF0B893CA@PAXPR04MB9185.eurprd04.prod.outlook.com>
Date: Sat, 23 Aug 2025 17:57:24 +0000
From: Shenwei Wang <shenwei.wang@....com>
To: Wei Fang <wei.fang@....com>
CC: Clark Wang <xiaoning.wang@....com>, Stanislav Fomichev <sdf@...ichev.me>,
	"imx@...ts.linux.dev" <imx@...ts.linux.dev>, "netdev@...r.kernel.org"
	<netdev@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, dl-linux-imx <linux-imx@....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>
Subject: RE: [PATCH v2 net-next 4/5] net: fec: add change_mtu to support
 dynamic buffer allocation



> -----Original Message-----
> From: Wei Fang <wei.fang@....com>
> Sent: Friday, August 22, 2025 3:45 AM
> To: Shenwei Wang <shenwei.wang@....com>
> Cc: Clark Wang <xiaoning.wang@....com>; Stanislav Fomichev
> <sdf@...ichev.me>; imx@...ts.linux.dev; netdev@...r.kernel.org; linux-
> kernel@...r.kernel.org; dl-linux-imx <linux-imx@....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>
> Subject: RE: [PATCH v2 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;
> > +	bool running;
> > +
> > +	order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN);
> > +	if (fep->pagepool_order == order) {
> > +		WRITE_ONCE(ndev->mtu, new_mtu);
> 
> No need to write ndev->mtu, same below, because __netif_set_mtu() will help
> update it.

It will only update the ndev->mtu if the driver doesn't have its own chang_mtu handler.

int __netif_set_mtu(struct net_device *dev, int new_mtu)
{
	const struct net_device_ops *ops = dev->netdev_ops;

	if (ops->ndo_change_mtu)
		return ops->ndo_change_mtu(dev, new_mtu);

	/* Pairs with all the lockless reads of dev->mtu in the stack */
	WRITE_ONCE(dev->mtu, new_mtu);
	return 0;
}

Regards,
Shenwei

> 
> > +		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));
> > +
> > +	running = netif_running(ndev);
> > +	if (!running) {
> 
> running is only used once, so we can use netif_running(ndev) directly to simplify
> the code.
> 
> > +		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);
> 
> I'm not sure whether read_poll_timeout() is necessary, because I get the info
> from the kernel doc of napi_disable()
> 
> /**
>  * napi_disable() - prevent NAPI from scheduling
>  * @n: NAPI context
>  *
>  * Stop NAPI from being scheduled on this context.
>  * Waits till any outstanding processing completes.
>  * Takes netdev_lock() for associated net_device.
>  */
> 
> > +	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;
> > +
> > +	fec_restart(ndev);
> > +	napi_enable(&fep->napi);
> > +	netif_tx_start_all_queues(ndev);
> > +
> > +	return 0;
> > +}
> > +


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ