Commit 0286b5ea authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Rusty Russell

lib/bug: Use RCU list ops for module_bug_list

Actually since module_bug_list should be used in BUG context,
we may not need this. But for someone who want to use this
from normal context, this makes module_bug_list an RCU list.
Signed-off-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 461e34ae
...@@ -1850,9 +1850,10 @@ static void free_module(struct module *mod) ...@@ -1850,9 +1850,10 @@ static void free_module(struct module *mod)
mutex_lock(&module_mutex); mutex_lock(&module_mutex);
/* Unlink carefully: kallsyms could be walking list. */ /* Unlink carefully: kallsyms could be walking list. */
list_del_rcu(&mod->list); list_del_rcu(&mod->list);
/* Wait for RCU synchronizing before releasing mod->list. */ /* Remove this module from bug list, this uses list_del_rcu */
synchronize_rcu();
module_bug_cleanup(mod); module_bug_cleanup(mod);
/* Wait for RCU synchronizing before releasing mod->list and buglist. */
synchronize_rcu();
mutex_unlock(&module_mutex); mutex_unlock(&module_mutex);
/* This may be NULL, but that's OK */ /* This may be NULL, but that's OK */
......
...@@ -64,16 +64,22 @@ static LIST_HEAD(module_bug_list); ...@@ -64,16 +64,22 @@ static LIST_HEAD(module_bug_list);
static const struct bug_entry *module_find_bug(unsigned long bugaddr) static const struct bug_entry *module_find_bug(unsigned long bugaddr)
{ {
struct module *mod; struct module *mod;
const struct bug_entry *bug = NULL;
list_for_each_entry(mod, &module_bug_list, bug_list) { rcu_read_lock();
const struct bug_entry *bug = mod->bug_table; list_for_each_entry_rcu(mod, &module_bug_list, bug_list) {
unsigned i; unsigned i;
bug = mod->bug_table;
for (i = 0; i < mod->num_bugs; ++i, ++bug) for (i = 0; i < mod->num_bugs; ++i, ++bug)
if (bugaddr == bug_addr(bug)) if (bugaddr == bug_addr(bug))
return bug; goto out;
} }
return NULL; bug = NULL;
out:
rcu_read_unlock();
return bug;
} }
void module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, void module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
...@@ -99,13 +105,15 @@ void module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, ...@@ -99,13 +105,15 @@ void module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
* Strictly speaking this should have a spinlock to protect against * Strictly speaking this should have a spinlock to protect against
* traversals, but since we only traverse on BUG()s, a spinlock * traversals, but since we only traverse on BUG()s, a spinlock
* could potentially lead to deadlock and thus be counter-productive. * could potentially lead to deadlock and thus be counter-productive.
* Thus, this uses RCU to safely manipulate the bug list, since BUG
* must run in non-interruptive state.
*/ */
list_add(&mod->bug_list, &module_bug_list); list_add_rcu(&mod->bug_list, &module_bug_list);
} }
void module_bug_cleanup(struct module *mod) void module_bug_cleanup(struct module *mod)
{ {
list_del(&mod->bug_list); list_del_rcu(&mod->bug_list);
} }
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment