Skip to content

Commit 01d5b16

Browse files
committed
Merge tag 'modules-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/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(). ...
2 parents 7405c0f + 897c0b4 commit 01d5b16

27 files changed

+160
-250
lines changed

MAINTAINERS

+3-1
Original file line numberDiff line numberDiff line change
@@ -16210,7 +16210,7 @@ F: include/dt-bindings/clock/mobileye,eyeq5-clk.h
1621016210

1621116211
MODULE SUPPORT
1621216212
M: Luis Chamberlain <[email protected]>
16213-
R: Petr Pavlu <[email protected]>
16213+
M: Petr Pavlu <[email protected]>
1621416214
R: Sami Tolvanen <[email protected]>
1621516215
R: Daniel Gomez <[email protected]>
1621616216
@@ -16221,8 +16221,10 @@ F: include/linux/kmod.h
1622116221
F: include/linux/module*.h
1622216222
F: kernel/module/
1622316223
F: lib/test_kmod.c
16224+
F: lib/tests/module/
1622416225
F: scripts/module*
1622516226
F: tools/testing/selftests/kmod/
16227+
F: tools/testing/selftests/module/
1622616228

1622716229
MONOLITHIC POWER SYSTEM PMIC DRIVER
1622816230
M: Saravanan Sekar <[email protected]>

arch/arm/kernel/module-plts.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,9 @@ bool in_module_plt(unsigned long loc)
285285
struct module *mod;
286286
bool ret;
287287

288-
preempt_disable();
288+
guard(rcu)();
289289
mod = __module_text_address(loc);
290290
ret = mod && (loc - (u32)mod->arch.core.plt_ent < mod->arch.core.plt_count * PLT_ENT_SIZE ||
291291
loc - (u32)mod->arch.init.plt_ent < mod->arch.init.plt_count * PLT_ENT_SIZE);
292-
preempt_enable();
293-
294292
return ret;
295293
}

arch/arm64/kernel/ftrace.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,13 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec,
320320
* dealing with an out-of-range condition, we can assume it
321321
* is due to a module being loaded far away from the kernel.
322322
*
323-
* NOTE: __module_text_address() must be called with preemption
324-
* disabled, but we can rely on ftrace_lock to ensure that 'mod'
323+
* NOTE: __module_text_address() must be called within a RCU read
324+
* section, but we can rely on ftrace_lock to ensure that 'mod'
325325
* retains its validity throughout the remainder of this code.
326326
*/
327327
if (!mod) {
328-
preempt_disable();
328+
guard(rcu)();
329329
mod = __module_text_address(pc);
330-
preempt_enable();
331330
}
332331

333332
if (WARN_ON(!mod))

arch/loongarch/kernel/ftrace_dyn.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec, struct module *mod
8585
* dealing with an out-of-range condition, we can assume it
8686
* is due to a module being loaded far away from the kernel.
8787
*
88-
* NOTE: __module_text_address() must be called with preemption
89-
* disabled, but we can rely on ftrace_lock to ensure that 'mod'
88+
* NOTE: __module_text_address() must be called within a RCU read
89+
* section, but we can rely on ftrace_lock to ensure that 'mod'
9090
* retains its validity throughout the remainder of this code.
9191
*/
9292
if (!mod) {
93-
preempt_disable();
94-
mod = __module_text_address(pc);
95-
preempt_enable();
93+
scoped_guard(rcu)
94+
mod = __module_text_address(pc);
9695
}
9796

9897
if (WARN_ON(!mod))

arch/loongarch/kernel/unwind_orc.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ bool unwind_next_frame(struct unwind_state *state)
399399
return false;
400400

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

404404
if (is_entry_func(state->pc))
405405
goto end;
@@ -514,14 +514,12 @@ bool unwind_next_frame(struct unwind_state *state)
514514
if (!__kernel_text_address(state->pc))
515515
goto err;
516516

517-
preempt_enable();
518517
return true;
519518

520519
err:
521520
state->error = true;
522521

523522
end:
524-
preempt_enable();
525523
state->stack_info.type = STACK_TYPE_UNKNOWN;
526524
return false;
527525
}

arch/powerpc/kernel/trace/ftrace.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ static unsigned long ftrace_lookup_module_stub(unsigned long ip, unsigned long a
115115
{
116116
struct module *mod = NULL;
117117

118-
preempt_disable();
119-
mod = __module_text_address(ip);
120-
preempt_enable();
121-
118+
scoped_guard(rcu)
119+
mod = __module_text_address(ip);
122120
if (!mod)
123121
pr_err("No module loaded at addr=%lx\n", ip);
124122

arch/powerpc/kernel/trace/ftrace_64_pg.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ static struct module *ftrace_lookup_module(struct dyn_ftrace *rec)
120120
{
121121
struct module *mod;
122122

123-
preempt_disable();
124-
mod = __module_text_address(rec->ip);
125-
preempt_enable();
126-
123+
scoped_guard(rcu)
124+
mod = __module_text_address(rec->ip);
127125
if (!mod)
128126
pr_err("No module loaded at addr=%lx\n", rec->ip);
129127

arch/x86/kernel/callthunks.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ static inline bool within_module_coretext(void *addr)
9898
#ifdef CONFIG_MODULES
9999
struct module *mod;
100100

101-
preempt_disable();
101+
guard(rcu)();
102102
mod = __module_address((unsigned long)addr);
103103
if (mod && within_module_core((unsigned long)addr, mod))
104104
ret = true;
105-
preempt_enable();
106105
#endif
107106
return ret;
108107
}

arch/x86/kernel/unwind_orc.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ bool unwind_next_frame(struct unwind_state *state)
476476
return false;
477477

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

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

672-
preempt_enable();
673672
return true;
674673

675674
err:
676675
state->error = true;
677676

678677
the_end:
679-
preempt_enable();
680678
state->stack_info.type = STACK_TYPE_UNKNOWN;
681679
return false;
682680
}

include/linux/kallsyms.h

+1-2
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
}

include/linux/module.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod)
665665
return within_module_init(addr, mod) || within_module_core(addr, mod);
666666
}
667667

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

671671
extern void __noreturn __module_put_and_kthread_exit(struct module *mod,

kernel/cfi.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,11 @@ static bool is_module_cfi_trap(unsigned long addr)
7373
struct module *mod;
7474
bool found = false;
7575

76-
rcu_read_lock_sched_notrace();
77-
76+
guard(rcu)();
7877
mod = __module_address(addr);
7978
if (mod)
8079
found = is_trap(addr, mod->kcfi_traps, mod->kcfi_traps_end);
8180

82-
rcu_read_unlock_sched_notrace();
83-
8481
return found;
8582
}
8683
#else /* CONFIG_MODULES */

kernel/jump_label.c

+15-16
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,12 @@ static int __jump_label_mod_text_reserved(void *start, void *end)
653653
struct module *mod;
654654
int ret;
655655

656-
preempt_disable();
657-
mod = __module_text_address((unsigned long)start);
658-
WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
659-
if (!try_module_get(mod))
660-
mod = NULL;
661-
preempt_enable();
662-
656+
scoped_guard(rcu) {
657+
mod = __module_text_address((unsigned long)start);
658+
WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
659+
if (!try_module_get(mod))
660+
mod = NULL;
661+
}
663662
if (!mod)
664663
return 0;
665664

@@ -746,9 +745,9 @@ static int jump_label_add_module(struct module *mod)
746745
kfree(jlm);
747746
return -ENOMEM;
748747
}
749-
preempt_disable();
750-
jlm2->mod = __module_address((unsigned long)key);
751-
preempt_enable();
748+
scoped_guard(rcu)
749+
jlm2->mod = __module_address((unsigned long)key);
750+
752751
jlm2->entries = static_key_entries(key);
753752
jlm2->next = NULL;
754753
static_key_set_mod(key, jlm2);
@@ -906,13 +905,13 @@ static void jump_label_update(struct static_key *key)
906905
return;
907906
}
908907

909-
preempt_disable();
910-
mod = __module_address((unsigned long)key);
911-
if (mod) {
912-
stop = mod->jump_entries + mod->num_jump_entries;
913-
init = mod->state == MODULE_STATE_COMING;
908+
scoped_guard(rcu) {
909+
mod = __module_address((unsigned long)key);
910+
if (mod) {
911+
stop = mod->jump_entries + mod->num_jump_entries;
912+
init = mod->state == MODULE_STATE_COMING;
913+
}
914914
}
915-
preempt_enable();
916915
#endif
917916
entry = static_key_entries(key);
918917
/* if there are no users, entry can be NULL */

kernel/kprobes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
15471547
/* Ensure the address is in a text area, and find a module if exists. */
15481548
*probed_mod = NULL;
15491549
if (!core_kernel_text((unsigned long) p->addr)) {
1550-
guard(preempt)();
1550+
guard(rcu)();
15511551
*probed_mod = __module_text_address((unsigned long) p->addr);
15521552
if (!(*probed_mod))
15531553
return -EINVAL;

kernel/livepatch/core.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void klp_find_object_module(struct klp_object *obj)
5959
if (!klp_is_module(obj))
6060
return;
6161

62-
rcu_read_lock_sched();
62+
guard(rcu)();
6363
/*
6464
* We do not want to block removal of patched modules and therefore
6565
* we do not take a reference here. The patches are removed by
@@ -75,8 +75,6 @@ static void klp_find_object_module(struct klp_object *obj)
7575
*/
7676
if (mod && mod->klp_alive)
7777
obj->mod = mod;
78-
79-
rcu_read_unlock_sched();
8078
}
8179

8280
static bool klp_initialized(void)

kernel/module/internal.h

-11
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ char *module_next_tag_pair(char *string, unsigned long *secsize);
124124
#define for_each_modinfo_entry(entry, info, name) \
125125
for (entry = get_modinfo(info, name); entry; entry = get_next_modinfo(info, name, entry))
126126

127-
static inline void module_assert_mutex_or_preempt(void)
128-
{
129-
#ifdef CONFIG_LOCKDEP
130-
if (unlikely(!debug_locks))
131-
return;
132-
133-
WARN_ON_ONCE(!rcu_read_lock_sched_held() &&
134-
!lockdep_is_held(&module_mutex));
135-
#endif
136-
}
137-
138127
static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
139128
{
140129
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS

0 commit comments

Comments
 (0)