From: Pavel Emelyanov <xemul@openvz.org>
To: Rusty Russell <rusty@rustcorp.com.au>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Module init call vs symbols exporting race?
Date: Tue, 06 Nov 2007 12:20:58 +0300 [thread overview]
Message-ID: <473031FA.2060707@openvz.org> (raw)
Hi.
I looked at the sys_init_module() and found that the ->init callback
for the module is called without the module_mutex held and *after*
the module's symbols are exported. Doesn't this create the race when
loading two modules in parallel? Like this.
Consider the first module to be (without any internal locking for
simplicity)
=== foo.c ===
static struct list_head foo_list;
void foo_register(struct list_head *elem)
{
list_add(elem, &foo_list);
}
EXPORT_SYMBOL(foo_register);
static int foo_init(void)
{
INIT_LIST_HEAD(&foo_list);
}
module_init(foo_init);
===
and the second one
=== bar.c ===
struct bar_struct {
struct list_head list;
...
} bar;
static int bar_init(void)
{
foo_register(&bar.list);
}
module_init(bar_init);
===
If I understand the sys_init_module() right, the following code
flow is possible:
1CPU 2CPU
sys_init_module(/* foo module */) sys_init_module(/* bar module */)
mutex_lock(&module_mutex);
load_module();
/* export the foo_init here */
mutex_unlock(&module_mutex);
mutex_lock(&module_mutex);
load_module();
/* resolve the foo_init here */
mutex_unlock(&mudule_mutex);
mod->init(); /* bar_init */
/*
* OOPS! The foo_list is not ready yet, because the foo_init
* is not called yet.
*/
mod->init(); /* foo_init... too late */
Is this analysis correct?
Thanks,
Pavel
next reply other threads:[~2007-11-06 9:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-06 9:20 Pavel Emelyanov [this message]
2007-11-06 12:41 ` Module init call vs symbols exporting race? Rusty Russell
2007-11-07 10:01 ` Jan Glauber
2007-11-08 2:10 ` Rusty Russell
2007-11-09 11:44 ` Jon Masters
2007-11-09 12:16 ` Jan Glauber
2007-11-10 7:27 ` Rusty Russell
2007-11-12 14:03 ` Jan Glauber
2007-11-09 16:06 ` Jan Glauber
2007-11-10 20:23 ` Andi Kleen
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=473031FA.2060707@openvz.org \
--to=xemul@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/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