Skip to contentSkip to conversation

net: ipv6: use the new fib6_nh_release_dsts helper in fib6_nh_release

PATCH Superseded Nikolay Aleksandrov 4 participants 5 messages Nov 29, 2021 – Nov 30, 2021

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

PATCH 1/1 net: ipv6: use the new fib6_nh_release_dsts helper in fib6_nh_release

From: Nikolay Aleksandrov <[email protected]>

We can remove a bit of code duplication by reusing the new fib6_nh_release_dsts helper in fib6_nh_release. Their only difference is that fib6_nh_release's version doesn't use atomic operation to swap the pointers because it assumes the fib6_nh is no longer visible, while fib6_nh_release_dsts can be used anywhere.

---
 net/ipv6/route.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)
net/ipv6/route.c +2 -17
index 62f1e16eea2b..b44438b9a030 100644
@@ -3656,24 +3656,9 @@ void fib6_nh_release(struct fib6_nh *fib6_nh)
 
 	rcu_read_unlock();
 
-	if (fib6_nh->rt6i_pcpu) {
-		int cpu;
-
-		for_each_possible_cpu(cpu) {
-			struct rt6_info **ppcpu_rt;
-			struct rt6_info *pcpu_rt;
-
-			ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);
-			pcpu_rt = *ppcpu_rt;
-			if (pcpu_rt) {
-				dst_dev_put(&pcpu_rt->dst);
-				dst_release(&pcpu_rt->dst);
-				*ppcpu_rt = NULL;
-			}
-		}
-
+	fib6_nh_release_dsts(fib6_nh);
+	if (fib6_nh->rt6i_pcpu)
 		free_percpu(fib6_nh->rt6i_pcpu);
-	}
 
 	fib_nh_common_release(&fib6_nh->nh_common);
 }
Signature · 1 line
2.31.1
#1 lore raw
Quoted 30 lines · Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>

We can remove a bit of code duplication by reusing the new fib6_nh_release_dsts helper in fib6_nh_release. Their only difference is that fib6_nh_release's version doesn't use atomic operation to swap the pointers because it assumes the fib6_nh is no longer visible, while fib6_nh_release_dsts can be used anywhere.

---
 net/ipv6/route.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)
net/ipv6/route.c +0 -8
index 62f1e16eea2b..b44438b9a030 100644
@@ -3656,24 +3656,9 @@ void fib6_nh_release(struct fib6_nh *fib6_nh)
 
 	rcu_read_unlock();
 
-	if (fib6_nh->rt6i_pcpu) {
-		int cpu;
-
-		for_each_possible_cpu(cpu) {
-			struct rt6_info **ppcpu_rt;
-			struct rt6_info *pcpu_rt;
-
-			ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);

net/ipv6/route.c void fib6_nh_release(struct fib6_nh *fib6_nh) · line 3660

Quoted 10 lines
net/ipv6/route.c +2 -8
-			pcpu_rt = *ppcpu_rt;
-			if (pcpu_rt) {
-				dst_dev_put(&pcpu_rt->dst);
-				dst_release(&pcpu_rt->dst);
-				*ppcpu_rt = NULL;
-			}
-		}
-
+	fib6_nh_release_dsts(fib6_nh);
+	if (fib6_nh->rt6i_pcpu)

Actually I can even drop the conditional here, free_percpu() is a noop if called with NULL. Will respin in a few..

#2 lore raw

PATCH v2 1/1 net: ipv6: use the new fib6_nh_release_dsts helper in fib6_nh_release

From: Nikolay Aleksandrov <[email protected]>

We can remove a bit of code duplication by reusing the new fib6_nh_release_dsts helper in fib6_nh_release. Their only difference is that fib6_nh_release's version doesn't use atomic operation to swap the pointers because it assumes the fib6_nh is no longer visible, while fib6_nh_release_dsts can be used anywhere.

---
v2: no need to check for NULL rt6i_pcpu before calling free_percpu

 net/ipv6/route.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
net/ipv6/route.c +2 -18
index 62f1e16eea2b..f0d29fcb2094 100644
@@ -3656,24 +3656,8 @@ void fib6_nh_release(struct fib6_nh *fib6_nh)
 
 	rcu_read_unlock();
 
-	if (fib6_nh->rt6i_pcpu) {
-		int cpu;
-
-		for_each_possible_cpu(cpu) {
-			struct rt6_info **ppcpu_rt;
-			struct rt6_info *pcpu_rt;
-
-			ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);
-			pcpu_rt = *ppcpu_rt;
-			if (pcpu_rt) {
-				dst_dev_put(&pcpu_rt->dst);
-				dst_release(&pcpu_rt->dst);
-				*ppcpu_rt = NULL;
-			}
-		}
-
-		free_percpu(fib6_nh->rt6i_pcpu);
-	}
+	fib6_nh_release_dsts(fib6_nh);
+	free_percpu(fib6_nh->rt6i_pcpu);
 
 	fib_nh_common_release(&fib6_nh->nh_common);
 }
Signature · 1 line
2.31.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 8 lines · Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>

We can remove a bit of code duplication by reusing the new fib6_nh_release_dsts helper in fib6_nh_release. Their only difference is that fib6_nh_release's version doesn't use atomic operation to swap the pointers because it assumes the fib6_nh is no longer visible, while fib6_nh_release_dsts can be used anywhere.

Quoted 8 lines

---
v2: no need to check for NULL rt6i_pcpu before calling free_percpu

 net/ipv6/route.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
#4 lore raw
In reply to Nikolay Aleksandrov
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Mon, 29 Nov 2021 17:44:11 +0200 you wrote:

From: Nikolay Aleksandrov <[email protected]>

We can remove a bit of code duplication by reusing the new fib6_nh_release_dsts helper in fib6_nh_release. Their only difference is that fib6_nh_release's version doesn't use atomic operation to swap the pointers because it assumes the fib6_nh is no longer visible, while fib6_nh_release_dsts can be used anywhere.

[...]

Here is the summary with links:
- [net-next,v2] net: ipv6: use the new fib6_nh_release_dsts helper in fib6_nh_release

    https://git.kernel.org/netdev/net-next/c/613080506665

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html