linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-modules@vger.kernel.org,
	Daniel Gomez <da.gomez@samsung.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Petr Pavlu <petr.pavlu@suse.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] module: Use complete RCU protection instead a mix of RCU and RCU-sched.
Date: Tue, 10 Dec 2024 13:08:01 +0100	[thread overview]
Message-ID: <20241210120801.GP21636@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20241205215102.hRywUW2A@linutronix.de>

On Thu, Dec 05, 2024 at 10:51:02PM +0100, Sebastian Andrzej Siewior wrote:
> The RCU usage in module was introduced in commit d72b37513cdfb ("Remove
> stop_machine during module load v2") and it claimed not to be RCU but
> similar. Then there was another improvement in commit e91defa26c527
> ("module: don't use stop_machine on module load"). It become a mix of
> RCU and RCU-sched and was eventually fixed 0be964be0d450 ("module:
> Sanitize RCU usage and locking"). Later RCU & RCU-sched was merged in
> commit cb2f55369d3a9 ("modules: Replace synchronize_sched() and
> call_rcu_sched()") so that was aligned.
> 
> Looking at it today, there is still leftovers. The preempt_disable() was
> used instead rcu_read_lock_sched(). The RCU & RCU-sched merge was not
> complete as there is still rcu_dereference_sched() for module::kallsyms.
> 
> The RCU-list modules and unloaded_tainted_modules are always accessed
> under RCU protection or the module_mutex. The modules list iteration can
> always happen safely because the module will not disappear.
> Once the module is removed (free_module()) then after removing the
> module from the list, there is a synchronize_rcu() which waits until
> every RCU reader left the section. That means iterating over the list
> within a RCU-read section is enough, there is no need to disable
> preemption. module::kallsyms is first assigned in add_kallsyms() before
> the module is added to the list. At this point, it points to init data.
> This pointer is later updated and before the init code is removed there
> is also synchronize_rcu() in do_free_init(). That means A RCU read lock
> is enough for protection and rcu_dereference() can be safely used.
> 
> Replace preempt-disable sections with RCU-read sections. Replace
> rcu_dereference_sched() with rcu_dereference(). Remove
> module_assert_mutex_or_preempt(), its goal is covered by the following
> RCU usage.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  kernel/module/internal.h | 11 -------
>  kernel/module/kallsyms.c | 45 +++++++++-------------------
>  kernel/module/main.c     | 64 ++++++++++++----------------------------
>  kernel/module/tracking.c |  2 --
>  kernel/module/version.c  | 11 ++++---
>  5 files changed, 38 insertions(+), 95 deletions(-)

There's more in kernel/jump_label.c and possibly other sites, grep for
__module_address.

  parent reply	other threads:[~2024-12-10 12:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05 21:51 [PATCH] module: Use complete RCU protection instead a mix of RCU and RCU-sched Sebastian Andrzej Siewior
2024-12-09 12:07 ` Peter Zijlstra
2024-12-10 12:08 ` Peter Zijlstra [this message]
2024-12-10 12:58   ` Sebastian Andrzej Siewior

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=20241210120801.GP21636@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bigeasy@linutronix.de \
    --cc=da.gomez@samsung.com \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=paulmck@kernel.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;
as well as URLs for NNTP newsgroup(s).