mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup.
@ 2011-12-16 10:51 Glauber Costa
  2011-12-16 10:52 ` [PATCH 2/2] net: fix compilation with !CONFIG_NET Glauber Costa
  2011-12-16 20:35 ` [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Glauber Costa @ 2011-12-16 10:51 UTC (permalink / raw)
  To: davem
  Cc: linux-kernel, kamezawa.hiroyu, netdev, eric.dumazet, cgroups,
	Glauber Costa, Stephen Rothwell, Randy Dunlap

We can't scan the proto_list to initialize sock cgroups, as it
holds a rwlock, and we also want to keep the code generic enough to
avoid calling the initialization functions of protocols directly,

Convert proto_list_lock into a mutex, so we can sleep and do the
necessary allocations. This lock is seldom taken, so there shouldn't
be any performance penalties associated with that

Signed-off-by: Glauber Costa <glommer@parallels.com>
CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com>
CC: David S. Miller <davem@davemloft.net>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: Randy Dunlap <rdunlap@xenotime.net>
---
 net/core/sock.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index 5a6a906..0c67fac 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -136,7 +136,7 @@
 #include <net/tcp.h>
 #endif
 
-static DEFINE_RWLOCK(proto_list_lock);
+static DEFINE_MUTEX(proto_list_mutex);
 static LIST_HEAD(proto_list);
 
 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
@@ -145,7 +145,7 @@ int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss)
 	struct proto *proto;
 	int ret = 0;
 
-	read_lock(&proto_list_lock);
+	mutex_lock(&proto_list_mutex);
 	list_for_each_entry(proto, &proto_list, node) {
 		if (proto->init_cgroup) {
 			ret = proto->init_cgroup(cgrp, ss);
@@ -154,13 +154,13 @@ int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss)
 		}
 	}
 
-	read_unlock(&proto_list_lock);
+	mutex_unlock(&proto_list_mutex);
 	return ret;
 out:
 	list_for_each_entry_continue_reverse(proto, &proto_list, node)
 		if (proto->destroy_cgroup)
 			proto->destroy_cgroup(cgrp, ss);
-	read_unlock(&proto_list_lock);
+	mutex_unlock(&proto_list_mutex);
 	return ret;
 }
 
@@ -168,11 +168,11 @@ void mem_cgroup_sockets_destroy(struct cgroup *cgrp, struct cgroup_subsys *ss)
 {
 	struct proto *proto;
 
-	read_lock(&proto_list_lock);
+	mutex_lock(&proto_list_mutex);
 	list_for_each_entry_reverse(proto, &proto_list, node)
 		if (proto->destroy_cgroup)
 			proto->destroy_cgroup(cgrp, ss);
-	read_unlock(&proto_list_lock);
+	mutex_unlock(&proto_list_mutex);
 }
 #endif
 
@@ -2479,10 +2479,10 @@ int proto_register(struct proto *prot, int alloc_slab)
 		}
 	}
 
-	write_lock(&proto_list_lock);
+	mutex_lock(&proto_list_mutex);
 	list_add(&prot->node, &proto_list);
 	assign_proto_idx(prot);
-	write_unlock(&proto_list_lock);
+	mutex_unlock(&proto_list_mutex);
 	return 0;
 
 out_free_timewait_sock_slab_name:
@@ -2505,10 +2505,10 @@ EXPORT_SYMBOL(proto_register);
 
 void proto_unregister(struct proto *prot)
 {
-	write_lock(&proto_list_lock);
+	mutex_lock(&proto_list_mutex);
 	release_proto_idx(prot);
 	list_del(&prot->node);
-	write_unlock(&proto_list_lock);
+	mutex_unlock(&proto_list_mutex);
 
 	if (prot->slab != NULL) {
 		kmem_cache_destroy(prot->slab);
@@ -2531,9 +2531,9 @@ EXPORT_SYMBOL(proto_unregister);
 
 #ifdef CONFIG_PROC_FS
 static void *proto_seq_start(struct seq_file *seq, loff_t *pos)
-	__acquires(proto_list_lock)
+	__acquires(proto_list_mutex)
 {
-	read_lock(&proto_list_lock);
+	mutex_lock(&proto_list_mutex);
 	return seq_list_start_head(&proto_list, *pos);
 }
 
@@ -2543,9 +2543,9 @@ static void *proto_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void proto_seq_stop(struct seq_file *seq, void *v)
-	__releases(proto_list_lock)
+	__releases(proto_list_mutex)
 {
-	read_unlock(&proto_list_lock);
+	mutex_unlock(&proto_list_mutex);
 }
 
 static char proto_method_implemented(const void *method)
-- 
1.7.6.4


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

* [PATCH 2/2] net: fix compilation with !CONFIG_NET
  2011-12-16 10:51 [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup Glauber Costa
@ 2011-12-16 10:52 ` Glauber Costa
  2011-12-16 20:35   ` David Miller
  2011-12-16 20:35 ` [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Glauber Costa @ 2011-12-16 10:52 UTC (permalink / raw)
  To: davem
  Cc: linux-kernel, kamezawa.hiroyu, netdev, eric.dumazet, cgroups,
	Glauber Costa, Stephen Rothwell

Reported-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Glauber Costa <glommer@parallels.com>
CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com>
CC: David S. Miller <davem@davemloft.net>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
---
 include/net/sock.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 6fe0dae..3144c79 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -66,8 +66,20 @@
 
 struct cgroup;
 struct cgroup_subsys;
+#ifdef CONFIG_NET
 int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss);
 void mem_cgroup_sockets_destroy(struct cgroup *cgrp, struct cgroup_subsys *ss);
+#else
+static inline
+int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss)
+{
+	return 0;
+}
+static inline
+void mem_cgroup_sockets_destroy(struct cgroup *cgrp, struct cgroup_subsys *ss)
+{
+}
+#endif
 /*
  * This structure really needs to be cleaned up.
  * Most of it is for TCP, and not used by any of
-- 
1.7.6.4


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

* Re: [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup.
  2011-12-16 10:51 [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup Glauber Costa
  2011-12-16 10:52 ` [PATCH 2/2] net: fix compilation with !CONFIG_NET Glauber Costa
@ 2011-12-16 20:35 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2011-12-16 20:35 UTC (permalink / raw)
  To: glommer
  Cc: linux-kernel, kamezawa.hiroyu, netdev, eric.dumazet, cgroups,
	sfr, rdunlap

From: Glauber Costa <glommer@parallels.com>
Date: Fri, 16 Dec 2011 14:51:59 +0400

> We can't scan the proto_list to initialize sock cgroups, as it
> holds a rwlock, and we also want to keep the code generic enough to
> avoid calling the initialization functions of protocols directly,
> 
> Convert proto_list_lock into a mutex, so we can sleep and do the
> necessary allocations. This lock is seldom taken, so there shouldn't
> be any performance penalties associated with that
> 
> Signed-off-by: Glauber Costa <glommer@parallels.com>

Applied.

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

* Re: [PATCH 2/2] net: fix compilation with !CONFIG_NET
  2011-12-16 10:52 ` [PATCH 2/2] net: fix compilation with !CONFIG_NET Glauber Costa
@ 2011-12-16 20:35   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2011-12-16 20:35 UTC (permalink / raw)
  To: glommer; +Cc: linux-kernel, kamezawa.hiroyu, netdev, eric.dumazet, cgroups, sfr

From: Glauber Costa <glommer@parallels.com>
Date: Fri, 16 Dec 2011 14:52:00 +0400

> Reported-by: Randy Dunlap <rdunlap@xenotime.net>
> Signed-off-by: Glauber Costa <glommer@parallels.com>

Applied.

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

end of thread, other threads:[~2011-12-16 20:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-16 10:51 [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup Glauber Costa
2011-12-16 10:52 ` [PATCH 2/2] net: fix compilation with !CONFIG_NET Glauber Costa
2011-12-16 20:35   ` David Miller
2011-12-16 20:35 ` [PATCH 1/2] net: fix sleeping while atomic problem in sock mem_cgroup David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®