Messages in this thread | | | Date | Thu, 28 Mar 2024 15:57:29 +0100 | Subject | Re: [PATCH net-next] net: create a dummy net_device allocator | From | Alexander Lobakin <> |
| |
From: Jakub Kicinski <kuba@kernel.org> Date: Wed, 27 Mar 2024 16:17:31 -0700
> On Wed, 27 Mar 2024 13:08:04 -0700 Breno Leitao wrote: >> It is impossible to use init_dummy_netdev together with alloc_netdev() >> as the 'setup' argument. >> >> This is because alloc_netdev() initializes some fields in the net_device >> structure, and later init_dummy_netdev() memzero them all. This causes >> some problems as reported here: >> >> https://lore.kernel.org/all/20240322082336.49f110cc@kernel.org/ >> >> Split the init_dummy_netdev() function in two. Create a new function called >> init_dummy_netdev_core() that does not memzero the net_device structure. >> Then have init_dummy_netdev() memzero-ing and calling >> init_dummy_netdev_core(), keeping the old behaviour. >> >> init_dummy_netdev_core() is the new function that could be called as an >> argument for alloc_netdev(). >> >> Also, create a helper to allocate and initialize dummy net devices, >> leveraging init_dummy_netdev_core() as the setup argument. This function >> basically simplify the allocation of dummy devices, by allocating and >> initializing it. Freeing the device continue to be done through >> free_netdev() > > Ah, but you need to make it part of the series with some caller. > Maybe convert all the ethernet ones? > > $ git grep 'struct net_device [^*]*;' -- drivers/net/ethernet/ > drivers/net/ethernet/cavium/thunder/thunder_bgx.c: struct net_device netdev; > drivers/net/ethernet/marvell/prestera/prestera_rxtx.c: struct net_device napi_dev; > drivers/net/ethernet/microchip/vcap/vcap_api_debugfs_kunit.c:static struct net_device test_netdev = {}; > drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c:static struct net_device test_netdev = {};
There are much more of them unfortunately. Pretty much every user of init_dummy_netdev()[0].
I would prefer *replacing* init_dummy_netdev() with alloc_dummy_netdev(), so that we'll be sure there are no embedded &net_devices and we can use a proper flex array there.
[0] https://elixir.bootlin.com/linux/v6.9-rc1/A/ident/init_dummy_netdev
Thanks, Olek
| |