netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 1/2] net: remove init_dummy_netdev()
@ 2025-01-13  0:34 Jakub Kicinski
  2025-01-13  0:34 ` [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core() Jakub Kicinski
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Jakub Kicinski @ 2025-01-13  0:34 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski,
	matttbe, martineau, geliang, steffen.klassert, herbert, mptcp

init_dummy_netdev() can initialize statically declared or embedded
net_devices. Such netdevs did not come from alloc_netdev_mqs().
After recent work by Breno, there are the only two cases where
we have do that.

Switch those cases to alloc_netdev_mqs() and delete init_dummy_netdev().
Dealing with static netdevs is not worth the maintenance burden.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: change of plan, delete init_dummy_netdev() completely
v1: https://lore.kernel.org/20250111065955.3698801-1-kuba@kernel.org
---
CC: matttbe@kernel.org
CC: martineau@kernel.org
CC: geliang@kernel.org
CC: steffen.klassert@secunet.com
CC: herbert@gondor.apana.org.au
CC: mptcp@lists.linux.dev
---
 include/linux/netdevice.h |  1 -
 net/core/dev.c            | 22 ----------------------
 net/mptcp/protocol.c      |  8 +++++---
 net/xfrm/xfrm_input.c     |  9 ++++++---
 4 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index aeb4a6cff171..dd8f6f8991fe 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3238,7 +3238,6 @@ static inline void unregister_netdevice(struct net_device *dev)
 
 int netdev_refcnt_read(const struct net_device *dev);
 void free_netdev(struct net_device *dev);
-void init_dummy_netdev(struct net_device *dev);
 
 struct net_device *netdev_get_xmit_slave(struct net_device *dev,
 					 struct sk_buff *skb,
diff --git a/net/core/dev.c b/net/core/dev.c
index 1a90ed8cc6cc..c9abc9fc770e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10762,28 +10762,6 @@ static void init_dummy_netdev_core(struct net_device *dev)
 	 */
 }
 
-/**
- *	init_dummy_netdev	- init a dummy network device for NAPI
- *	@dev: device to init
- *
- *	This takes a network device structure and initializes the minimum
- *	amount of fields so it can be used to schedule NAPI polls without
- *	registering a full blown interface. This is to be used by drivers
- *	that need to tie several hardware interfaces to a single NAPI
- *	poll scheduler due to HW limitations.
- */
-void init_dummy_netdev(struct net_device *dev)
-{
-	/* Clear everything. Note we don't initialize spinlocks
-	 * as 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));
-	init_dummy_netdev_core(dev);
-}
-EXPORT_SYMBOL_GPL(init_dummy_netdev);
-
 /**
  *	register_netdev	- register a network device
  *	@dev: device to register
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1b2e7cbb577f..c44c89ecaca6 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -47,7 +47,7 @@ static void __mptcp_destroy_sock(struct sock *sk);
 static void mptcp_check_send_data_fin(struct sock *sk);
 
 DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
-static struct net_device mptcp_napi_dev;
+static struct net_device *mptcp_napi_dev;
 
 /* Returns end sequence number of the receiver's advertised window */
 static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
@@ -4147,11 +4147,13 @@ void __init mptcp_proto_init(void)
 	if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
 		panic("Failed to allocate MPTCP pcpu counter\n");
 
-	init_dummy_netdev(&mptcp_napi_dev);
+	mptcp_napi_dev = alloc_netdev_dummy(0);
+	if (!mptcp_napi_dev)
+		panic("Failed to allocate MPTCP dummy netdev\n");
 	for_each_possible_cpu(cpu) {
 		delegated = per_cpu_ptr(&mptcp_delegated_actions, cpu);
 		INIT_LIST_HEAD(&delegated->head);
-		netif_napi_add_tx(&mptcp_napi_dev, &delegated->napi,
+		netif_napi_add_tx(mptcp_napi_dev, &delegated->napi,
 				  mptcp_napi_poll);
 		napi_enable(&delegated->napi);
 	}
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 2c4ae61e7e3a..7e6a71b9d6a3 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -48,7 +48,7 @@ static DEFINE_SPINLOCK(xfrm_input_afinfo_lock);
 static struct xfrm_input_afinfo const __rcu *xfrm_input_afinfo[2][AF_INET6 + 1];
 
 static struct gro_cells gro_cells;
-static struct net_device xfrm_napi_dev;
+static struct net_device *xfrm_napi_dev;
 
 static DEFINE_PER_CPU(struct xfrm_trans_tasklet, xfrm_trans_tasklet);
 
@@ -825,8 +825,11 @@ void __init xfrm_input_init(void)
 	int err;
 	int i;
 
-	init_dummy_netdev(&xfrm_napi_dev);
-	err = gro_cells_init(&gro_cells, &xfrm_napi_dev);
+	xfrm_napi_dev = alloc_netdev_dummy(0);
+	if (!xfrm_napi_dev)
+		panic("Failed to allocate XFRM dummy netdev\n");
+
+	err = gro_cells_init(&gro_cells, xfrm_napi_dev);
 	if (err)
 		gro_cells.cells = NULL;
 
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core()
  2025-01-13  0:34 [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Jakub Kicinski
@ 2025-01-13  0:34 ` Jakub Kicinski
  2025-01-13 22:00   ` Joe Damato
  2025-01-13 12:14 ` [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Alexander Lobakin
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2025-01-13  0:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski

init_dummy_netdev_core() used to cater to net_devices which
did not come from alloc_netdev_mqs(). Since that's no longer
supported remove the init logic which duplicates alloc_netdev_mqs().

While at it rename back to init_dummy_netdev().

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/core/dev.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index c9abc9fc770e..fda4e1039bf0 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10736,26 +10736,20 @@ int register_netdevice(struct net_device *dev)
 EXPORT_SYMBOL(register_netdevice);
 
 /* Initialize the core of a dummy net device.
- * This is useful if you are calling this function after alloc_netdev(),
- * since it does not memset the net_device fields.
+ * The setup steps dummy netdevs need which normal netdevs get by going
+ * through register_netdevice().
  */
-static void init_dummy_netdev_core(struct net_device *dev)
+static void init_dummy_netdev(struct net_device *dev)
 {
 	/* make sure we BUG if trying to hit standard
 	 * register/unregister code path
 	 */
 	dev->reg_state = NETREG_DUMMY;
 
-	/* NAPI wants this */
-	INIT_LIST_HEAD(&dev->napi_list);
-
 	/* a dummy interface is started by default */
 	set_bit(__LINK_STATE_PRESENT, &dev->state);
 	set_bit(__LINK_STATE_START, &dev->state);
 
-	/* napi_busy_loop stats accounting wants this */
-	dev_net_set(dev, &init_net);
-
 	/* Note : We dont allocate pcpu_refcnt for dummy devices,
 	 * because users of this 'device' dont need to change
 	 * its refcount.
@@ -11440,7 +11434,7 @@ EXPORT_SYMBOL(free_netdev);
 struct net_device *alloc_netdev_dummy(int sizeof_priv)
 {
 	return alloc_netdev(sizeof_priv, "dummy#", NET_NAME_UNKNOWN,
-			    init_dummy_netdev_core);
+			    init_dummy_netdev);
 }
 EXPORT_SYMBOL_GPL(alloc_netdev_dummy);
 
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/2] net: remove init_dummy_netdev()
  2025-01-13  0:34 [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Jakub Kicinski
  2025-01-13  0:34 ` [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core() Jakub Kicinski
@ 2025-01-13 12:14 ` Alexander Lobakin
  2025-01-13 16:16 ` Matthieu Baerts
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Alexander Lobakin @ 2025-01-13 12:14 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, matttbe,
	martineau, geliang, steffen.klassert, herbert, mptcp

From: Jakub Kicinski <kuba@kernel.org>
Date: Sun, 12 Jan 2025 16:34:55 -0800

> init_dummy_netdev() can initialize statically declared or embedded
> net_devices. Such netdevs did not come from alloc_netdev_mqs().
> After recent work by Breno, there are the only two cases where
> we have do that.
> 
> Switch those cases to alloc_netdev_mqs() and delete init_dummy_netdev().
> Dealing with static netdevs is not worth the maintenance burden.

Series:

Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>

> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: change of plan, delete init_dummy_netdev() completely
> v1: https://lore.kernel.org/20250111065955.3698801-1-kuba@kernel.org

Thanks,
Olek

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/2] net: remove init_dummy_netdev()
  2025-01-13  0:34 [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Jakub Kicinski
  2025-01-13  0:34 ` [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core() Jakub Kicinski
  2025-01-13 12:14 ` [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Alexander Lobakin
@ 2025-01-13 16:16 ` Matthieu Baerts
  2025-01-13 21:58 ` Joe Damato
  2025-01-14  3:30 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: Matthieu Baerts @ 2025-01-13 16:16 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev, davem, edumazet, pabeni, andrew+netdev, horms, martineau,
	geliang, steffen.klassert, herbert, mptcp

Hi Jakub,

On 13/01/2025 01:34, Jakub Kicinski wrote:
> init_dummy_netdev() can initialize statically declared or embedded
> net_devices. Such netdevs did not come from alloc_netdev_mqs().
> After recent work by Breno, there are the only two cases where
> we have do that.
> 
> Switch those cases to alloc_netdev_mqs() and delete init_dummy_netdev().
> Dealing with static netdevs is not worth the maintenance burden.

Thank you for the patch!

(...)

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1b2e7cbb577f..c44c89ecaca6 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -47,7 +47,7 @@ static void __mptcp_destroy_sock(struct sock *sk);
>  static void mptcp_check_send_data_fin(struct sock *sk);
>  
>  DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
> -static struct net_device mptcp_napi_dev;
> +static struct net_device *mptcp_napi_dev;
>  
>  /* Returns end sequence number of the receiver's advertised window */
>  static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
> @@ -4147,11 +4147,13 @@ void __init mptcp_proto_init(void)
>  	if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
>  		panic("Failed to allocate MPTCP pcpu counter\n");
>  
> -	init_dummy_netdev(&mptcp_napi_dev);
> +	mptcp_napi_dev = alloc_netdev_dummy(0);

This seems to initialise quite a few things that are not needed for the
MPTCP case. But it doesn't seem to hurt, and the dummy net device
doesn't seem to be exposed to the userspace (net devices, sysfs). So if
it helps with the maintenance, it looks fine to do that.

For the modifications in MPTCP code:

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

> +	if (!mptcp_napi_dev)
> +		panic("Failed to allocate MPTCP dummy netdev\n");
>  	for_each_possible_cpu(cpu) {
>  		delegated = per_cpu_ptr(&mptcp_delegated_actions, cpu);
>  		INIT_LIST_HEAD(&delegated->head);
> -		netif_napi_add_tx(&mptcp_napi_dev, &delegated->napi,
> +		netif_napi_add_tx(mptcp_napi_dev, &delegated->napi,
>  				  mptcp_napi_poll);
>  		napi_enable(&delegated->napi);
>  	}

(...)

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/2] net: remove init_dummy_netdev()
  2025-01-13  0:34 [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Jakub Kicinski
                   ` (2 preceding siblings ...)
  2025-01-13 16:16 ` Matthieu Baerts
@ 2025-01-13 21:58 ` Joe Damato
  2025-01-14  3:30 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: Joe Damato @ 2025-01-13 21:58 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, matttbe,
	martineau, geliang, steffen.klassert, herbert, mptcp

On Sun, Jan 12, 2025 at 04:34:55PM -0800, Jakub Kicinski wrote:
> init_dummy_netdev() can initialize statically declared or embedded
> net_devices. Such netdevs did not come from alloc_netdev_mqs().
> After recent work by Breno, there are the only two cases where
> we have do that.
> 
> Switch those cases to alloc_netdev_mqs() and delete init_dummy_netdev().
> Dealing with static netdevs is not worth the maintenance burden.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: change of plan, delete init_dummy_netdev() completely
> v1: https://lore.kernel.org/20250111065955.3698801-1-kuba@kernel.org
> ---
> CC: matttbe@kernel.org
> CC: martineau@kernel.org
> CC: geliang@kernel.org
> CC: steffen.klassert@secunet.com
> CC: herbert@gondor.apana.org.au
> CC: mptcp@lists.linux.dev
> ---
>  include/linux/netdevice.h |  1 -
>  net/core/dev.c            | 22 ----------------------
>  net/mptcp/protocol.c      |  8 +++++---
>  net/xfrm/xfrm_input.c     |  9 ++++++---
>  4 files changed, 11 insertions(+), 29 deletions(-)

Reviewed-by: Joe Damato <jdamato@fastly.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core()
  2025-01-13  0:34 ` [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core() Jakub Kicinski
@ 2025-01-13 22:00   ` Joe Damato
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Damato @ 2025-01-13 22:00 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms

On Sun, Jan 12, 2025 at 04:34:56PM -0800, Jakub Kicinski wrote:
> init_dummy_netdev_core() used to cater to net_devices which
> did not come from alloc_netdev_mqs(). Since that's no longer
> supported remove the init logic which duplicates alloc_netdev_mqs().
> 
> While at it rename back to init_dummy_netdev().
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  net/core/dev.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)

Reviewed-by: Joe Damato <jdamato@fastly.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/2] net: remove init_dummy_netdev()
  2025-01-13  0:34 [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Jakub Kicinski
                   ` (3 preceding siblings ...)
  2025-01-13 21:58 ` Joe Damato
@ 2025-01-14  3:30 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-01-14  3:30 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, matttbe,
	martineau, geliang, steffen.klassert, herbert, mptcp

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 12 Jan 2025 16:34:55 -0800 you wrote:
> init_dummy_netdev() can initialize statically declared or embedded
> net_devices. Such netdevs did not come from alloc_netdev_mqs().
> After recent work by Breno, there are the only two cases where
> we have do that.
> 
> Switch those cases to alloc_netdev_mqs() and delete init_dummy_netdev().
> Dealing with static netdevs is not worth the maintenance burden.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/2] net: remove init_dummy_netdev()
    https://git.kernel.org/netdev/net-next/c/f835bdae7167
  - [net-next,v2,2/2] net: cleanup init_dummy_netdev_core()
    https://git.kernel.org/netdev/net-next/c/37adf101f6f7

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-14  3:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-13  0:34 [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Jakub Kicinski
2025-01-13  0:34 ` [PATCH net-next v2 2/2] net: cleanup init_dummy_netdev_core() Jakub Kicinski
2025-01-13 22:00   ` Joe Damato
2025-01-13 12:14 ` [PATCH net-next v2 1/2] net: remove init_dummy_netdev() Alexander Lobakin
2025-01-13 16:16 ` Matthieu Baerts
2025-01-13 21:58 ` Joe Damato
2025-01-14  3:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).