Skip to contentSkip to conversation

inet: convert to exit_batch_rtnl

PATCH In review Eric Dumazet 2 participants 9 messages Feb 8, 2024 – Feb 9, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover inet: convert to exit_batch_rtnl

Even if these four modules exit_batch methods do not unregister devices, it is worth converting them to exit_batch_rtnl to save rtnl_lock()/rtnl_unlock() pairs in netns dismantles.

Eric Dumazet (4):
ip6mr: use exit_batch_rtnl method
ipv6: fib6: use exit_batch_rtnl method
ipmr: use exit_batch_rtnl method
ipv4: fib: use exit_batch_rtnl method

 net/ipv4/fib_frontend.c | 8 +++-----
 net/ipv4/ipmr.c         | 7 +++----
 net/ipv6/fib6_rules.c   | 7 +++----
 net/ipv6/ip6mr.c        | 7 +++----
 4 files changed, 12 insertions(+), 17 deletions(-)
Signature · 1 line
2.43.0.594.gd9cf4e227d-goog
#1 lore raw

PATCH 1/4 ip6mr: use exit_batch_rtnl method

Using exit_batch_rtnl method instead of exit_batch avoids one rtnl_lock()/rtnl_unlock() pair in netns dismantle.

---
 net/ipv6/ip6mr.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/ipv6/ip6mr.c +3 -4
index 9782c180fee646ab0fad7f0f911254b4b3a592c4..ed2cf29bc9d1bcddbf325860769138ce970f7f18 100644
@@ -1353,20 +1353,19 @@ static void __net_exit ip6mr_net_exit(struct net *net)
 	ip6mr_notifier_exit(net);
 }
 
-static void __net_exit ip6mr_net_exit_batch(struct list_head *net_list)
+static void __net_exit ip6mr_net_exit_batch_rtnl(struct list_head *net_list,
+						 struct list_head *dev_to_kill)
 {
 	struct net *net;
 
-	rtnl_lock();
 	list_for_each_entry(net, net_list, exit_list)
 		ip6mr_rules_exit(net);
-	rtnl_unlock();
 }
 
 static struct pernet_operations ip6mr_net_ops = {
 	.init = ip6mr_net_init,
 	.exit = ip6mr_net_exit,
-	.exit_batch = ip6mr_net_exit_batch,
+	.exit_batch_rtnl = ip6mr_net_exit_batch_rtnl,
 };
 
 int __init ip6_mr_init(void)
Signature · 1 line
2.43.0.594.gd9cf4e227d-goog
#2 lore raw

PATCH 2/4 ipv6: fib6: use exit_batch_rtnl method

In reply to Eric Dumazet

Using exit_batch_rtnl method instead of exit_batch avoids one rtnl_lock()/rtnl_unlock() pair in netns dismantle.

---
 net/ipv6/fib6_rules.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/ipv6/fib6_rules.c +3 -4
index 7523c4baef35e23d39e9537943593107a79ff551..44194332ee09f673d993271f2e1f278bd6f2c5a2 100644
@@ -493,21 +493,20 @@ static int __net_init fib6_rules_net_init(struct net *net)
 	goto out;
 }
 
-static void __net_exit fib6_rules_net_exit_batch(struct list_head *net_list)
+static void __net_exit fib6_rules_exit_batch_rtnl(struct list_head *net_list,
+						  struct list_head *dev_to_kill)
 {
 	struct net *net;
 
-	rtnl_lock();
 	list_for_each_entry(net, net_list, exit_list) {
 		fib_rules_unregister(net->ipv6.fib6_rules_ops);
 		cond_resched();
 	}
-	rtnl_unlock();
 }
 
 static struct pernet_operations fib6_rules_net_ops = {
 	.init = fib6_rules_net_init,
-	.exit_batch = fib6_rules_net_exit_batch,
+	.exit_batch_rtnl = fib6_rules_exit_batch_rtnl,
 };
 
 int __init fib6_rules_init(void)
Signature · 1 line
2.43.0.594.gd9cf4e227d-goog
#3 lore raw

PATCH 3/4 ipmr: use exit_batch_rtnl method

In reply to Eric Dumazet

Using exit_batch_rtnl method instead of exit_batch avoids one rtnl_lock()/rtnl_unlock() pair in netns dismantle.

---
 net/ipv4/ipmr.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/ipv4/ipmr.c +3 -4
index 3622298365105d99c0277f1c1616fb5fc63cdc2d..708c79c465e7212d24d2eb74165b227b9bde1c5f 100644
@@ -3119,20 +3119,19 @@ static void __net_exit ipmr_net_exit(struct net *net)
 	ipmr_notifier_exit(net);
 }
 
-static void __net_exit ipmr_net_exit_batch(struct list_head *net_list)
+static void __net_exit ipmr_exit_batch_rtnl(struct list_head *net_list,
+					    struct list_head *dev_to_kill)
 {
 	struct net *net;
 
-	rtnl_lock();
 	list_for_each_entry(net, net_list, exit_list)
 		ipmr_rules_exit(net);
-	rtnl_unlock();
 }
 
 static struct pernet_operations ipmr_net_ops = {
 	.init = ipmr_net_init,
 	.exit = ipmr_net_exit,
-	.exit_batch = ipmr_net_exit_batch,
+	.exit_batch = ipmr_exit_batch_rtnl,
 };
 
 int __init ip_mr_init(void)
Signature · 1 line
2.43.0.594.gd9cf4e227d-goog
#4 lore raw

Re: [PATCH net-next 3/4] ipmr: use exit_batch_rtnl method

Quoted 11 lines · Eric Dumazet

Using exit_batch_rtnl method instead of exit_batch avoids one rtnl_lock()/rtnl_unlock() pair in netns dismantle.

static struct pernet_operations ipmr_net_ops = {
.init = ipmr_net_init,
.exit = ipmr_net_exit,

net/ipv4/ipmr.c static void __net_exit ipmr_net_exit(struct net *net) · line 3135

Quoted 3 lines
net/ipv4/ipmr.c +1 -1
-       .exit_batch = ipmr_net_exit_batch,
+       .exit_batch = ipmr_exit_batch_rtnl,
 };

Oh well, I thought I fixed this error, I must have missed a step.

#5 lore raw

Re: [PATCH net-next 3/4] ipmr: use exit_batch_rtnl method

In reply to Eric Dumazet
kernel test robot noticed the following build errors:

Hi Eric,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Dumazet/ip6mr-use-exit_batch_rtnl-method/20240208-192057
base:   net-next/main
patch link:    https://lore.kernel.org/r/20240208111646.535705-4-edumazet%40google.com
patch subject: [PATCH net-next 3/4] ipmr: use exit_batch_rtnl method
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20240209/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240209/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> net/ipv4/ipmr.c:3134:23: error: initialization of 'void (*)(struct list_head *)' from incompatible pointer type 'void (*)(struct list_head *, struct list_head *)' [-Werror=incompatible-pointer-types]

3134 | .exit_batch = ipmr_exit_batch_rtnl,
| ^~~~~~~~~~~~~~~~~~~~
net/ipv4/ipmr.c:3134:23: note: (near initialization for 'ipmr_net_ops.exit_batch')
cc1: some warnings being treated as errors

vim +3134 net/ipv4/ipmr.c

3130
3131 static struct pernet_operations ipmr_net_ops = {
3132 .init = ipmr_net_init,
3133 .exit = ipmr_net_exit,

> 3134		.exit_batch = ipmr_exit_batch_rtnl,

3135 };
3136

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw

Re: [PATCH net-next 3/4] ipmr: use exit_batch_rtnl method

In reply to Eric Dumazet
kernel test robot noticed the following build errors:

Hi Eric,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Dumazet/ip6mr-use-exit_batch_rtnl-method/20240208-192057
base:   net-next/main
patch link:    https://lore.kernel.org/r/20240208111646.535705-4-edumazet%40google.com
patch subject: [PATCH net-next 3/4] ipmr: use exit_batch_rtnl method
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240209/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240209/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> net/ipv4/ipmr.c:3134:16: error: incompatible function pointer types initializing 'void (*)(struct list_head *)' with an expression of type 'void (struct list_head *, struct list_head *)' [-Wincompatible-function-pointer-types]

3134 | .exit_batch = ipmr_exit_batch_rtnl,
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.

vim +3134 net/ipv4/ipmr.c

3130
3131 static struct pernet_operations ipmr_net_ops = {
3132 .init = ipmr_net_init,
3133 .exit = ipmr_net_exit,

> 3134		.exit_batch = ipmr_exit_batch_rtnl,

3135 };
3136

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

PATCH 4/4 ipv4: fib: use exit_batch_rtnl method

In reply to Eric Dumazet

Using exit_batch_rtnl method instead of exit_batch avoids one rtnl_lock()/rtnl_unlock() pair in netns dismantle.

---
 net/ipv4/fib_frontend.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
net/ipv4/fib_frontend.c +3 -5
index 390f4be7f7bec20f33aa80e9bf12d5e2f3760562..b5f52639aeda382ac959d3207a18d0d088bcb297 100644
@@ -1631,21 +1631,19 @@ static void __net_exit fib_net_exit(struct net *net)
 	nl_fib_lookup_exit(net);
 }
 
-static void __net_exit fib_net_exit_batch(struct list_head *net_list)
+static void __net_exit fib_net_exit_batch_rtnl(struct list_head *net_list,
+					       struct list_head *dev_to_kill)
 {
 	struct net *net;
 
-	rtnl_lock();
 	list_for_each_entry(net, net_list, exit_list)
 		ip_fib_net_exit(net);
-
-	rtnl_unlock();
 }
 
 static struct pernet_operations fib_net_ops = {
 	.init = fib_net_init,
 	.exit = fib_net_exit,
-	.exit_batch = fib_net_exit_batch,
+	.exit_batch_rtnl = fib_net_exit_batch_rtnl,
 };
 
 void __init ip_fib_init(void)
Signature · 1 line
2.43.0.594.gd9cf4e227d-goog
#8 lore raw
In reply to Eric Dumazet
Quoted 5 lines · Eric Dumazet

Even if these four modules exit_batch methods do not unregister devices, it is worth converting them to exit_batch_rtnl to save rtnl_lock()/rtnl_unlock() pairs in netns dismantles.

Please ignore the whole series, more work is needed.