Skip to content

Commit 6593a2c

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
module: Use RCU in all users of __module_address().
__module_address() can be invoked within a RCU section, there is no requirement to have preemption disabled. Replace the preempt_disable() section around __module_address() with RCU. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20250108090457.512198-15-bigeasy@linutronix.de Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
1 parent 2abf84f commit 6593a2c

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

include/linux/kallsyms.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ static inline void *dereference_symbol_descriptor(void *ptr)
5555
if (is_ksym_addr((unsigned long)ptr))
5656
return ptr;
5757

58-
preempt_disable();
58+
guard(rcu)();
5959
mod = __module_address((unsigned long)ptr);
6060

6161
if (mod)
6262
ptr = dereference_module_function_descriptor(mod, ptr);
63-
preempt_enable();
6463
#endif
6564
return ptr;
6665
}

kernel/module/kallsyms.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void * __weak dereference_module_function_descriptor(struct module *mod,
316316

317317
/*
318318
* For kallsyms to ask for address resolution. NULL means not found. Careful
319-
* not to lock to avoid deadlock on oopses, simply disable preemption.
319+
* not to lock to avoid deadlock on oopses, RCU is enough.
320320
*/
321321
int module_address_lookup(unsigned long addr,
322322
unsigned long *size,
@@ -330,7 +330,6 @@ int module_address_lookup(unsigned long addr,
330330
struct module *mod;
331331

332332
guard(rcu)();
333-
preempt_disable();
334333
mod = __module_address(addr);
335334
if (mod) {
336335
if (modname)
@@ -348,8 +347,6 @@ int module_address_lookup(unsigned long addr,
348347
if (sym)
349348
ret = strscpy(namebuf, sym, KSYM_NAME_LEN);
350349
}
351-
preempt_enable();
352-
353350
return ret;
354351
}
355352

kernel/module/main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,13 +3731,8 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
37313731
*/
37323732
bool is_module_address(unsigned long addr)
37333733
{
3734-
bool ret;
3735-
3736-
preempt_disable();
3737-
ret = __module_address(addr) != NULL;
3738-
preempt_enable();
3739-
3740-
return ret;
3734+
guard(rcu)();
3735+
return __module_address(addr) != NULL;
37413736
}
37423737

37433738
/**

0 commit comments

Comments
 (0)