Messages in this thread Patch in this message | | | From | Cong Wang <> | Subject | [PATCH 5/7] module: take rcu_read_lock_sched() for /proc read | Date | Thu, 15 Mar 2012 22:48:59 +0800 |
| |
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@gmail.com> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.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
| |