Skip to content

Commit

Permalink
Merge tag 'modules-6.15-rc1' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/modules/linux

Pull modules updates from Petr Pavlu:

 - Use RCU instead of RCU-sched

   The mix of rcu_read_lock(), rcu_read_lock_sched() and
   preempt_disable() in the module code and its users has
   been replaced with just rcu_read_lock()

 - The rest of changes are smaller fixes and updates

* tag 'modules-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux: (32 commits)
  MAINTAINERS: Update the MODULE SUPPORT section
  module: Remove unnecessary size argument when calling strscpy()
  module: Replace deprecated strncpy() with strscpy()
  params: Annotate struct module_param_attrs with __counted_by()
  bug: Use RCU instead RCU-sched to protect module_bug_list.
  static_call: Use RCU in all users of __module_text_address().
  kprobes: Use RCU in all users of __module_text_address().
  bpf: Use RCU in all users of __module_text_address().
  jump_label: Use RCU in all users of __module_text_address().
  jump_label: Use RCU in all users of __module_address().
  x86: Use RCU in all users of __module_address().
  cfi: Use RCU while invoking __module_address().
  powerpc/ftrace: Use RCU in all users of __module_text_address().
  LoongArch: ftrace: Use RCU in all users of __module_text_address().
  LoongArch/orc: Use RCU in all users of __module_address().
  arm64: module: Use RCU in all users of __module_text_address().
  ARM: module: Use RCU in all users of __module_text_address().
  module: Use RCU in all users of __module_text_address().
  module: Use RCU in all users of __module_address().
  module: Use RCU in search_module_extables().
  ...
  • Loading branch information
Linus Torvalds committed Mar 30, 2025
2 parents 7405c0f + 897c0b4 commit 01d5b16
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 250 deletions.
4 changes: 3 additions & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -16210,7 +16210,7 @@ F: include/dt-bindings/clock/mobileye,eyeq5-clk.h

MODULE SUPPORT
M: Luis Chamberlain <mcgrof@kernel.org>
R: Petr Pavlu <petr.pavlu@suse.com>
M: Petr Pavlu <petr.pavlu@suse.com>
R: Sami Tolvanen <samitolvanen@google.com>
R: Daniel Gomez <da.gomez@samsung.com>
L: linux-modules@vger.kernel.org
Expand All @@ -16221,8 +16221,10 @@ F: include/linux/kmod.h
F: include/linux/module*.h
F: kernel/module/
F: lib/test_kmod.c
F: lib/tests/module/
F: scripts/module*
F: tools/testing/selftests/kmod/
F: tools/testing/selftests/module/

MONOLITHIC POWER SYSTEM PMIC DRIVER
M: Saravanan Sekar <sravanhome@gmail.com>
Expand Down
4 changes: 1 addition & 3 deletions arch/arm/kernel/module-plts.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,9 @@ bool in_module_plt(unsigned long loc)
struct module *mod;
bool ret;

preempt_disable();
guard(rcu)();
mod = __module_text_address(loc);
ret = mod && (loc - (u32)mod->arch.core.plt_ent < mod->arch.core.plt_count * PLT_ENT_SIZE ||
loc - (u32)mod->arch.init.plt_ent < mod->arch.init.plt_count * PLT_ENT_SIZE);
preempt_enable();

return ret;
}
7 changes: 3 additions & 4 deletions arch/arm64/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,13 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec,
* dealing with an out-of-range condition, we can assume it
* is due to a module being loaded far away from the kernel.
*
* NOTE: __module_text_address() must be called with preemption
* disabled, but we can rely on ftrace_lock to ensure that 'mod'
* NOTE: __module_text_address() must be called within a RCU read
* section, but we can rely on ftrace_lock to ensure that 'mod'
* retains its validity throughout the remainder of this code.
*/
if (!mod) {
preempt_disable();
guard(rcu)();
mod = __module_text_address(pc);
preempt_enable();
}

if (WARN_ON(!mod))
Expand Down
9 changes: 4 additions & 5 deletions arch/loongarch/kernel/ftrace_dyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec, struct module *mod
* dealing with an out-of-range condition, we can assume it
* is due to a module being loaded far away from the kernel.
*
* NOTE: __module_text_address() must be called with preemption
* disabled, but we can rely on ftrace_lock to ensure that 'mod'
* NOTE: __module_text_address() must be called within a RCU read
* section, but we can rely on ftrace_lock to ensure that 'mod'
* retains its validity throughout the remainder of this code.
*/
if (!mod) {
preempt_disable();
mod = __module_text_address(pc);
preempt_enable();
scoped_guard(rcu)
mod = __module_text_address(pc);
}

if (WARN_ON(!mod))
Expand Down
4 changes: 1 addition & 3 deletions arch/loongarch/kernel/unwind_orc.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ bool unwind_next_frame(struct unwind_state *state)
return false;

/* Don't let modules unload while we're reading their ORC data. */
preempt_disable();
guard(rcu)();

if (is_entry_func(state->pc))
goto end;
Expand Down Expand Up @@ -514,14 +514,12 @@ bool unwind_next_frame(struct unwind_state *state)
if (!__kernel_text_address(state->pc))
goto err;

preempt_enable();
return true;

err:
state->error = true;

end:
preempt_enable();
state->stack_info.type = STACK_TYPE_UNKNOWN;
return false;
}
Expand Down
6 changes: 2 additions & 4 deletions arch/powerpc/kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ static unsigned long ftrace_lookup_module_stub(unsigned long ip, unsigned long a
{
struct module *mod = NULL;

preempt_disable();
mod = __module_text_address(ip);
preempt_enable();

scoped_guard(rcu)
mod = __module_text_address(ip);
if (!mod)
pr_err("No module loaded at addr=%lx\n", ip);

Expand Down
6 changes: 2 additions & 4 deletions arch/powerpc/kernel/trace/ftrace_64_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ static struct module *ftrace_lookup_module(struct dyn_ftrace *rec)
{
struct module *mod;

preempt_disable();
mod = __module_text_address(rec->ip);
preempt_enable();

scoped_guard(rcu)
mod = __module_text_address(rec->ip);
if (!mod)
pr_err("No module loaded at addr=%lx\n", rec->ip);

Expand Down
3 changes: 1 addition & 2 deletions arch/x86/kernel/callthunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ static inline bool within_module_coretext(void *addr)
#ifdef CONFIG_MODULES
struct module *mod;

preempt_disable();
guard(rcu)();
mod = __module_address((unsigned long)addr);
if (mod && within_module_core((unsigned long)addr, mod))
ret = true;
preempt_enable();
#endif
return ret;
}
Expand Down
4 changes: 1 addition & 3 deletions arch/x86/kernel/unwind_orc.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ bool unwind_next_frame(struct unwind_state *state)
return false;

/* Don't let modules unload while we're reading their ORC data. */
preempt_disable();
guard(rcu)();

/* End-of-stack check for user tasks: */
if (state->regs && user_mode(state->regs))
Expand Down Expand Up @@ -669,14 +669,12 @@ bool unwind_next_frame(struct unwind_state *state)
goto err;
}

preempt_enable();
return true;

err:
state->error = true;

the_end:
preempt_enable();
state->stack_info.type = STACK_TYPE_UNKNOWN;
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions include/linux/kallsyms.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ static inline void *dereference_symbol_descriptor(void *ptr)
if (is_ksym_addr((unsigned long)ptr))
return ptr;

preempt_disable();
guard(rcu)();
mod = __module_address((unsigned long)ptr);

if (mod)
ptr = dereference_module_function_descriptor(mod, ptr);
preempt_enable();
#endif
return ptr;
}
Expand Down
2 changes: 1 addition & 1 deletion include/linux/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod)
return within_module_init(addr, mod) || within_module_core(addr, mod);
}

/* Search for module by name: must be in a RCU-sched critical section. */
/* Search for module by name: must be in a RCU critical section. */
struct module *find_module(const char *name);

extern void __noreturn __module_put_and_kthread_exit(struct module *mod,
Expand Down
5 changes: 1 addition & 4 deletions kernel/cfi.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ static bool is_module_cfi_trap(unsigned long addr)
struct module *mod;
bool found = false;

rcu_read_lock_sched_notrace();

guard(rcu)();
mod = __module_address(addr);
if (mod)
found = is_trap(addr, mod->kcfi_traps, mod->kcfi_traps_end);

rcu_read_unlock_sched_notrace();

return found;
}
#else /* CONFIG_MODULES */
Expand Down
31 changes: 15 additions & 16 deletions kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,12 @@ static int __jump_label_mod_text_reserved(void *start, void *end)
struct module *mod;
int ret;

preempt_disable();
mod = __module_text_address((unsigned long)start);
WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
if (!try_module_get(mod))
mod = NULL;
preempt_enable();

scoped_guard(rcu) {
mod = __module_text_address((unsigned long)start);
WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
if (!try_module_get(mod))
mod = NULL;
}
if (!mod)
return 0;

Expand Down Expand Up @@ -746,9 +745,9 @@ static int jump_label_add_module(struct module *mod)
kfree(jlm);
return -ENOMEM;
}
preempt_disable();
jlm2->mod = __module_address((unsigned long)key);
preempt_enable();
scoped_guard(rcu)
jlm2->mod = __module_address((unsigned long)key);

jlm2->entries = static_key_entries(key);
jlm2->next = NULL;
static_key_set_mod(key, jlm2);
Expand Down Expand Up @@ -906,13 +905,13 @@ static void jump_label_update(struct static_key *key)
return;
}

preempt_disable();
mod = __module_address((unsigned long)key);
if (mod) {
stop = mod->jump_entries + mod->num_jump_entries;
init = mod->state == MODULE_STATE_COMING;
scoped_guard(rcu) {
mod = __module_address((unsigned long)key);
if (mod) {
stop = mod->jump_entries + mod->num_jump_entries;
init = mod->state == MODULE_STATE_COMING;
}
}
preempt_enable();
#endif
entry = static_key_entries(key);
/* if there are no users, entry can be NULL */
Expand Down
2 changes: 1 addition & 1 deletion kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
/* Ensure the address is in a text area, and find a module if exists. */
*probed_mod = NULL;
if (!core_kernel_text((unsigned long) p->addr)) {
guard(preempt)();
guard(rcu)();
*probed_mod = __module_text_address((unsigned long) p->addr);
if (!(*probed_mod))
return -EINVAL;
Expand Down
4 changes: 1 addition & 3 deletions kernel/livepatch/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void klp_find_object_module(struct klp_object *obj)
if (!klp_is_module(obj))
return;

rcu_read_lock_sched();
guard(rcu)();
/*
* We do not want to block removal of patched modules and therefore
* we do not take a reference here. The patches are removed by
Expand All @@ -75,8 +75,6 @@ static void klp_find_object_module(struct klp_object *obj)
*/
if (mod && mod->klp_alive)
obj->mod = mod;

rcu_read_unlock_sched();
}

static bool klp_initialized(void)
Expand Down
11 changes: 0 additions & 11 deletions kernel/module/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ char *module_next_tag_pair(char *string, unsigned long *secsize);
#define for_each_modinfo_entry(entry, info, name) \
for (entry = get_modinfo(info, name); entry; entry = get_next_modinfo(info, name, entry))

static inline void module_assert_mutex_or_preempt(void)
{
#ifdef CONFIG_LOCKDEP
if (unlikely(!debug_locks))
return;

WARN_ON_ONCE(!rcu_read_lock_sched_held() &&
!lockdep_is_held(&module_mutex));
#endif
}

static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
{
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
Expand Down
Loading

0 comments on commit 01d5b16

Please sign in to comment.