Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

module: Use RCU in find_module_all().

The modules list and module::kallsyms can be accessed under RCU
assumption.

Remove module_assert_mutex_or_preempt() from find_module_all() so it can
be used under RCU protection without warnings. Update its callers to use
RCU protection instead of preempt_disable().

Cc: Jiri Kosina <jikos@kernel.org>
Cc: Joe Lawrence <joe.lawrence@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Miroslav Benes <mbenes@suse.cz>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-kernel@vger.kernel.org
Cc: live-patching@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20250108090457.512198-7-bigeasy@linutronix.de
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>

authored by

Sebastian Andrzej Siewior and committed by
Petr Pavlu
febaa65c c4fadf38

+8 -14
+1 -1
include/linux/module.h
··· 666 666 return within_module_init(addr, mod) || within_module_core(addr, mod); 667 667 } 668 668 669 - /* Search for module by name: must be in a RCU-sched critical section. */ 669 + /* Search for module by name: must be in a RCU critical section. */ 670 670 struct module *find_module(const char *name); 671 671 672 672 extern void __noreturn __module_put_and_kthread_exit(struct module *mod,
+1 -3
kernel/livepatch/core.c
··· 59 59 if (!klp_is_module(obj)) 60 60 return; 61 61 62 - rcu_read_lock_sched(); 62 + guard(rcu)(); 63 63 /* 64 64 * We do not want to block removal of patched modules and therefore 65 65 * we do not take a reference here. The patches are removed by ··· 75 75 */ 76 76 if (mod && mod->klp_alive) 77 77 obj->mod = mod; 78 - 79 - rcu_read_unlock_sched(); 80 78 } 81 79 82 80 static bool klp_initialized(void)
+1
kernel/module/kallsyms.c
··· 450 450 unsigned long ret; 451 451 452 452 /* Don't lock: we're in enough trouble already. */ 453 + guard(rcu)(); 453 454 preempt_disable(); 454 455 ret = __module_kallsyms_lookup_name(name); 455 456 preempt_enable();
+2 -4
kernel/module/main.c
··· 374 374 } 375 375 376 376 /* 377 - * Search for module by name: must hold module_mutex (or preempt disabled 378 - * for read-only access). 377 + * Search for module by name: must hold module_mutex (or RCU for read-only 378 + * access). 379 379 */ 380 380 struct module *find_module_all(const char *name, size_t len, 381 381 bool even_unformed) 382 382 { 383 383 struct module *mod; 384 - 385 - module_assert_mutex_or_preempt(); 386 384 387 385 list_for_each_entry_rcu(mod, &modules, list, 388 386 lockdep_is_held(&module_mutex)) {
+3 -6
kernel/trace/trace_kprobe.c
··· 124 124 if (!p) 125 125 return true; 126 126 *p = '\0'; 127 - rcu_read_lock_sched(); 128 - ret = !!find_module(tk->symbol); 129 - rcu_read_unlock_sched(); 127 + scoped_guard(rcu) 128 + ret = !!find_module(tk->symbol); 130 129 *p = ':'; 131 130 132 131 return ret; ··· 795 796 { 796 797 struct module *mod; 797 798 798 - rcu_read_lock_sched(); 799 + guard(rcu)(); 799 800 mod = find_module(name); 800 801 if (mod && !try_module_get(mod)) 801 802 mod = NULL; 802 - rcu_read_unlock_sched(); 803 - 804 803 return mod; 805 804 } 806 805 #else