Re: [PATCH] ath10k: allocate dummy net_device dynamically
From: Jakub Kicinski
Date: Fri Mar 22 2024 - 11:24:03 EST
On Fri, 22 Mar 2024 07:58:02 -0700 Breno Leitao wrote:
> > Looks like init_dummy_netdev wipes the netdev structure clean, so I
> > don't think we can use it directly as the setup function, Breno :(
>
> Before my patch, init_dummy_netdev was being also used. The patch was
> basically replacing the init_dummy_netdev by alloc_netdev() with will
> call "setup(dev);" later.
>
> - init_dummy_netdev(&irq_grp->napi_ndev);
> + irq_grp->napi_ndev = alloc_netdev(0, "dummy", NET_NAME_UNKNOWN,
> + init_dummy_netdev);
>
> I am wondering if alloc_netdev() is messing with something instead of
> init_dummy_netdev().
alloc_netdev() allocates some memory and initializes lists which
free_netdev() wants to free, basically. But init_dummy_netdev() does:
/* Clear everything. Note we don't initialize spinlocks
* are they aren't supposed to be taken by any of the
* NAPI code and this dummy netdev is supposed to be
* only ever used for NAPI polls
*/
memset(dev, 0, sizeof(struct net_device));
so all those pointers and init alloc_netdev() did before calling setup
will get wiped.
> Also, Kalle's crash is during rmmod, and not during initialization.
> getting NULL after free_netdev() is called.
>
> > Maybe we should add a new helper to "alloc dummy netdev" which can
> > call alloc_netdev() with right arguments and do necessary init?
>
> What are the right arguments in this case?
I'm not sure we have a noop setup() callback today. If you define a
wrapper to allocate a dummy netdev you can define a new empty function
next to it and pass that as init? Hope I got the question right.