netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update
@ 2019-02-23  7:28 Kefeng Wang
  2019-02-23  7:28 ` [PATCH net-next v2 1/3] ipv4: icmp: use icmp_sk_exit() Kefeng Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kefeng Wang @ 2019-02-23  7:28 UTC (permalink / raw)
  To: davem, netdev, eric.dumazet; +Cc: Kefeng Wang

v2:
- Add cover letter and user proper patch subject-prefix suggested-by Eric Dumazet

This patch series contains some small cleanup and update,
1) use icmp/v6_sk_exit when icmp_sk_init fails instead of open-code
2) use new percpu allocation interface for the ipv6.icmp_sk

Kefeng Wang (3):
  ipv4: icmp: use icmp_sk_exit()
  ipv6: icmp: use icmpv6_sk_exit()
  ipv6: icmp: use percpu allocation

 include/net/netns/ipv6.h |  2 +-
 net/ipv4/icmp.c          |  4 +---
 net/ipv6/icmp.c          | 32 ++++++++++++++------------------
 3 files changed, 16 insertions(+), 22 deletions(-)

-- 
2.20.1


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

* [PATCH net-next v2 1/3] ipv4: icmp: use icmp_sk_exit()
  2019-02-23  7:28 [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update Kefeng Wang
@ 2019-02-23  7:28 ` Kefeng Wang
  2019-02-23  7:28 ` [PATCH net-next v2 2/3] ipv6: icmp: use icmpv6_sk_exit() Kefeng Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2019-02-23  7:28 UTC (permalink / raw)
  To: davem, netdev, eric.dumazet; +Cc: Kefeng Wang

Simply use icmp_sk_exit() when inet_ctl_sock_create() fail in icmp_sk_init().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 net/ipv4/icmp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 065997f414e6..364cfe5e414b 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -1245,9 +1245,7 @@ static int __net_init icmp_sk_init(struct net *net)
 	return 0;
 
 fail:
-	for_each_possible_cpu(i)
-		inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.icmp_sk, i));
-	free_percpu(net->ipv4.icmp_sk);
+	icmp_sk_exit(net);
 	return err;
 }
 
-- 
2.20.1


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

* [PATCH net-next v2 2/3] ipv6: icmp: use icmpv6_sk_exit()
  2019-02-23  7:28 [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update Kefeng Wang
  2019-02-23  7:28 ` [PATCH net-next v2 1/3] ipv4: icmp: use icmp_sk_exit() Kefeng Wang
@ 2019-02-23  7:28 ` Kefeng Wang
  2019-02-23  7:28 ` [PATCH net-next v2 3/3] ipv6: icmp: use percpu allocation Kefeng Wang
  2019-02-25  5:57 ` [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2019-02-23  7:28 UTC (permalink / raw)
  To: davem, netdev, eric.dumazet; +Cc: Kefeng Wang

Simply use icmpv6_sk_exit() when inet_ctl_sock_create() fail
in icmpv6_sk_init().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 net/ipv6/icmp.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index bbcdfd299692..af520014def5 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -953,10 +953,19 @@ void icmpv6_flow_init(struct sock *sk, struct flowi6 *fl6,
 	security_sk_classify_flow(sk, flowi6_to_flowi(fl6));
 }
 
+static void __net_exit icmpv6_sk_exit(struct net *net)
+{
+	int i;
+
+	for_each_possible_cpu(i)
+		inet_ctl_sock_destroy(net->ipv6.icmp_sk[i]);
+	kfree(net->ipv6.icmp_sk);
+}
+
 static int __net_init icmpv6_sk_init(struct net *net)
 {
 	struct sock *sk;
-	int err, i, j;
+	int err, i;
 
 	net->ipv6.icmp_sk =
 		kcalloc(nr_cpu_ids, sizeof(struct sock *), GFP_KERNEL);
@@ -982,22 +991,10 @@ static int __net_init icmpv6_sk_init(struct net *net)
 	return 0;
 
  fail:
-	for (j = 0; j < i; j++)
-		inet_ctl_sock_destroy(net->ipv6.icmp_sk[j]);
-	kfree(net->ipv6.icmp_sk);
+	icmpv6_sk_exit(net);
 	return err;
 }
 
-static void __net_exit icmpv6_sk_exit(struct net *net)
-{
-	int i;
-
-	for_each_possible_cpu(i) {
-		inet_ctl_sock_destroy(net->ipv6.icmp_sk[i]);
-	}
-	kfree(net->ipv6.icmp_sk);
-}
-
 static struct pernet_operations icmpv6_sk_ops = {
 	.init = icmpv6_sk_init,
 	.exit = icmpv6_sk_exit,
-- 
2.20.1


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

* [PATCH net-next v2 3/3] ipv6: icmp: use percpu allocation
  2019-02-23  7:28 [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update Kefeng Wang
  2019-02-23  7:28 ` [PATCH net-next v2 1/3] ipv4: icmp: use icmp_sk_exit() Kefeng Wang
  2019-02-23  7:28 ` [PATCH net-next v2 2/3] ipv6: icmp: use icmpv6_sk_exit() Kefeng Wang
@ 2019-02-23  7:28 ` Kefeng Wang
  2019-02-25  5:57 ` [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2019-02-23  7:28 UTC (permalink / raw)
  To: davem, netdev, eric.dumazet; +Cc: Kefeng Wang

Use percpu allocation for the ipv6.icmp_sk.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/net/netns/ipv6.h |  2 +-
 net/ipv6/icmp.c          | 11 +++++------
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index ef1ed529f33c..b028a1dc150d 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -83,7 +83,7 @@ struct netns_ipv6 {
 	struct fib6_table       *fib6_local_tbl;
 	struct fib_rules_ops    *fib6_rules_ops;
 #endif
-	struct sock		**icmp_sk;
+	struct sock * __percpu	*icmp_sk;
 	struct sock             *ndisc_sk;
 	struct sock             *tcp_sk;
 	struct sock             *igmp_sk;
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index af520014def5..802faa2fcc0e 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -81,7 +81,7 @@
  */
 static inline struct sock *icmpv6_sk(struct net *net)
 {
-	return net->ipv6.icmp_sk[smp_processor_id()];
+	return *this_cpu_ptr(net->ipv6.icmp_sk);
 }
 
 static int icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
@@ -958,8 +958,8 @@ static void __net_exit icmpv6_sk_exit(struct net *net)
 	int i;
 
 	for_each_possible_cpu(i)
-		inet_ctl_sock_destroy(net->ipv6.icmp_sk[i]);
-	kfree(net->ipv6.icmp_sk);
+		inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv6.icmp_sk, i));
+	free_percpu(net->ipv6.icmp_sk);
 }
 
 static int __net_init icmpv6_sk_init(struct net *net)
@@ -967,8 +967,7 @@ static int __net_init icmpv6_sk_init(struct net *net)
 	struct sock *sk;
 	int err, i;
 
-	net->ipv6.icmp_sk =
-		kcalloc(nr_cpu_ids, sizeof(struct sock *), GFP_KERNEL);
+	net->ipv6.icmp_sk = alloc_percpu(struct sock *);
 	if (!net->ipv6.icmp_sk)
 		return -ENOMEM;
 
@@ -981,7 +980,7 @@ static int __net_init icmpv6_sk_init(struct net *net)
 			goto fail;
 		}
 
-		net->ipv6.icmp_sk[i] = sk;
+		*per_cpu_ptr(net->ipv6.icmp_sk, i) = sk;
 
 		/* Enough space for 2 64K ICMP packets, including
 		 * sk_buff struct overhead.
-- 
2.20.1


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

* Re: [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update
  2019-02-23  7:28 [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update Kefeng Wang
                   ` (2 preceding siblings ...)
  2019-02-23  7:28 ` [PATCH net-next v2 3/3] ipv6: icmp: use percpu allocation Kefeng Wang
@ 2019-02-25  5:57 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-02-25  5:57 UTC (permalink / raw)
  To: wangkefeng.wang; +Cc: netdev, eric.dumazet

From: Kefeng Wang <wangkefeng.wang@huawei.com>
Date: Sat, 23 Feb 2019 15:28:25 +0800

> v2:
> - Add cover letter and user proper patch subject-prefix suggested-by Eric Dumazet
> 
> This patch series contains some small cleanup and update,
> 1) use icmp/v6_sk_exit when icmp_sk_init fails instead of open-code
> 2) use new percpu allocation interface for the ipv6.icmp_sk

Series applied, thanks.

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

end of thread, other threads:[~2019-02-25  5:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-23  7:28 [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update Kefeng Wang
2019-02-23  7:28 ` [PATCH net-next v2 1/3] ipv4: icmp: use icmp_sk_exit() Kefeng Wang
2019-02-23  7:28 ` [PATCH net-next v2 2/3] ipv6: icmp: use icmpv6_sk_exit() Kefeng Wang
2019-02-23  7:28 ` [PATCH net-next v2 3/3] ipv6: icmp: use percpu allocation Kefeng Wang
2019-02-25  5:57 ` [PATCH net-next v2 0/3] ipv4/v6: icmp: small cleanup and update David Miller

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).