__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 <a...@kernel.org>
Cc: Andrii Nakryiko <and...@kernel.org>
Cc: Daniel Borkmann <dan...@iogearbox.net>
Cc: Eduard Zingerman <eddy...@gmail.com>
Cc: Hao Luo <hao...@google.com>
Cc: Jiri Olsa <jo...@kernel.org>
Cc: John Fastabend <john.fastab...@gmail.com>
Cc: KP Singh <kpsi...@kernel.org>
Cc: Martin KaFai Lau <martin....@linux.dev>
Cc: Masami Hiramatsu <mhira...@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoy...@efficios.com>
Cc: Matt Bobrowski <mattbobrow...@google.com>
Cc: Song Liu <s...@kernel.org>
Cc: Stanislav Fomichev <s...@fomichev.me>
Cc: Steven Rostedt <rost...@goodmis.org>
Cc: Yonghong Song <yonghong.s...@linux.dev>
Cc: b...@vger.kernel.org
Cc: linux-trace-kernel@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bige...@linutronix.de>
---
 kernel/trace/bpf_trace.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 1b8db5aee9d38..020df7b6ff90c 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2336,10 +2336,9 @@ void bpf_put_raw_tracepoint(struct bpf_raw_event_map 
*btp)
 {
        struct module *mod;
 
-       preempt_disable();
+       guard(rcu)();
        mod = __module_address((unsigned long)btp);
        module_put(mod);
-       preempt_enable();
 }
 
 static __always_inline
@@ -2907,16 +2906,14 @@ static int get_modules_for_addrs(struct module ***mods, 
unsigned long *addrs, u3
        for (i = 0; i < addrs_cnt; i++) {
                struct module *mod;
 
-               preempt_disable();
-               mod = __module_address(addrs[i]);
-               /* Either no module or we it's already stored  */
-               if (!mod || has_module(&arr, mod)) {
-                       preempt_enable();
-                       continue;
+               scoped_guard(rcu) {
+                       mod = __module_address(addrs[i]);
+                       /* Either no module or we it's already stored  */
+                       if (!mod || has_module(&arr, mod))
+                               continue;
+                       if (!try_module_get(mod))
+                               err = -EINVAL;
                }
-               if (!try_module_get(mod))
-                       err = -EINVAL;
-               preempt_enable();
                if (err)
                        break;
                err = add_module(&arr, mod);
-- 
2.45.2


Reply via email to