Skip to content

Commit f013692

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
module: Use RCU in find_kallsyms_symbol().
The modules list and module::kallsyms can be accessed under RCU assumption. Use rcu_dereference() to reference the kallsyms pointer in find_kallsyms_symbol(). Use a RCU section instead of preempt_disable in callers of find_kallsyms_symbol(). Keep the preempt-disable in module_address_lookup() due to __module_address(). Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Pavlu <[email protected]>
1 parent 039de46 commit f013692

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

kernel/module/kallsyms.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static const char *find_kallsyms_symbol(struct module *mod,
257257
{
258258
unsigned int i, best = 0;
259259
unsigned long nextval, bestval;
260-
struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
260+
struct mod_kallsyms *kallsyms = rcu_dereference(mod->kallsyms);
261261
struct module_memory *mod_mem;
262262

263263
/* At worse, next value is at end of module */
@@ -329,6 +329,7 @@ int module_address_lookup(unsigned long addr,
329329
int ret = 0;
330330
struct module *mod;
331331

332+
guard(rcu)();
332333
preempt_disable();
333334
mod = __module_address(addr);
334335
if (mod) {
@@ -356,7 +357,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
356357
{
357358
struct module *mod;
358359

359-
preempt_disable();
360+
guard(rcu)();
360361
list_for_each_entry_rcu(mod, &modules, list) {
361362
if (mod->state == MODULE_STATE_UNFORMED)
362363
continue;
@@ -368,12 +369,10 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
368369
goto out;
369370

370371
strscpy(symname, sym, KSYM_NAME_LEN);
371-
preempt_enable();
372372
return 0;
373373
}
374374
}
375375
out:
376-
preempt_enable();
377376
return -ERANGE;
378377
}
379378

0 commit comments

Comments
 (0)