* [PATCH v3 06/28] module: Use RCU in find_module_all().
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
@ 2025-01-08 9:04 ` Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 17/28] arm64: module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
` (4 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-08 9:04 UTC (permalink / raw)
To: linux-modules, linux-kernel
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner,
Sebastian Andrzej Siewior, Jiri Kosina, Joe Lawrence,
Josh Poimboeuf, Masami Hiramatsu, Mathieu Desnoyers,
Miroslav Benes, Petr Mladek, Steven Rostedt, linux-trace-kernel,
live-patching
The modules list and module::kallsyms can be accessed under RCU
assumption.
Remove module_assert_mutex_or_preempt() from find_module_all() so it can
be used under RCU protection without warnings. Update its callers to use
RCU protection instead of preempt_disable().
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Joe Lawrence <joe.lawrence@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Miroslav Benes <mbenes@suse.cz>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-kernel@vger.kernel.org
Cc: live-patching@vger.kernel.org
Reviewed-by: Petr Mladek <pmladek@suse.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
include/linux/module.h | 2 +-
kernel/livepatch/core.c | 4 +---
kernel/module/kallsyms.c | 1 +
kernel/module/main.c | 6 ++----
kernel/trace/trace_kprobe.c | 9 +++------
5 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/include/linux/module.h b/include/linux/module.h
index 94acbacdcdf18..5c1f7ea76c8cb 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -663,7 +663,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,
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 3c21c31796db0..f8932c63b08e3 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -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
@@ -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)
diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c
index 4eef518204eb5..3cba9f933b24f 100644
--- a/kernel/module/kallsyms.c
+++ b/kernel/module/kallsyms.c
@@ -450,6 +450,7 @@ unsigned long module_kallsyms_lookup_name(const char *name)
unsigned long ret;
/* Don't lock: we're in enough trouble already. */
+ guard(rcu)();
preempt_disable();
ret = __module_kallsyms_lookup_name(name);
preempt_enable();
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 5cce4a92d7ba3..5aa56ec8e203e 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -374,16 +374,14 @@ bool find_symbol(struct find_symbol_arg *fsa)
}
/*
- * Search for module by name: must hold module_mutex (or preempt disabled
- * for read-only access).
+ * Search for module by name: must hold module_mutex (or RCU for read-only
+ * access).
*/
struct module *find_module_all(const char *name, size_t len,
bool even_unformed)
{
struct module *mod;
- module_assert_mutex_or_preempt();
-
list_for_each_entry_rcu(mod, &modules, list,
lockdep_is_held(&module_mutex)) {
if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 935a886af40c9..37ff78ee17fe0 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -123,9 +123,8 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
if (!p)
return true;
*p = '\0';
- rcu_read_lock_sched();
- ret = !!find_module(tk->symbol);
- rcu_read_unlock_sched();
+ scoped_guard(rcu)
+ ret = !!find_module(tk->symbol);
*p = ':';
return ret;
@@ -800,12 +799,10 @@ static struct module *try_module_get_by_name(const char *name)
{
struct module *mod;
- rcu_read_lock_sched();
+ guard(rcu)();
mod = find_module(name);
if (mod && !try_module_get(mod))
mod = NULL;
- rcu_read_unlock_sched();
-
return mod;
}
#else
--
2.47.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 17/28] arm64: module: Use RCU in all users of __module_text_address().
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
2025-01-08 9:04 ` [PATCH v3 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
@ 2025-01-08 9:04 ` Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
` (3 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-08 9:04 UTC (permalink / raw)
To: linux-modules, linux-kernel
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner,
Sebastian Andrzej Siewior, Catalin Marinas, Mark Rutland,
Masami Hiramatsu, Steven Rostedt, Will Deacon, linux-arm-kernel,
linux-trace-kernel
__module_text_address() can be invoked within a RCU section, there is no
requirement to have preemption disabled.
Replace the preempt_disable() section around __module_text_address()
with RCU.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-trace-kernel@vger.kernel.org
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
arch/arm64/kernel/ftrace.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 245cb419ca24d..2b76939b6304f 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -257,14 +257,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))
--
2.47.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address().
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
2025-01-08 9:04 ` [PATCH v3 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 17/28] arm64: module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
@ 2025-01-08 9:04 ` Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
` (2 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-08 9:04 UTC (permalink / raw)
To: linux-modules, linux-kernel
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner,
Sebastian Andrzej Siewior, Huacai Chen, Mark Rutland,
Masami Hiramatsu, Steven Rostedt, WANG Xuerui, linux-trace-kernel,
loongarch
__module_text_address() can be invoked within a RCU section, there is no
requirement to have preemption disabled.
Replace the preempt_disable() section around __module_text_address()
with RCU.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: linux-trace-kernel@vger.kernel.org
Cc: loongarch@lists.linux.dev
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
arch/loongarch/kernel/ftrace_dyn.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c
index 18056229e22e4..5b7b8ac13e350 100644
--- a/arch/loongarch/kernel/ftrace_dyn.c
+++ b/arch/loongarch/kernel/ftrace_dyn.c
@@ -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))
--
2.47.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 20/28] powerpc/ftrace: Use RCU in all users of __module_text_address().
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
` (2 preceding siblings ...)
2025-01-08 9:04 ` [PATCH v3 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
@ 2025-01-08 9:04 ` Sebastian Andrzej Siewior
2025-01-20 10:09 ` Shrikanth Hegde
2025-01-08 9:04 ` [PATCH v3 25/28] bpf: " Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 26/28] kprobes: " Sebastian Andrzej Siewior
5 siblings, 1 reply; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-08 9:04 UTC (permalink / raw)
To: linux-modules, linux-kernel
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner,
Sebastian Andrzej Siewior, Christophe Leroy, Madhavan Srinivasan,
Mark Rutland, Masami Hiramatsu, Michael Ellerman, Naveen N Rao,
Nicholas Piggin, Steven Rostedt, linux-trace-kernel, linuxppc-dev
__module_text_address() can be invoked within a RCU section, there is no
requirement to have preemption disabled.
Replace the preempt_disable() section around __module_text_address()
with RCU.
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-kernel@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
arch/powerpc/kernel/trace/ftrace.c | 6 ++----
arch/powerpc/kernel/trace/ftrace_64_pg.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index 5ccd791761e8f..558d7f4e4bea6 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -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);
diff --git a/arch/powerpc/kernel/trace/ftrace_64_pg.c b/arch/powerpc/kernel/trace/ftrace_64_pg.c
index 98787376eb87c..531d40f10c8a1 100644
--- a/arch/powerpc/kernel/trace/ftrace_64_pg.c
+++ b/arch/powerpc/kernel/trace/ftrace_64_pg.c
@@ -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);
--
2.47.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 25/28] bpf: Use RCU in all users of __module_text_address().
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
` (3 preceding siblings ...)
2025-01-08 9:04 ` [PATCH v3 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
@ 2025-01-08 9:04 ` Sebastian Andrzej Siewior
2025-01-09 18:38 ` Alexei Starovoitov
2025-01-08 9:04 ` [PATCH v3 26/28] kprobes: " Sebastian Andrzej Siewior
5 siblings, 1 reply; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-08 9:04 UTC (permalink / raw)
To: linux-modules, linux-kernel
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner,
Sebastian Andrzej Siewior, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Eduard Zingerman, Hao Luo, Jiri Olsa,
John Fastabend, KP Singh, Martin KaFai Lau, Masami Hiramatsu,
Mathieu Desnoyers, Matt Bobrowski, Song Liu, Stanislav Fomichev,
Steven Rostedt, Yonghong Song, bpf, linux-trace-kernel
__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
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@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.47.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 26/28] kprobes: Use RCU in all users of __module_text_address().
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
` (4 preceding siblings ...)
2025-01-08 9:04 ` [PATCH v3 25/28] bpf: " Sebastian Andrzej Siewior
@ 2025-01-08 9:04 ` Sebastian Andrzej Siewior
2025-01-28 5:44 ` Masami Hiramatsu
5 siblings, 1 reply; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-08 9:04 UTC (permalink / raw)
To: linux-modules, linux-kernel
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner,
Sebastian Andrzej Siewior, David S. Miller, Anil S Keshavamurthy,
Masami Hiramatsu, Naveen N Rao, linux-trace-kernel
__module_text_address() can be invoked within a RCU section, there is no
requirement to have preemption disabled.
Replace the preempt_disable() section around __module_text_address()
with RCU.
Cc: David S. Miller <davem@davemloft.net>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/kprobes.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index b027a4030976a..22e47a27df4aa 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1566,7 +1566,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
if (ret)
return ret;
jump_label_lock();
- preempt_disable();
+ rcu_read_lock();
/* Ensure the address is in a text area, and find a module if exists. */
*probed_mod = NULL;
@@ -1612,7 +1612,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
}
out:
- preempt_enable();
+ rcu_read_unlock();
jump_label_unlock();
return ret;
--
2.47.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v3 25/28] bpf: Use RCU in all users of __module_text_address().
2025-01-08 9:04 ` [PATCH v3 25/28] bpf: " Sebastian Andrzej Siewior
@ 2025-01-09 18:38 ` Alexei Starovoitov
2025-01-09 20:54 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 14+ messages in thread
From: Alexei Starovoitov @ 2025-01-09 18:38 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-modules, LKML, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Eduard Zingerman, Hao Luo, Jiri Olsa,
John Fastabend, KP Singh, Martin KaFai Lau, Masami Hiramatsu,
Mathieu Desnoyers, Matt Bobrowski, Song Liu, Stanislav Fomichev,
Steven Rostedt, Yonghong Song, bpf, linux-trace-kernel
On Wed, Jan 8, 2025 at 1:05 AM Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
>
> __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
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@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;
lgtm.
Should we take into bpf-next or the whole set is handled together
somewhere?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 25/28] bpf: Use RCU in all users of __module_text_address().
2025-01-09 18:38 ` Alexei Starovoitov
@ 2025-01-09 20:54 ` Sebastian Andrzej Siewior
2025-01-09 21:00 ` Alexei Starovoitov
0 siblings, 1 reply; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-09 20:54 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: linux-modules, LKML, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Eduard Zingerman, Hao Luo, Jiri Olsa,
John Fastabend, KP Singh, Martin KaFai Lau, Masami Hiramatsu,
Mathieu Desnoyers, Matt Bobrowski, Song Liu, Stanislav Fomichev,
Steven Rostedt, Yonghong Song, bpf, linux-trace-kernel
On 2025-01-09 10:38:03 [-0800], Alexei Starovoitov wrote:
> lgtm.
> Should we take into bpf-next or the whole set is handled together
> somewhere?
If you don't mind, I would hope to route the whole series via the
modules tree. Some of the lower functions (__module_address()) check for
disabled preemption and will trigger warnings at runtime if this gets
applied before (earlier in the series) the check gets replaced.
Sebastian
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 25/28] bpf: Use RCU in all users of __module_text_address().
2025-01-09 20:54 ` Sebastian Andrzej Siewior
@ 2025-01-09 21:00 ` Alexei Starovoitov
2025-01-29 8:47 ` [PATCH v3.5 " Sebastian Andrzej Siewior
0 siblings, 1 reply; 14+ messages in thread
From: Alexei Starovoitov @ 2025-01-09 21:00 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-modules, LKML, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Eduard Zingerman, Hao Luo, Jiri Olsa,
John Fastabend, KP Singh, Martin KaFai Lau, Masami Hiramatsu,
Mathieu Desnoyers, Matt Bobrowski, Song Liu, Stanislav Fomichev,
Steven Rostedt, Yonghong Song, bpf, linux-trace-kernel
On Thu, Jan 9, 2025 at 12:54 PM Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
>
> On 2025-01-09 10:38:03 [-0800], Alexei Starovoitov wrote:
> > lgtm.
> > Should we take into bpf-next or the whole set is handled together
> > somewhere?
>
> If you don't mind, I would hope to route the whole series via the
> modules tree. Some of the lower functions (__module_address()) check for
> disabled preemption and will trigger warnings at runtime if this gets
> applied before (earlier in the series) the check gets replaced.
I see. Then
Acked-by: Alexei Starovoitov <ast@kernel.org>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 20/28] powerpc/ftrace: Use RCU in all users of __module_text_address().
2025-01-08 9:04 ` [PATCH v3 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
@ 2025-01-20 10:09 ` Shrikanth Hegde
0 siblings, 0 replies; 14+ messages in thread
From: Shrikanth Hegde @ 2025-01-20 10:09 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Daniel Gomez, Luis Chamberlain, Paul E . McKenney, Peter Zijlstra,
Petr Pavlu, Sami Tolvanen, Thomas Gleixner, Christophe Leroy,
Madhavan Srinivasan, Mark Rutland, Masami Hiramatsu,
Michael Ellerman, Naveen N Rao, Nicholas Piggin, Steven Rostedt,
linux-trace-kernel, linuxppc-dev, linux-modules, linux-kernel
On 1/8/25 14:34, Sebastian Andrzej Siewior wrote:
> __module_text_address() can be invoked within a RCU section, there is no
> requirement to have preemption disabled.
>
> Replace the preempt_disable() section around __module_text_address()
> with RCU.
>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Naveen N Rao <naveen@kernel.org>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: linux-trace-kernel@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> arch/powerpc/kernel/trace/ftrace.c | 6 ++----
> arch/powerpc/kernel/trace/ftrace_64_pg.c | 6 ++----
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
Ran ftrace (function graph) on preempt=full kernel with rcutorture while doing modprobe/rmmod.
rcutorture succeeded and didn't see any splats.
If there is any other method to test it out, please let me know.
So for powerpc bits:
Tested-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
> index 5ccd791761e8f..558d7f4e4bea6 100644
> --- a/arch/powerpc/kernel/trace/ftrace.c
> +++ b/arch/powerpc/kernel/trace/ftrace.c
> @@ -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);
>
> diff --git a/arch/powerpc/kernel/trace/ftrace_64_pg.c b/arch/powerpc/kernel/trace/ftrace_64_pg.c
> index 98787376eb87c..531d40f10c8a1 100644
> --- a/arch/powerpc/kernel/trace/ftrace_64_pg.c
> +++ b/arch/powerpc/kernel/trace/ftrace_64_pg.c
> @@ -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);
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 26/28] kprobes: Use RCU in all users of __module_text_address().
2025-01-08 9:04 ` [PATCH v3 26/28] kprobes: " Sebastian Andrzej Siewior
@ 2025-01-28 5:44 ` Masami Hiramatsu
2025-01-28 7:10 ` Sebastian Andrzej Siewior
2025-01-29 8:49 ` [PATCH v3.5 25/28] " Sebastian Andrzej Siewior
0 siblings, 2 replies; 14+ messages in thread
From: Masami Hiramatsu @ 2025-01-28 5:44 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-modules, linux-kernel, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, David S. Miller, Anil S Keshavamurthy,
Masami Hiramatsu, Naveen N Rao, linux-trace-kernel
On Wed, 8 Jan 2025 10:04:55 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> __module_text_address() can be invoked within a RCU section, there is no
> requirement to have preemption disabled.
>
> Replace the preempt_disable() section around __module_text_address()
> with RCU.
Hi,
Since the below cleanup has been merged, this patch needs to be updated.
https://lore.kernel.org/all/20241121-kprobes-preempt-v1-1-fd581ee7fcbb@linutronix.de/
(may need to change the guard(preempt)() -> guard(rcu)() in the new version.)
Thank you,
>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Naveen N Rao <naveen@kernel.org>
> Cc: linux-trace-kernel@vger.kernel.org
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> kernel/kprobes.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index b027a4030976a..22e47a27df4aa 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1566,7 +1566,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
> if (ret)
> return ret;
> jump_label_lock();
> - preempt_disable();
> + rcu_read_lock();
>
> /* Ensure the address is in a text area, and find a module if exists. */
> *probed_mod = NULL;
> @@ -1612,7 +1612,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
> }
>
> out:
> - preempt_enable();
> + rcu_read_unlock();
> jump_label_unlock();
>
> return ret;
> --
> 2.47.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 26/28] kprobes: Use RCU in all users of __module_text_address().
2025-01-28 5:44 ` Masami Hiramatsu
@ 2025-01-28 7:10 ` Sebastian Andrzej Siewior
2025-01-29 8:49 ` [PATCH v3.5 25/28] " Sebastian Andrzej Siewior
1 sibling, 0 replies; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-28 7:10 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: linux-modules, linux-kernel, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, David S. Miller, Anil S Keshavamurthy,
Naveen N Rao, linux-trace-kernel
On 2025-01-28 14:44:52 [+0900], Masami Hiramatsu wrote:
> Hi,
Hi,
> Since the below cleanup has been merged, this patch needs to be updated.
>
> https://lore.kernel.org/all/20241121-kprobes-preempt-v1-1-fd581ee7fcbb@linutronix.de/
>
> (may need to change the guard(preempt)() -> guard(rcu)() in the new version.)
Thanks, I'm on it.
> Thank you,
Sebastian
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3.5 25/28] bpf: Use RCU in all users of __module_text_address().
2025-01-09 21:00 ` Alexei Starovoitov
@ 2025-01-29 8:47 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-29 8:47 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: linux-modules, LKML, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, Alexei Starovoitov, Andrii Nakryiko,
Daniel Borkmann, Eduard Zingerman, Hao Luo, Jiri Olsa,
John Fastabend, KP Singh, Martin KaFai Lau, Masami Hiramatsu,
Mathieu Desnoyers, Matt Bobrowski, Song Liu, Stanislav Fomichev,
Steven Rostedt, Yonghong Song, bpf, linux-trace-kernel
__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
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
The previous version was broken in terms that the break statement broke
out of the scoped_guard loop and added something to the list. This is
now fixed by adding the "skip_add" bool.
While at it, I updated the comment by removing the "we".
kernel/trace/bpf_trace.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index adc947587eb81..e6a17a60d8787 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2345,10 +2345,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
@@ -2932,18 +2931,21 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
u32 i, err = 0;
for (i = 0; i < addrs_cnt; i++) {
+ bool skip_add = false;
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 it's already stored */
+ if (!mod || has_module(&arr, mod)) {
+ skip_add = true;
+ break; /* scoped_guard */
+ }
+ if (!try_module_get(mod))
+ err = -EINVAL;
}
- if (!try_module_get(mod))
- err = -EINVAL;
- preempt_enable();
+ if (skip_add)
+ continue;
if (err)
break;
err = add_module(&arr, mod);
--
2.47.2
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3.5 25/28] kprobes: Use RCU in all users of __module_text_address().
2025-01-28 5:44 ` Masami Hiramatsu
2025-01-28 7:10 ` Sebastian Andrzej Siewior
@ 2025-01-29 8:49 ` Sebastian Andrzej Siewior
1 sibling, 0 replies; 14+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-29 8:49 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: linux-modules, linux-kernel, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, David S. Miller, Anil S Keshavamurthy,
Naveen N Rao, linux-trace-kernel
__module_text_address() can be invoked within a RCU section, there is no
requirement to have preemption disabled.
Replace the preempt_disable() section around __module_text_address()
with RCU.
Cc: David S. Miller <davem@davemloft.net>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
Update due to the collision during the merge window.
kernel/kprobes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 0305692106709..9c8afbb957b0f 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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;
--
2.47.2
^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2025-01-29 8:49 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250108090457.512198-1-bigeasy@linutronix.de>
2025-01-08 9:04 ` [PATCH v3 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 17/28] arm64: module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
2025-01-20 10:09 ` Shrikanth Hegde
2025-01-08 9:04 ` [PATCH v3 25/28] bpf: " Sebastian Andrzej Siewior
2025-01-09 18:38 ` Alexei Starovoitov
2025-01-09 20:54 ` Sebastian Andrzej Siewior
2025-01-09 21:00 ` Alexei Starovoitov
2025-01-29 8:47 ` [PATCH v3.5 " Sebastian Andrzej Siewior
2025-01-08 9:04 ` [PATCH v3 26/28] kprobes: " Sebastian Andrzej Siewior
2025-01-28 5:44 ` Masami Hiramatsu
2025-01-28 7:10 ` Sebastian Andrzej Siewior
2025-01-29 8:49 ` [PATCH v3.5 25/28] " Sebastian Andrzej Siewior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox