netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] netns: correctly use per-netns ipv4 sysctl_tcp_mem
@ 2012-07-12  9:33 Huang Qiang
  2012-07-12 11:17 ` Lin Ming
       [not found] ` <4FFE99EE.70003-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Huang Qiang @ 2012-07-12  9:33 UTC (permalink / raw)
  To: David Miller, glommer; +Cc: netdev, containers, yangzhenzhang

From: Yang Zhenzhang <yangzhenzhang@huawei.com>

Now, kernel allows each net namespace to independently set up its levels
for tcp memory pressure thresholds.

But it seems there is a bug, as using the following steps:

[root@host socket]# lxc-start -n test -f config /bin/bash
[root@net-test socket]# ip route add default via 192.168.58.2
[root@net-test socket]# echo 0 0 0 > /proc/sys/net/ipv4/tcp_mem
[root@net-test socket]# scp root@192.168.58.174:/home/tcp_mem_test .

and it still can transport the "tcp_mem_test" file which we hope it
would not.

It's because inet_init() (net/ipv4/af_inet.c)initialize the tcp_prot.sysctl_mem:
tcp_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem;

So when the protocal is TCP, sk->sk_prot->sysctl_mem(following code)
always use the ipv4 sysctl_tcp_mem of init_net namespace rather than
it's own net namespace.
This patch simply set "prot" equal to net->ipv4.sysctl_tcp_mem when
the protocol type is TCP.

Signed-off-by: Yang Zhenzhang <yangzhenzhang@huawei.com>
Signed-off-by: Huang Qiang <h.huangqiang@huawei.com>
---
 include/net/sock.h |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 4a45216..ee85d8b 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -59,6 +59,7 @@
 #include <linux/static_key.h>
 #include <linux/aio.h>
 #include <linux/sched.h>
+#include <linux/in.h>

 #include <linux/filter.h>
 #include <linux/rculist_nulls.h>
@@ -1060,14 +1061,6 @@ static inline void sk_enter_memory_pressure(struct sock *sk)
 	sk->sk_prot->enter_memory_pressure(sk);
 }

-static inline long sk_prot_mem_limits(const struct sock *sk, int index)
-{
-	long *prot = sk->sk_prot->sysctl_mem;
-	if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
-		prot = sk->sk_cgrp->sysctl_mem;
-	return prot[index];
-}
-
 static inline void memcg_memory_allocated_add(struct cg_proto *prot,
 					      unsigned long amt,
 					      int *parent_status)
@@ -2150,6 +2143,21 @@ static inline void sk_change_net(struct sock *sk, struct net *net)
 	sock_net_set(sk, hold_net(net));
 }

+static inline long sk_prot_mem_limits(const struct sock *sk, int index)
+{
+	long *prot = sk->sk_prot->sysctl_mem;
+
+	if (sk->sk_protocol == IPPROTO_TCP) {
+		struct net *net = sock_net(sk);
+		prot = net->ipv4.sysctl_tcp_mem;
+	}
+
+	if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
+		prot = sk->sk_cgrp->sysctl_mem;
+
+	return prot[index];
+}
+
 static inline struct sock *skb_steal_sock(struct sk_buff *skb)
 {
 	if (unlikely(skb->sk)) {
-- 
1.7.1

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

* Re: [PATCH v2] netns: correctly use per-netns ipv4 sysctl_tcp_mem
  2012-07-12  9:33 [PATCH v2] netns: correctly use per-netns ipv4 sysctl_tcp_mem Huang Qiang
@ 2012-07-12 11:17 ` Lin Ming
       [not found] ` <4FFE99EE.70003-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Lin Ming @ 2012-07-12 11:17 UTC (permalink / raw)
  To: Huang Qiang; +Cc: David Miller, glommer, netdev, containers, yangzhenzhang

On Thu, Jul 12, 2012 at 5:33 PM, Huang Qiang <h.huangqiang@huawei.com> wrote:
> From: Yang Zhenzhang <yangzhenzhang@huawei.com>
>
> Now, kernel allows each net namespace to independently set up its levels
> for tcp memory pressure thresholds.
>
> But it seems there is a bug, as using the following steps:
>
> [root@host socket]# lxc-start -n test -f config /bin/bash
> [root@net-test socket]# ip route add default via 192.168.58.2
> [root@net-test socket]# echo 0 0 0 > /proc/sys/net/ipv4/tcp_mem
> [root@net-test socket]# scp root@192.168.58.174:/home/tcp_mem_test .
>
> and it still can transport the "tcp_mem_test" file which we hope it
> would not.
>
> It's because inet_init() (net/ipv4/af_inet.c)initialize the tcp_prot.sysctl_mem:
> tcp_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem;
>
> So when the protocal is TCP, sk->sk_prot->sysctl_mem(following code)

s/protocal/protocol/

> always use the ipv4 sysctl_tcp_mem of init_net namespace rather than
> it's own net namespace.
> This patch simply set "prot" equal to net->ipv4.sysctl_tcp_mem when
> the protocol type is TCP.
>
> Signed-off-by: Yang Zhenzhang <yangzhenzhang@huawei.com>
> Signed-off-by: Huang Qiang <h.huangqiang@huawei.com>

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

* Re: [PATCH v2] netns: correctly use per-netns ipv4 sysctl_tcp_mem
       [not found] ` <4FFE99EE.70003-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2012-07-18 16:41   ` David Miller
  2012-07-19  2:29     ` Huang Qiang
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2012-07-18 16:41 UTC (permalink / raw)
  To: h.huangqiang-hv44wF8Li93QT0dZR+AlfA
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

From: Huang Qiang <h.huangqiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Date: Thu, 12 Jul 2012 17:33:34 +0800

> From: Yang Zhenzhang <yangzhenzhang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> 
> Now, kernel allows each net namespace to independently set up its levels
> for tcp memory pressure thresholds.
> 
> But it seems there is a bug, as using the following steps:
> 
> [root@host socket]# lxc-start -n test -f config /bin/bash
> [root@net-test socket]# ip route add default via 192.168.58.2
> [root@net-test socket]# echo 0 0 0 > /proc/sys/net/ipv4/tcp_mem
> [root@net-test socket]# scp root-Q0ErXNX1RuabR28l3DCWlg@public.gmane.org:/home/tcp_mem_test .
> 
> and it still can transport the "tcp_mem_test" file which we hope it
> would not.
> 
> It's because inet_init() (net/ipv4/af_inet.c)initialize the tcp_prot.sysctl_mem:
> tcp_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem;
> 
> So when the protocal is TCP, sk->sk_prot->sysctl_mem(following code)
> always use the ipv4 sysctl_tcp_mem of init_net namespace rather than
> it's own net namespace.
> This patch simply set "prot" equal to net->ipv4.sysctl_tcp_mem when
> the protocol type is TCP.
> 
> Signed-off-by: Yang Zhenzhang <yangzhenzhang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Huang Qiang <h.huangqiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

This patch doesn't apply cleanly to net-next, please respin it.

Thank you.

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

* Re: [PATCH v2] netns: correctly use per-netns ipv4 sysctl_tcp_mem
  2012-07-18 16:41   ` David Miller
@ 2012-07-19  2:29     ` Huang Qiang
  0 siblings, 0 replies; 4+ messages in thread
From: Huang Qiang @ 2012-07-19  2:29 UTC (permalink / raw)
  To: David Miller; +Cc: glommer, netdev, containers, yangzhenzhang

On 2012-7-19 0:41, David Miller wrote:

> From: Huang Qiang <h.huangqiang@huawei.com>
> Date: Thu, 12 Jul 2012 17:33:34 +0800
> 
>> From: Yang Zhenzhang <yangzhenzhang@huawei.com>
>>
>> Now, kernel allows each net namespace to independently set up its levels
>> for tcp memory pressure thresholds.
>>
>> But it seems there is a bug, as using the following steps:
>>
>> [root@host socket]# lxc-start -n test -f config /bin/bash
>> [root@net-test socket]# ip route add default via 192.168.58.2
>> [root@net-test socket]# echo 0 0 0 > /proc/sys/net/ipv4/tcp_mem
>> [root@net-test socket]# scp root@192.168.58.174:/home/tcp_mem_test .
>>
>> and it still can transport the "tcp_mem_test" file which we hope it
>> would not.
>>
>> It's because inet_init() (net/ipv4/af_inet.c)initialize the tcp_prot.sysctl_mem:
>> tcp_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem;
>>
>> So when the protocal is TCP, sk->sk_prot->sysctl_mem(following code)
>> always use the ipv4 sysctl_tcp_mem of init_net namespace rather than
>> it's own net namespace.
>> This patch simply set "prot" equal to net->ipv4.sysctl_tcp_mem when
>> the protocol type is TCP.
>>
>> Signed-off-by: Yang Zhenzhang <yangzhenzhang@huawei.com>
>> Signed-off-by: Huang Qiang <h.huangqiang@huawei.com>
> 
> This patch doesn't apply cleanly to net-next, please respin it.
> 
> Thank you.

Ok, I will send patch v3 for net-next. Thank you!

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

end of thread, other threads:[~2012-07-19  2:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-12  9:33 [PATCH v2] netns: correctly use per-netns ipv4 sysctl_tcp_mem Huang Qiang
2012-07-12 11:17 ` Lin Ming
     [not found] ` <4FFE99EE.70003-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-07-18 16:41   ` David Miller
2012-07-19  2:29     ` Huang Qiang

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