mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Benjamin Berg <benjamin@sipsolutions.net>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	 linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
	 johannes@sipsolutions.net
Cc: Daniel Gomez <da.gomez@samsung.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	 "Paul E . McKenney"	 <paulmck@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Petr Pavlu	 <petr.pavlu@suse.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Thomas Gleixner	 <tglx@linutronix.de>
Subject: Re: [PATCH v3 15/28] module: Use RCU in all users of __module_text_address().
Date: Wed, 23 Apr 2025 17:17:31 +0200	[thread overview]
Message-ID: <db0f8ec385762e6edb3edf5054a76ea189135e6e.camel@sipsolutions.net> (raw)
In-Reply-To: <20250108090457.512198-16-bigeasy@linutronix.de>

Hi,

On Wed, 2025-01-08 at 10:04 +0100, 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.

Unfortunately, this patch causes a performance regression for us. The
trouble is that we enable kmemleak and run trace-cmd so a lot of stack
traces need to be collected. Obviously, we also have lockdep enabled.

Now, combine this with the UML stack dumping code calling into
__kernel_text_address a lot[1] and it really has a relevant performance
impact. I saw the kernel spending 40% of its own CPU time just on the
lock in is_module_text_address.

Maybe kernel_text_address should leave the RCU handling to the caller
and assume that the RCU read lock is already taken?

Benjamin

[1] The UM arch dump_stack function reads every "unsigned long" on the
stack and tests it using __kernel_text_address.

> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  kernel/module/main.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 80877741ac7e5..6a99076146cbc 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -823,13 +823,12 @@ void symbol_put_addr(void *addr)
>  
>  	/*
>  	 * Even though we hold a reference on the module; we still
> need to
> -	 * disable preemption in order to safely traverse the data
> structure.
> +	 * RCU read section in order to safely traverse the data
> structure.
>  	 */
> -	preempt_disable();
> +	guard(rcu)();
>  	modaddr = __module_text_address(a);
>  	BUG_ON(!modaddr);
>  	module_put(modaddr);
> -	preempt_enable();
>  }
>  EXPORT_SYMBOL_GPL(symbol_put_addr);
>  
> @@ -3694,20 +3693,15 @@ struct module *__module_address(unsigned long
> addr)
>   */
>  bool is_module_text_address(unsigned long addr)
>  {
> -	bool ret;
> -
> -	preempt_disable();
> -	ret = __module_text_address(addr) != NULL;
> -	preempt_enable();
> -
> -	return ret;
> +	guard(rcu)();
> +	return __module_text_address(addr) != NULL;
>  }
>  
>  /**
>   * __module_text_address() - get the module whose code contains an
> address.
>   * @addr: the address.
>   *
> - * Must be called with preempt disabled or module mutex held so that
> + * Must be called within RCU read section or module mutex held so
> that
>   * module doesn't get freed during this.
>   */
>  struct module *__module_text_address(unsigned long addr)


  reply	other threads:[~2025-04-23 15:17 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08  9:04 [PATCH v3 00/28] module: Use RCU instead of RCU-sched Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 01/28] module: Extend the preempt disabled section in dereference_symbol_descriptor() Sebastian Andrzej Siewior
2025-01-08  9:55   ` Helge Deller
2025-01-08 10:52     ` Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 02/28] module: Begin to move from RCU-sched to RCU Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 03/28] module: Use proper RCU assignment in add_kallsyms() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 04/28] module: Use RCU in find_kallsyms_symbol() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 05/28] module: Use RCU in module_get_kallsym() Sebastian Andrzej Siewior
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 07/28] module: Use RCU in __find_kallsyms_symbol_value() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 08/28] module: Use RCU in module_kallsyms_on_each_symbol() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 09/28] module: Remove module_assert_mutex_or_preempt() from try_add_tainted_module() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 10/28] module: Use RCU in find_symbol() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 11/28] module: Use RCU in __is_module_percpu_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 12/28] module: Allow __module_address() to be called from RCU section Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 13/28] module: Use RCU in search_module_extables() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 14/28] module: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 15/28] module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2025-04-23 15:17   ` Benjamin Berg [this message]
2025-04-23 18:16     ` Paul E. McKenney
2025-04-24  9:05       ` Sebastian Andrzej Siewior
2025-04-24  9:30         ` Benjamin Berg
2025-04-24 14:47           ` Paul E. McKenney
2025-04-24 15:17           ` Peter Zijlstra
2025-01-08  9:04 ` [PATCH v3 16/28] ARM: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 17/28] arm64: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 18/28] LoongArch/orc: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address() 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 21/28] cfi: Use RCU while invoking __module_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 22/28] x86: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2025-11-03 10:08   ` Michal Pecio
2025-11-03 10:34     ` Sebastian Andrzej Siewior
2025-11-03 10:39       ` Michal Pecio
2025-11-03 11:37         ` Sebastian Andrzej Siewior
2025-11-03 17:37           ` Michal Pecio
2025-01-08  9:04 ` [PATCH v3 23/28] jump_label: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 24/28] jump_label: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
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
2025-01-08  9:04 ` [PATCH v3 27/28] static_call: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 28/28] bug: Use RCU instead RCU-sched to protect module_bug_list Sebastian Andrzej Siewior
2025-01-13 11:09 ` [PATCH v3 00/28] module: Use RCU instead of RCU-sched Petr Pavlu
2025-01-13 13:23   ` Sebastian Andrzej Siewior
2025-01-24 17:49   ` Sebastian Andrzej Siewior
2025-01-27 12:22     ` Petr Pavlu
2025-01-29  8:52       ` Sebastian Andrzej Siewior
2025-01-30 13:42         ` Petr Pavlu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db0f8ec385762e6edb3edf5054a76ea189135e6e.camel@sipsolutions.net \
    --to=benjamin@sipsolutions.net \
    --cc=bigeasy@linutronix.de \
    --cc=da.gomez@samsung.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®