lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 15 Mar 2012 22:48:59 +0800
From:	Cong Wang <xiyou.wangcong@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	Andrew Morton <akpm@...ux-foundation.org>, Dennis1.Chen@....com,
	Cong Wang <xiyou.wangcong@...il.com>,
	Eric Dumazet <eric.dumazet@...il.com>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Rusty Russell <rusty@...tcorp.com.au>,
	Alexander Viro <viro@...iv.linux.org.uk>,
	NeilBrown <neilb@...e.de>, Kay Sievers <kay.sievers@...y.org>,
	Joe Perches <joe@...ches.com>, linux-fsdevel@...r.kernel.org
Subject: [PATCH 5/7] module: take rcu_read_lock_sched() for /proc read

In the seq file operations, it still hold module_mutex for just reading
the module list, switch to rcu_read_lock_sched() too.

A new function seq_list_start_rcu() is introduced for this.

Cc: Eric Dumazet <eric.dumazet@...il.com>
Cc: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Cc: Rusty Russell <rusty@...tcorp.com.au>
Signed-off-by: Cong Wang <xiyou.wangcong@...il.com>

---
 fs/seq_file.c            |   12 ++++++++++++
 include/linux/seq_file.h |    2 ++
 kernel/module.c          |    6 +++---
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 4023d6b..5b01e04 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -674,6 +674,18 @@ struct list_head *seq_list_start(struct list_head *head, loff_t pos)
 }
 EXPORT_SYMBOL(seq_list_start);
 
+struct list_head *seq_list_start_rcu(struct list_head *head, loff_t pos)
+{
+	struct list_head *lh = head;
+
+	list_for_each_continue_rcu(lh, head)
+		if (pos-- == 0)
+			return lh;
+
+	return NULL;
+}
+EXPORT_SYMBOL(seq_list_start_rcu);
+
 struct list_head *seq_list_start_head(struct list_head *head, loff_t pos)
 {
 	if (!pos)
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 44f1514..7848189 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -130,6 +130,8 @@ int seq_release_private(struct inode *, struct file *);
 
 extern struct list_head *seq_list_start(struct list_head *head,
 		loff_t pos);
+extern struct list_head *seq_list_start_rcu(struct list_head *head,
+		loff_t pos);
 extern struct list_head *seq_list_start_head(struct list_head *head,
 		loff_t pos);
 extern struct list_head *seq_list_next(void *v, struct list_head *head,
diff --git a/kernel/module.c b/kernel/module.c
index 73e1f95..06e7dc5 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3313,8 +3313,8 @@ static char *module_flags(struct module *mod, char *buf)
 /* Called by the /proc file system to return a list of modules. */
 static void *m_start(struct seq_file *m, loff_t *pos)
 {
-	mutex_lock(&module_mutex);
-	return seq_list_start(&modules, *pos);
+	rcu_read_lock_sched();
+	return seq_list_start_rcu(&modules, *pos);
 }
 
 static void *m_next(struct seq_file *m, void *p, loff_t *pos)
@@ -3324,7 +3324,7 @@ static void *m_next(struct seq_file *m, void *p, loff_t *pos)
 
 static void m_stop(struct seq_file *m, void *p)
 {
-	mutex_unlock(&module_mutex);
+	rcu_read_unlock_sched();
 }
 
 static int m_show(struct seq_file *m, void *p)
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ