Skip to content

Commit 8c6eb7c

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
bpf: Use RCU in all users of __module_text_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. Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Eduard Zingerman <eddyz87@gmail.com> Cc: Hao Luo <haoluo@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Fastabend <john.fastabend@gmail.com> Cc: KP Singh <kpsingh@kernel.org> Cc: Martin KaFai Lau <martin.lau@linux.dev> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Matt Bobrowski <mattbobrowski@google.com> Cc: Song Liu <song@kernel.org> Cc: Stanislav Fomichev <sdf@fomichev.me> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Yonghong Song <yonghong.song@linux.dev> Cc: bpf@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/r/20250129084751.tH6iidUO@linutronix.de Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
1 parent 72ee1c2 commit 8c6eb7c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

kernel/trace/bpf_trace.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,10 +2345,9 @@ void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
23452345
{
23462346
struct module *mod;
23472347

2348-
preempt_disable();
2348+
guard(rcu)();
23492349
mod = __module_address((unsigned long)btp);
23502350
module_put(mod);
2351-
preempt_enable();
23522351
}
23532352

23542353
static __always_inline
@@ -2932,18 +2931,21 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
29322931
u32 i, err = 0;
29332932

29342933
for (i = 0; i < addrs_cnt; i++) {
2934+
bool skip_add = false;
29352935
struct module *mod;
29362936

2937-
preempt_disable();
2938-
mod = __module_address(addrs[i]);
2939-
/* Either no module or we it's already stored */
2940-
if (!mod || has_module(&arr, mod)) {
2941-
preempt_enable();
2942-
continue;
2937+
scoped_guard(rcu) {
2938+
mod = __module_address(addrs[i]);
2939+
/* Either no module or it's already stored */
2940+
if (!mod || has_module(&arr, mod)) {
2941+
skip_add = true;
2942+
break; /* scoped_guard */
2943+
}
2944+
if (!try_module_get(mod))
2945+
err = -EINVAL;
29432946
}
2944-
if (!try_module_get(mod))
2945-
err = -EINVAL;
2946-
preempt_enable();
2947+
if (skip_add)
2948+
continue;
29472949
if (err)
29482950
break;
29492951
err = add_module(&arr, mod);

0 commit comments

Comments
 (0)