Commit 505b9309 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-convert-exit_batch_rtnl-to-exit_rtnl'

Kuniyuki Iwashima says:

====================
net: Convert ->exit_batch_rtnl() to ->exit_rtnl().

While converting nexthop to per-netns RTNL, there are two blockers
to using rtnl_net_dereference(), flush_all_nexthops() and
__unregister_nexthop_notifier(), both of which are called from
->exit_batch_rtnl().

Instead of spreading __rtnl_net_lock() over each ->exit_batch_rtnl(),
we should convert all ->exit_batch_rtnl() to per-net ->exit_rtnl() and
run it under __rtnl_net_lock() because all ->exit_batch_rtnl() functions
do not have anything to factor out for batching.

Patch 1 & 2 factorise the undo mechanism against ->init() into a single
function, and Patch 3 adds ->exit_batch_rtnl().

Patch 4 ~ 13 convert all ->exit_batch_rtnl() users.

Patch 14 removes ->exit_batch_rtnl().

Later, we can convert pfcp and ppp to use ->exit_rtnl().

v1: https://lore.kernel.org/all/20250410022004.8668-1-kuniyu@amazon.com/
====================

Link: https://patch.msgid.link/20250411205258.63164-1-kuniyu@amazon.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents ceaceaf7 c57a9c50
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -777,27 +777,19 @@ static __net_init int bareudp_init_net(struct net *net)
	return 0;
}

static void bareudp_destroy_tunnels(struct net *net, struct list_head *head)
static void __net_exit bareudp_exit_rtnl_net(struct net *net,
					     struct list_head *dev_kill_list)
{
	struct bareudp_net *bn = net_generic(net, bareudp_net_id);
	struct bareudp_dev *bareudp, *next;

	list_for_each_entry_safe(bareudp, next, &bn->bareudp_list, next)
		unregister_netdevice_queue(bareudp->dev, head);
}

static void __net_exit bareudp_exit_batch_rtnl(struct list_head *net_list,
					       struct list_head *dev_kill_list)
{
	struct net *net;

	list_for_each_entry(net, net_list, exit_list)
		bareudp_destroy_tunnels(net, dev_kill_list);
		bareudp_dellink(bareudp->dev, dev_kill_list);
}

static struct pernet_operations bareudp_net_ops = {
	.init = bareudp_init_net,
	.exit_batch_rtnl = bareudp_exit_batch_rtnl,
	.exit_rtnl = bareudp_exit_rtnl_net,
	.id   = &bareudp_net_id,
	.size = sizeof(struct bareudp_net),
};
+9 −14
Original line number Diff line number Diff line
@@ -6558,7 +6558,7 @@ static int __net_init bond_net_init(struct net *net)

/* According to commit 69b0216ac255 ("bonding: fix bonding_masters
 * race condition in bond unloading") we need to remove sysfs files
 * before we remove our devices (done later in bond_net_exit_batch_rtnl())
 * before we remove our devices (done later in bond_net_exit_rtnl())
 */
static void __net_exit bond_net_pre_exit(struct net *net)
{
@@ -6567,25 +6567,20 @@ static void __net_exit bond_net_pre_exit(struct net *net)
	bond_destroy_sysfs(bn);
}

static void __net_exit bond_net_exit_batch_rtnl(struct list_head *net_list,
static void __net_exit bond_net_exit_rtnl(struct net *net,
					  struct list_head *dev_kill_list)
{
	struct bond_net *bn;
	struct net *net;

	/* Kill off any bonds created after unregistering bond rtnl ops */
	list_for_each_entry(net, net_list, exit_list) {
	struct bond_net *bn = net_generic(net, bond_net_id);
	struct bonding *bond, *tmp_bond;

		bn = net_generic(net, bond_net_id);
	/* Kill off any bonds created after unregistering bond rtnl ops */
	list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list)
		unregister_netdevice_queue(bond->dev, dev_kill_list);
}
}

/* According to commit 23fa5c2caae0 ("bonding: destroy proc directory
 * only after all bonds are gone") bond_destroy_proc_dir() is called
 * after bond_net_exit_batch_rtnl() has completed.
 * after bond_net_exit_rtnl() has completed.
 */
static void __net_exit bond_net_exit_batch(struct list_head *net_list)
{
@@ -6601,7 +6596,7 @@ static void __net_exit bond_net_exit_batch(struct list_head *net_list)
static struct pernet_operations bond_net_ops = {
	.init = bond_net_init,
	.pre_exit = bond_net_pre_exit,
	.exit_batch_rtnl = bond_net_exit_batch_rtnl,
	.exit_rtnl = bond_net_exit_rtnl,
	.exit_batch = bond_net_exit_batch,
	.id   = &bond_net_id,
	.size = sizeof(struct bond_net),
+4 −12
Original line number Diff line number Diff line
@@ -1946,22 +1946,14 @@ static __net_init int geneve_init_net(struct net *net)
	return 0;
}

static void geneve_destroy_tunnels(struct net *net, struct list_head *head)
static void __net_exit geneve_exit_rtnl_net(struct net *net,
					    struct list_head *dev_to_kill)
{
	struct geneve_net *gn = net_generic(net, geneve_net_id);
	struct geneve_dev *geneve, *next;

	list_for_each_entry_safe(geneve, next, &gn->geneve_list, next)
		geneve_dellink(geneve->dev, head);
}

static void __net_exit geneve_exit_batch_rtnl(struct list_head *net_list,
					      struct list_head *dev_to_kill)
{
	struct net *net;

	list_for_each_entry(net, net_list, exit_list)
		geneve_destroy_tunnels(net, dev_to_kill);
		geneve_dellink(geneve->dev, dev_to_kill);
}

static void __net_exit geneve_exit_net(struct net *net)
@@ -1973,7 +1965,7 @@ static void __net_exit geneve_exit_net(struct net *net)

static struct pernet_operations geneve_net_ops = {
	.init = geneve_init_net,
	.exit_batch_rtnl = geneve_exit_batch_rtnl,
	.exit_rtnl = geneve_exit_rtnl_net,
	.exit = geneve_exit_net,
	.id   = &geneve_net_id,
	.size = sizeof(struct geneve_net),
+7 −11
Original line number Diff line number Diff line
@@ -2475,23 +2475,19 @@ static int __net_init gtp_net_init(struct net *net)
	return 0;
}

static void __net_exit gtp_net_exit_batch_rtnl(struct list_head *net_list,
static void __net_exit gtp_net_exit_rtnl(struct net *net,
					 struct list_head *dev_to_kill)
{
	struct net *net;

	list_for_each_entry(net, net_list, exit_list) {
	struct gtp_net *gn = net_generic(net, gtp_net_id);
	struct gtp_dev *gtp, *gtp_next;

	list_for_each_entry_safe(gtp, gtp_next, &gn->gtp_dev_list, list)
		gtp_dellink(gtp->dev, dev_to_kill);
}
}

static struct pernet_operations gtp_net_ops = {
	.init	= gtp_net_init,
	.exit_batch_rtnl = gtp_net_exit_batch_rtnl,
	.exit_rtnl = gtp_net_exit_rtnl,
	.id	= &gtp_net_id,
	.size	= sizeof(struct gtp_net),
};
+7 −11
Original line number Diff line number Diff line
@@ -4966,20 +4966,16 @@ static void __net_exit vxlan_destroy_tunnels(struct vxlan_net *vn,
		vxlan_dellink(vxlan->dev, dev_to_kill);
}

static void __net_exit vxlan_exit_batch_rtnl(struct list_head *net_list,
static void __net_exit vxlan_exit_rtnl(struct net *net,
				       struct list_head *dev_to_kill)
{
	struct net *net;

	ASSERT_RTNL();
	list_for_each_entry(net, net_list, exit_list) {
	struct vxlan_net *vn = net_generic(net, vxlan_net_id);

		__unregister_nexthop_notifier(net, &vn->nexthop_notifier_block);
	ASSERT_RTNL_NET(net);

	__unregister_nexthop_notifier(net, &vn->nexthop_notifier_block);
	vxlan_destroy_tunnels(vn, dev_to_kill);
}
}

static void __net_exit vxlan_exit_net(struct net *net)
{
@@ -4992,7 +4988,7 @@ static void __net_exit vxlan_exit_net(struct net *net)

static struct pernet_operations vxlan_net_ops = {
	.init = vxlan_init_net,
	.exit_batch_rtnl = vxlan_exit_batch_rtnl,
	.exit_rtnl = vxlan_exit_rtnl,
	.exit = vxlan_exit_net,
	.id   = &vxlan_net_id,
	.size = sizeof(struct vxlan_net),
Loading