From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Subject: [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators
Date: Mon, 20 Aug 2007 16:26:02 -0400 [thread overview]
Message-ID: <20070820202646.555561265@polymtl.ca> (raw)
In-Reply-To: 20070820202600.116795129@polymtl.ca
[-- Attachment #1: module.c-sort-module-list.patch --]
[-- Type: text/plain, Size: 3510 bytes --]
A race that appears both in /proc/modules and in kallsyms: if, between the
seq file reads, the process is put to sleep and at this moment a module is
or removed from the module list, the listing will skip an amount of
modules/symbols corresponding to the amount of elements present in the unloaded
module, but at the current position in the list if the iteration is located
after the removed module.
The cleanest way I found to deal with this problem is to sort the module list.
We can then keep the old struct module * as the old iterator, knowing the it may
be removed between the seq file reads, but we only use it as "get next". If it
is not present in the module list, the next pointer will be used.
By doing this, removing a given module will now only fuzz the output related to
this specific module, not any random module anymore. Since modprobe uses
/proc/modules, it might be important to make sure multiple concurrent running
modprobes won't interfere with each other.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
kernel/module.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
Index: linux-2.6-lttng/kernel/module.c
===================================================================
--- linux-2.6-lttng.orig/kernel/module.c 2007-08-12 10:05:39.000000000 -0400
+++ linux-2.6-lttng/kernel/module.c 2007-08-12 10:22:05.000000000 -0400
@@ -63,8 +63,10 @@ extern int module_sysfs_initialized;
/* If this is set, the section belongs in the init part of the module */
#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
-/* List of modules, protected by module_mutex or preempt_disable
- * (add/delete uses stop_machine). */
+/*
+ * List of modules, protected by module_mutex or preempt_disable
+ * (add/delete uses stop_machine). Sorted by ascending list node address.
+ */
DEFINE_MUTEX(module_mutex);
LIST_HEAD(modules);
static DECLARE_MUTEX(notify_mutex);
@@ -2134,10 +2136,24 @@ nomodsectinfo:
/*
* link the module with the whole machine is stopped with interrupts off
* - this defends against kallsyms not taking locks
+ * We sort the modules by struct module pointer address to permit correct
+ * iteration over modules of, at least, kallsyms for preemptible operations,
+ * such as read(). Sorting by struct module pointer address is equivalent to
+ * sort by list node address.
*/
static int __link_module(void *_mod)
{
- struct module *mod = _mod;
+ struct module *mod = _mod, *iter;
+
+ list_for_each_entry_reverse(iter, &modules, list) {
+ BUG_ON(iter == mod); /* Should never be in the list twice */
+ if (iter < mod) {
+ /* We belong to the location right after iter. */
+ list_add(&mod->list, &iter->list);
+ return 0;
+ }
+ }
+ /* We should be added at the head of the list */
list_add(&mod->list, &modules);
return 0;
}
@@ -2402,12 +2418,14 @@ unsigned long module_kallsyms_lookup_nam
static void *m_start(struct seq_file *m, loff_t *pos)
{
mutex_lock(&module_mutex);
- return seq_list_start(&modules, *pos);
+ if (!*pos)
+ m->private = NULL;
+ return seq_sorted_list_start(&modules, m->private);
}
static void *m_next(struct seq_file *m, void *p, loff_t *pos)
{
- return seq_list_next(p, &modules, pos);
+ return seq_sorted_list_next(p, &modules, &m->private);
}
static void m_stop(struct seq_file *m, void *p)
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2007-08-20 20:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-20 20:26 [patch 0/2] Sort module list Mathieu Desnoyers
2007-08-20 20:26 ` [patch 1/2] Seq_file add support for sorted list Mathieu Desnoyers
2007-08-20 20:26 ` Mathieu Desnoyers [this message]
2007-08-21 0:08 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Rusty Russell
2007-08-24 15:45 ` Mathieu Desnoyers
2007-08-25 21:44 ` Rusty Russell
2007-08-25 21:53 ` Mathieu Desnoyers
-- strict thread matches above, loose matches on Subject: below --
2007-09-18 21:09 [patch 0/2] Sorted Module List for 2.6.23-rc6-mm1 Mathieu Desnoyers
2007-09-18 21:09 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-09-17 18:43 [patch 0/2] Sort module list Mathieu Desnoyers
2007-09-17 18:43 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-09-06 20:05 [patch 0/2] Sort module list for /proc/modules Mathieu Desnoyers
2007-09-06 20:05 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-08-27 16:02 [patch 0/2] Sort module list for /proc/modules seq file reads Mathieu Desnoyers
2007-08-27 16:02 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-08-12 15:08 [patch 0/2] Sorted seq_file Mathieu Desnoyers
2007-08-12 15:08 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
[not found] ` <20070815033945.GA13134@mail.ustc.edu.cn>
2007-08-15 3:39 ` Fengguang Wu
2007-08-15 4:18 ` Al Viro
[not found] ` <20070815063741.GB5175@mail.ustc.edu.cn>
2007-08-15 6:37 ` Fengguang Wu
2007-08-15 6:53 ` Al Viro
[not found] ` <20070815083645.GA6544@mail.ustc.edu.cn>
2007-08-15 8:36 ` Fengguang Wu
[not found] ` <20070815084625.GA18892@mail.ustc.edu.cn>
2007-08-15 8:46 ` Fengguang Wu
2007-08-18 15:56 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070820202646.555561265@polymtl.ca \
--to=mathieu.desnoyers@polymtl.ca \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox