From patchwork Fri Dec 20 17:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917194 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A52D21B182; Fri, 20 Dec 2024 17:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; cv=none; b=H9aSzaLDU7t0KWnLFIfde+/u2R7A6cb6LugHkYODYc5uvBbiE1r3p4XJWUb2a3nxWHJmTS84QLj5mwbEtLU/v3f4as5AJuzg7DzZ6Vj4h3BwCJWWvqzPvtyH3eMlp0neDNnjcUdgaTl6jml19V5Ebgcpfhx3pXInkRVvAqKNGc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; c=relaxed/simple; bh=Ez9a8QqH18hxi3K7lFzriilp7Ti8WL3yb/1TbjOD3jM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZktWysRMa9tB/Q5Lp7n8P5OxsSWruOPTi3ELyqD+hST2K5H9Wlo01/P14ZDVTkXOyxUs4B/xDGiqIlO55bxgWfpESle3HMbQ550+2LZyp2PNDyoPoLy7M6vwpgy0kZEfpVqGvAaTsE/JjVuO5SqifDssWNCdj7nM7D95wo4WCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VeWM7rW9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fMKoUaee; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VeWM7rW9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fMKoUaee" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mUoDDG+l47O3+vMUk6eVXEzXq+1GxAnfmkZBqPU3miY=; b=VeWM7rW9QXtAMWnHN9WczxUc8haDbC9szTWTTWi1ntBBobpSJCm6AvixLsi5EK9Lb380y8 DFoFOB2i/diTlb5SXTH0+m1Wlqc9IjtX8EoJS1rBn2USkwu4mu2n8vuE3/jiiJB7cdoduG TjWlcB+QEr4ItWUiSJRLYi4VFU0XIT+sqTD3S9y+cXGZsQXoUn00OpnHyu8sar4TZ6fP6M j+E+ywk+liYExCeT679qnQyqlvXwtPE+QReVRbAOtglXDepHRwYhlH/v0MGxTlhLugx3CM vK/9c7WIDzTJ7RdlYOS1YK0LaRXplkCsVPKsovr6ZYWZOLU5kMGbIJD6Cq4T4w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mUoDDG+l47O3+vMUk6eVXEzXq+1GxAnfmkZBqPU3miY=; b=fMKoUaee6BrFn2ilOUvKtZTzJ99Gmt55PbVZODBJtohd+3QWbGix3h5CEtsqB532rftSSe IAum2v4ago/eu3CA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , "James E.J. Bottomley" , Christophe Leroy , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Naveen N Rao , Nicholas Piggin , Sergey Senozhatsky , linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 01/28] module: Extend the preempt disabled section in dereference_symbol_descriptor(). Date: Fri, 20 Dec 2024 18:41:15 +0100 Message-ID: <20241220174731.514432-2-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 dereference_symbol_descriptor() needs to obtain the module pointer belonging to pointer in order to resolve that pointer. The returned mod pointer is obtained under RCU-sched/ preempt_disable() guarantees and needs to be used within this section to ensure that the module is not removed in the meantime. Extend the preempt_disable() section to also cover dereference_module_function_descriptor(). Fixes: 04b8eb7a4ccd9 ("symbol lookup: introduce dereference_symbol_descriptor()") Cc: "James E.J. Bottomley" Cc: Christophe Leroy Cc: Helge Deller Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Naveen N Rao Cc: Nicholas Piggin Cc: Sergey Senozhatsky Cc: linux-parisc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Sebastian Andrzej Siewior --- include/linux/kallsyms.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index c3f075e8f60cb..1c6a6c1704d8d 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -57,10 +57,10 @@ static inline void *dereference_symbol_descriptor(void *ptr) preempt_disable(); mod = __module_address((unsigned long)ptr); - preempt_enable(); if (mod) ptr = dereference_module_function_descriptor(mod, ptr); + preempt_enable(); #endif return ptr; } From patchwork Fri Dec 20 17:41:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917196 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A59221B8EC; Fri, 20 Dec 2024 17:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; cv=none; b=oHFWiNBpo5wY8/qqqsRPZyFwpjauitLanIbE1JxFXj8bg/cB4UuCKZ/fCwD8BCBZtabZHGBQSunOHt4qNdKx6iZo2L0uXSYOcf5zmXFV38Kt92HizILWqVlVyKxAxhSGbbxzuBEkWQitiYWCtU5KXvMBJdNr6E/i+OV8di0xP/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; c=relaxed/simple; bh=QdGgvi5tGLhqK/dn8eqwWdqKTl7Q/eJpMW6qel5l0U4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JkWOVzmyV7ZFgVbeyj45PlzxcgZ44YvIMQNu9Lcrs+COe3Xg/cRtcaSTLwE9bdSKP8y15clw4rG0X1fOPCqMnmOEYx5GVJ2V4yzZRlfLK81C94bxU2/MBo/oNmR1l5klQZM/faT9eujyd9tn8/cMuoVwcgLxgm5EcGKz0f3FlAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uzaDzhxy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UCDe4W+R; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uzaDzhxy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UCDe4W+R" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZPVA+hMuMw4hY+ZysB1dEUHiJRu5pyZbasptXv2BLE=; b=uzaDzhxyXTmQkSAc0K1o4EMvNAGHIaRmJgFnXUDBLpnvTUnNrZF3IxQkXMle9DOIFP09p/ O7zZLgMPdleFJZIXFqLSZJcrzBvqqKE/kEvGg0zipZGBRgVKz+mhEmDP1287wupJV/gLxF ypzJD+OaLRCOvUuBu8NmmmJ0bGMOHWk20iKmmZreszoLH0892mlHLatJ1MtUAyeUv4ESn0 mNgAaImBa82wn6k4oDam631nNIqzntqcABW1NoiMb5HF/vlwSwLpME4lHkktI92H76Gy+J UfFAC79ayMJdVL2FR69lvI1bz3KOtmPS5NJkHKLzEI42zrSvAOfpG9+5Pcdw/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZPVA+hMuMw4hY+ZysB1dEUHiJRu5pyZbasptXv2BLE=; b=UCDe4W+R3XaIKdQffGUi5fHZGIwds2AsVpryRDLi64OiuicjkjUwQiZYw0G0az544Oncy+ VrA1AxFUfEkyrVDw== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 02/28] module: Begin to move from RCU-sched to RCU. Date: Fri, 20 Dec 2024 18:41:16 +0100 Message-ID: <20241220174731.514432-3-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Convert module code and its users step by step. Update comments and convert print_modules() to use RCU. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/main.c | 9 ++++----- kernel/module/tree_lookup.c | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 5399c182b3cbe..5cce4a92d7ba3 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -67,7 +67,7 @@ /* * Mutex protects: - * 1) List of modules (also safely readable with preempt_disable), + * 1) List of modules (also safely readable within RCU read section), * 2) module_use links, * 3) mod_tree.addr_min/mod_tree.addr_max. * (delete and add uses RCU list operations). @@ -1348,7 +1348,7 @@ static void free_module(struct module *mod) mod_tree_remove(mod); /* Remove this module from bug list, this uses list_del_rcu */ module_bug_cleanup(mod); - /* Wait for RCU-sched synchronizing before releasing mod->list and buglist. */ + /* Wait for RCU synchronizing before releasing mod->list and buglist. */ synchronize_rcu(); if (try_add_tainted_module(mod)) pr_err("%s: adding tainted module to the unloaded tainted modules list failed.\n", @@ -2965,7 +2965,7 @@ static noinline int do_init_module(struct module *mod) #endif /* * We want to free module_init, but be aware that kallsyms may be - * walking this with preempt disabled. In all the failure paths, we + * walking this within an RCU read section. In all the failure paths, we * call synchronize_rcu(), but we don't want to slow down the success * path. execmem_free() cannot be called in an interrupt, so do the * work and call synchronize_rcu() in a work queue. @@ -3754,7 +3754,7 @@ void print_modules(void) printk(KERN_DEFAULT "Modules linked in:"); /* Most callers should already have preempt disabled, but make sure */ - preempt_disable(); + guard(rcu)(); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; @@ -3762,7 +3762,6 @@ void print_modules(void) } print_unloaded_tainted_modules(); - preempt_enable(); if (last_unloaded_module.name[0]) pr_cont(" [last unloaded: %s%s]", last_unloaded_module.name, last_unloaded_module.taints); diff --git a/kernel/module/tree_lookup.c b/kernel/module/tree_lookup.c index 277197977d438..d3204c5c74eb7 100644 --- a/kernel/module/tree_lookup.c +++ b/kernel/module/tree_lookup.c @@ -12,11 +12,11 @@ /* * Use a latched RB-tree for __module_address(); this allows us to use - * RCU-sched lookups of the address from any context. + * RCU lookups of the address from any context. * - * This is conditional on PERF_EVENTS || TRACING because those can really hit - * __module_address() hard by doing a lot of stack unwinding; potentially from - * NMI context. + * This is conditional on PERF_EVENTS || TRACING || CFI_CLANG because those can + * really hit __module_address() hard by doing a lot of stack unwinding; + * potentially from NMI context. */ static __always_inline unsigned long __mod_tree_val(struct latch_tree_node *n) From patchwork Fri Dec 20 17:41:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917195 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8302221C9EF; Fri, 20 Dec 2024 17:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; cv=none; b=NRFIVdy6xltuyMzMv1v8Wx/D9xQ5oPv39Iu/8W7/b63d9RbkKan+8wmmARwyFveq1L4rC+ETB/OfkwKK7V4wm2qte7u0hiTqy/eQaP7V+6elvZQRdN/Ir0q07Ze8Z0W1am3Byzb6cGpHp5Le5PDQ7nGXxyJZkDtY0ivEgmMyIXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; c=relaxed/simple; bh=ApxMQvvcCvnB5ydSNW0iQzeRyKqqIkkgQTrsnUfXqX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gHN7AGobhb3JTbXGoHpWUAcpZySshFGn/fNMQv1M3bLpoCeXBkKdF3fhOYVjqXWNliyto+SAj0p+UEB8hsNCqOvnRfs/WjjcYNX1ucE+DbXfvkCOO/qo+aeCgsPrLhm6vPzJQWmkjy8o86J9lgkud8c+Pr07+CCUwjkoWp3/hYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UzPefDkJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XFV5oera; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UzPefDkJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XFV5oera" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bQ6ZqxuwJeNb/vKpE3WEBj3zTXNytGr0GQv7pX1w1to=; b=UzPefDkJBXEBPRcOg51PLcgiYOmoVQvAfNE6budNXvJeQ0Y/rvWgvX945kODJtJgnHSQco 3n/X4L8NYrsD2FYRjRLvWsbE3y27iLoGprzkowXGaV90DNfNMSlZQU4JViVfmL2gLxE/jW lDiUEHvc035IZ99+pRGbvsIFbc2YxFfp858r0qjWQMzcJkWs81V73i2dlRm+4+hwJmmUV/ 2rMJYpFFA8I+1A19m2xlsF9G8EOfQtOTiKBcs5xt9V5mVvYuvQ6JpPQKKErYdkqiqsQ/iD ZVDFLin9DVDQFKa+Tf6LhW2aj11gh66+LkKaEyDwMYQKhAHrSehXM1DTFE790g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bQ6ZqxuwJeNb/vKpE3WEBj3zTXNytGr0GQv7pX1w1to=; b=XFV5oeraBYcJoGPH+xe621s4U2cGAEAwxxLYBpAgHvuuxbj+tO1K7rQJMNhSzcQmFdy5Hf 3AP89P23zOluCGCA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 03/28] module: Use proper RCU assignment in add_kallsyms(). Date: Fri, 20 Dec 2024 18:41:17 +0100 Message-ID: <20241220174731.514432-4-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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; } From patchwork Fri Dec 20 17:41:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917197 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E76A421CA00; Fri, 20 Dec 2024 17:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; cv=none; b=ksZdic3SIl5Q7a1kw/Erx4Ug1nu0t+1c3mGnWWyNHLh9uRH84YLmw6QGbtwY2hHSUGdMX2IRe/iN6P78TblRpSqbqnitqjTA91YoO6HaOhQPEI7qEZdD+9buDOFGgaRCw1mqpz3+wu2Zreo/EhcU3akbXTLmgUvN88vQWxKE2u4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716861; c=relaxed/simple; bh=+tMmuDHymxm4vFnd5USrEbmUauXQHlCNL/qrRG/E+z0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TU57FbGQbGr3xwggUoQmIEU17prK1Tm4MIqORFs6QrpWnN39c2ij30zeXyf2Wj51FJWTX12cgzDOpRvCGbBMmm7t1zerqXtmcmv4BQaxXeYakEGlVWmF6G+w5Kk87806BZCpOzrZOrdT0pwSoad3P/vLFCtUsD1OqQbSc8H9zpk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zJHZQy7a; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cRWwGbMS; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zJHZQy7a"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cRWwGbMS" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBQkgNJsnyD1dMyjjHJldsklJJimcQF6KjLARswWJz4=; b=zJHZQy7a2uxj6v/PogTSedLmCA9KIMQaNtY/vslFIBa+tVxuLKZH/7rlUpUJ/TtCxXy9of vt7ThkYxZ/ot7OZGorEGdIMf3pqlqEHw/0HxTsGNehIcZ9gk/XUjEGWBmEU0L/2C03VHII QtLEsocJcf87pjKOhjp1PG2bAkDailB57EkAlhW/Ppo4VpOfcwzkzUW7qM7XPqYAgIZkAT lWeaqGKGd3gnMciQMPtc/FaTsVixpxkLxR/caFeO2OZmhIlm0qLVqdXC2rdB2KsGq2rb3j 12M1vfB9P8jQq05H86jOIMxT1mkvGllb0Ht8prdCydFAv/0I/3DmQSShP80Evg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBQkgNJsnyD1dMyjjHJldsklJJimcQF6KjLARswWJz4=; b=cRWwGbMS9RG2bIk6NZ/gAcSUj4/H+CPt62mvwZUUuvTEdBZKQM1W8LTeDPSZnI/OWcjDGU 04Vrc824M86AH1Dg== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 04/28] module: Use RCU in find_kallsyms_symbol(). Date: Fri, 20 Dec 2024 18:41:18 +0100 Message-ID: <20241220174731.514432-5-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The modules list and module::kallsyms can be accessed under RCU assumption. Use rcu_dereference() to reference the kallsyms pointer in find_kallsyms_symbol(). Use a RCU section instead of preempt_disable in callers of find_kallsyms_symbol(). Keep the preempt-disable in module_address_lookup() due to __module_address(). Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/kallsyms.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index 45846ae4042d1..3f59d04795572 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -257,7 +257,7 @@ static const char *find_kallsyms_symbol(struct module *mod, { unsigned int i, best = 0; unsigned long nextval, bestval; - struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms); + struct mod_kallsyms *kallsyms = rcu_dereference(mod->kallsyms); struct module_memory *mod_mem; /* At worse, next value is at end of module */ @@ -329,6 +329,7 @@ int module_address_lookup(unsigned long addr, int ret = 0; struct module *mod; + guard(rcu)(); preempt_disable(); mod = __module_address(addr); if (mod) { @@ -356,7 +357,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) { struct module *mod; - preempt_disable(); + guard(rcu)(); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; @@ -368,12 +369,10 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) goto out; strscpy(symname, sym, KSYM_NAME_LEN); - preempt_enable(); return 0; } } out: - preempt_enable(); return -ERANGE; } From patchwork Fri Dec 20 17:41:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917198 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9B60223E8C; Fri, 20 Dec 2024 17:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716863; cv=none; b=KQe0gC9rgBvkB0p3kR9RDGeaZPJCCE4/AJIcoZiAf0ossMjHUW5DLadr66+aAOglbUjMwaga5Gwe7rcBlPjKfDwHl9rxOcceoNYHcjEgJmoWMF3xdYu2ZA2/mKg6tGRgPmvrp237pZvZM5qQfpDthicqmaiHRz3dsGtVqlx6u4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716863; c=relaxed/simple; bh=uffhon2stlFtjZNpQSBh5jUuFAMhJe2bHv90BPUz7UM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gZ3ZIiktdcknsMCM1JR8fEqU3QAyyo2lZFn2jvUhk9ya808CMTqbxA2Q76h272SKzzWM4mMmEWP4KUA83vpbattI2R10jjr7yK6jZXihqnK9VwSf9pSJhlxkqu7/vGfobLmLq6Du5NdrqPrJR6hVDQZSgTIeVtD+V4wzQBSmzrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dEu7ODm0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zsz3UG2V; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dEu7ODm0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zsz3UG2V" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mqxEYbtkExcGhym+IUJ5OSXHEpRmnlTHv1UF2Zfl2oo=; b=dEu7ODm0Mx3txgKEZ3uGPQoiHjPsPmEH2gf7cBnx0OtmqPlRJXHGoGmDDyRsJLr1yuZPPA +1YykkrOboFGhK8gxUWqWNAZYt1TgE31OC4ia+KCI7d/nCWxTnmrk5QWh2xZRuti0g6jPv gku/7x0oBfJbNjrPWCR5o8vVl+BDMs2rXJTBxNWLIPVq3YR845RJvm7EQehhvW6XW4gJlu SQWnnCyx3z6MIBaQbBR+3f07azw1kFZiQ2mepEWU2uf62E27dh2u4i7b8gfv+fQTXd0cKk HjP/yM8OxNM8AR0V7vxwuzj0B7imP3AKtNOMb10UPKfjFLrckutkJEXAZunZhQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mqxEYbtkExcGhym+IUJ5OSXHEpRmnlTHv1UF2Zfl2oo=; b=zsz3UG2VEpwUikzUEVpPK3PxCHdHUa6RsbjThIv+Y22vrAfTj0rdmIGVBHBtHnQeigM15U Fsn9APrdBWGWhKCA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 05/28] module: Use RCU in module_get_kallsym(). Date: Fri, 20 Dec 2024 18:41:19 +0100 Message-ID: <20241220174731.514432-6-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The modules list and module::kallsyms can be accessed under RCU assumption. Iterate the modules with RCU protection, use rcu_dereference() to access the kallsyms pointer. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/kallsyms.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index 3f59d04795572..4eef518204eb5 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -381,13 +381,13 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, { struct module *mod; - preempt_disable(); + guard(rcu)(); list_for_each_entry_rcu(mod, &modules, list) { struct mod_kallsyms *kallsyms; if (mod->state == MODULE_STATE_UNFORMED) continue; - kallsyms = rcu_dereference_sched(mod->kallsyms); + kallsyms = rcu_dereference(mod->kallsyms); if (symnum < kallsyms->num_symtab) { const Elf_Sym *sym = &kallsyms->symtab[symnum]; @@ -396,12 +396,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, strscpy(name, kallsyms_symbol_name(kallsyms, symnum), KSYM_NAME_LEN); strscpy(module_name, mod->name, MODULE_NAME_LEN); *exported = is_exported(name, *value, mod); - preempt_enable(); return 0; } symnum -= kallsyms->num_symtab; } - preempt_enable(); return -ERANGE; } From patchwork Fri Dec 20 17:41:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917199 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9AEB223E85; Fri, 20 Dec 2024 17:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716863; cv=none; b=MpdVYH1K3vCjVi3mEiV6wJpofY3JA6vHydUNv7QtEi3FQ1KFyFCCGdYho6Ilo8lczXPX2PV0oR3k37FWlS5WHqXO336RhoJmtzp7tn3f9IMiRFlPD+6zvFwTqBYX9J3Q9nXKwhnvvdtbW4qoO+2Hc62XygrAglsExPra2QxcwkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716863; c=relaxed/simple; bh=J9y/1aSSXq1tZhT6PnlsnHYagJsUv+gTorVH8FTXEts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NWy3nsVW6Hp9xjNe0Zio37s8037udxUmStLvWttxdSnCggHPE7RBxJY8EyIzRbQet1L9OCprbhdY5P90lWjvdz+45nzcWdroErixKAKKgUpflxOg6bvQT7O79GPJjFWT6L/NSG/3O7S+LeU89ipFs5oA7hJFWJbWbsZy2u20EKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JmPnU7Sr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w9swUvbu; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JmPnU7Sr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w9swUvbu" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9g6lXeoRfGQe6QicLk0OYONPG5zsQWqzIwVn4RNwwbs=; b=JmPnU7SrCtKZo77aBtLgCa1NQyUmL2SR080UfpWQosR6W6mnbJ1Kgf9ZH2dGQm5/Sbp4U8 lMl7V4vGVA+koLi4+5/L8rqNkltgt7WzXljT3OFDVGM11yRsKd0UusOY1/FZabpESRwEz3 n8/Hxt2Ey9eaiUAlDCDf8aGrunCqo/UMPxlbRTDWgTa9y6mbsxuGrIzNQVJv5K+iCt/Yb9 4ig06to82lx9z5I713odCAT/JhKIJ9UofSZuUNn4mxc9NzI57ETFBtxi6BL+VRNQR1AuaN WCwU30x2k0zPFTx1BAYQjCSrg+dG5VE3k/eTa+VmP7UNDVlLt9ZimkdIQPL3kQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9g6lXeoRfGQe6QicLk0OYONPG5zsQWqzIwVn4RNwwbs=; b=w9swUvbuaxMF6akzq9NHRE0kOx5Z/RjiMuatUG+i1zNe0ZUOgdS6jY1IgigUtxXDpmOey6 V94k4flLzbVHsxAQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org 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@vger.kernel.org, live-patching@vger.kernel.org Subject: [PATCH v2 06/28] module: Use RCU in find_module_all(). Date: Fri, 20 Dec 2024 18:41:20 +0100 Message-ID: <20241220174731.514432-7-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Cc: Joe Lawrence Cc: Josh Poimboeuf Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Miroslav Benes Cc: Petr Mladek Cc: Steven Rostedt Cc: linux-trace-kernel@vger.kernel.org Cc: live-patching@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- 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 From patchwork Fri Dec 20 17:41:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917207 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C084C225A23; Fri, 20 Dec 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; cv=none; b=ullcMJudfBOzphkCZA/UK6XbOz0TTU3XULjFjF5aOXP/jup7G/by0EF3xrXYG/e2bKQTD/xzE0bjhMVjzXv6p8lB0xjLvUK/GxOT8kX5X6f1hbabRmTCF75kEvg9IncXLeksNqz019PfMQtKnK8LWkXu/tR0R0CYvuDVoBnRaG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; c=relaxed/simple; bh=XeX9Wfr/ate0+cmWN4pQDA5SZgUW3jGRJaYXMkHeWio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zlr5geUMDhONo9XTUYYNqRTIH/aoEqsxA9uAIsITr/TByaUABdacj+qIlsiXGuVfRF7A9hLn02IDBIIwdkYU91CByye+Nu2CkFvuR71hkk/QodBVyaVrqgNIeppftKld+oHRI9LzQq8q/bx88t4AjWFCkcwjyJg5bF3nu8w66Jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NDgm5Pz8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Dn+69Yco; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NDgm5Pz8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Dn+69Yco" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IqVQDyEYACd6Buc8karGtHVOgbp3vA8Z1uEZRkvpdV8=; b=NDgm5Pz8jcpfVzjsGvRFFOtKI3kmtbLqbOMuszc5W3Q2PErvUqQ/Wh8TICFzD2lP1Uhqqc qaTqhxNuIek97XnwB46dBEccInMpJ7GeSJ+7UAjO7dF76niXqnVYVbgP+gNv6WwFF4X5nY 1LUyQe6KRewZ9D7sEqjlQ47txkWyl7y6DICtQ+8WrRn8xp1nWgd0KtphtiorZPn+pCAmGL FFKDOS0hIDV3QPiEDtFX16O/hvSUZ6Y2c3G+Cs82AcwR3r3RzaJLUjrVB6x3wHYirl4Sx9 fX2ld3vLHq7vDOlcVijYrVV/UrfkT3P1WYIZJAZ/+bDXvsH5pw7kbr7jTEl3eg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IqVQDyEYACd6Buc8karGtHVOgbp3vA8Z1uEZRkvpdV8=; b=Dn+69Yco3oJO/j3hc7IxM2yhf1qEoaCjQl9ydL+nYFwj+9b9H2YgtSVbkIsFS77baZuJVS j+Cab1xrBbsDkSAQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 07/28] module: Use RCU in __find_kallsyms_symbol_value(). Date: Fri, 20 Dec 2024 18:41:21 +0100 Message-ID: <20241220174731.514432-8-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 module::kallsyms can be accessed under RCU assumption. Use rcu_dereference() to access module::kallsyms. Update callers. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/kallsyms.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index 3cba9f933b24f..e3c55bc879c11 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -407,7 +407,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, static unsigned long __find_kallsyms_symbol_value(struct module *mod, const char *name) { unsigned int i; - struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms); + struct mod_kallsyms *kallsyms = rcu_dereference(mod->kallsyms); for (i = 0; i < kallsyms->num_symtab; i++) { const Elf_Sym *sym = &kallsyms->symtab[i]; @@ -447,24 +447,15 @@ static unsigned long __module_kallsyms_lookup_name(const char *name) /* Look for this name: can be of form module:name. */ 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(); - return ret; + return __module_kallsyms_lookup_name(name); } unsigned long find_kallsyms_symbol_value(struct module *mod, const char *name) { - unsigned long ret; - - preempt_disable(); - ret = __find_kallsyms_symbol_value(mod, name); - preempt_enable(); - return ret; + guard(rcu)(); + return __find_kallsyms_symbol_value(mod, name); } int module_kallsyms_on_each_symbol(const char *modname, From patchwork Fri Dec 20 17:41:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917200 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98FC2225798; Fri, 20 Dec 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716864; cv=none; b=FefHXyAObHIdPCzlw4IBpBh5d1rh2+wvEok1VnVuJkXMNNc9Ji2sIHSVFpAgg6nqU0BWhF7qyu/9eAaLbYsBfxT3z6mAn6oikCIqsLjQxZNfLOL7FNKWSDAAn8sEJBGcf/Nu6oD6tssd1Ta9Sg4MjHqNQVjZ5lOsMcBDuXKGO/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716864; c=relaxed/simple; bh=k1ONQSZNQOOKbcdH+TMsaEXVr8iuBZjgNMkNEsJKXVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KLqulg5HZNAtPUuWHDecWLlKZltJbZ0wl0zgwNm6ZzasvuQutRd24T9prahUgZn/LPqrsVdYvaFPRclfwgFIVTPNsxylU73bDSU8jvpxb/OVpkddFPQbDUvROGEughY2r4NrBLmkf883cF30sVBXwarQB4ZVRID4pKhNLw0Yg2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=suSwIAkE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=85eG/JOl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="suSwIAkE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="85eG/JOl" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uLIPxdv+rgZYNiaIzIjicHG2numdAPy4IIa5FKVKOP4=; b=suSwIAkECQLbtC95Gz5w2S2NnFmH9K8BEodyekRWKACAhj1aexIz8040VTCy4dQC8+5ZMZ ZXoPb4Fcsk8EDWuhS3YE+wlXmxeoTqS2FyxLHUECrZnqEjAvUNyE9Y4KFw7aVSOMnl5VRt xYdypXv5pI7h1pl3sDMrq6LY+lPIaqNjqun90WiHQuaQWt/minuuPES1VVSzHOCOvjldeL sCrNGnozb5nuQE44SnfD7fWzqcZ1ummOjg/lzwdxgfRN15fqmouf0cImiXQBEGPc3uM/my JnLYMC2K5wDWAx0S3b335P2kWd9bJOr1tFsCzrU7Hpw9HA8u+n5WTXRH7f23Cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uLIPxdv+rgZYNiaIzIjicHG2numdAPy4IIa5FKVKOP4=; b=85eG/JOlus3ZgkIPpRPGgqV3M4y7soc7OMRJq2TQrop6ixfSTta7e6G75RxcwguoAfe2Hc M9HzVMzBXujMBFBg== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 08/28] module: Use RCU in module_kallsyms_on_each_symbol(). Date: Fri, 20 Dec 2024 18:41:22 +0100 Message-ID: <20241220174731.514432-9-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 module::kallsyms can be accessed under RCU assumption. Use rcu_dereference() to access module::kallsyms. Update callers. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/kallsyms.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index e3c55bc879c11..0e8ec6486d95c 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -476,10 +476,8 @@ int module_kallsyms_on_each_symbol(const char *modname, if (modname && strcmp(modname, mod->name)) continue; - /* Use rcu_dereference_sched() to remain compliant with the sparse tool */ - preempt_disable(); - kallsyms = rcu_dereference_sched(mod->kallsyms); - preempt_enable(); + kallsyms = rcu_dereference_check(mod->kallsyms, + lockdep_is_held(&module_mutex)); for (i = 0; i < kallsyms->num_symtab; i++) { const Elf_Sym *sym = &kallsyms->symtab[i]; From patchwork Fri Dec 20 17:41:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917203 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C174F225A28; Fri, 20 Dec 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; cv=none; b=SRrGR+TIRZnq69Sl2NE9qjRgMdknYWHB2fCJYx4uCz19h0ENdinlHftzCYaNUVpVxWRho6V3eoKTdjIRHNo5Nw8FbUUdLYZ0OV6/1eHc4GzwOlgCR6WULZyT6P9LwaNrEhZgYoGO58Tig+Zzok/2alUMz0rwb3cCvUwsUa5NNvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; c=relaxed/simple; bh=PsTa+u2CgL96hyiRYTqffjxvlq2SDc8+rediGZAjvkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=izegIxm7f5T+e7jTNNpVFkBJth3aT43EdZ8G7spldS0iCAxzEbqHHeMsEDUVA1h+5wqf/ozcQM6LrH2wdnwZZpt93AJ6FW3qjQsUkOIUXVpwT4NbIthYniZWsqEuH8bcl4iIEFBAWbZEjqMrsl6nGbT8g+Vim/tOVRRVaIaGnqw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=f4QPmeDY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=v6ETjZvi; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="f4QPmeDY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="v6ETjZvi" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3aBio7NzcJmfogdbfJFBCrfW8ZRBESMCA8R5ZDYz5YA=; b=f4QPmeDYIxjr3LPVvmFN+RPQjzP/w2l/kBL5tXPY45V0nU6CuS7VPJeYi5bUKa0D6CqpCx nTz0TltZfC8Ub9HfLy6G691fpzJTSequTkFc6vQW6ar/dIqieH8U4fvHM0k8zQh7n92mHq g+3olW2FxvhOMtWABqdvC6MvT+vvvOaf5tjEou6oM58RJOFgoVYT4Ac0pQfTO4+9K3BVWh Ig5IYoEFHpA89RQAsiTIHzfU3N0iIg/y/XpAHAVSqEpd5/NsEB7ACsWBKWuJ3lVosRcCct R7TOz9ClT9P3QLrOHMzTB3EpWTJs1uvxRgqfZ567tvNo/rpXA7V6fYT/49FVfw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3aBio7NzcJmfogdbfJFBCrfW8ZRBESMCA8R5ZDYz5YA=; b=v6ETjZvidzOI+b8ivUJdCuypKonQSYhJMDvggZ1X0G+Q4TX6Fyl4daqEgwCRj4ulBY6ic0 6LHsFHeAdVNimDAQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 09/28] module: Remove module_assert_mutex_or_preempt() from try_add_tainted_module(). Date: Fri, 20 Dec 2024 18:41:23 +0100 Message-ID: <20241220174731.514432-10-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 module_assert_mutex_or_preempt() is not needed in try_add_tainted_module(). The function checks for RCU-sched or the module_mutex to be acquired. The list_for_each_entry_rcu() below does the same check. Remove module_assert_mutex_or_preempt() from try_add_tainted_module(). Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/tracking.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/module/tracking.c b/kernel/module/tracking.c index 16742d1c630c6..4fefec5b683c6 100644 --- a/kernel/module/tracking.c +++ b/kernel/module/tracking.c @@ -21,8 +21,6 @@ int try_add_tainted_module(struct module *mod) { struct mod_unload_taint *mod_taint; - module_assert_mutex_or_preempt(); - if (!mod->taints) goto out; From patchwork Fri Dec 20 17:41:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917201 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDE0D225A22; Fri, 20 Dec 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716864; cv=none; b=qp8AKaO/jiEGdhKC9kqjDdwuF5phra6C0zk5PEEInYqXIDZaqLUtYceDLN681Dzk1NRVjdd8y4yfSb1UpQeaRg+96IyQ+vEhudfNXrfZV9y3ZZHGQWQGJDTlbO7BZi/Kxc6HFQkXV+fNAPmQjkmw2FTLpkigMTl9uOly9j/0yV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716864; c=relaxed/simple; bh=qeik2/OfYfJZuKgOeRr+DQMcj6bOyAd3+P5c3QdhHuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LZMc33Zvhl1LZy7KzFl3FeF+Ofp+YU4VIBD9HU39q56ncB+AWf28iSoZl8O5bk9RdKfnUNtJihu+wputlPdCBkKx2fEENbWrokfQwQNeaUgbgJmexFtrDuGwl+nA+xv2twiGZ7R8nL9m5X4Jel3ufgA0lnMGi7uAXE//2lDPEwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hW+aGK/j; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sHVSrCpT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hW+aGK/j"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sHVSrCpT" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8J/JiS2ZAzuxxgQolNqGisl2jwm8es42jWGQ03W873A=; b=hW+aGK/jvnKx7dPIhQwuWNZCJBbmvun8c8t0afkLJM57AAEf7HIHqHKjKBfC/w4HaeaXfC BCsLINXQiU6LyZMR17v3hhGUnqHEUGYTZXBPJ6GoJd2PQ6LywLCKx/78R5w2rdUAXpnoH7 VptiXv3puospzFek8o6PWCQa2B2ChMpVn6+Ljdb5QYr2Z6pOmZ2uEaV+8JJscwx9uDbFoa PvywDDwnz8dT8HuDab2C0KPKP48JXGKjYXllj/yv7VIqtRpb2vja3F8oT7xUdrkANkqJOV 6KAh39juQWFc5Yk+DDz0AM7WwOPnK+miDWDPhVJSKjsH9IxNuvB3/GAIJuQ50A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8J/JiS2ZAzuxxgQolNqGisl2jwm8es42jWGQ03W873A=; b=sHVSrCpTDH+jfOhgIHJxb/MRDa6KbtZMi+TygTQz+0jFGsCpyp6uGsGAQlPwRgKFYJ/Mwj nmnt29BJU8QNlWCw== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 10/28] module: Use RCU in find_symbol(). Date: Fri, 20 Dec 2024 18:41:24 +0100 Message-ID: <20241220174731.514432-11-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 module_assert_mutex_or_preempt() is not needed in find_symbol(). The function checks for RCU-sched or the module_mutex to be acquired. The list_for_each_entry_rcu() below does the same check. Remove module_assert_mutex_or_preempt() from try_add_tainted_module(). Use RCU protection to invoke find_symbol() and update callers. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/main.c | 30 ++++++++++++------------------ kernel/module/version.c | 14 +++++++------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 5aa56ec8e203e..71e73deed76c0 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -331,7 +331,7 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms, /* * Find an exported symbol and return it, along with, (optional) crc and - * (optional) module which owns it. Needs preempt disabled or module_mutex. + * (optional) module which owns it. Needs RCU or module_mutex. */ bool find_symbol(struct find_symbol_arg *fsa) { @@ -345,8 +345,6 @@ bool find_symbol(struct find_symbol_arg *fsa) struct module *mod; unsigned int i; - module_assert_mutex_or_preempt(); - for (i = 0; i < ARRAY_SIZE(arr); i++) if (find_exported_symbol_in_section(&arr[i], NULL, fsa)) return true; @@ -812,10 +810,9 @@ void __symbol_put(const char *symbol) .gplok = true, }; - preempt_disable(); + guard(rcu)(); BUG_ON(!find_symbol(&fsa)); module_put(fsa.owner); - preempt_enable(); } EXPORT_SYMBOL(__symbol_put); @@ -1369,21 +1366,18 @@ void *__symbol_get(const char *symbol) .warn = true, }; - preempt_disable(); - if (!find_symbol(&fsa)) - goto fail; - if (fsa.license != GPL_ONLY) { - pr_warn("failing symbol_get of non-GPLONLY symbol %s.\n", - symbol); - goto fail; + scoped_guard(rcu) { + if (!find_symbol(&fsa)) + return NULL; + if (fsa.license != GPL_ONLY) { + pr_warn("failing symbol_get of non-GPLONLY symbol %s.\n", + symbol); + return NULL; + } + if (strong_try_module_get(fsa.owner)) + return NULL; } - if (strong_try_module_get(fsa.owner)) - goto fail; - preempt_enable(); return (void *)kernel_symbol_value(fsa.sym); -fail: - preempt_enable(); - return NULL; } EXPORT_SYMBOL_GPL(__symbol_get); diff --git a/kernel/module/version.c b/kernel/module/version.c index 53f43ac5a73e9..65ef8f2a821da 100644 --- a/kernel/module/version.c +++ b/kernel/module/version.c @@ -62,17 +62,17 @@ int check_modstruct_version(const struct load_info *info, .name = "module_layout", .gplok = true, }; + bool have_symbol; /* * Since this should be found in kernel (which can't be removed), no - * locking is necessary -- use preempt_disable() to placate lockdep. + * locking is necessary. Regardless use a RCU read section to keep + * lockdep happy. */ - preempt_disable(); - if (!find_symbol(&fsa)) { - preempt_enable(); - BUG(); - } - preempt_enable(); + scoped_guard(rcu) + have_symbol = find_symbol(&fsa); + BUG_ON(!have_symbol); + return check_version(info, "module_layout", mod, fsa.crc); } From patchwork Fri Dec 20 17:41:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917202 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0DFA225A36; Fri, 20 Dec 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716864; cv=none; b=tQb3NtOhKmXlgsRU4GLbv6yFkZ2tnWnj3/0MAPI/b5reTi5sBQ8NNOpNwuVBnxqguX4tjlcRKi6Ib+lTen7QewGSLVkuEWdVK7TyXDL9iVlkXVSuZfgpzbxkweiMXjEH3oleojnpFhQ9X9I7FQdBMsLpg1/jKe00BrGYre+AGLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716864; c=relaxed/simple; bh=VpIIPt2CV4LrZsknKLmqtKCrrarrj5IxRTnAIqBP4/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lb9WsgS4UOquv7NcHAcZWEx5NeBSYoBA5smNoKnvJJAWasmxbNFmsagbWSatiBbtjM6wrSVv+qnYo3WQ05x3mYqHpy/axOJev8PtUHeNoY67z8DIaCu+VTiTqeOcOLXmfi5bGjcxmMXeT9X9tPpqNknd9JPEs1PsQRbM7HmU8WM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=t+NIZr1J; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6plwZ2Ya; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="t+NIZr1J"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6plwZ2Ya" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AnLbUlJTtBlesn5+tJwa7V6G+8fL1YHPmCXigSuptPg=; b=t+NIZr1J5VzthNHQlHyQrK/fXgtFzUyavo9uKi8POl0ajC3O857YW9mtQ+9ptInJng9pHW CcLQWJKb9GeBCs4tbd4ZTDhPF1xfIo3VH5C6yk2CSLqc/GHqqAlJGz4SZpYBHsvC9cc4IE VvSE56PM+YcjfdnrVqL7VYDZ7MmR3c+1yQY7jVNx/thwb7ihUWKBqwg4jZrTigStIcCI8F bLCerTXnkSl4xcCXSwoK6Y6vJXaAgw/0aCjxPUWM06RHdNKSoG1CiLLTguKbVeOgMKafFV Atj6EVcXc8YMWK6utafZry1u4W3oFDri4Jr/puDQS3D3Ws5sy1XN3ywlQ4EiYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AnLbUlJTtBlesn5+tJwa7V6G+8fL1YHPmCXigSuptPg=; b=6plwZ2YasoSBrfLC9HnHyj9HMiALSdt01g0emA0tJCicggl6kEmSbR7tqnzk5I8iRnalPV dF3bX9RsO3C1YdAA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 11/28] module: Use RCU in __is_module_percpu_address(). Date: Fri, 20 Dec 2024 18:41:25 +0100 Message-ID: <20241220174731.514432-12-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The modules list can be accessed under RCU assumption. Use RCU protection instead preempt_disable(). Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 71e73deed76c0..126f7f05dedf8 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -450,8 +450,7 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr) struct module *mod; unsigned int cpu; - preempt_disable(); - + guard(rcu)(); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; @@ -468,13 +467,10 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr) per_cpu_ptr(mod->percpu, get_boot_cpu_id()); } - preempt_enable(); return true; } } } - - preempt_enable(); return false; } From patchwork Fri Dec 20 17:41:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917204 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E21CB225A37; Fri, 20 Dec 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; cv=none; b=TsdBOVGsDKTwOuySRnwcQRjE/UUUyJ+zgKG7Yhdos0j/4byj8c43Pb+/q17BFA77NNEGg0CrY49oQf/z0ZhnTqFOIYY+uaN1KXvnJKzJCXaihHmDQJC1ifpldLknVwzacPQglLq2RpxWgnEhNwDci4kW1mKuipGZL/K9jIK1958= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; c=relaxed/simple; bh=p46Zi8HZh7rK2wim6LSHAw0u6ln86cdHlUXQPiayMx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LhDOBu1QAJNNA8RZ5l3Rzqek7so2Yz7WihyPc76PHvigghuCF9mMBJlHB/GydMl58akl5VG/0xYkwQgDp5JWA022INRHgCmB5U/8qNLEBYGeiEM12UBY2hC8L2sisgleR5gLSoI23kWqSygKgwYxQlyElSGjYlXLHl5T//qsaNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=o+ROmk5T; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5NvTcBPK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="o+ROmk5T"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5NvTcBPK" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l93Mh1PZlJhbIRISSNiIm8u+tlwexgZoP5TCMyYdWPA=; b=o+ROmk5TAuaTgso64Q/7cJgKj0hOCyVciBTWw621y6APXIBVDQpM5bQdoWFMch5XX+y2Qa RjN3m1IIWRAvo0Fk730d4hxW+e0FmSnsW+SnYu9zqR34GNUOe6mTkZOJPMH98k/vlQyl53 eCVKFqm+yr3T0ypGjaxJctv/amiZpmX86OuuYlz+p1L9u6UI1czjnUZD4Q0N6vJbV7L/AS SIKHMG5DNBz9E5Yi2A1f+eqwqledI5c3H1oO9TYF4AGf2GOwJRrRI+QY1rVmAiBNWIYvsM zZn+/gBEYP2Ql7GYS31LioCHqa7hdURTE3d0eyVjPKkGYr9OQbHlcFVUh2z0Xw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l93Mh1PZlJhbIRISSNiIm8u+tlwexgZoP5TCMyYdWPA=; b=5NvTcBPK+/978UnkmArQeLjGyEbLTqxCdAZPw1+NAuxqfMKRx9Wai6XyAalE26mULikd1X AOxnw3HapkjS+aAg== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 12/28] module: Allow __module_address() to be called from RCU section. Date: Fri, 20 Dec 2024 18:41:26 +0100 Message-ID: <20241220174731.514432-13-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 mod_find() uses either the modules list to find a module or a tree lookup (CONFIG_MODULES_TREE_LOOKUP). The list and the tree can both be iterated under RCU assumption (as well as RCU-sched). Remove module_assert_mutex_or_preempt() from __module_address() and entirely since __module_address() is the last user. Update comments. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/internal.h | 11 ----------- kernel/module/main.c | 4 +--- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index daef2be839022..030d2ed175fa8 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -122,17 +122,6 @@ char *module_next_tag_pair(char *string, unsigned long *secsize); #define for_each_modinfo_entry(entry, info, name) \ for (entry = get_modinfo(info, name); entry; entry = get_next_modinfo(info, name, entry)) -static inline void module_assert_mutex_or_preempt(void) -{ -#ifdef CONFIG_LOCKDEP - if (unlikely(!debug_locks)) - return; - - WARN_ON_ONCE(!rcu_read_lock_sched_held() && - !lockdep_is_held(&module_mutex)); -#endif -} - static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym) { #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS diff --git a/kernel/module/main.c b/kernel/module/main.c index 126f7f05dedf8..686b74c7c17f5 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3667,7 +3667,7 @@ bool is_module_address(unsigned long addr) * __module_address() - get the module which 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_address(unsigned long addr) @@ -3685,8 +3685,6 @@ struct module *__module_address(unsigned long addr) return NULL; lookup: - module_assert_mutex_or_preempt(); - mod = mod_find(addr, &mod_tree); if (mod) { BUG_ON(!within_module(addr, mod)); From patchwork Fri Dec 20 17:41:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917205 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 444A0225A48; Fri, 20 Dec 2024 17:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; cv=none; b=Vlg8+QVKIH/bbzAPbCk2s/YHpPDqQwMXf/Iz7f6boC2xPJlOmEdgBufuvJxdsnEu/DTApSM6AVc3gUad3bR13+RKpwYBY0yCjXJZPyElsoM5dv/TxWRPGzexV4xsia0MFRa4QmcvOQRltaNzHHsZkmUmHQDGHq8hPMMDmquRhSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; c=relaxed/simple; bh=zjSk4OAv6kN5bCYVgE5P6AEooaeh6BxuDm5ltMSVg2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XbK1wdIwd+xYnH6d3VSsP+nDXBzjYvL0iW/xRGx9jUpZUf29S+ctB9IkW1tfzFzOUlopyE788ep2BiRuQOl/xZMy84LJWB03x96Np20hKJJ1Y89L2AoGPZs9LMeLM5cu0aPy2gwQqEf9S1bh1v1UJfhVwyjDP909m28oxGYXlJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dQw+qz9x; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=g2/YPLSP; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dQw+qz9x"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="g2/YPLSP" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9b8RuGxslAGY/6F9yvrmsbza0BlNXvO30wkM+IliBVo=; b=dQw+qz9xcV7CFpOTGWvZS3RYh4LxkF44ufyHTzX5pniFVZNoeXEgVSdeAmFkaxZvPxIRt/ 85cadmw7qOUeWOp02x2k7N+o9sXa+gM7yMxNrMHvBgvm54Pe0fQK5C2xZZfzS9I+RZen3G Fw6p0Wozd5gKkjM3itETddJ/qkVvhRFsscF8LxNpsMgX7RdAUufEzWMwDK1fea8QSNUh1d Bq+Qp9nK9ICgkeVlbSSkyn3XM/ba8R8Z8CSoyNNQ7owjIysHh7UGxCmHNdALvqD32MKThE xaGsOYvSAr4K34EOXVyPbILDqKuHFppDSn3xsphXKWROPsZb0tJM1DOz8bruyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9b8RuGxslAGY/6F9yvrmsbza0BlNXvO30wkM+IliBVo=; b=g2/YPLSP6q3QM00UsXfCNwnPs8knZTb+9OGcYrxe10px4SNblJlRULh2jvRlyS6MA0XRUQ Va7imO9jY86OV9Bw== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 13/28] module: Use RCU in search_module_extables(). Date: Fri, 20 Dec 2024 18:41:27 +0100 Message-ID: <20241220174731.514432-14-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 search_module_extables() returns an exception_table_entry belonging to a module. The lookup via __module_address() can be performed with RCU protection. The returned exception_table_entry remains valid because the passed address usually belongs to a module that is currently executed. So the module can not be removed because "something else" holds a reference to it, ensuring that it can not be removed. Exceptions here are: - kprobe, acquires a reference on the module beforehand - MCE, invokes the function from within a timer and the RCU lifetime guarantees (of the timer) are sufficient. Therefore it is safe to return the exception_table_entry outside the RCU section which provided the module. Use RCU for the lookup in search_module_extables() and update the comment. Signed-off-by: Sebastian Andrzej Siewior --- kernel/module/main.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 686b74c7c17f5..74b9e9ddb4b65 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3621,28 +3621,23 @@ char *module_flags(struct module *mod, char *buf, bool show_state) /* Given an address, look for it in the module exception tables. */ const struct exception_table_entry *search_module_extables(unsigned long addr) { - const struct exception_table_entry *e = NULL; struct module *mod; - preempt_disable(); + guard(rcu)(); mod = __module_address(addr); if (!mod) - goto out; + return NULL; if (!mod->num_exentries) - goto out; - - e = search_extable(mod->extable, - mod->num_exentries, - addr); -out: - preempt_enable(); - + return NULL; /* - * Now, if we found one, we are running inside it now, hence - * we cannot unload the module, hence no refcnt needed. + * The address passed here belongs to a module that is currently + * invoked (we are running inside it). Therefore its module::refcnt + * needs already be >0 to ensure that it is not removed at this stage. + * All other user need to invoke this function within a RCU read + * section. */ - return e; + return search_extable(mod->extable, mod->num_exentries, addr); } /** From patchwork Fri Dec 20 17:41:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917206 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4644F225A49; Fri, 20 Dec 2024 17:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; cv=none; b=CiKhJcpx2D5Wi0dR/OYIVU8k3eHtnyi74T7PaglfgqhAe9Wb83TNwg1nu2h4AVEvuVGzz/flpFoYmzid9U/WgecEWyfcK/qNgVVk2xitfmwh26ObGIH323ept8QIBrnBT7KBCmCtvE5qqfbguphD9Cb6RrZ5FUATMPnLHnQlqh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716865; c=relaxed/simple; bh=VdI5h+LUrY15pCOe9PvBPANJxeKtXWjDJLIoPFNZvc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IHwbkbsvQhmdOCJ6eRP8taDkyGJRLef+K+/zllo76Dc5GlCk24n04d5+X6vCQlxhMAhODYdSbBMTA4O+UuuroNmwKUO/SdX7WPKRa4FxfTrCDaCiBrrLcmh3Rmhfy9uwshBn9Py9UwQ2NNkfEYgsVt7LsCrEcnsl0jKlIBeBLq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IGUMNEDb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Oygx32kJ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IGUMNEDb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Oygx32kJ" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A3RpndSc/R2r+/8h7P3FIFwE0RAdhRhdzrnR4zSM1ig=; b=IGUMNEDbNoyyp3UgaroxfQ4g96xPTUzfUR2Z+DUheCst/3cKrhZ+4MYRsqAbCbF8jHov5M /WPHI56DrlJZ+XjrqvgUQyS8E5zx7a+IHfrodSfOLteF5lSSYF91TRD8yonhic1Yg092FE ZhivyWuR4dNFSz/A//pclipK68hu6CIrSBvNik8rSz6ggE5WW2XpvuSUTSikJ4BHo1hqQq nmdIZYDCn1diGKW92qSJ5dCYdr2i3YmrTiAwKSY0CP4PjOXREGeDh1pfkqdeJU7dKIrq4c WzRBOIaCF/T0kGA1UJd/q7Gjz/3niEzuVXmiQAcOWmU8exTSHGMg4Khwt4eFLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A3RpndSc/R2r+/8h7P3FIFwE0RAdhRhdzrnR4zSM1ig=; b=Oygx32kJ8ZxkNrsoYVpFGbhc9XOk4lQxp5Vl1nYCAya/wYAxjrWY7rUZSt8jysjtucjJQ+ ikTssShzU2V3q4AQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 14/28] module: Use RCU in all users of __module_address(). Date: Fri, 20 Dec 2024 18:41:28 +0100 Message-ID: <20241220174731.514432-15-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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. Signed-off-by: Sebastian Andrzej Siewior --- include/linux/kallsyms.h | 3 +-- kernel/module/kallsyms.c | 5 +---- kernel/module/main.c | 9 ++------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index 1c6a6c1704d8d..d5dd54c53ace6 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -55,12 +55,11 @@ static inline void *dereference_symbol_descriptor(void *ptr) if (is_ksym_addr((unsigned long)ptr)) return ptr; - preempt_disable(); + guard(rcu)(); mod = __module_address((unsigned long)ptr); if (mod) ptr = dereference_module_function_descriptor(mod, ptr); - preempt_enable(); #endif return ptr; } diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index 0e8ec6486d95c..00a60796327c0 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -316,7 +316,7 @@ void * __weak dereference_module_function_descriptor(struct module *mod, /* * For kallsyms to ask for address resolution. NULL means not found. Careful - * not to lock to avoid deadlock on oopses, simply disable preemption. + * not to lock to avoid deadlock on oopses, RCU is enough. */ int module_address_lookup(unsigned long addr, unsigned long *size, @@ -330,7 +330,6 @@ int module_address_lookup(unsigned long addr, struct module *mod; guard(rcu)(); - preempt_disable(); mod = __module_address(addr); if (mod) { if (modname) @@ -348,8 +347,6 @@ int module_address_lookup(unsigned long addr, if (sym) ret = strscpy(namebuf, sym, KSYM_NAME_LEN); } - preempt_enable(); - return ret; } diff --git a/kernel/module/main.c b/kernel/module/main.c index 74b9e9ddb4b65..80877741ac7e5 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3649,13 +3649,8 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) */ bool is_module_address(unsigned long addr) { - bool ret; - - preempt_disable(); - ret = __module_address(addr) != NULL; - preempt_enable(); - - return ret; + guard(rcu)(); + return __module_address(addr) != NULL; } /** From patchwork Fri Dec 20 17:41:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917209 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23E9A227574; Fri, 20 Dec 2024 17:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; cv=none; b=c+WtC/Q+JTRIuxuiGaEzQloUfXhlK/HiJ2cTzrUxfsc/rcAikUalaXA9LtvzV5tdjmCltTQc7vwMeiDYL8x20s7dyNaSNIETHEotXdqMWraeaYtiB4176Uq3UwC9OSNSVG3fBqJlwEEagS2Rvwe1Z5qxF725U/X1iq5V7G3p5b8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; c=relaxed/simple; bh=9tX8FkO6CJFLnOxZNgzkW2mst4BbpND+XHbfRLQzNLc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pbagMSKRxSDn1zVb4XDp/tv/swK4H4CtRrmGMHGt0I0wyP3V2ePcIs0DZEiqq4FCikLU4/qHbQy275KmAkz7Emaz8Xf/r8GnwaSEugrzXw/prKtj1FMj7UanwTixg4u9gZdIk8FFr9xTboX8Nn/FrLHMnNxHMuzlqKWBtx/SJ+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DrPhO5Nh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YrIKQoNw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DrPhO5Nh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YrIKQoNw" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=160WDRdmuV++cCvmQlZL+oeRlLa+Yt8ROZGJz/QxIhE=; b=DrPhO5NhbGJrkb5rxgXdnAlYIc4lgjuIy/847/urrFn2AVI9MSqEUmqdoqVifpaWkni7v2 XE3SxVDJVZWjr+UCqX41t+yoyBXF0Pbfmzuz5c8UqqliYDK0hxlPo1QnBeFO28uUwa/0m4 PVppOHoSTAYqG/R7KZuCCK2dAzWmS5KFJccRJmhhf4rlam1QffYMsk92+TkvwTPuhkS35n DOOx4r5LStTMNwdGJ8mkELZVtkhI08BSUhY+7szKYARjYmsZkUQ23zb+UEeNgcmoGq0F0Q C76TOL3gfXktVw8qJMcj81lel2KZhDmKJH9AhvDZ1lt1lhlehq545ENw+/Ythg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=160WDRdmuV++cCvmQlZL+oeRlLa+Yt8ROZGJz/QxIhE=; b=YrIKQoNwcQnV5IHMrdPzqw7tHIYnJIDA6GC5ANTGCw+daftB9bqDVWKXXmmxb83/5upU/3 ws0WYQ/ezbgxq1CA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 15/28] module: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:29 +0100 Message-ID: <20241220174731.514432-16-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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. Signed-off-by: Sebastian Andrzej Siewior --- 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) From patchwork Fri Dec 20 17:41:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917208 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23EFE227575; Fri, 20 Dec 2024 17:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; cv=none; b=J/qxoAJvRzx3qng5uvOtdCtODqlpMOus2PsnW07Mk141YmcPSmFhkD6PJdBxYqJjIhT8bdK3JPtP3uJlC9OkKdZvUIWZ8pkpcRwAHkCqBvEEqjv4PK4F8MiV6Ioz8vxi0E+B4kcBFoIv1B42BQRs8v1BGeFefUbUGjU6rSyD2Xk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; c=relaxed/simple; bh=v4NO/FjLD7R+3JjvcSQW4GHXMTeRHN6qezJyxaWSwTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iimdPqJLuYOcjgaJMd46gJR34PAOGP+3r0sUFxw8MZ241m1BAupXneuFogRs9fVkX0QdiKznH1pi73oVFJS/Alw6+n3ivo3oJVYac+zwhVQyfdcD5EWa8bp+vQ7F2CVr17pUT15iuBhJBldzrvbmg2xpZEgfo1n3CXJ/M4gVMgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uwZHwo6e; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=n2Rwu/VT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uwZHwo6e"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="n2Rwu/VT" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hGYN4ff5lKOeQEcqe/g4bGLpQfsoz5UlJMjakVJzeFk=; b=uwZHwo6eNmwA7kya9O3GI4iA8IAlCQOOukqHJWYAa6K+3KfgKuyLtLRUdLGbgYLGanUzaG aiphp82LdodS2mLsk2Qd9S8NkKkNc7zYbJQWSAoDC79FCQ2TVVIRV5OIttrftP1FBeqZDa 6IUXwn4Hb6xFgFf/8go5mtCepamkeQx9TkDntwXDQgKAulbhkUkQj3PXHkwwmZ9Hf0u67Z 0g/xa6CTwr9llsRQB6nMxgDy1/HIdMpza0zROTWUw/FMPRUVc2tXhUr3RJwqFESFfyylVI 5HgNyGrnKikqy/1+dKob9mxnWUMaNYGcI3Jh5VIV5If1VteNtKXQEs4KOjZG0A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hGYN4ff5lKOeQEcqe/g4bGLpQfsoz5UlJMjakVJzeFk=; b=n2Rwu/VTOnU8F7k6F/wKH79A9noqoGu1s3Du9ttx9cs1WIJBbPRrLJWHfLUsFdg8QywFjQ nb1x3jg1ZWpWT5Ag== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , Russell King , linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 16/28] ARM: module: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:30 +0100 Message-ID: <20241220174731.514432-17-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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: Russell King Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior --- arch/arm/kernel/module-plts.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/arm/kernel/module-plts.c b/arch/arm/kernel/module-plts.c index da2ee8d6ef1a7..354ce16d83cb5 100644 --- a/arch/arm/kernel/module-plts.c +++ b/arch/arm/kernel/module-plts.c @@ -285,11 +285,9 @@ bool in_module_plt(unsigned long loc) struct module *mod; bool ret; - preempt_disable(); + guard(rcu)(); mod = __module_text_address(loc); ret = mod && (loc - (u32)mod->arch.core.plt_ent < mod->arch.core.plt_count * PLT_ENT_SIZE || loc - (u32)mod->arch.init.plt_ent < mod->arch.init.plt_count * PLT_ENT_SIZE); - preempt_enable(); - return ret; } From patchwork Fri Dec 20 17:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917210 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4816622759E; Fri, 20 Dec 2024 17:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; cv=none; b=rZ+PtWVG/+poEXU0NtJ/HHZJqYYN2SuhmGFjef7rC6ifJ10dZbp2Ji73Xk0p+4CPJwPBjQqmbJxe3dvd7vo+NnNOlpeiYlfOai+NehDSST1IN00YhQJqlgFoe9k3eHvkCaqXQm7E/OVc14HyI+T7lKLkzvdLUEMDmV+Xe/pvz4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; c=relaxed/simple; bh=nijB/UnysS7vk+pFqu8+upO4BLDrLMQWbB8mD4qf/88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PGNl/n9Fc5fd9a1WVhglWUrqQv4ChjOscp8b+0W9j+oCf5ZqZRXcSbmRKh7uxUu6UHg1Oj6j5ruwck4xuKyQpKIEwYgshSKMKzQMlSLm4TDA6nWsd1OtPkiEXvfDoL3kCHHFBaiHA8C1yIB8VqfJtgrKiG9piPszeolc+em8d1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=On3qaA/t; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wP3SU0f9; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="On3qaA/t"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wP3SU0f9" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B42kRDJLK5sW+Ny84inWQy8805pd8AwUNUb75zPNPLQ=; b=On3qaA/twJ77SLnuRkru+5uQE5ZKBQhFay/+nLBh6xN3SX7UJftST8sHfDPa7ea47vdNAZ idXh9UZrztg2QDpZqo5r2KDtqUdUUQy4DZW0/Q2kY3288WC8tbh+komb3VRtgLX2X/+eLV 6gh5IiEbq6BPf0yzOqrCLK5mbo4GRvQoX1Q46SArpUKYkMbU+6gA+M7jKFKSBXqXzB5bNi J89qbyLyottgcWoow0Kz4No4atEU0CLK369SKj0d/7AO9q6Ro7NM21+G1Ovw0F4seLlS4T 5faShVWC0FjU40sPhMXVi6QlMhr8B1f2wrUhEvXiYW905avRmgk16GoBN3lLtA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B42kRDJLK5sW+Ny84inWQy8805pd8AwUNUb75zPNPLQ=; b=wP3SU0f9++QJgKMFDAs2/M0ayS1yvZ1EajxroFHRFh/A4bAKgjgkMzUWuOJ+6W/3JOSGb6 Iya0Jf1kXqQFcjAg== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org 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@lists.infradead.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 17/28] arm64: module: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:31 +0100 Message-ID: <20241220174731.514432-18-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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 Cc: Mark Rutland Cc: Masami Hiramatsu Cc: Steven Rostedt Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Cc: linux-trace-kernel@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- 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)) From patchwork Fri Dec 20 17:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917211 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 481CE227B83; Fri, 20 Dec 2024 17:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; cv=none; b=gFV4LUK1/3wXWE1N87QZmqOl3Rjc273rXsX1ZxLQV88EOFSnAMLPd+3nhRT9pweD+yh8IXNO9c6i/jdR6T2H4F+NTODKumfMekszoxH6f9SxhC3OBL9pRrIDwRYEVZG0o/1IUExXg8wwFXUI7gGIZGY23w+YbyAK0pEmLfoN7/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716867; c=relaxed/simple; bh=8GhjdGyZlhSd+u5XuDcl+fATkvBHdZQ8G05mszSHBn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lq+J2nHsn65dInultHuiBxX1ggzyzb26DBcaUgvRJBbVQkXjBI7DSoQaZCG6vmfiDpdoPYNfA0Ftgb5GGIo5MY/zhUQXRiG7DWrxzsFZddwmmj0I8jNNwZmpQKeu1PDbq3wyOfYurBxN5XT62IguuW76pX5TyOjquBIKGrJeKK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cpVzP0oh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MdH6HyVg; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cpVzP0oh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MdH6HyVg" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ljs2jZrg2BL9VEhLxJX9ekollT4zmDGIk7v5ipaXh/Y=; b=cpVzP0ohHAm5pZrQASOuHlpsjdo/i7DReDawcu+bn52+UjOf4l9PoAZUK/61GQDpWt0CZT Yh0QCx39Lnsd7vdBy3r/k+TY+SErCWkdDX7p7Ao25TyMXf0LqXciBWJ1qywiESj4qfFXUo Dsde0rfiS3MagZwRZxULEnmkhSQtr+wSEfm9Mso3E+tnADf32S5yJb5kYUqABDZyS2LKx0 yVVwKGHYaKlpyC2GrmuBd7BVg1uoY0wMIGx1OOqWfAe0o68vbRvG/tpqYXjI3pwqnZmWOM huZxMVqPiSckp9LuWI7uVBVM3XiZHJ2aLpGKXoF2PxMQ2ruBvEerLOwVYNi2LQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ljs2jZrg2BL9VEhLxJX9ekollT4zmDGIk7v5ipaXh/Y=; b=MdH6HyVg39qtamm+1xIfFxU5cTC7T3KWszaXdykLG8E8Ga/1WONP84nlrNeJ3YGGT9TA1r b2ATouRkr6VpNFAA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev Subject: [PATCH v2 18/28] LoongArch/orc: Use RCU in all users of __module_address(). Date: Fri, 20 Dec 2024 18:41:32 +0100 Message-ID: <20241220174731.514432-19-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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: Huacai Chen Cc: WANG Xuerui Cc: loongarch@lists.linux.dev Signed-off-by: Sebastian Andrzej Siewior --- arch/loongarch/kernel/unwind_orc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/loongarch/kernel/unwind_orc.c b/arch/loongarch/kernel/unwind_orc.c index b257228763317..d623935a75471 100644 --- a/arch/loongarch/kernel/unwind_orc.c +++ b/arch/loongarch/kernel/unwind_orc.c @@ -399,7 +399,7 @@ bool unwind_next_frame(struct unwind_state *state) return false; /* Don't let modules unload while we're reading their ORC data. */ - preempt_disable(); + guard(rcu)(); if (is_entry_func(state->pc)) goto end; @@ -514,14 +514,12 @@ bool unwind_next_frame(struct unwind_state *state) if (!__kernel_text_address(state->pc)) goto err; - preempt_enable(); return true; err: state->error = true; end: - preempt_enable(); state->stack_info.type = STACK_TYPE_UNKNOWN; return false; } From patchwork Fri Dec 20 17:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917213 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEA64227BAC; Fri, 20 Dec 2024 17:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716868; cv=none; b=peH7w+YRwWZZc/3qQ5kEJ2l5BD4xz+goxre2/YM1MozhiRhKzzZnuZbF3dyMlfkgpwBRLfRnwtlnmkAhC0Nj0qSw4GYGH6nEU0RV7GKmzx+0bUdjH8UtPztiTLNTBwUJ6s1CPKTwQI150RqjpvutWR1jZNAmANfkZpVIL8yLcqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716868; c=relaxed/simple; bh=ttlHFu3gMwY1VQt+XZunT0z7GD671/sbqto0CfwXAa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jwHAJ+oWRNuwEhr04MbJIMTFFzKZLN/RUg4hfHCSgT4x5QpzpLTBIJ/oHQXFPXgrWnTfp3Y/I6yBvguFYvCf2Umm9IPGNga6NDqUWonZhy7m1F+DHEwt+NB0CE85GJGx656ct+F4fhMgMBYkOf/16rXLNmKqoHziuixdMlEPSq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=u1Gg5xD+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=C5zOkrNo; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="u1Gg5xD+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="C5zOkrNo" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aq+7SEGJUTKa/Bn1/z1CJTxjtvmAy27khjcI6tCzE7c=; b=u1Gg5xD+dhrMVIMDZUPbt92FBu6s0DSjzHyIfRQsJL6kMqK5HQ/fRk095USwc8UVYtZaK0 DmvD4X5fkMeVM3CXhaLUejVoF6634jqwUCYcdJynLrVdDaTn/urwHrHVcJ35iiK/HtlEaD mjIbPzj3AIFPDax5MxgFHsqSp7jB0FF1daE8er4OZwkEGMWM+Rf8hreXUiyhoBH9yMmWCG sH7o/UJj7JjE1H0wbKMGZsDHqnhLlJ0LJVl9YLGksgYC8xkaXxMABDF2z41QNg7MQ0rL9D SlmDwyW0Chd7KaJL44jdstaVNsAwDXOHgQqS5g+PlCYcDzvNOqjbfy2suOVUVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aq+7SEGJUTKa/Bn1/z1CJTxjtvmAy27khjcI6tCzE7c=; b=C5zOkrNo8i3Cb9FVlv34sBRm+FnOtE6B2tBlfe1LezVq+IYoO+Ue7rq1dFFysL+fAv9LP5 D6vM0gELbS9VD2AA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org 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@vger.kernel.org, loongarch@lists.linux.dev Subject: [PATCH v2 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:33 +0100 Message-ID: <20241220174731.514432-20-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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 Cc: Mark Rutland Cc: Masami Hiramatsu Cc: Steven Rostedt Cc: WANG Xuerui Cc: linux-trace-kernel@vger.kernel.org Cc: loongarch@lists.linux.dev Signed-off-by: Sebastian Andrzej Siewior --- 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)) From patchwork Fri Dec 20 17:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917212 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE191227BAB; Fri, 20 Dec 2024 17:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716868; cv=none; b=mtmAP9NP+EOeCjt6roqSZ2wZbQDeV2JpRKsOsQNm6pTdX6TdXUasDjeDrbXnHJCWGDwvYWiWCBiihHAE5nqsXhM6iO7EymWGSmB8jEtz62/MC/3hbcpUWfFlZnmVD8ihTSspCh7As4CtNMDFEo56SdrDCBQdrVUlaxAm/w/zXIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716868; c=relaxed/simple; bh=ZCYpbinhL6uGHkLuSdwWLthc9rjMA4h7HhoINLswtfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ph/TiwB6OhBGblGJg0eVSC9N2btHwGwZuKPm3kntx/HDZ9PSC4BPjnfVA31yIEDywY79/GD5ABSwSAG8msr9mKgHg8giAIX1onPISqjKG0RcVuCNSB/WI7cxBiZl5UBhvBMSP6f37dXWomXaCwUQ5Vm1yYXhEt7xOZVRWOzbThQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Dr+7RMQB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AZSx8zxz; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Dr+7RMQB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AZSx8zxz" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8cOfqq93x0oPQPFrMlSeinUf1WhvLlURcCwn2/B9V34=; b=Dr+7RMQBSI0JHm4g6BniB6jZDFuoF+xofjsoJ8mUEF2oBm+1pGpYluIuQVawxnxclkoWaJ +HHeJBPpIxk7UerRguKKBX73oK4rTa/opx2cKh9HdBB6ModF7+KqAqvujSc+c8C7E/GEB2 2P2Z3sAj93+oQ9J0lHeDlAqnaBLZUnzWVGNB5byDwB7t2xlZvn00gNvuJb8rFdpBjx/nfJ nakdz1wMlCaf7VD5ufRxyM5CrLVZAFX5mCYHZEC0nBMOkhCqK6c7JGVPG2qOYxb23Iq8bI DxnpERqrc++5KxybwLFKL9NKo0xzTZE/KG4CUYbw2mnFxT7hApBL8P6Z7hhqLQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8cOfqq93x0oPQPFrMlSeinUf1WhvLlURcCwn2/B9V34=; b=AZSx8zxzXWRhcOocsxUzld2ZvnNF5RCFUWhKFiEwKDv3uSi2sPubKCRsLiteienIG1tdMy 8jLsoA1ckq2ECHCA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org 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@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 20/28] powerpc/ftrace: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:34 +0100 Message-ID: <20241220174731.514432-21-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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 Cc: Madhavan Srinivasan Cc: Mark Rutland Cc: Masami Hiramatsu Cc: Michael Ellerman Cc: Naveen N Rao Cc: Nicholas Piggin Cc: Steven Rostedt Cc: linux-trace-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Sebastian Andrzej Siewior --- 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); From patchwork Fri Dec 20 17:41:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917214 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D56922837A; Fri, 20 Dec 2024 17:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716868; cv=none; b=h05GDhc0XqL4FFcGcHjeaWesb1azSInzq9i72QEJqgpIGx4KrjbsZxWiRUNultm23BTOjVU3ALi4EhdyCm7F4drKHZjNmjk5Jq9IgXhKYuBuN0BxOpXeqFkYAEzSCgDEClKwEp0STvUxUw+hYrmp37xd5761862/nRN2h3VZTnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716868; c=relaxed/simple; bh=uy+vf7E+WfZsLxge9FFBznnF2wQaw/y3udEfK0Dg6s8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d17mwF41eeOpAYPh5aDeAxphREzf0hVuV5qfC5G/Cuqx6m5AoDxiQ1mbl1Y3EHPyB8rvQ2++SOZ0CgiigiNWcLzuqjUSEbYK0+AC8K3HsncZizkn+BPA3sIPNMleKXwXk/Lt5iVlSivRNev4fQaHBUu+MRA7otI2uO143NFlTzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dYH09CJf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YdJZcQT5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dYH09CJf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YdJZcQT5" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zadty3eQK5ahsxvh3g//PrCMcOyHeT1X/IulzEQzgzA=; b=dYH09CJf8Wms0bX922U37fQ2/ndExBQQmr95yw73FUz7nJSJBjmiUN9CjhyYwqiACxpH/C 3KHck505E9GWMy6YdXyeRlJ3SSo4UCHI891csitkxagHKvzcMjg2BG8JnTiUWj37n8CBhy WjslPXyoNXrlMP7P2ByIGmEVDA+nLmWAqshB5obtS/rpaqidX6DGV/ZGdMUPIgUSWf8got hDaCU/F12J5Dc3SY/tc/PGbUPzU5WbNG6udUa/7DtSFe+Xxa2OWd2TFnFwfhM7opOFHXMd AOTe08cW0HxFB0hI2VXQOxATbZPJDWjpwfHXrr9N79lVDPb/5WokqZie8PCZOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zadty3eQK5ahsxvh3g//PrCMcOyHeT1X/IulzEQzgzA=; b=YdJZcQT5FY/R32LX8UPyCRGuevjhYrBTHTEPgSzKIItAMMBgQnytGaDQxG8ZT2V0+Lq56C MYFoOyI18DuckzBg== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , "H. Peter Anvin" , Borislav Petkov , Dave Hansen , Ingo Molnar , Josh Poimboeuf , x86@kernel.org Subject: [PATCH v2 21/28] x86: Use RCU in all users of __module_address(). Date: Fri, 20 Dec 2024 18:41:35 +0100 Message-ID: <20241220174731.514432-22-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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: "H. Peter Anvin" Cc: Borislav Petkov Cc: Dave Hansen Cc: Ingo Molnar Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: x86@kernel.org Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/kernel/callthunks.c | 3 +-- arch/x86/kernel/unwind_orc.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c index 4656474567533..15bcec780881f 100644 --- a/arch/x86/kernel/callthunks.c +++ b/arch/x86/kernel/callthunks.c @@ -98,11 +98,10 @@ static inline bool within_module_coretext(void *addr) #ifdef CONFIG_MODULES struct module *mod; - preempt_disable(); + guard(rcu)(); mod = __module_address((unsigned long)addr); if (mod && within_module_core((unsigned long)addr, mod)) ret = true; - preempt_enable(); #endif return ret; } diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index d4705a348a804..977ee75e047c8 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -476,7 +476,7 @@ bool unwind_next_frame(struct unwind_state *state) return false; /* Don't let modules unload while we're reading their ORC data. */ - preempt_disable(); + guard(rcu)(); /* End-of-stack check for user tasks: */ if (state->regs && user_mode(state->regs)) @@ -669,14 +669,12 @@ bool unwind_next_frame(struct unwind_state *state) goto err; } - preempt_enable(); return true; err: state->error = true; the_end: - preempt_enable(); state->stack_info.type = STACK_TYPE_UNKNOWN; return false; } From patchwork Fri Dec 20 17:41:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917215 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06B532288D0; Fri, 20 Dec 2024 17:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716869; cv=none; b=NM6emAibqNwZTfif3ejaRDkGOfkumCcPtvytELMDNRCAnMFQekwnjSwzQYt/Z8nRWL0hg7JjDI9ZiTnerNLUmKy0YP9iNlNMzx6bphXhd9rvvlVR3yZAM9qM67vNwbgGmg3QLTl4OFn/YV3I+9UMdu6ypAuJ09esiUhaOANka3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716869; c=relaxed/simple; bh=2XFKVoH9xoHAvUb+r6+4ArT2m6dzdDe4FeXSZTHHfAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c6Xq+pUNonOZ26wIuyY4vGg+diEM/TmsyNbx1zF8bVfAAkHeTSPnR+wTpbGIfrlpc5RDHsBoVbGEaJwBPZxzGinV4z3th/agzMM9aeHaPXVkCeaz9gj/AuH155H8DjEDeqeoF4R35BN7KocJd3hRTL7hrqTXty57h82re7O8yXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iueFOBOB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3zfEw1cC; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iueFOBOB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3zfEw1cC" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QN7XAVkRHsrtCJIPCdbMv/hgOMW5RUaasxW+AHUKamA=; b=iueFOBOBF1XA+8uZlT6Lv9AyjsTiL6mYfRPQWL+pRk00nCVY30jPfGmczFJeyxPsNr8TrF HUInqrtVAr+e0K2p8mFeqS1iau6HPVN252z/leAwzsAqY1yn9KG9JnPibYmAduVHQe1m6A aFzDtSdXGMG8DcHHn48kgXT7JUigCt3HFK1CgzzDtbKLNPtRSGsjM6xvJYRoBm+U2L5yQs tdKl3howaBaRxlhdBoVt8rfRBoRzGOP7Pz5tlL5ti4rChFwoXbkBMrOd3tbfPUQfWEgH5O 67nYd0hikDwSlD+s9d5yHNrWZwKCV9ceAFccbJleK1n42s7JT8RHYRH7JWrhnA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QN7XAVkRHsrtCJIPCdbMv/hgOMW5RUaasxW+AHUKamA=; b=3zfEw1cCyALOINESRPLlGZkpmVhFyKGekw42+llIZu3Tk89yUuP3/+OgBQekIhQ4vu50AE 81V1KwipbF+I+wCA== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel , Jason Baron , Josh Poimboeuf , Steven Rostedt Subject: [PATCH v2 22/28] jump_label: Use RCU in all users of __module_address(). Date: Fri, 20 Dec 2024 18:41:36 +0100 Message-ID: <20241220174731.514432-23-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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: Ard Biesheuvel Cc: Jason Baron Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Steven Rostedt Signed-off-by: Sebastian Andrzej Siewior --- kernel/jump_label.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 93a822d3c468c..7fcf4017cb383 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -746,9 +746,9 @@ static int jump_label_add_module(struct module *mod) kfree(jlm); return -ENOMEM; } - preempt_disable(); - jlm2->mod = __module_address((unsigned long)key); - preempt_enable(); + scoped_guard(rcu) + jlm2->mod = __module_address((unsigned long)key); + jlm2->entries = static_key_entries(key); jlm2->next = NULL; static_key_set_mod(key, jlm2); @@ -906,13 +906,13 @@ static void jump_label_update(struct static_key *key) return; } - preempt_disable(); - mod = __module_address((unsigned long)key); - if (mod) { - stop = mod->jump_entries + mod->num_jump_entries; - init = mod->state == MODULE_STATE_COMING; + scoped_guard(rcu) { + mod = __module_address((unsigned long)key); + if (mod) { + stop = mod->jump_entries + mod->num_jump_entries; + init = mod->state == MODULE_STATE_COMING; + } } - preempt_enable(); #endif entry = static_key_entries(key); /* if there are no users, entry can be NULL */ From patchwork Fri Dec 20 17:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917216 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 092892288D1; Fri, 20 Dec 2024 17:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716869; cv=none; b=s60FIrnDmb5L4bmCw/AGE9WgP12WTwBPbcU1DG+1Ar1WJO8uGs7gnAv7H+g7faLGzEdnMgOrxjfB9bXnG6h0kXX3XF/nV2lJ3zN9nPjliXa+nLs48pzFoH4DXSXgF3ucT51xMnsHxiZnPr6TknV9maBHB+63piX7/d0gxRZOyxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716869; c=relaxed/simple; bh=6uJlA4reOfjymoCzgxYse8O4N1MM5NG+OXL3Be9LAqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fLHHLM+8EhOaGJMbIIvWZkqv7KXFe8ljLIj8xm2LbvWteBTXouBT2FigdXs73QRRx5sCgmwRjosimCy0Al/Z66wwfUbwI0jYsT5jPZp3gLsXpNFDDONHy/+4WO7fEz05DyRazPptpkr/jc0V3E54tpuyCohZfoD4BWsrvsU1zlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vpKAtvfB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VnjFHEUC; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vpKAtvfB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VnjFHEUC" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W07uvuPp3idmgtEJy1Zr7/RQ/o7cQBRopmcRQ6ih8IY=; b=vpKAtvfBYhoPO4pRMabTHrfqdiFg84pjuM1VXrGLoeWZOUroKKYgNOOWEuhP1O+KDxuUUj RqwLV+F4F6q+pv0Y9EyAObvppZHUKPu37k1l5c6KoquR+7ddn7qCRstAd+sbrP/uAIcL5l X/xuDjdeDcMtNcpzKMkGUIW6GIrWYIYbPWW1F0o6RHDgWgZ6ARjsny4NOUIsYE+bZJZ3sj mwUYpND9XUfQmNv2FXCJnIwGjZW1ZdhGPW+G54dmf98ymb6UirZB1UXrIRPSSPOsvYo96w 2d2rbCpN8T6ypg+z19eQ1bjysVH0vBr9ImoEfY11hdZ4z23a/ByYBOSeXlvG+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W07uvuPp3idmgtEJy1Zr7/RQ/o7cQBRopmcRQ6ih8IY=; b=VnjFHEUCkGYpQf1hIX7SWktleDybCH3z+Jmbfhl6zcgciIkhrQZzgK9hqMLk4/PjLAcuIK EoHCdpCFyHUVcJBQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , Ard Biesheuvel , Jason Baron , Josh Poimboeuf , Steven Rostedt Subject: [PATCH v2 23/28] jump_label: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:37 +0100 Message-ID: <20241220174731.514432-24-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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: Ard Biesheuvel Cc: Jason Baron Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Steven Rostedt Signed-off-by: Sebastian Andrzej Siewior --- kernel/jump_label.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 7fcf4017cb383..7cb19e6014266 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -653,13 +653,12 @@ static int __jump_label_mod_text_reserved(void *start, void *end) struct module *mod; int ret; - preempt_disable(); - mod = __module_text_address((unsigned long)start); - WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod); - if (!try_module_get(mod)) - mod = NULL; - preempt_enable(); - + scoped_guard(rcu) { + mod = __module_text_address((unsigned long)start); + WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod); + if (!try_module_get(mod)) + mod = NULL; + } if (!mod) return 0; From patchwork Fri Dec 20 17:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917217 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD6D7228C87; Fri, 20 Dec 2024 17:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716870; cv=none; b=uNSAzK9P9Z3feeYMLX2XXluL3k1ONQq5LXjnJBBdcauW4NmZYNKDs9uNdwZXtJV5LQTd2ELBQcHo51QFWm6jGYkcqGMcXtOFlsORjognVeQEwMuxOPS7mHmctlAbO0dlUV0m/Gwk9KN44cbANWjP6JT7xDdlRV15xAKGQ9QEqLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716870; c=relaxed/simple; bh=wT1uBpL1/SaJ4hNyMwwXG5byQc1hQ2W8jUnWEH+nwtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/VwdXURULv5F7UEaCTIjoSRFfPbD0gCWwIiPgujIH7zcIfJRQGBP9rm/lza3mSt9CAMQWdIdIOwzCf6SCRhtedJNWJev7dEPizmNkClWOQSw0TViil960aWZrhh8hm/x+5HdK9ls8f3PmQ0J4j01PRttX6ZCamqxfcc8EzcyxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=D9ahDB8R; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eeW9haKq; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="D9ahDB8R"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eeW9haKq" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kG1v1wu3D3TuS8vhLDHRaF7dmu7B/vJ02VdgW4EZUoE=; b=D9ahDB8RXZP0FtEdc1K/ru4TjyLny1CvEWUccj/8qDL3JOmdQaKnqUfVD+5Zf0NP14XOT8 +eZxOXzNIomH4vyUH6d44nxYhI9Tnx2s+fjaxsPcggMHo9qLDKNgRq+CeHKYvmZsHLdOPF Lb/lnZI2q8y/5ia53tHAYCkzI3WCK1ZwJ5yj11d5ejhwHCoJ4vid/pBXEnpVC7R+hRZX7s Luz0K3hLjrUdbXIyFPsl3KxB9Zts77Mt+5pn43WXjGRppaMGptPmPplypEE6R5iVcHIpQ7 /OPg0nGDhabIy9XwWkOESpRLMsFqRH2qhMn5fhfFV2qD/micRXTaG6Xo0btN8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kG1v1wu3D3TuS8vhLDHRaF7dmu7B/vJ02VdgW4EZUoE=; b=eeW9haKq3KowFdehTfjJFroB4yIBxuCgvJQQ+lUIH+tMDD5bZ+6Vyrs8xQNLbZj+YfH9cM 45VM35EtlGj7qmBg== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org 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@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 24/28] bpf: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:38 +0100 Message-ID: <20241220174731.514432-25-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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 Cc: Andrii Nakryiko Cc: Daniel Borkmann Cc: Eduard Zingerman Cc: Hao Luo Cc: Jiri Olsa Cc: John Fastabend Cc: KP Singh Cc: Martin KaFai Lau Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Matt Bobrowski Cc: Song Liu Cc: Stanislav Fomichev Cc: Steven Rostedt Cc: Yonghong Song Cc: bpf@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- 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); From patchwork Fri Dec 20 17:41:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917218 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0425B228CB7; Fri, 20 Dec 2024 17:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716870; cv=none; b=o3bAECc8tp2WUUu29W9LawvTb/BELHCiCLbAQlKHGroqfMauCrNPWHUKYKmVHKUUCOEt/ZWShGQENjaDkiFc6aCGhqYyuJRN6WCJiC0SFrbQkA4oN1jULSvLIv5O5XMBRKCzzrdbYBv90wzNHNY6VYe7ywmH/1y4JIA4YFVhV1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716870; c=relaxed/simple; bh=3UnPfdticdpfn4zOxUtBMTJfpAGccJ0U76N0KLoCaRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gbRXnaF6Pz2KipMtnu8cExT0c0Cox3J7Nh0N6v9ZDpcwsJgfiIrWriUIMK+7+qX4kSQAsdb0zmiCergyT47tppi1CMvuZdZ8zZkDo7tFqdPzacDPGkghy5siOn5U1lMOK0UETxO2GXuEJEcO9wZqNNkFSml3TYj+SAHDYOlnYD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1ykdfWEq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ANWS8DVa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1ykdfWEq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ANWS8DVa" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ydVul0a4FP+4PcNCblFv1cuoHBvYBqlDRcudAEX3HxI=; b=1ykdfWEqERs6z+sN+CC5mt7JT2VWDpWx+RG3bRRhW8U55w1uQua/IbtYuEg/kbtdr87hf2 u4V7SRRmflZZETm2hsT+zq3gRwKtaniD+qYVXzeqQnwdBYtU973l+PWGXYFGA1TnuzAvqL LqT8E2VJPSQO84hfFWgosMFZmPDUTCwbLjpD9CEig+bUBSqmZIEq2G3BN55LWuz34xwXdn cWou0jcsmrsPsiIrsZ+YHqIPVOF1xojlW0M2fKNb0sipWU78FyhLX7Tzg++mMZfmkLPQzu bgInwvzw3s12+k3oFES0A4vLF+m2FY4ESnyVO2UlKndQ4ogjAGbHIqtDQI+Lfg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ydVul0a4FP+4PcNCblFv1cuoHBvYBqlDRcudAEX3HxI=; b=ANWS8DVaCIsH4vMRyvsNCOBy50NaPHu9JO4Rbf66Co8zWhL/qr3B+vfMXOXHoA/PEvVlwF 3eKqauufaQpAiECw== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org 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@vger.kernel.org Subject: [PATCH v2 25/28] kprobes: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:39 +0100 Message-ID: <20241220174731.514432-26-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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" Cc: Anil S Keshavamurthy Cc: Masami Hiramatsu Cc: Naveen N Rao Cc: linux-trace-kernel@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- 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; From patchwork Fri Dec 20 17:41:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917219 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76F4522913D; Fri, 20 Dec 2024 17:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716870; cv=none; b=d81Co2yGlKqo3ApZYJ//u0uh12riZ6m6qJSkzwcJt3vIu6jvLBRj37V4reSbd+OvDTnwIvuFgBOOsojpj+ZS7i0CAsY1BXUA7NdEUqnmuxSAN2/YSYTjf69wLkD++412J3274lRpu56hdZynMFw5EBmTfSH2M/lh1ViZXu+V8Ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716870; c=relaxed/simple; bh=szZNjdiDOEbAPd7FllNALlPuBiIF6DYqyTi5RLt33+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FaObGH9NHRwhYGmLUJGzOENtBk7PnIjs+gR8vCd6gCjHIifvOg8Em1eZDcGI2WaSCVIg8PcEYAnHPc3q08ThIMfVLH7uPGEl7CZdrZjR0BTEJb1XwGQrkEWovzKEfESYcKOgGQSc9b6p/7IXxgH9SKHMbhMc/uYEk1r5QCXJC9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=L3KpbHi1; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WgdOINiI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="L3KpbHi1"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WgdOINiI" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nbrqJ09qm4S44mrWUWsD4EMkSiLFUJiV1ZfIl3x0Psc=; b=L3KpbHi1MSob3yXJdwsUs3J9glYVEaJwI77qPch7dyC3dNvwgxkEbJJmSPnoTzHELfUcyi LitspVMYt2bew92nRpbBFiOEm6BZ931FJ+wj7bOm4HxHyrKxc8/sbx7OJI6GL3F6kiEuVU WsPiIBJctMxcQT14lXLm5gPj6bnhEBC8+u9BP6mMKHn7Dslke0aOtGCg9GnDRY7mwOGi/m uKe8GcL/Wgg8U9dEGFfHNbotIyl2qAKOhOx5b33d2pNjTF6I7hv2JLcT0Rr6IVKFPc2hCH 4osXuTh/VvRW3ZDbPhhf2/vz06ndcRUvwU+F5TRgYREtTmXhsNiA8/USS47LfA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nbrqJ09qm4S44mrWUWsD4EMkSiLFUJiV1ZfIl3x0Psc=; b=WgdOINiIuSgdwN+o+2EqLai5hSMpj5PCm6svRJWhnTPJLBAV4AxUjncgM0oXQ+7BIddkWA sBCCUccuDBJVEKBQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v2 26/28] static_call: Use RCU in all users of __module_text_address(). Date: Fri, 20 Dec 2024 18:41:40 +0100 Message-ID: <20241220174731.514432-27-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __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. Signed-off-by: Sebastian Andrzej Siewior --- kernel/static_call_inline.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c index 5259cda486d05..06b14d8362b9b 100644 --- a/kernel/static_call_inline.c +++ b/kernel/static_call_inline.c @@ -325,13 +325,12 @@ static int __static_call_mod_text_reserved(void *start, void *end) struct module *mod; int ret; - preempt_disable(); - mod = __module_text_address((unsigned long)start); - WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod); - if (!try_module_get(mod)) - mod = NULL; - preempt_enable(); - + scoped_guard(rcu) { + mod = __module_text_address((unsigned long)start); + WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod); + if (!try_module_get(mod)) + mod = NULL; + } if (!mod) return 0; From patchwork Fri Dec 20 17:41:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917220 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFF6C22915F; Fri, 20 Dec 2024 17:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716871; cv=none; b=XeiYB3PRRlC7dnrkma3HhdioXdq+dHug6AlsKugn9gjl6s34kqu5mIUuhDBuWcGc8JQ1hDaWVSYdBOCSPlQ9AKQIJM1zMnMKrehGfxUhxktoOg83RLoW/VOISOci125RwDfTn3yFD4y0EtOTdz9p/a9M1hyQ82cAg4gWINybQko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716871; c=relaxed/simple; bh=RXxizPVXirBfVfQbgsJ3kSHvA7FoXQLVDWdkWj59TPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jjnJ161IXzGENVd7d77rr99Uxw59rDkk2xIES5s0QWBSM8pcauU+tpOW+fJqcm6nENGa637TFdfBEbd8W8kt8XPz/C2TpGZ2FmyqdqUV5Kp+3d1XfqGtx9W4fwwCMs+itGKtqoef4J691YeD2ZjdQSxao+vJsmUvL0++h/WD/0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=E4Tm8ah9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JZvdk6Xk; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E4Tm8ah9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JZvdk6Xk" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pRK0w0tqhurswwZaNufUaRKsGvAocCKzSLzr6eB0tBg=; b=E4Tm8ah9OC2LBwwBB4oSR/ST/BDvArTaReTdwUxjz+fC82d4enrwL38sZa153iGMwMYm6H DtS/hp0x5+nrLycPQn40kqx3KwCmdSZDbGeuDEcaW/+oddxCol70P0JrfhAKbanhnYhVPS cTyBxpueATZ5iP85MmcP0uL21XpC9m8ES1MFgJi7+bQP9kZprVXx/aL6lsK9Q8kfUUtqsi RoXhdKHc9ncR+VnzlcMhSXNYx+yEisRsXAMNG/wZoi+vp2cy38ZDSFNQpcw35gV7CZPib4 3WVCh70heYfB5gbUPNdgfpiZtt8Y98FBKk/65SnEaL8FH08gkE00JhHukbzczA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pRK0w0tqhurswwZaNufUaRKsGvAocCKzSLzr6eB0tBg=; b=JZvdk6XkJ3G2R3/NWfo3BXLpAVNxdlwod7c9d6PG98RN0SuBqNuwRh9acZfbB92qtF4gqv ub0qzWrpnMxjwNAQ== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , Andrew Morton Subject: [PATCH v2 27/28] bug: Use RCU instead RCU-sched to protect module_bug_list. Date: Fri, 20 Dec 2024 18:41:41 +0100 Message-ID: <20241220174731.514432-28-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The list module_bug_list relies on module_mutex for writer synchronisation. The list is already RCU style. The list removal is synchronized with modules' synchronize_rcu() in free_module(). Use RCU read lock protection instead of RCU-sched. Cc: Andrew Morton Signed-off-by: Sebastian Andrzej Siewior --- lib/bug.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/bug.c b/lib/bug.c index e0ff219899902..b1f07459c2ee3 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -66,23 +66,19 @@ static LIST_HEAD(module_bug_list); static struct bug_entry *module_find_bug(unsigned long bugaddr) { + struct bug_entry *bug; struct module *mod; - struct bug_entry *bug = NULL; - rcu_read_lock_sched(); + guard(rcu)(); list_for_each_entry_rcu(mod, &module_bug_list, bug_list) { unsigned i; bug = mod->bug_table; for (i = 0; i < mod->num_bugs; ++i, ++bug) if (bugaddr == bug_addr(bug)) - goto out; + return bug; } - bug = NULL; -out: - rcu_read_unlock_sched(); - - return bug; + return NULL; } void module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, @@ -235,11 +231,11 @@ void generic_bug_clear_once(void) #ifdef CONFIG_MODULES struct module *mod; - rcu_read_lock_sched(); - list_for_each_entry_rcu(mod, &module_bug_list, bug_list) - clear_once_table(mod->bug_table, - mod->bug_table + mod->num_bugs); - rcu_read_unlock_sched(); + scoped_guard(rcu) { + list_for_each_entry_rcu(mod, &module_bug_list, bug_list) + clear_once_table(mod->bug_table, + mod->bug_table + mod->num_bugs); + } #endif clear_once_table(__start___bug_table, __stop___bug_table); From patchwork Fri Dec 20 17:41:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13917221 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E133E229666; Fri, 20 Dec 2024 17:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716871; cv=none; b=WaOw6IiMYutrEX1BY8egUj8god1oCaZfVBiyQ/L/MAzk6QTAB316ZRMKdSd+FCjMLNs7BAS9yPs1yP7B60MdV3H4bdzuetgZOFyEfSFpCeYDVSkg4tVd0gizU06TSldijEgA+FRiqsV5vJfg8O4pdohcYTHw3pOsfzPWpvrBww8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734716871; c=relaxed/simple; bh=qCVZ6MXEQCZKbpVFTGMRYGzHJ160bIV49ZUWguKAVVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MEQqYIBnzBNL0zqhm5UiaJ5PNNDZBJGax8SvoGQzGb66Ibj+WQ8DQ3+W107fXGwBYRAW+YJ6328qWxYTKSu00qnfyFqTPpRT3qXG6cfk5g2uF3xKGu1C/WCszB73lf/afd3pIYzmaYijyKVTSHlUIcHvF8xRHOGBWvWU40SGFv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zWIUN96C; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cgHM558s; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zWIUN96C"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cgHM558s" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734716867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cEtU1/INZZG1AUWOp9SKyBC5+mBME4Va/ulzQZtpooU=; b=zWIUN96CcPeolG0ZYxkjsK3EL720Iqhm6WEVV1bZMz2m4KEpGzQNCtPBIctID3jC7krnh2 xp4eneV0EHTCOCfMrcwJJ7ttjjE3gAurfXNEdf7Bf0jz9aw0ThN5LeaipKMGir80vqDGnO tAE09a7+LBcENXf4yYTxynf7DvCXawjNkJEo6WpEEH+x0jrUeHqMR97a8wj5P2dXnKhV7x sFu1ebBkibO/F+qGCOdbyiYUSdsxoFUn+SSabS4clejR5Oy5oZ+yBZEM2xVvtqGD3rfNV2 Og6D0qp/Nu2m1bk1jg8QqRR2MWOmo3bu4ZCgk80gcdg3uff/TQyiIz2zWUzWMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734716867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cEtU1/INZZG1AUWOp9SKyBC5+mBME4Va/ulzQZtpooU=; b=cgHM558sw+JBKQVTWQKLskEmlEA2lnQiirxPbv5hwgQVEUyuvQ7N4KKVtC98bVutse8xND h295X/l0fNAHkBBw== To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Gomez , Luis Chamberlain , "Paul E . McKenney" , Peter Zijlstra , Petr Pavlu , Sami Tolvanen , Thomas Gleixner , Sebastian Andrzej Siewior , Elliot Berman , Kees Cook , Nathan Chancellor , Steven Rostedt , llvm@lists.linux.dev Subject: [PATCH v2 28/28] cfi: Use RCU while invoking __module_address(). Date: Fri, 20 Dec 2024 18:41:42 +0100 Message-ID: <20241220174731.514432-29-bigeasy@linutronix.de> In-Reply-To: <20241220174731.514432-1-bigeasy@linutronix.de> References: <20241220174731.514432-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __module_address() can be invoked within a RCU section, there is no requirement to have preemption disabled. I'm not sure if using rcu_read_lock() will introduce the regression that has been fixed in commit 14c4c8e41511a ("cfi: Use rcu_read_{un}lock_sched_notrace"). Cc: Elliot Berman Cc: Kees Cook Cc: Nathan Chancellor Cc: Sami Tolvanen Cc: Steven Rostedt Cc: llvm@lists.linux.dev Signed-off-by: Sebastian Andrzej Siewior --- kernel/cfi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/cfi.c b/kernel/cfi.c index 08caad7767176..c8f2b5a51b2e6 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -71,6 +71,10 @@ static bool is_module_cfi_trap(unsigned long addr) struct module *mod; bool found = false; + /* + * XXX this could be RCU protected but would it introcude the regression + * fixed in 14c4c8e41511a ("cfi: Use rcu_read_{un}lock_sched_notrace") + */ rcu_read_lock_sched_notrace(); mod = __module_address(addr);