mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
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>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH v2 03/28] module: Use proper RCU assignment in add_kallsyms().
Date: Fri, 20 Dec 2024 18:41:17 +0100	[thread overview]
Message-ID: <20241220174731.514432-4-bigeasy@linutronix.de> (raw)
In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de>

add_kallsyms() assigns the RCU pointer module::kallsyms and setups the
structures behind it which point to init-data. The module was not
published yet, nothing can see the kallsyms pointer and the data behind
it. Also module's init function was not yet invoked.
There is no need to use rcu_dereference() here, it is just to keep
checkers quiet. The whole RCU read section is also not needed.

Use a local kallsyms pointer and setup the data structures. Assign that
pointer to the data structure at the end via rcu_assign_pointer().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/module/kallsyms.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c
index bf65e0c3c86fc..45846ae4042d1 100644
--- a/kernel/module/kallsyms.c
+++ b/kernel/module/kallsyms.c
@@ -177,19 +177,15 @@ void add_kallsyms(struct module *mod, const struct load_info *info)
 	unsigned long strtab_size;
 	void *data_base = mod->mem[MOD_DATA].base;
 	void *init_data_base = mod->mem[MOD_INIT_DATA].base;
+	struct mod_kallsyms *kallsyms;
 
-	/* Set up to point into init section. */
-	mod->kallsyms = (void __rcu *)init_data_base +
-		info->mod_kallsyms_init_off;
+	kallsyms = init_data_base + info->mod_kallsyms_init_off;
 
-	rcu_read_lock();
-	/* The following is safe since this pointer cannot change */
-	rcu_dereference(mod->kallsyms)->symtab = (void *)symsec->sh_addr;
-	rcu_dereference(mod->kallsyms)->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
+	kallsyms->symtab = (void *)symsec->sh_addr;
+	kallsyms->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
 	/* Make sure we get permanent strtab: don't use info->strtab. */
-	rcu_dereference(mod->kallsyms)->strtab =
-		(void *)info->sechdrs[info->index.str].sh_addr;
-	rcu_dereference(mod->kallsyms)->typetab = init_data_base + info->init_typeoffs;
+	kallsyms->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
+	kallsyms->typetab = init_data_base + info->init_typeoffs;
 
 	/*
 	 * Now populate the cut down core kallsyms for after init
@@ -199,20 +195,19 @@ void add_kallsyms(struct module *mod, const struct load_info *info)
 	mod->core_kallsyms.strtab = s = data_base + info->stroffs;
 	mod->core_kallsyms.typetab = data_base + info->core_typeoffs;
 	strtab_size = info->core_typeoffs - info->stroffs;
-	src = rcu_dereference(mod->kallsyms)->symtab;
-	for (ndst = i = 0; i < rcu_dereference(mod->kallsyms)->num_symtab; i++) {
-		rcu_dereference(mod->kallsyms)->typetab[i] = elf_type(src + i, info);
+	src = kallsyms->symtab;
+	for (ndst = i = 0; i < kallsyms->num_symtab; i++) {
+		kallsyms->typetab[i] = elf_type(src + i, info);
 		if (i == 0 || is_livepatch_module(mod) ||
 		    is_core_symbol(src + i, info->sechdrs, info->hdr->e_shnum,
 				   info->index.pcpu)) {
 			ssize_t ret;
 
 			mod->core_kallsyms.typetab[ndst] =
-			    rcu_dereference(mod->kallsyms)->typetab[i];
+				kallsyms->typetab[i];
 			dst[ndst] = src[i];
 			dst[ndst++].st_name = s - mod->core_kallsyms.strtab;
-			ret = strscpy(s,
-				      &rcu_dereference(mod->kallsyms)->strtab[src[i].st_name],
+			ret = strscpy(s, &kallsyms->strtab[src[i].st_name],
 				      strtab_size);
 			if (ret < 0)
 				break;
@@ -220,7 +215,9 @@ void add_kallsyms(struct module *mod, const struct load_info *info)
 			strtab_size -= ret + 1;
 		}
 	}
-	rcu_read_unlock();
+
+	/* Set up to point into init section. */
+	rcu_assign_pointer(mod->kallsyms, kallsyms);
 	mod->core_kallsyms.num_symtab = ndst;
 }
 
-- 
2.45.2


  parent reply	other threads:[~2024-12-20 17:47 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-20 17:41 [PATCH v2 00/28] module: Use RCU instead of RCU-sched Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 01/28] module: Extend the preempt disabled section in dereference_symbol_descriptor() Sebastian Andrzej Siewior
2025-01-07 10:58   ` Sergey Senozhatsky
2024-12-20 17:41 ` [PATCH v2 02/28] module: Begin to move from RCU-sched to RCU Sebastian Andrzej Siewior
2024-12-20 17:41 ` Sebastian Andrzej Siewior [this message]
2024-12-20 17:41 ` [PATCH v2 04/28] module: Use RCU in find_kallsyms_symbol() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 05/28] module: Use RCU in module_get_kallsym() Sebastian Andrzej Siewior
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 07/28] module: Use RCU in __find_kallsyms_symbol_value() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 08/28] module: Use RCU in module_kallsyms_on_each_symbol() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 09/28] module: Remove module_assert_mutex_or_preempt() from try_add_tainted_module() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 10/28] module: Use RCU in find_symbol() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 11/28] module: Use RCU in __is_module_percpu_address() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 12/28] module: Allow __module_address() to be called from RCU section Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 13/28] module: Use RCU in search_module_extables() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 14/28] module: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 15/28] module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 16/28] ARM: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 17/28] arm64: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 18/28] LoongArch/orc: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address() 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 21/28] x86: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 22/28] jump_label: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 23/28] jump_label: Use RCU in all users of __module_text_address() 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
2024-12-20 17:41 ` [PATCH v2 26/28] static_call: " Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 27/28] bug: Use RCU instead RCU-sched to protect module_bug_list Sebastian Andrzej Siewior
2024-12-20 17:41 ` [PATCH v2 28/28] cfi: Use RCU while invoking __module_address() Sebastian Andrzej Siewior
2024-12-30 21:13   ` Petr Pavlu
2025-01-02 23:59     ` Sami Tolvanen
2024-12-31  3:33   ` Elliot Berman
2025-01-03  0:24     ` Sami Tolvanen
2025-01-06 18:00       ` Elliot Berman
2025-01-06 21:24         ` Sami Tolvanen
2025-01-07 15:44           ` Sebastian Andrzej Siewior
2025-01-02 12:47 ` [PATCH v2 00/28] module: Use RCU instead of RCU-sched Christophe Leroy
2025-01-07 15:45   ` Sebastian Andrzej Siewior
2025-01-07  8:48 ` Peter Zijlstra

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=20241220174731.514432-4-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=da.gomez@samsung.com \
    --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®