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 <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Eduard Zingerman <[email protected]> Cc: Hao Luo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Fastabend <[email protected]> Cc: KP Singh <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Matt Bobrowski <[email protected]> Cc: Song Liu <[email protected]> Cc: Stanislav Fomichev <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Yonghong Song <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Pavlu <[email protected]>
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)