* [PATCH v2 06/28] module: Use RCU in find_module_all().
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
@ 2024-12-20 17:41 ` Sebastian Andrzej Siewior
2025-01-02 14:16 ` Petr Mladek
2024-12-20 17:41 ` [PATCH v2 17/28] arm64: module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
` (4 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-12-20 17:41 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
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 263fac44d3ca3..c7db326f4e88e 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.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 17/28] arm64: module: Use RCU in all users of __module_text_address().
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
2024-12-20 17:41 ` [PATCH v2 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
@ 2024-12-20 17:41 ` Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-12-20 17:41 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
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.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address().
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
2024-12-20 17:41 ` [PATCH v2 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 17/28] arm64: module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
@ 2024-12-20 17:41 ` Sebastian Andrzej Siewior
2024-12-27 17:19 ` Steven Rostedt
2024-12-20 17:41 ` [PATCH v2 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
` (2 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-12-20 17:41 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
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
arch/loongarch/kernel/ftrace_dyn.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c
index 18056229e22e4..5e0d870935542 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();
+ guard(rcu)();
mod = __module_text_address(pc);
- preempt_enable();
}
if (WARN_ON(!mod))
--
2.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 20/28] powerpc/ftrace: Use RCU in all users of __module_text_address().
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
` (2 preceding siblings ...)
2024-12-20 17:41 ` [PATCH v2 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
@ 2024-12-20 17:41 ` Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 24/28] bpf: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 25/28] kprobes: " Sebastian Andrzej Siewior
5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-12-20 17:41 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
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.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 24/28] bpf: Use RCU in all users of __module_text_address().
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
` (3 preceding siblings ...)
2024-12-20 17:41 ` [PATCH v2 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
@ 2024-12-20 17:41 ` Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 25/28] kprobes: " Sebastian Andrzej Siewior
5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-12-20 17:41 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
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.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 25/28] kprobes: Use RCU in all users of __module_text_address().
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
` (4 preceding siblings ...)
2024-12-20 17:41 ` [PATCH v2 24/28] bpf: " Sebastian Andrzej Siewior
@ 2024-12-20 17:41 ` Sebastian Andrzej Siewior
5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-12-20 17:41 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
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.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address().
2024-12-20 17:41 ` [PATCH v2 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
@ 2024-12-27 17:19 ` Steven Rostedt
2025-01-07 17:12 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2024-12-27 17:19 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, Huacai Chen, Mark Rutland, Masami Hiramatsu,
WANG Xuerui, linux-trace-kernel, loongarch
On Fri, 20 Dec 2024 18:41:33 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> --- 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();
> + guard(rcu)();
> mod = __module_text_address(pc);
> - preempt_enable();
> }
>
> if (WARN_ON(!mod))
> --
I personally dislike swapping one line of protection for the guard() code.
Although, I do think scoped_guard() can work.
That is:
if (!mod) {
read_rcu_lock();
mod = __module_text_address(pc);
read_rcu_unlock();
}
Is easier to understand than:
if (!mod) {
guard(rcu)();
mod = __module_text_address(pc);
}
Because it makes me wonder, why use a guard() for a one liner?
But, when I saw your other patch, if we had:
if (!mod) {
scoped_guard(rcu)()
mod = __module_text_address(pc);
}
To me, hat looks much better than the guard() as it is obvious to what the
code is protecting. Even though, I still prefer the explicit, lock/unlock.
Maybe, just because I'm more used to it.
IMHO, guard() is for complex functions that are error prone. A single line
is not something that is error prone (unless you don't match the lock and
unlock properly, but that's pretty obvious when that happens).
But this is just my own opinion.
-- Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 06/28] module: Use RCU in find_module_all().
2024-12-20 17:41 ` [PATCH v2 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
@ 2025-01-02 14:16 ` Petr Mladek
0 siblings, 0 replies; 9+ messages in thread
From: Petr Mladek @ 2025-01-02 14:16 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, Jiri Kosina, Joe Lawrence, Josh Poimboeuf,
Masami Hiramatsu, Mathieu Desnoyers, Miroslav Benes,
Steven Rostedt, linux-trace-kernel, live-patching
On Fri 2024-12-20 18:41:20, Sebastian Andrzej Siewior wrote:
> 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
> 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(-)
I looked primary on the changes in the livepatch code. But the entire
patch looks good to me:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address().
2024-12-27 17:19 ` Steven Rostedt
@ 2025-01-07 17:12 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-01-07 17:12 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-modules, linux-kernel, Daniel Gomez, Luis Chamberlain,
Paul E . McKenney, Peter Zijlstra, Petr Pavlu, Sami Tolvanen,
Thomas Gleixner, Huacai Chen, Mark Rutland, Masami Hiramatsu,
WANG Xuerui, linux-trace-kernel, loongarch
On 2024-12-27 12:19:46 [-0500], Steven Rostedt wrote:
…
> Is easier to understand than:
>
> if (!mod) {
> guard(rcu)();
> mod = __module_text_address(pc);
> }
>
> Because it makes me wonder, why use a guard() for a one liner?
Why not? The context ends immediately after.
> But, when I saw your other patch, if we had:
>
> if (!mod) {
> scoped_guard(rcu)()
> mod = __module_text_address(pc);
> }
Okay, if this looks better, let me update it. It just you already have a
scope (the {} after the if) and then we start yet another block. But if
this looks better so be it.
> To me, hat looks much better than the guard() as it is obvious to what the
> code is protecting. Even though, I still prefer the explicit, lock/unlock.
> Maybe, just because I'm more used to it.
I'm probably also used to the explicit part but numerous people said to
use this from now on. And it results in less lines and you don't have to
worry about each return statement. So it somehow looks/ feels line an
upgrade.
> IMHO, guard() is for complex functions that are error prone. A single line
> is not something that is error prone (unless you don't match the lock and
> unlock properly, but that's pretty obvious when that happens).
True but this is now a one liner which might be extended later on. Also
the context is one line.
> But this is just my own opinion.
>
> -- Steve
Sebastian
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-01-07 17:12 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20241220174731.514432-1-bigeasy@linutronix.de>
2024-12-20 17:41 ` [PATCH v2 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
2025-01-02 14:16 ` Petr Mladek
2024-12-20 17:41 ` [PATCH v2 17/28] arm64: module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 19/28] LoongArch: ftrace: " Sebastian Andrzej Siewior
2024-12-27 17:19 ` Steven Rostedt
2025-01-07 17:12 ` Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 24/28] bpf: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 25/28] kprobes: " 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;
as well as URLs for NNTP newsgroup(s).