netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <antonio@openvpn.net>
Cc: <andrew@lunn.ch>, <antony.antony@secunet.com>,
	<edumazet@google.com>, <kuba@kernel.org>,
	<netdev@vger.kernel.org>, <pabeni@redhat.com>,
	<ryazanov.s.a@gmail.com>, <sd@queasysnail.net>,
	<steffen.klassert@secunet.com>, <kuniyu@amazon.com>
Subject: Re: [PATCH net-next v7 03/25] net: introduce OpenVPN Data Channel Offload (ovpn)
Date: Thu, 19 Sep 2024 07:52:59 +0200	[thread overview]
Message-ID: <20240919055259.17622-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20240917010734.1905-4-antonio@openvpn.net>

From: Antonio Quartulli <antonio@openvpn.net>
Date: Tue, 17 Sep 2024 03:07:12 +0200
> +/* we register with rtnl to let core know that ovpn is a virtual driver and
> + * therefore ifaces should be destroyed when exiting a netns
> + */
> +static struct rtnl_link_ops ovpn_link_ops = {
> +};

This looks like abusing rtnl_link_ops.

Instead of a hack to rely on default_device_exit_batch()
and rtnl_link_unregister(), this should be implemented as
struct pernet_operations.exit_batch_rtnl().

Then, the patch 2 is not needed, which is confusing for
all other rtnl_link_ops users.

If we want to avoid extra RTNL in default_device_exit_batch(),
I can post this patch after merge window.

---8<---
diff --git a/net/core/dev.c b/net/core/dev.c
index 1e740faf9e78..eacf6f5a6ace 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11916,7 +11916,8 @@ static void __net_exit default_device_exit_net(struct net *net)
 	}
 }
 
-static void __net_exit default_device_exit_batch(struct list_head *net_list)
+void __net_exit default_device_exit_batch(struct list_head *net_list,
+					  struct list_head *dev_kill_list)
 {
 	/* At exit all network devices most be removed from a network
 	 * namespace.  Do this in the reverse order of registration.
@@ -11925,9 +11926,7 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list)
 	 */
 	struct net_device *dev;
 	struct net *net;
-	LIST_HEAD(dev_kill_list);
 
-	rtnl_lock();
 	list_for_each_entry(net, net_list, exit_list) {
 		default_device_exit_net(net);
 		cond_resched();
@@ -11936,19 +11935,13 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list)
 	list_for_each_entry(net, net_list, exit_list) {
 		for_each_netdev_reverse(net, dev) {
 			if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink)
-				dev->rtnl_link_ops->dellink(dev, &dev_kill_list);
+				dev->rtnl_link_ops->dellink(dev, dev_kill_list);
 			else
-				unregister_netdevice_queue(dev, &dev_kill_list);
+				unregister_netdevice_queue(dev, dev_kill_list);
 		}
 	}
-	unregister_netdevice_many(&dev_kill_list);
-	rtnl_unlock();
 }
 
-static struct pernet_operations __net_initdata default_device_ops = {
-	.exit_batch = default_device_exit_batch,
-};
-
 static void __init net_dev_struct_check(void)
 {
 	/* TX read-mostly hotpath */
@@ -12140,9 +12133,6 @@ static int __init net_dev_init(void)
 	if (register_pernet_device(&loopback_net_ops))
 		goto out;
 
-	if (register_pernet_device(&default_device_ops))
-		goto out;
-
 	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
 	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
 
diff --git a/net/core/dev.h b/net/core/dev.h
index 5654325c5b71..d1feecab9c4a 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -99,6 +99,9 @@ void __dev_notify_flags(struct net_device *dev, unsigned int old_flags,
 void unregister_netdevice_many_notify(struct list_head *head,
 				      u32 portid, const struct nlmsghdr *nlh);
 
+void default_device_exit_batch(struct list_head *net_list,
+			       struct list_head *dev_kill_list);
+
 static inline void netif_set_gso_max_size(struct net_device *dev,
 					  unsigned int size)
 {
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 11e4dd4f09ed..0a9bce599d54 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -27,6 +27,8 @@
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 
+#include "dev.h"
+
 /*
  *	Our network namespace constructor/destructor lists
  */
@@ -380,6 +382,7 @@ static __net_init int setup_net(struct net *net)
 		if (ops->exit_batch_rtnl)
 			ops->exit_batch_rtnl(&net_exit_list, &dev_kill_list);
 	}
+	default_device_exit_batch(&net_exit_list, &dev_kill_list);
 	unregister_netdevice_many(&dev_kill_list);
 	rtnl_unlock();
 
@@ -618,6 +621,7 @@ static void cleanup_net(struct work_struct *work)
 		if (ops->exit_batch_rtnl)
 			ops->exit_batch_rtnl(&net_exit_list, &dev_kill_list);
 	}
+	default_device_exit_batch(&net_exit_list, &dev_kill_list);
 	unregister_netdevice_many(&dev_kill_list);
 	rtnl_unlock();
 
@@ -1214,6 +1218,7 @@ static void free_exit_list(struct pernet_operations *ops, struct list_head *net_
 
 		rtnl_lock();
 		ops->exit_batch_rtnl(net_exit_list, &dev_kill_list);
+		default_device_exit_batch(net_exit_list, &dev_kill_list);
 		unregister_netdevice_many(&dev_kill_list);
 		rtnl_unlock();
 	}
---8<---

  reply	other threads:[~2024-09-19  5:53 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17  1:07 [PATCH net-next v7 00/25] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 01/25] netlink: add NLA_POLICY_MAX_LEN macro Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 02/25] rtnetlink: don't crash on unregister if no dellink exists Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 03/25] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2024-09-19  5:52   ` Kuniyuki Iwashima [this message]
2024-09-19 11:57     ` Antonio Quartulli
2024-09-20  9:32       ` Kuniyuki Iwashima
2024-09-20  9:46         ` Antonio Quartulli
2024-09-22 20:51           ` Sergey Ryazanov
2024-09-23 12:51             ` Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 04/25] ovpn: add basic netlink support Antonio Quartulli
2024-09-17 13:23   ` Donald Hunter
2024-09-17 21:28     ` Antonio Quartulli
2024-09-18 10:07       ` Donald Hunter
2024-09-18 11:16         ` Antonio Quartulli
2024-09-22 22:24           ` Sergey Ryazanov
2024-09-25 11:36         ` Antonio Quartulli
2024-09-26 15:06           ` Donald Hunter
2024-09-27  7:52             ` Antonio Quartulli
2024-09-22 23:20   ` Sergey Ryazanov
2024-09-23 12:59     ` Antonio Quartulli
2024-09-24 22:10       ` Sergey Ryazanov
2024-09-25  0:01         ` Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 05/25] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 06/25] ovpn: implement interface creation/destruction via netlink Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 07/25] ovpn: keep carrier always on Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 08/25] ovpn: introduce the ovpn_peer object Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 09/25] ovpn: introduce the ovpn_socket object Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 10/25] ovpn: implement basic TX path (UDP) Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 11/25] ovpn: implement basic RX " Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 12/25] ovpn: implement packet processing Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 13/25] ovpn: store tunnel and transport statistics Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 14/25] ovpn: implement TCP transport Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 15/25] ovpn: implement multi-peer support Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 16/25] ovpn: implement peer lookup logic Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 17/25] ovpn: implement keepalive mechanism Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 18/25] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 19/25] ovpn: add support for peer floating Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 20/25] ovpn: implement peer add/dump/delete via netlink Antonio Quartulli
2024-09-23 14:36   ` Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 21/25] ovpn: implement key add/del/swap " Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 22/25] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 23/25] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 24/25] ovpn: add basic ethtool support Antonio Quartulli
2024-09-17  1:07 ` [PATCH net-next v7 25/25] testing/selftest: add test tool and scripts for ovpn module Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240919055259.17622-1-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=andrew@lunn.ch \
    --cc=antonio@openvpn.net \
    --cc=antony.antony@secunet.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).