netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netlink: switch net_ns only if net is not init_net
@ 2014-03-07 10:47 Gu Zheng
  2014-03-09 23:09 ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Gu Zheng @ 2014-03-07 10:47 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev, linux-kernel

Many netlink users create netlink sock in the init_net, and the
switching nes_ns(init_net-->net) is needless in this case. So here
we add a pre-check to avoid this.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
---
 net/netlink/af_netlink.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index fdf5135..e9e4be9 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2429,7 +2429,8 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
 		goto out_sock_release_nosk;
 
 	sk = sock->sk;
-	sk_change_net(sk, net);
+	if (!net_eq(net, &init_net))
+		sk_change_net(sk, net);
 
 	if (!cfg || cfg->groups < 32)
 		groups = 32;
-- 
1.7.7

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

* Re: [PATCH] netlink: switch net_ns only if net is not init_net
  2014-03-07 10:47 [PATCH] netlink: switch net_ns only if net is not init_net Gu Zheng
@ 2014-03-09 23:09 ` David Miller
  2014-03-10  1:11   ` Gu Zheng
  2014-03-10  1:57   ` [PATCH] net: add a pre-check of net_ns in sk_change_net() Gu Zheng
  0 siblings, 2 replies; 5+ messages in thread
From: David Miller @ 2014-03-09 23:09 UTC (permalink / raw)
  To: guz.fnst; +Cc: netdev, linux-kernel

From: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date: Fri, 07 Mar 2014 18:47:30 +0800

> Many netlink users create netlink sock in the init_net, and the
> switching nes_ns(init_net-->net) is needless in this case. So here
> we add a pre-check to avoid this.
> 
> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>

This check is more appropriately placed into sk_change_net() itself.

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

* Re: [PATCH] netlink: switch net_ns only if net is not init_net
  2014-03-09 23:09 ` David Miller
@ 2014-03-10  1:11   ` Gu Zheng
  2014-03-10  1:57   ` [PATCH] net: add a pre-check of net_ns in sk_change_net() Gu Zheng
  1 sibling, 0 replies; 5+ messages in thread
From: Gu Zheng @ 2014-03-10  1:11 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, linux-kernel

On 03/10/2014 07:09 AM, David Miller wrote:

> From: Gu Zheng <guz.fnst@cn.fujitsu.com>
> Date: Fri, 07 Mar 2014 18:47:30 +0800
> 
>> Many netlink users create netlink sock in the init_net, and the
>> switching nes_ns(init_net-->net) is needless in this case. So here
>> we add a pre-check to avoid this.
>>
>> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
> 
> This check is more appropriately placed into sk_change_net() itself.

Agree. I'll update it soon.

Regards,
Gu

> 

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

* [PATCH] net: add a pre-check of net_ns in sk_change_net()
  2014-03-09 23:09 ` David Miller
  2014-03-10  1:11   ` Gu Zheng
@ 2014-03-10  1:57   ` Gu Zheng
  2014-03-10 20:30     ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Gu Zheng @ 2014-03-10  1:57 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, linux-kernel

We do not need to switch the net_ns if the target net_ns the same
as the current one, so here we add a pre-check of net_ns to avoid
this as David suggested.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
---
 include/net/sock.h |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 5c3f7c3..9678569 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2252,8 +2252,12 @@ void sock_net_set(struct sock *sk, struct net *net)
  */
 static inline void sk_change_net(struct sock *sk, struct net *net)
 {
-	put_net(sock_net(sk));
-	sock_net_set(sk, hold_net(net));
+	struct net *current_net = sock_net(sk);
+
+	if (!net_eq(current_net, net)) {
+		put_net(current_net);
+		sock_net_set(sk, hold_net(net));
+	}
 }
 
 static inline struct sock *skb_steal_sock(struct sk_buff *skb)
-- 
1.7.7

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

* Re: [PATCH] net: add a pre-check of net_ns in sk_change_net()
  2014-03-10  1:57   ` [PATCH] net: add a pre-check of net_ns in sk_change_net() Gu Zheng
@ 2014-03-10 20:30     ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2014-03-10 20:30 UTC (permalink / raw)
  To: guz.fnst; +Cc: netdev, linux-kernel

From: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date: Mon, 10 Mar 2014 09:57:34 +0800

> We do not need to switch the net_ns if the target net_ns the same
> as the current one, so here we add a pre-check of net_ns to avoid
> this as David suggested.
> 
> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>

Applied to net-next, thank you.

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

end of thread, other threads:[~2014-03-10 20:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-07 10:47 [PATCH] netlink: switch net_ns only if net is not init_net Gu Zheng
2014-03-09 23:09 ` David Miller
2014-03-10  1:11   ` Gu Zheng
2014-03-10  1:57   ` [PATCH] net: add a pre-check of net_ns in sk_change_net() Gu Zheng
2014-03-10 20:30     ` 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).