Skip to content

Commit 0286b5e

Browse files
mhiramathitachirustyrussell
authored andcommitted
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: Masami Hiramatsu <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent 461e34a commit 0286b5e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

kernel/module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,9 +1850,10 @@ static void free_module(struct module *mod)
18501850
mutex_lock(&module_mutex);
18511851
/* Unlink carefully: kallsyms could be walking list. */
18521852
list_del_rcu(&mod->list);
1853-
/* Wait for RCU synchronizing before releasing mod->list. */
1854-
synchronize_rcu();
1853+
/* Remove this module from bug list, this uses list_del_rcu */
18551854
module_bug_cleanup(mod);
1855+
/* Wait for RCU synchronizing before releasing mod->list and buglist. */
1856+
synchronize_rcu();
18561857
mutex_unlock(&module_mutex);
18571858

18581859
/* This may be NULL, but that's OK */

lib/bug.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,22 @@ static LIST_HEAD(module_bug_list);
6464
static const struct bug_entry *module_find_bug(unsigned long bugaddr)
6565
{
6666
struct module *mod;
67+
const struct bug_entry *bug = NULL;
6768

68-
list_for_each_entry(mod, &module_bug_list, bug_list) {
69-
const struct bug_entry *bug = mod->bug_table;
69+
rcu_read_lock();
70+
list_for_each_entry_rcu(mod, &module_bug_list, bug_list) {
7071
unsigned i;
7172

73+
bug = mod->bug_table;
7274
for (i = 0; i < mod->num_bugs; ++i, ++bug)
7375
if (bugaddr == bug_addr(bug))
74-
return bug;
76+
goto out;
7577
}
76-
return NULL;
78+
bug = NULL;
79+
out:
80+
rcu_read_unlock();
81+
82+
return bug;
7783
}
7884

7985
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,
99105
* Strictly speaking this should have a spinlock to protect against
100106
* traversals, but since we only traverse on BUG()s, a spinlock
101107
* could potentially lead to deadlock and thus be counter-productive.
108+
* Thus, this uses RCU to safely manipulate the bug list, since BUG
109+
* must run in non-interruptive state.
102110
*/
103-
list_add(&mod->bug_list, &module_bug_list);
111+
list_add_rcu(&mod->bug_list, &module_bug_list);
104112
}
105113

106114
void module_bug_cleanup(struct module *mod)
107115
{
108-
list_del(&mod->bug_list);
116+
list_del_rcu(&mod->bug_list);
109117
}
110118

111119
#else

0 commit comments

Comments
 (0)