From patchwork Wed Jan 8 09:04:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930342 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 0D3FC1E131B; Wed, 8 Jan 2025 09:05:15 +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=1736327118; cv=none; b=HxbUf0WS6VFTR6K51VgvCcu7rpESz/C9L6NanJOevvTkb23IEU/Z3OK+b5ZbvK6ZZzQ19vFMTVkIVYpya07+f/6Otbx3RcjjVl7OYrj/SNd6Yj5yftvnCDfheGGO6HBwNU2xUwqNcxPcpFzf7SFP7x8gNRuTo5ec0wyoYcXU6mU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327118; c=relaxed/simple; bh=F9jM9tja/ixm4H725fMZuMP2ARoMzvTSWq/U6XJx5R4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EjiPzUxT3Uvlu20pibpMbuF9oVME5+4v9srA01tLUMmGOUG9/ox/+IoMaEapKv4dN4GKxZUUlAFM+ZRcftQIIvDTBT532gIxdnda79Im2uLJa9AYpRCjHOsmyJbSer9YGRFZVR8sV5YbjnsYL4+zhRRiXkMuJwvNsIo0IjAcKcE= 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=fbL7PaM/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OSBg5lXo; 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="fbL7PaM/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OSBg5lXo" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327114; 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=PPE2aj8MMacLBet/cFcEFX/RuW9ep+ZbC89Owtm7YeQ=; b=fbL7PaM/jGm3qxpDrkSd+OOV7zI9CCrWhK14XQQj/sTBnt5P0YQD0RVra8HFOMFBUfOQ9o ZeiwMHWOi5LYUi7Di9bJgMSxMDCUW3fiwPp2judcLdfWVK23tgF678cOtYn+yVpFoN/Gms I7BHOMfWvtyv1WlXNjtgE8b3v2b2o9BAuH01E+17hUdm4tCDN7jwTWbpwetE+wKsYlEJdN v2tTEdls+9oQiny3wsLcc02lP+uZFcluG4fQMCkxJSTbRWtzCVikVgqv3E6qJmVBwzPuLc MgGtp/snz9ICbfa9JSaVWBETsCxx7ltqjFwZ1mEtKO1dTNwu9FmqvY5nz50DLA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327114; 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=PPE2aj8MMacLBet/cFcEFX/RuW9ep+ZbC89Owtm7YeQ=; b=OSBg5lXo+ufWWbp8J7i4SouYnhWhb4+QsBz5t/KMyFqT4Mz+2/cdk9gWc2IFkA4tH5UwY5 s+fGjtoLVNIUGsAg== 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, Sergey Senozhatsky Subject: [PATCH v3 01/28] module: Extend the preempt disabled section in dereference_symbol_descriptor(). Date: Wed, 8 Jan 2025 10:04:30 +0100 Message-ID: <20250108090457.512198-2-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Reviewed-by: Sergey Senozhatsky Acked-by: Peter Zijlstra (Intel) Signed-off-by: Sebastian Andrzej Siewior Acked-by: Helge Deller --- 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 Wed Jan 8 09:04:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930339 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 0D3A81DFE0F; Wed, 8 Jan 2025 09:05:15 +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=1736327117; cv=none; b=LNnrOAUBIgfnnqPPq9gNEISbb5HaaRTOEnRdzPcZ/fkOA/XafUplVMr5m+Pna4qiLiTPhD55dDP37/divD7TWYWBlKJBbbtSNfPnlJG9s/TPBOZBnfhYEJWrs5NN/2AhGBfgMsnYpXVg0o/gyrFCrdXOqQuHi/DZXGBNEolFI30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327117; c=relaxed/simple; bh=oGPF7Zd2vnWJKWA99d11GeH6xe2HCN/J9syt+qgqTrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nDwUn4/Laz0dRfwInCrVIDO/j2ynmEFTHokrYQ3OnV6BwS+pV7d7iaqxcHQ9LqzBSXGfSC3+xxry/XdCrHbZM9aeRuNDbObWuQXuCw0URtYvm4rP2tIh2uwGsTJpFiLFfxnv7oOS3vjjnjzZBhwloioaABxNadaR7MUSZEp2BiM= 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=MrMA6cX7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2foOFeLv; 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="MrMA6cX7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2foOFeLv" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327114; 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=ZHrOtRyfsvy2nZTHiTQiSYA3hKf2e/GwmU3pg86f0Gw=; b=MrMA6cX7Pe66mkqLta0uDcb/QJRUxrwhLZY7rM3qEqUTY0Jd1zTDklvwuMiU24G6c7mDh3 +XrXR4cDWrJe9yAsrxmS7hS6EDxmQ6oZ9I1dLPDolJob8l6KrwPGwUB6q6T6vlSngw2hZ8 AaEAoCS7HU6ptIhzoPW/vNG2BOg9AtYbJiGtZCo41r60uqUnOCwD0ubV29+uLFBbr1mwq1 rMGdfxopyEdgyG2P6mzF2Yl/isE4tsyzxQkVJZQTOKDyxqzits0DKotb2GPiY99bssyNt/ oyqu3baV9jPn3TkYIwNh4QScBpx66Tw8EsHLadiLMaIs9wLFrvMvQ23+n0wh5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327114; 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=ZHrOtRyfsvy2nZTHiTQiSYA3hKf2e/GwmU3pg86f0Gw=; b=2foOFeLv7njPALi/Sj4jfmsN+yxlP+tORWKvnQhB+ylNwpcSNfwb8Ev1DNcN1gMxDojhLx 6ppIeJom1vJqUIBg== 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 v3 02/28] module: Begin to move from RCU-sched to RCU. Date: Wed, 8 Jan 2025 10:04:31 +0100 Message-ID: <20250108090457.512198-3-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930340 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 6F6AD14B95A; Wed, 8 Jan 2025 09:05:16 +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=1736327118; cv=none; b=fJl7/1qPAPhzoORScBv1pPFj7AnaZ47EkEWoic5UTzBrhma3C/res7c6avi8jhldj0ke4O/ebgo8vJKiVA+ZUCSstZvDGEAVM5s6ffRhzd/9+xAy8rrMV+0u0WHNe7qubP8Q7S40gcA+QgZP73snTgHNcA8WPuZ8VFkXxCzlZAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327118; c=relaxed/simple; bh=zJzXwl6QYBFCHDOHlQ0pCX7P/0Z8hVJ6wcBRmnq1Mr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GAtU8jLn4qlECGw/CIZM3G9Fo6zvrwbo8IX1q6auE37Sv6QVlrhMZM4ckeKB6lVT6XHCIZF61nhvv3NA8BPk8o0aLUZMqM/jeeEwv/yaU8vR/n8OeS/LgA3XPqXIydYHlWwuDrSaoAPYzAlZ06YqT823Brik/Y8Ab4AsOaTgHsk= 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=dMGu5mNQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eQ+S/9fz; 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="dMGu5mNQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eQ+S/9fz" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327114; 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=nqFCtsDnDVNdkbpS3y+1msrlanYbghspKlyRIpJlAgU=; b=dMGu5mNQ5Cy1C6m/T4Ld6y7GnPIo9vXCghR6ekMae/1QrCEEHq25IbnRnluJGT0umag4Pf rhYW7zU7Kbzncf5TEw0o77Qub34O/dCmoqlLG+V6U6Q0C2xArd9Gpmv5Taa2fZACDMUXQI raYO8jUDtCHnCzSbQa/+XWPZ4pGI9x5SZyNjCul5PhVjLDdlholVOY0hvfORVXgfrXlGOa KK2KTJEdfN/sIkNitSPndgnkH3uG26tgxBdDdDXbR3jbJobJNk2Bl+2KCpQhI8ZXmMBQLf rqbAZA25Mwb6if0aWn8fUt/AQxVBSVS/DSFBoMnEkwYE/4AfdlLYGtX+YVEPRw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327114; 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=nqFCtsDnDVNdkbpS3y+1msrlanYbghspKlyRIpJlAgU=; b=eQ+S/9fzFkx7/8onRJrmK/0J5ltmUAMyMKtwO9OofqDZAk5UNG+/h9kK38MIVE3AIPg0n0 nvTREfKfa/Sqw0AA== 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 v3 03/28] module: Use proper RCU assignment in add_kallsyms(). Date: Wed, 8 Jan 2025 10:04:32 +0100 Message-ID: <20250108090457.512198-4-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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(). Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930343 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 9D1881E9B2B; Wed, 8 Jan 2025 09:05:16 +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=1736327119; cv=none; b=HbuRrXm7MmwCBo9YE3TuyrerOhe15jJO6rSGcQSXSsuYfC8PQH6fjEgd6rV9fCu51s5Z3FLJBE9vTGkO3JJ+3L806faEsdcDFFWnAOjOzpwuzNGKbXHGfT7n+0M7TSqpzKe29K5iGr2gIEt8WtoBYN/XzrYfxMf2+ND4Yetdw+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327119; c=relaxed/simple; bh=GtZm9OUff8mdUA7NEazwjLhkXhghK5GN8Su5E/jEgMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TtW94Z0ZmQl/TPprHQ15Dy3p6Od8c+7+nNFVpEK4x0DAmUlviOfCCXsEgALsIZtuxbOZBGH2uKKJ7riDPeINcNYHJWif6Tpdh4qqcxGUEmPW/D2MSy/9OEc06qwCWXFTXauKoAXGq3qESFf1N8VpL/GuFezXvo1tIjZU/Wa1alE= 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=wFeVnlqT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IJ0UJYZW; 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="wFeVnlqT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IJ0UJYZW" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327115; 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=IBep5q6+Gwd0en0hg4Rnt4q4GwKIUucRGk1ABlTBQ0U=; b=wFeVnlqTo05QQPNvrygBQPKXhgiiulPS40wZLLtBjFjcXumKkpCL8EjX9TLfXJ5RTjcNe0 su2eawtw4eYbLrUCOeXDNcgCStTkiLOyO2JtJxjs4oeexQiKyvio5Ou/D+PTZ6A5UkY+cw BZ4UdnCLXNoJf1lriy/ks+dx7MTh2eKOqKBAGRVGFrX7PY9brWyPAk0TFSja4U/VaYOb77 hlZRN1BsQjpFfIg0sCMaJps6/GG4yxmd7AKEukMcFRN4XmjUKmrRENcyG7ciuYX5cLTgmv pYOc+FIrCnE/hNYcGmhxPCS59Fac638QWPoLgOJ12NQa/QBVM62Kig7RmDDwoA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327115; 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=IBep5q6+Gwd0en0hg4Rnt4q4GwKIUucRGk1ABlTBQ0U=; b=IJ0UJYZW7l1EQDyZdhP5XPywBVT1Pf65tlkVmztwkn60W9CWUIP+dPvMiBiuYY+X4uQpv3 ux1KQlX6a0b1ABAg== 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 v3 04/28] module: Use RCU in find_kallsyms_symbol(). Date: Wed, 8 Jan 2025 10:04:33 +0100 Message-ID: <20250108090457.512198-5-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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(). Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930341 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 DFC751EB9ED; Wed, 8 Jan 2025 09:05:16 +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=1736327118; cv=none; b=Joqge7SvmnPkIoQ9SFoZBZcjBGzOBKo83CQsvwy670t6veJE895xgxfLgpm1IoNEJik1yQ6kSbX5DULhdYTzZY+Ger/VHfiIaT3hs09gWcw1BrZfYG2BtjBZBay4GI8JGSWwjL2uFLXBkSGudbi/0fl89UlL5v2nJLrfiS6njhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327118; c=relaxed/simple; bh=HkaERP1XClK8uXSeXDwlQH7sFdeU3xriW1MEHDK4iSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FyuRjp5M42vIP+1EGgQtJntZs43jPfUpZoUW1/di1RFdLGE/ZNwzcJH0IZeuLVzj87xtvIfg9GaY6DP+MiALKYkra4li5ZGVYpqN+GoyY5TzJZIYrLfOtvdRc2J7pE1NnBIzZxbb3edaOV2iI87TD3D8o6QRLB9r6jO5AcQcUNQ= 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=Qx2dCkoF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Cbc3JwIn; 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="Qx2dCkoF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Cbc3JwIn" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327115; 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=BHaIm+dVbfH2vg9ZsyIqluwaG6MflVMse3Qcc2GJuB8=; b=Qx2dCkoF1ICu2M6YRLp1omVn683yLzzXw81T+gcLfVFyaw9Wwsgz0bt/UpzNLl7aq8EAKr ec4z+gyqGHJokOODpE7FWnY6o72EHcaryZ1eNOb4wTLP0128cJqDd/J8A6hHypCR/c86DS bHZDF2yQ1iBBiljAj0WSZECFjrnocU9IHMX4q5qzZBOjHKU3FII0No4TPCZKXcJi/e8gXr abzMLkzTnbIRZeqY1KgWUamIsU3deUU/rKf9CFVedAabVJ+B0XujmPMRL0Q67heFHB/G3B /YzqhFPAfcGGOJZM5jiqUHe0IoUTccM+o4+LYcspT8sxmk+RFkie+938Ir1OqA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327115; 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=BHaIm+dVbfH2vg9ZsyIqluwaG6MflVMse3Qcc2GJuB8=; b=Cbc3JwInX4nieV2P/nXjeFkwcBsDUlEkhhb+cPbcr9NghAC6YKk0Mi72bMLoTHf5EPcIxL ox4UETCPAQd7qSDQ== 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 v3 05/28] module: Use RCU in module_get_kallsym(). Date: Wed, 8 Jan 2025 10:04:34 +0100 Message-ID: <20250108090457.512198-6-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930346 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 598031F2C44; Wed, 8 Jan 2025 09:05:19 +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=1736327121; cv=none; b=bIeAsXKU+YXIVhiqbM6yR46U+o1S4YYVRUUL7iAu7mvNdDNMze4PjjWNiuKMnpiCBErhWAOyyo4YilFcA2YRsNZT75nJvniaTSrZ/U0O0C0kuHVtbO9w+ViNvoSNStkBoMys2+2EcxFlJyP71hMDg7usE6alQy8jeFqPshRzHHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327121; c=relaxed/simple; bh=Lq/578psMJ7xGA1MC6Fb72suiu4e26yPqzxxiBL1vRY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZQ6J+OE1EKKp6Y1bSGh8PPcqzwm9me6iCxGmLcu1iB6hRe9nzKp+hTuAi7mQ1KGUdilcEI89obq1fQDsm8DgTheDsu3tZZkIQ1r72YzwKbCA/NL0Z8Rx03dXL+FoP6hSv517VQkSak2kpLmwpdmEAB40TO+OAteeVdKoL60XoZI= 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=2NWsnHYD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Radbmlg1; 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="2NWsnHYD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Radbmlg1" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327115; 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=Dl0IiwCR3ilXTxBcYNupLq7U5e515iyR9fTpq03YpK4=; b=2NWsnHYDRTA58xM51vdPnzxpA853qVzlsE3h/6QMdiUM154kZ1qtsE9Baes12JWw9zjDuu BeV/u9cBOxSnL5UudUvnUo6+yeMx1dABdZFshGHI1d8fU7UUT6oLxrg6uYdRjIwOLiqsoL k+TalvqwOpDLOztEh7YN1xQK6J5Km/hYXGdRa93tjUcTZ+hzCyjtr5izfR+CPTn4w4r2A1 99raKF2o0NaeXyGImTxR9us6yKdPLyT1WhPmkImJ04m3JVCgB0Icq13a8BesDEkFb1Fp/j Dw4RJVls2P+HyyFsrAdoSA8oJ2yVrzAkiQ+bD7yyPmrzcnhW01bjdjSqOcYdFQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327115; 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=Dl0IiwCR3ilXTxBcYNupLq7U5e515iyR9fTpq03YpK4=; b=Radbmlg1VcUiFOGoj9wk5Vae7DRGB0WrW/kGlDYZe4YpKonGZXcr6qdzDK4LWmM/K4Ge8v V6azuNKTwTBmCuBw== 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 v3 06/28] module: Use RCU in find_module_all(). Date: Wed, 8 Jan 2025 10:04:35 +0100 Message-ID: <20250108090457.512198-7-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Reviewed-by: Petr Mladek Acked-by: Peter Zijlstra (Intel) 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 935a886af40c9..37ff78ee17fe0 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 Wed Jan 8 09:04:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930344 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 598701F2C50; Wed, 8 Jan 2025 09:05:19 +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=1736327121; cv=none; b=BvJhrfLnQoYtYYd73gGLOe+G3wHOoXA7v8ydk6a4Mle90xG3lLtMw2oHRBsEYXlzaISBlSUAj/cUB6T+rBKPQ2tUEMLbOYNE622IOg2fEKs6ndKS6QXZKbBdZUD7WDOv73zWJEL2jwJj/YHger4meUHGsSxt64X/Q80m//VAFFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327121; c=relaxed/simple; bh=Y8KO8AjL4Wlp00NcVyzY4VrfkvuRnK0pthhJzJeBi5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ObXVnZUc7smiWu8bDNbqc9GJaB6/Y4XvxfwTY/4cOJKcJ4Q2NAnzXi9w+PIH0u0qcBxukKykJuICeKtW3jJlUbU/0zTGkutQxJ+LvK1XeGOYblsepI9lf532wxjZM1tMmBFeKNY5C7G2h5qeZAAZox2zc6Yhtgas4mgQhrG10Cg= 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=dQw546Fe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yELo2Ron; 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="dQw546Fe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yELo2Ron" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327116; 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=F/i2pw6yEUIHHaqk5xMWOKQ4ktctxeUDzPoI+9p2J9E=; b=dQw546FemZWA5DZl3GgQ9Z9y7QJ95YI3DW+C5DaF34P0fbpmOq/II42Mf+3LhKCDkHfhFz JLmdwpWpZPz9vV76LNDsCf4h6Pv98KZqd9VJ79ALyjqEXoMRDVpL89UvzIj5xR0D6MNPwD kInzP969+40qAXeBZC5K1XCDZYEolhxgyXY+EpxZAgB1l0PbdPQBxXd8OQmjdL4faDh0E2 75Uw/s/X+HXqCaRu3OtRJ7Ju7d7qdnF6ChfjgTCdscziqwAqlDIDi33M+t64cmh81OX4oF OBhJxPcPXCwvMLXp9pFQ2QSWAH75nnRSgjoZj+vCHl/QoC79bHoGHndnTRyTCA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327116; 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=F/i2pw6yEUIHHaqk5xMWOKQ4ktctxeUDzPoI+9p2J9E=; b=yELo2RonuTymhIA3uhM5pDJgXzKStGcLZB9ULHCytAJLeu/4p3x50qFT/CNFGNNHTHXpmj DyWmRALNfWx+cGAw== 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 v3 07/28] module: Use RCU in __find_kallsyms_symbol_value(). Date: Wed, 8 Jan 2025 10:04:36 +0100 Message-ID: <20250108090457.512198-8-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930350 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 C9E101F3D3E; Wed, 8 Jan 2025 09:05:19 +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=1736327122; cv=none; b=RrRv0d8t/5guUQqyWXWZZHgQDrixnRZiEVG4kxkp8h6/QzBDSH+g4ztqc2952M1Q4XV2O/HZldUyFKnD65cN5NIbDXT/Ab6t3xut45Mh4hvMIbUqLxMMR5VdZbwor4BR2kCBlDkQ22SGAKHWetUr1KsU1To0x5W0OjDQrGOXEM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327122; c=relaxed/simple; bh=/4aSMjCGaTwkJHHFm5YLWbwzZmQ4wgL8t+6KjrZ2sxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ci4qGH+m5lkMX7LC/4j5HmHT0ZCcH1jJc7auQDbTSBXdKmbBKheaFa/BpfnDK9y/YIC70OHEqjWQSTeg7f/jDiVW/1qKF40XouLhAoj8egUk+DvjOWfHohRIXznFhw6KUGAEOyacsNUOD8n+sn3jI47YZWzAD+BTpSQiEvzGuSo= 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=FRRGTIZB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bMuIZux3; 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="FRRGTIZB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bMuIZux3" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327116; 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=QLNy3Nm0g98q8kMW8Wxa6YyKbP0OEU3KFHzMhwk5Nkk=; b=FRRGTIZBu4vIjG96079PLl1DfqRCE4j3zSwLZmQZuU+PQ2DfX+3178aRJYAfgOjj+EfDV2 gsc+dlWfEkm6x7Y5/GhMKYbHl7b+CJk1SD+YA9GwDp17aZQU1bEbKcNsZVWp7IAMjLmoYM tKrUwOzIvUrS3CjlbUNPhbEPE0OSI8uLEhe6P/kOV6xe37Mejn/npM1zqVHvPPCnd0TXM2 va6i4aLlVP5TuvtycGVdWlKfFAz7ho1T6Uhh1n9aIdn5H9kUL3dvzrpttsupZDPdNzwCrh Alt7k3si3OdxYAMJpkVWn+uPHA9aqkXy5REBEO1RcTlaJUgPUGTprKGS9x00PA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327116; 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=QLNy3Nm0g98q8kMW8Wxa6YyKbP0OEU3KFHzMhwk5Nkk=; b=bMuIZux3nCGrrDuKu4+dG6tITI0R2AQjEetDLBXlzGdvRJVu2K5xPsCisVP9lhLt+kaIyj hSwbLLI+Hqo/bvAA== 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 v3 08/28] module: Use RCU in module_kallsyms_on_each_symbol(). Date: Wed, 8 Jan 2025 10:04:37 +0100 Message-ID: <20250108090457.512198-9-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930345 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 A0E221F37BB; Wed, 8 Jan 2025 09:05:19 +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=1736327121; cv=none; b=UrKEUqR++bKiR08aXDjg3eKGZPncVlY5WBi06Pz2MFN5t2+k9yu100pcBs/zTJ22FSIsXBo2OV4TniF0qPuaEr4rko30gjEG56x4YnowwFlLBC//kZPxngQDN5WbqO4PGy7t38uNVC2qoBAG+SpHP9ZoqhkuIisL+WnP6oRNBds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327121; c=relaxed/simple; bh=+fSSWy+fySzQclNpCT2E1vgWXSq4i07JqpwHIz6/Xtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MN8vx7FWdROGQ0b8nubj66+9fVV/QIwTLzwpmdOj0xjFgTg4fxnpjr/7bJMJi+971aYrZkwvXgswyq+PfGDwOxEIyUHIAReHRVKQRbek0pEbHkpdGuyZ95RDVma1XM5TG+uHwPSKvfSEiwtXTvjdhj+xJ/7x8jlt/OmL/9izhq4= 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=dVV40QTc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zAgwkyLH; 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="dVV40QTc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zAgwkyLH" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327116; 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=ilrd0MEGQs/sE+kksjagNa1uRWCb3COiwDhm4RX4LIY=; b=dVV40QTcOsjKHL9CKFZkjsE32q4v2jCLXVMANins+8F5indNkSuw1y1OPQK7eBRQpp0d6g TlVTTIeP/3vm/qIb5VivGPPu+3NkHPQ0gfDYauNn6S1lilBHflBoTijlNUSwHBsKpChKtj eu1QytFdy/rzy2FV7vOdIMwfBLZ7965O4ZDgHumAI9D6GDdfRZAzxcwNx93SbnfMt+l2Wt LZXJLO0HktMuaWk3qvjg7MSpJfdBqX4rAlEK/xdobVcXfHdvQEVRJACBfOTQKghxLBhE+X Gd5nYT91C/T6zncmG2V55HGRzgtxsPXzylbtkoJKhGnJvcSoDzln7L7lBNWJlw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327116; 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=ilrd0MEGQs/sE+kksjagNa1uRWCb3COiwDhm4RX4LIY=; b=zAgwkyLHkImLyn3X0LEb6gs9E+0DXC/Kb7pJF6AVP5beEuvDyxXM0+20Bng3sTeeWJWeMv zb/Q0b2VQKquAPDA== 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 v3 09/28] module: Remove module_assert_mutex_or_preempt() from try_add_tainted_module(). Date: Wed, 8 Jan 2025 10:04:38 +0100 Message-ID: <20250108090457.512198-10-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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(). Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930349 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 F38B01F427A; Wed, 8 Jan 2025 09:05:19 +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=1736327122; cv=none; b=hmsMiHAa6uXmpd85JCIgHJhrnN0xR13fDoThOsoYpICFtpfkH9SJnGdvhPmF+Zvw+iZo5Qjj/WobHOA+k8ckFFtqX2dYUz5KYo8ImkimrURY2ONHT+oeJVbkdYmgPQ1kndghEu9O4Tu6sO4PgUcaVCV9d3Gcsy9qC2g6pStrpCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327122; c=relaxed/simple; bh=4qjk4ZgYgYdcxmkh6VNIf6ytI19yT8vGBa1ibzSe1MQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BidQGwwNNWQ6D2L2DAPPz//qtRf2QsYqw/DWVvg8e0QnM8WViRhOWvrdghlNiNMRGtQnaO8KFSLrKRK9A2tdGvtxp7HqISPUEyfJxxYz6Xmyluy22BCCfUVJmTP1T5dQWa0DopgjRv+6FDMIbtM9vc68uLcWQCklX93o9257KD0= 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=c2P2D9eS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7o7UMwa2; 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="c2P2D9eS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7o7UMwa2" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327117; 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=UeRBwot1ZOna4cw61E4j7JYR+wcb0jWq9QvmlD1DT/0=; b=c2P2D9eSh4XHo2/Blrmx/hYuzX2oqNMwhAse4kcS895ethl2GkmDlBGqOCU4Tibyb+94oC cS0EZOvclEU832SmZR0w00BVA4IFLqmnQia47ZsjYPa+Bya97m8b+NCpoAN/b8LghduC5V /aGK4ict8yPZ+xe0lLPH23HxbIenAtafWiuguOJpw143QWK//BOgqVXUmfRZLx3Pp6Dyl4 ru8UuXp26Ae06H6z0ENF/ITy3m5C0BcX3Risa2XPJSdfnpPnu5KZgSElfHIMpKoFPaRFOR Dw/X19vjyf7O84n1ODSXUJhMc70bUToLZxhE39cYuLkPTQCIxUKQg9wlbBZw8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327117; 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=UeRBwot1ZOna4cw61E4j7JYR+wcb0jWq9QvmlD1DT/0=; b=7o7UMwa2KRtBbBqfWNQiapLOAixcH6GT8QOILrmP52Dm1bFGOU6/Fgo5AZwrmOfIbIBwoa ikm+YjGPUrlTyFDA== 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 v3 10/28] module: Use RCU in find_symbol(). Date: Wed, 8 Jan 2025 10:04:39 +0100 Message-ID: <20250108090457.512198-11-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930347 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 E31491F3D46; Wed, 8 Jan 2025 09:05:19 +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=1736327121; cv=none; b=qj6Ima8Tzu4X3lmrVZODAbxYOQvEB7thGpM1pzS1A9pdic9ohoCa8oN/DFLNMifnj+kEa+18lmUX5gmuQRrjpcLOq5LcCvptU+UUfRwM1WHViBRrS5bn4nMQ15odvDvsAYlPW05z/RzzrhUlmiEmPAEG/GooRI/6zDmVU/dJ/RI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327121; c=relaxed/simple; bh=oB83UaSp1qFOvtEHzn7IJKhNapwXigzAWoUq9jK7Ea4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nmBmUPdUIQGtDHBtvCTiYfXPbQdiHOqDTMs0ZdZoFuqfds0GUxIjnnIhywHjhBAnseKBNUMlvz82hLNMwU7ToR6MpeOKAwS2U0n9RIoHAG/O/e7dOLGqxPbX2ySDU+4pA38dYMicls4jCyvTvGWmKVyh2cTSwHPGqgEFBa4WOp0= 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=IErKknma; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GAgVeDmt; 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="IErKknma"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GAgVeDmt" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327118; 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=x8wtAHd+IQLsYzDyMqjprxSKD9xTpu50XdFLIZhS7qA=; b=IErKknmaTjKyf/ql5Yi7VQF+PuYgnEy+x2GQ1Cz8L/ERZ79EH18luUh06m3i0/4+zZmQuG W+740ujZcRgji/gtPd2zzau6hd3kQsuL41EYnQqH9ZTp3kbChzwFyu8JxJjy+7DUutgHAR pxOi3YROCaK4yPiU/TrPqXdMmEt2tM7i3+QcZPb1NZdoisxXWu9B+BXnBvVf+HpaTuiqEp jO8Ya6R2c+MAiejAGx+CbQEa19jrnnJmL4Crzl5pwUmSLlX3NLYCrLHQ0CZDRudU1x2VCe a/tfeKYomasIi9PPuzsA2Fx6e2SiKNk8+5X/9ljUFjCE7RGRMcQGBZt/i2XrMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327118; 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=x8wtAHd+IQLsYzDyMqjprxSKD9xTpu50XdFLIZhS7qA=; b=GAgVeDmtMa9JnOOzyU3MLouTXlmfKpg+HWb0/q93SUIaGTWzuN+sutJfiPnsazTyBbCXdM o6j5ieribl667JBQ== 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 v3 11/28] module: Use RCU in __is_module_percpu_address(). Date: Wed, 8 Jan 2025 10:04:40 +0100 Message-ID: <20250108090457.512198-12-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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(). Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930348 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 F29C91F426E; Wed, 8 Jan 2025 09:05:19 +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=1736327121; cv=none; b=FRn3nqEijM1Wt3aygc3hNy8wNxHw1cJKXNhV/KWni1Fhj7VNqKbWbNghSF3cviRm+HQRwiQAhUcxNvc6Qq0azkCMD/kZxKfmKHdYcDbl0O22UfkFhEdKu1Ry+iv0LYctqLaG6+jO2eV+AYpZfllJ1bX787OATjKBBOp6d6+bxac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327121; c=relaxed/simple; bh=axvyxnWooo75BTWGLQAmaIhNJhO70bD+tkHMIyPTibk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hHVFRbaq6rW5Wsey6RpwTR9FujWJHpf4gn2kLAdz1/wqjgj8/5QIflywCJhCgOktm/TYWl7exr9poS3gQQ+KxfSCusOVEC1uQvXpf/e8Oj3l605uTn4Y9Gt5eL2z6ynL8eKapDshcjW0MUse8DlHbLwQRTgfyWZslTcRRk+PDcA= 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=l6Vstg6w; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jIGs/Hd3; 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="l6Vstg6w"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jIGs/Hd3" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327118; 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=71h+qS2tty8Z0drmH+HaOoie0zIG/EW33SGidtl3NOY=; b=l6Vstg6wTnoul4HLT4y0awP4b0tbXsHV+yWypjiAlreQ/QNUjbS+Pxuff7eam5HTXr9UG+ yv9HGOD2UNaSaT8DPcG30gdXM9roaKq8AXVVOso/A5/lsBKDZw0HyuJYo444Qbm8n3JqNf nxd5QssopBV/Egvimusx/zYOswEHL4bq9m4msKre6/rOiDQL4G+63VxTnFtDMPSLZh1KQA ucJv1l1/5klwBOmvP81Utr4+ypyKHpEYw33vNSc7Bk3uXYCHqFubgzYGEIQCCUka4bPTTg AOlX9vpaTmiJCqVi6k/6+1eNvtuloOD6E4HZ9rNU7Kes2XLbWRr+L4yRcSIksg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327118; 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=71h+qS2tty8Z0drmH+HaOoie0zIG/EW33SGidtl3NOY=; b=jIGs/Hd3yi8VlbPOb0ijPhLNJNFP8QFisXKRp7RidRarCiy2ykn1jovqfH2ZfK8xnt/4ng 57elPqhDvvFT55BA== 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 v3 12/28] module: Allow __module_address() to be called from RCU section. Date: Wed, 8 Jan 2025 10:04:41 +0100 Message-ID: <20250108090457.512198-13-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930351 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 6963E1F4E32; Wed, 8 Jan 2025 09:05:20 +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=1736327123; cv=none; b=Tda7OLjVTP3xGdbYpM/zICe4WpEVufAmMnebaELDFGD8VJ4mbzCS7FHENODutxdNzIDGqRgBHT46gl8YMx8xJjmLsSaeQ2bla2ui8je5L+ro00ZnUCXqSeiG+lzl8yxvF7qYIYR8fwNuZHlAlYUvehFaMjsQgV9h2rscSI+DJQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327123; c=relaxed/simple; bh=j71SAc1feOMUcJOMEOonn0bRXR91q7WidaoHZw+Dzm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uyGRunkG6QAG0wSpEkeQMVVEK2HiX+0HCMEGi78O86Rx3qhe81//6G1Yl2ovLyIyzf/FT+dIuL+AzpZeN8Oe42d0BrMVW+DtQoG+1VZZr63f9usW7n5y8IfFbZDORJEPaBkER4kBuJYM8Dat9R8hj+IoXUOhR4qi+ywmJ+zhMzo= 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=UXyXn6qs; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kB2FQPbP; 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="UXyXn6qs"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kB2FQPbP" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327118; 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=MN0x3ummrzZ41bq/tcp8fUaKeaZduci8Y57Jyt5cghg=; b=UXyXn6qsDLwFTrdU2IMUOmERGnRfEHW6YwPtqITSqBPCcZZGX+NPxKHsbkKFR2Vt4ppaeK bYoUxeTEC5PY1t3iP2XiV73lqK3KTy2wXvswp84IWNyxsMjfRePcDoZiucG3XZacbMMh6p 8D87l+HQbRGDKG/5whXIVrxvUxihzrplt29Kd3E+m12vkiy66EGbywjiRpyUdivsMranEW Px68VC12QVJQQqlBMHHVyxufw3w+WyjnZx2vV5mX5ZRqd/HZRtRp2F1/tbqwuAKbgbAiHj bm34EcnFuGAxcTp6XHvfNC1hku9dGuw8Lck72RZopdP1e4FfSmfMKlhP06907Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327118; 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=MN0x3ummrzZ41bq/tcp8fUaKeaZduci8Y57Jyt5cghg=; b=kB2FQPbPCXAbQRhuZi0w8hYUgBkHt7xEkZcSssQONfXd5v50yLr8zw4wmDj4Ink8eOuNHW QWnjD4HC+8dNugCA== 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 v3 13/28] module: Use RCU in search_module_extables(). Date: Wed, 8 Jan 2025 10:04:42 +0100 Message-ID: <20250108090457.512198-14-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930353 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 6DAF41F6684; Wed, 8 Jan 2025 09:05:21 +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=1736327123; cv=none; b=rOooZxtWRmfTfAC8I9WHKQFnajHkrTeymte8HRerwJLBHSClhWDf7vMEHSc7lN0gBFdlL6TY6orv8w5PCNAVWivIfAbYYftVj1URTv8o9iQUsDVuCdx7a40Tizbkx8AgOFZD1KHJPeiaum3ILQeZn27ElWzWFo0F8G1UI3Tc46o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327123; c=relaxed/simple; bh=ohNt+IpE9y1EvrRtmwIXXsVBrl//72vKsf1EMenX3SI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rUXyoCBGyFXAZo0NbZNnCv0pgyNxM8H9pT76N9d3WYOQkPLtpxjSpwXFUPEi99D/8WF05naTLpSH/POjfxdX6G0BByv4P4ibrKHjn/AKeX+fxBs5NEUYvhxNSXzpv/uPuE/BJ+1d0LTZCBoPP02QYYaNsWTAfKrPGS1Vt6EG4NE= 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=tn6QcbAV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+ibczjjk; 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="tn6QcbAV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+ibczjjk" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327119; 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=GCMK/mF4CB3GzOpmLFR2eFXjQv5molDTvEmw2VyQ6Dc=; b=tn6QcbAV6lbve0+ob1buhBc7xxvQ+UILG89+UvzYHUFwnWYo3a/4dfHiReBRg+6gd5jtHF OShFzsOeSzYg4FgaV8t3UZrdMF5VMK/D0Sa0cWsY4Fe9t6dMlYXQ+xm0XMmXxIR7MU3Ve7 w+MyeD/Weri5LV2Jzv2yZ3TNl4wgH3VwHyzPSF3VOhV2fTY5ioIl03ZtCI19NE0crqaCQ7 YXMuSGt7P7yTp/hXXW548aEP4g2K+i9nRbLYlivI4UyPoZcjxdtCo47ZFHso8h8KvH4Bh7 WxKsDkLH0n0QW5A+N/JUhh5XAFHtIW0u0/EQDk4wPF3mEytIJGAzNfslAIPYJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327119; 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=GCMK/mF4CB3GzOpmLFR2eFXjQv5molDTvEmw2VyQ6Dc=; b=+ibczjjkcy4EN3QrXwP1iZ6Hm7kRRdoC2XZXirOv93caaBdZwhdORFKbRK3xxVyodt4qB7 u9Y2xeft3dtYoSDQ== 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 v3 14/28] module: Use RCU in all users of __module_address(). Date: Wed, 8 Jan 2025 10:04:43 +0100 Message-ID: <20250108090457.512198-15-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930352 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 6DA301F6667; Wed, 8 Jan 2025 09:05:21 +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=1736327123; cv=none; b=huERPS9EMFnwsg5u9FfCMqFDNZbv6uwun1B7iKcreVGFcTbaNI84kHtK7Yab2qUSFbrGM1e/n1OUwOnfjNW43yDvs0pwglNbgcuD+xaWjNps/TW1ib3/ciu4TLvza8IxLyaVRals5eWsna6xIDHzHduNcZ3C/rZSYFWzKuZVUM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327123; c=relaxed/simple; bh=4YfCwpsDNu10d16uLvt2ftKgzSjz5rZGc0e3lZY1kSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qxtdZTiJDHweTQ2ZL3fz6WyfJlfiEY4HJ/uYRwZbW/EYkKepFcK1KiTNIjybVVa9RQi8xR7BpRUiOXfaH/ON4lE3V+SUtec7aaCR1D1qavDcm94HzVnPFLWwdAOvoP7eWfIjLpI3rkCvaxCk/c5iRm80WtQ0kXxwvkhVv7B9Fro= 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=0sVR6cTe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/2agCRE4; 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="0sVR6cTe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/2agCRE4" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327119; 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=o25ZzV5RH6ZFftfvyXoFK8KiOkIRV6q0g+c/tnCIM0M=; b=0sVR6cTev+LkI7Ca+JfYPKISZNzOMrBcWcY6BXH0ztCcWJJLGWAYNDDpfrQWWzyq53T3v+ X0BRM3OIIo2JzkFf0gn0pjTNTqh6nz2Hna4KqcvQRwJyxLGZMK6R51ig/WBCtf3xBGxgRs d6B5xZzP76egaAloN3i4UMBRC9oilL2NF4t4Xxg2LySNxEPJUBYOzgCbyx23LWtTpFoWiC yDhIt813TgAoAwWY9QwF589K1UeUz+wWyc0QCJe7j++pvtCZoxdNJQcjWwwJMpI49NaRI3 p1PeWwqC0y+OniC5DqP5QVcPGhBap5a3smrPKoZk6Wkg6cCAjEJAGNevaAzfJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327119; 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=o25ZzV5RH6ZFftfvyXoFK8KiOkIRV6q0g+c/tnCIM0M=; b=/2agCRE4MSuFSBvHxRUEYPTiwIdCGZbd8InWlbPPJ/33PZsCcg1r7pbNGbuTeFGx2Rx4DY vMgZvT71aOnyCFCQ== 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 v3 15/28] module: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:44 +0100 Message-ID: <20250108090457.512198-16-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930355 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 9C7AF1F76D8; Wed, 8 Jan 2025 09:05:22 +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=1736327124; cv=none; b=ZQLA9i0hm45B4RQE4rwGn/JKiydALALxVVJb/GFYwhBXLHsfeDQbzDNXRBSJjdMXOr2V2uh2RJs1B4mDnlwAgB9OmMfrAwpjpTGv7Xs0vi7t4Tv6EeLE4Jf8M0UHguPjXpNGVGyghWPSMaLsBe2WcR3rwBH5tSJf+6HnEiITq4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327124; c=relaxed/simple; bh=aLRiik+82B5sq3YU4UIJY/BRKKGgXuEBGHtc33FevpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QbQbZcMd7B0A7A55hgoAT04pMRHFaykiBxhYlekqBtE0i8i/yAtCRqOsLMdMDU9pK49+rlDGndlEqxNhJQmzj6/nkUwJ+9XsekQHZHhbPXxV7GNtNDI7dNiBCuM27JesSqtAec8wR+WTCUMMRNuGqcT2McvFH5Z2ht8v7g5PW6Y= 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=aHWOD9Uv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=03lSaS47; 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="aHWOD9Uv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="03lSaS47" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327120; 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=llMQUR+wwEgcNFKsWw7SwALRhRZ8Hk9MwBUMNVtb2mw=; b=aHWOD9UvZeeU8Ir7Qavbls53FEG2Xe8Gv1/qATtpio2CaQM5AhaNUBpylTtnLd4e5z5i3B HP/18AHWf0FN5MToKXBVSURD//SomAAqYKHnzWsfYGFSA58Zbo13m+Dk/Z6yezFdRxTBDG mNoalLKtcvXr6vKRycAQuaJY5FkU29U4phi4/tqu9jgwSc0aYAN2GOopOPUJT6GbBbceaE RL/NRUfSDZtGLNyQUvf3qiE6BGvhaW0wpOE0Xb46rnxRZjtsGbf4V0c2bWQpKZvUjmxR4+ jBZma0KTgNcHf2OSfxJZEBO606z1g588NXeCsjuL9+duzhcrcuZjowT8eas25Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327120; 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=llMQUR+wwEgcNFKsWw7SwALRhRZ8Hk9MwBUMNVtb2mw=; b=03lSaS47ru0spuAwkaF2+tUNIqOm2UkglqnqHkgXkSl+watQnRd0jZv1xntHJBYnM8rGBe ckU7+LKwwcQXw9CQ== 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 v3 16/28] ARM: module: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:45 +0100 Message-ID: <20250108090457.512198-17-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930354 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 9C72A1F76D7; Wed, 8 Jan 2025 09:05:22 +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=1736327124; cv=none; b=pIIC48rWaFmNTHY1VYrXkfcsEpXcuAxL5T1DXLBbxXP1GQeZRn59sXKYO2mzmHdMKIs54lP+jBh5WitCbP0YhUvPrN+8WQkqG7nVi3GArt+90RbqKeW3K3vSCrwePLDuoT7skzrgsFrksrrHRCBLe34ouOtnpAoiyUEPhGnHgro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327124; c=relaxed/simple; bh=xNkHK5skl0w0C9lJamZwTCTHZMhBReuD0NcedcOei+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mj5POqZflDGbKm4gSILhemyMgtjlHZXM4iipaKSNPFj91yg0hVXzubNVNTAw2+LCAiowphN5a4YjSmY24D+km60TiauhU7EaGh7FgDsBz/6er9/9TPegeedeNyqItFZnVjpKCXHYDc8uNi47/LqUrBvno5S1MJi1QtbKgz0yg9Q= 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=qZGqUNiL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JhnK0Yu4; 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="qZGqUNiL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JhnK0Yu4" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327120; 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=luYbbdZNCAXl/IP2EISod9yvpOfM235A0wCO9dfQi8c=; b=qZGqUNiLevk3ULvmOAgodsKpMRTtpdv6zZ5qUtcVO8ZwmriORfqt+BAiiwnzpFb4pj7wGJ qqIrEs42Lod/4DpYI4l0IL434kVxZV3x+XaZ3TbpdcrNBYRR4lP0VEUHk8ZUzgfPd+3/MO a+FI63LXtZjf0rHQ5aK2L0M0T1UZOb4GeqtD3Y5HvX3pJKhuimEoUeA/AhEZjRj0pYyfL5 +amDJ/rpmcycJ3/zeQNMje5n0Xnql5aGiTx6ld96PiO6RPYSW/AGgTbzc8k2h7yTa2mj4E k9ofqTkV3//mwiIDmmTC20MOYsAaVNPdrp5VNOXL6tRR872cXmzwLhnKHPnm7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327120; 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=luYbbdZNCAXl/IP2EISod9yvpOfM235A0wCO9dfQi8c=; b=JhnK0Yu4bXTsTOoq/2QpxdG2IUFKpBcbjrCKe3W7xFQhlFCjP6V59gChgnIT16k/VUPy28 I8OAkeg4E0fvk/Cw== 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 v3 17/28] arm64: module: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:46 +0100 Message-ID: <20250108090457.512198-18-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930356 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 10F521F76DD; Wed, 8 Jan 2025 09:05:22 +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=1736327125; cv=none; b=ukCjuAOecWO34y1vMY0wsi9429TUoLUiejnCETfQsm/uPx6SOPolKix2oWn7zWSlCvJUIfxA8BbtaOLwrnUCv9T96ZUKQKOSlFFS2DpAvcgEHmGQmYa6tJEEAP2gdYMwFfKfYHAY1eyMntlVK3Uz0phYhsRJ0TWgzqbZt0dBGTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327125; c=relaxed/simple; bh=G5X0+l7fLr+Gr8mHaQ0KTZ50NSlxoDTZjLHVdH7IbPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pCzU5ifWS/kdpAi4WTxyc0GtSKlIVxvq7bpzXC4o4JJPyqxwO3ah58tBZxSb2+EqaJx1p74ByUhEKCessPykaJLWawGY+LhKB5sETFWaKUgZR+HMP2qBixCBA/USJhtbRGSz3h2epV3gvPZhpcSWLoJ6vSiz1l5e6lLGKqJOvEE= 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=YLIfDCbl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OyFhdP9V; 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="YLIfDCbl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OyFhdP9V" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327121; 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=7OHg3jZyf02ebMcCYNUEnflayAq9sYcMtyqzXVGGUlQ=; b=YLIfDCbletV3pU0iX98tJQKNzlx+X4ose1G+gNKVvj24SEtro3XGjJyTFaRselJaoZA/fO VtmraRUjNG8cgxJo4K71Ck4A0aoI0oeMR7XGJqr4Y5bnMph4HDjH3JLYxkWFmO7AyRvuOS qZZownHU37PMX+Xu5ffXuB2nIle8LTTt45sDubSBnJpi2T2pIt4tWkqzHh/SxPRFKeVvYy O+jsLLCuHBB7aQXTCO6BGjCf5FX4BEOvC3ByYebdgfIENxl+CM6x7ZVcin1NIi2BcZmVjA 9JCA9nCUB1xDSXz1FWJVSqXUtq2z61jmeIYZvWTE5+3RDQzZAhPkkBhO37AxGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327121; 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=7OHg3jZyf02ebMcCYNUEnflayAq9sYcMtyqzXVGGUlQ=; b=OyFhdP9VaOnPKru4VN6IQKpFbHpWH58pMLlhK1zp71dWnqHZrF9vLu365AZOsLjpXBrMGZ 6EkUlkgrqqIcxXCw== 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 v3 18/28] LoongArch/orc: Use RCU in all users of __module_address(). Date: Wed, 8 Jan 2025 10:04:47 +0100 Message-ID: <20250108090457.512198-19-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930357 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 730D01F8900; Wed, 8 Jan 2025 09:05:23 +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=1736327125; cv=none; b=BfCV/+1vj/5O2IFUQ7S0SKYt5xHXC/cJPwC8zFFzKrzMGYAh54z0yZw08LiVIr+Rpcp4XEQtEsBHyYwbuTge3fC4IBu8Y278+GQZ2e5L18RRQrnbJr7aQeD7k8HxrFIMR0nMOLm/7fDwlaWeaMcCTQR7ZddBjCKVrKtdv6lyR1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327125; c=relaxed/simple; bh=JMLSIq4XCqh7X46oF8dvRjupa8G10AN+Bi4dbH6ayzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GljypC4TMdKHbQUTy+Ymfk1eWANd3ShyWh8TYQFMPojM1h/uB7i/a5nizrvj+rZDz+xNV6x0TunaOIDv6Ho+y7KP7sN1CF3aumtxra0DIeUk88UXRLH84g8q2nzQg2bDFg/WaDROYQryErDbOfNPCJ4mAurOyNk4w+IYEqX6wII= 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=Zeq82ZZt; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=o9rVqG6g; 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="Zeq82ZZt"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="o9rVqG6g" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327121; 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=dKkEa1oBjIwyFreZFvtbWG1WNxqNuZKzuLQp9IQamCY=; b=Zeq82ZZtfycF+dEkhvnQG4m5Gm/Dg336iRPpNCa0jIIynUDK44CLaWcEHM91iLvvyVeDwf NRZdcAl0pca++p4iXsTy1ATeNGWQ0/ttOEarFzUqIaQLSXgLGkLjRtrObC8AUsP16pSHl4 A93Z/xemaCJmcGKVUSTlDyAxp1RGB7VdiBSnn73ZwFXLJl+ggc+UB38zEeybmelfsR82Oh lBe0gsu3NkVEDGFh4ak12MI1+L1bJg2JybDwqVktkHEJnrLbMEebPLUZRv7A1tv5z9QURT rDyhVxLNQiChLewieqy0QvpLZv1OhExoOvlkAfkAIZqeAI6F196664v7KmzUdA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327121; 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=dKkEa1oBjIwyFreZFvtbWG1WNxqNuZKzuLQp9IQamCY=; b=o9rVqG6g7PSN1elXM/7opz1M1ZZG8+lypfGps76VIls8huRnp2KWGJw/AyhZ6XhIyzGHkr 7w4eXU89djJIcTAg== 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 v3 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:48 +0100 Message-ID: <20250108090457.512198-20-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) Signed-off-by: Sebastian Andrzej Siewior --- arch/loongarch/kernel/ftrace_dyn.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c index 18056229e22e4..5b7b8ac13e350 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(); - mod = __module_text_address(pc); - preempt_enable(); + scoped_guard(rcu) + mod = __module_text_address(pc); } if (WARN_ON(!mod)) From patchwork Wed Jan 8 09:04:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930358 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 B6B121F8924; Wed, 8 Jan 2025 09:05:23 +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=1736327126; cv=none; b=Una/u4/wkoQ5IlhP4eFl9bhu8do5aDb5y3MelpiRxbS7IMXgPrcP9E1vios2tN7/Y77xU8cKBm/UUUDHOl1mKx3tUskDhQ/e2kpsoPXRiIAsOpIZAsvRChGNIdUEG2d0jNjvh69GpfBvsCGJ4xXZoGTzZVb8uVc9BgxTXW6fBS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327126; c=relaxed/simple; bh=QLtectwvLpXIdURiO0vN4A+c/rzqgAPwxEpJeUhAO7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EklHxS1vUdjh1goZQQbjoamthwrsaPyU26yr9Jm2uUFi3haQQPeggnHZuAhdIA6Uag8drmXUvHe+mMajDBdbdzOc131r2LCTFmWb9iSEIEwy0uSToRPj6AVE3PnIgXRwKVw2/3smSQ0j/mztzS7+AqZNPWUp85+ObIMRQ02uz1s= 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=LEApxjYZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dKYJumFF; 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="LEApxjYZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dKYJumFF" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327122; 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=rwBYB6GDGtwSo0ZVmHQeUUNLy015tLjU3w/e5JgGy/c=; b=LEApxjYZTkhUm30+CjLuvcHX5E2bkNJXnvyUNg8o7S/Fx61HuGetUOphWXxK7KkRlZqXpf HIajKikSPhM8iYZN10EyVeaIzc72/iuTnHo0mHHluGSqAyHpEEYIRDomEhG9ucd0bA5QNe mRPhhSVD5Mw3kKlEi3iLDkgTEd9R0q6Yh3r6PhO3zt9soyTkYfj7cbuQJvgsCtqdXTTnlw ziHMU5S1znSAkYMIhcFJfJmVQN6bapUF4Om3FT+TXqop0bh27OgxrqxKTt84hR6nd7BVvF tLQEVolIS16851bhceciMfsJOItqvtrr+VnjFSLqFCRl5W7HJYyANETR5/2Arw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327122; 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=rwBYB6GDGtwSo0ZVmHQeUUNLy015tLjU3w/e5JgGy/c=; b=dKYJumFF1zyEaO2G91SGXq3IYr7DTmPO/R3ooBrOdSFGUIexbJ7PDdRkr4PzJr+nPMoUvE ybGJf41RElFb2sDA== 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 v3 20/28] powerpc/ftrace: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:49 +0100 Message-ID: <20250108090457.512198-21-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930359 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 6F0F31F8ADA; Wed, 8 Jan 2025 09:05:24 +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=1736327126; cv=none; b=nCHt0tLNcYkFHAoxnkdwBlzFteV1IHIRLzz7V7t6iOIV9ru2PPOF7Oujhb/CPml7JRkXjL6ax12GvFQ8lV8SudgRcDOkpBjsKWFFwYFMqtdXv+y4OCBUjvhvvko/y/qy0Grj8SNG9B3YQiauz+pxoS92KfR6R50cd6J5E78mPWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327126; c=relaxed/simple; bh=oLOdODeMcawG2LLLnTFfjNKMo+cYM0/7nhosikokPXo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TLkQ3rXnieHCIaIfUozA5f9eZ9tYSa98tQSuNTDMBvxkLd+8pS7ymvgZy15zmZZNAN4bSVqNotdsDWVGaB1BnDIgpdhXJvr6KFSWAtPwyHM2k8qF2A1llLwmEwsfH/CGy09aXtwAFq+hBdDCSY0dsx0PZLdtVSrs+n72CA1SEuc= 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=T4jBf+7C; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qztIvoOg; 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="T4jBf+7C"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qztIvoOg" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327122; 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=THX2NyChGogo3Kth4sMAsXNutUP9P3pw+jNEWRR9NrU=; b=T4jBf+7CrkH3J1Rd1UOzoEpqLYVQpHHS1gwCmJhR46N2jWCrkBdSbK7by7qWjt0YGhV4MM 951PWXsNhK6EO8n/pa8ueI7le6PkxGkJ2RrULoy+bbv5xqc0QySLey5R1LMS8uO2dYInBF n6ixMKw2Ugku/bh7U6OvGM0wLNjYYqRSW7GaxM9F1qzQeiIGSDYuXrGaL2wkdp798LBQCg 1uh7RkcxM7Evd7fl5k8szTkBrJ1sfYAprSyzSjYE1a+LmKGakMww09QwrcHKG0TKSAoXdw Eg/B2/jggwfOhWCV7S/+QqwCSlxOOD3EIGbN5XwyLj/oh+22sYTpWzVy/7i2Rg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327122; 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=THX2NyChGogo3Kth4sMAsXNutUP9P3pw+jNEWRR9NrU=; b=qztIvoOg4O/H0Tj/WlT2tQcGX0BI8x6o+7eiQXnGVnKGsifQNL2002sAHg44Vtvak+SAe6 9pN1x0mwDCZt1gDw== 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, Elliot Berman Subject: [PATCH v3 21/28] cfi: Use RCU while invoking __module_address(). Date: Wed, 8 Jan 2025 10:04:50 +0100 Message-ID: <20250108090457.512198-22-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. The _notrace() variant was introduced in commit 14c4c8e41511a ("cfi: Use rcu_read_{un}lock_sched_notrace"). The recursive case where __cfi_slowpath_diag() could end up calling itself is no longer present, as all that logic is gone since commit 89245600941e ("cfi: Switch to -fsanitize=kcfi"). Sami Tolvanen said that KCFI checks don't perform function calls. Elliot Berman verified it with | modprobe -a dummy_stm stm_ftrace stm_p_basic | mkdir -p /sys/kernel/config/stp-policy/dummy_stm.0.my-policy/default | echo function > /sys/kernel/tracing/current_tracer | echo 1 > /sys/kernel/tracing/tracing_on | echo dummy_stm.0 > /sys/class/stm_source/ftrace/stm_source_link Replace the rcu_read_lock_sched_notrace() section around __module_address() with RCU. Cc: Elliot Berman Cc: Kees Cook Cc: Nathan Chancellor Cc: Sami Tolvanen Cc: Steven Rostedt Cc: llvm@lists.linux.dev Tested-by: Elliot Berman # sm8650-qrd Link: https://lore.kernel.org/all/20241230185812429-0800.eberman@hu-eberman-lv.qualcomm.com Acked-by: Peter Zijlstra (Intel) Signed-off-by: Sebastian Andrzej Siewior --- kernel/cfi.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/cfi.c b/kernel/cfi.c index 08caad7767176..abcd4d1f98eab 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -71,14 +71,11 @@ static bool is_module_cfi_trap(unsigned long addr) struct module *mod; bool found = false; - rcu_read_lock_sched_notrace(); - + guard(rcu)(); mod = __module_address(addr); if (mod) found = is_trap(addr, mod->kcfi_traps, mod->kcfi_traps_end); - rcu_read_unlock_sched_notrace(); - return found; } #else /* CONFIG_MODULES */ From patchwork Wed Jan 8 09:04:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930361 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 8664E1F8ADE; Wed, 8 Jan 2025 09:05:24 +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=1736327127; cv=none; b=Q0Oya7k58rogaxur9A4jiObrmassvgAjJ8HdyGVSEHmb15KJEe355dEdQRHJ8Wpn01v2Gwxtawa03Aksm5gVLr3VrXmqLixOCoxHEym2Kzp+y2s8x1EBEvWf+8h+qc4zlLPIG5lrj6Bgd7afGKN9PhGTbPW91MAoL7uJtL1smlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327127; c=relaxed/simple; bh=P8cpM73cMdV4X9RLYh8MiEJZf1KAJJ/PkpaW8qvgJ5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vq7642nvcqqlcwl2wxKvbnIqtJvNgGBFYZp9kNptYqcrJdrU54fyLEw99PNbUIEQ+Ire0BIpU4J9T0tqf4iK1uZMACIvoqRYwo7ZnqoEQehYL/tfMZwscKEcFDdzEPWJxvKYN+7DEc7BInqjmwhSMa/cY+p93zZPqvY+Uu44OTI= 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=Smh3V6vU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TCMkjn4t; 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="Smh3V6vU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TCMkjn4t" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327122; 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=lprawi1Wy0blHcfKhZWeO6Nu25/xNNrs6hneQ3+r2fM=; b=Smh3V6vUWgb2Z4rtmOumtw4pf4+Q8qg1bz9YNY0OiT+E18yri12DCO8BBIxHyHnJpE7v+X Di+T3/WzvbjkM2l+qI2eAJa9oZIpTKOnvPpJe8lEYBbgR7IdnNHw3sw9W7K/x7tFxcNViz dKCfJo1BSccUD7iBuLEimuoyE3tMnJ89rKhKuPQJur5YnS/3vzXT54RZYqc+hkhqz6uO2Z 82Z0wJxBip8UNC+8UT1+mi3TeE9Jf4TA8SRVK0ksIemdsPMsVBKMeiPWmxPjTWPZlJlZRI SmLl4LeV9/nAOU6FQ4EvRU454tl0oTAZa3k4hWVaVZ+ZIDCSa9m8YB7eB+bOnQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327122; 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=lprawi1Wy0blHcfKhZWeO6Nu25/xNNrs6hneQ3+r2fM=; b=TCMkjn4tKyPMEXkg2pCiQnC3MTbFdMMSSH7u+iWfE3/HoOmxq+yZeEhfMffFdLoGQYQtX1 sV/EQOg0G+BujpBA== 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 v3 22/28] x86: Use RCU in all users of __module_address(). Date: Wed, 8 Jan 2025 10:04:51 +0100 Message-ID: <20250108090457.512198-23-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 f17d166078823..276b5368ff6b0 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 Wed Jan 8 09:04:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930360 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 AF0C51F8AE6; Wed, 8 Jan 2025 09:05:24 +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=1736327127; cv=none; b=temFjwtBaO9qA9Bh3KCguEi3E0OAQ67l3Kw98ERaBT8RhJhmyXbxQirBCai+MSnVjfA3AAud8rL1yGC4+grETbEzlPaYFI5AEPW802nFru1f8ip8x1ALFAJNENdKSNEcjJ+PWesYtHUrlrl5KbhTNDAfTbEk3F9YpXo+5ipJ1aU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327127; c=relaxed/simple; bh=dnHZYtRQRqUncQkV4yyJr8LboGs1uhLkzkoM41kcf0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MbsMDfLwtaxqmL9YBc9s2OAnYaYqTDGzoOiGmj7vwNqmCAoN22TmA1R7u95q8Rzl+MTaDI+vavBsZWc5lBJEg/ycjQFDmu1WThrCPh58M7A2Uh4Vtr8C1rejTaLJ3Kgui9iuzyEQ3m321qaiQ1cBrI0QPwQM0mw2BCgnsmwGtrA= 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=KEX+o1uS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kNF4ExyG; 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="KEX+o1uS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kNF4ExyG" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327123; 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=Hfagbwpj3df9q7ePOIyVBofNwKk4yX9AX2H1Tk2ZCkc=; b=KEX+o1uSt4ezKkiXlbcixjyMcaXTOpYuLKGxDN98o0SAs1N+ARvBDeILqSXQUEKvwExik/ /KCrHsVYKJV3GmxhPrduLM0WBFY54PNWPzCGD8Fp+0BHO3Cmkp+jFLvqi0vfzu8qvXj6it Ju4cnNC/Iim0sGfzVJOy/U8DaD2ryM/KiKwWOKdHY4hHGO9BcT7PWXiQF05RxLTt8UNeMc uPfXdCKiZukWbi0Y3DqytAlzE8SsMLldTOcvuybJyYJnWpZgDV062bwE2/aDM2PpAAaA64 mGqQ63F2hzit/ejryZ6h8mkvp13xpvwuoezi8fkgNAc6ve5HjVcig9i+cnhhUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327123; 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=Hfagbwpj3df9q7ePOIyVBofNwKk4yX9AX2H1Tk2ZCkc=; b=kNF4ExyGCnG/OhL7DX/Q6MpdEqr370zPqck+Xth++7nVaGZ+I9vRJrZDYPGIP8jcHhYdRH a1YNiqpuT4uzzZBw== 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 v3 23/28] jump_label: Use RCU in all users of __module_address(). Date: Wed, 8 Jan 2025 10:04:52 +0100 Message-ID: <20250108090457.512198-24-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930365 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 4E67C1F8EFA; Wed, 8 Jan 2025 09:05:25 +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=1736327129; cv=none; b=CtqWBtCrwgO0T4teHcSzsTyCpStCWWxQyVkNZLbCvQgW3nliMW/awqMNECDQK1yCMpwKGXtc7EOMV50gnUZ2i+lTftOZlMk7+GQn/+6Bu2dCG8TJu93T5UNTC4qMMu4ISH/umPjq3RU0dK7IQz8ETBoRdI69tvk1cR2HvzqmM8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327129; c=relaxed/simple; bh=iKbdR1j0aT1R0yqWNU9KhIuS/PlEZVL2OGX+RnZA0c4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tk2ONIpjdPK4DE4thZnTxbbfJ6QQwZl754nSAq14YNvGw1W25E6/esngjQdMOmyaeZiXaSuWWYchXNhp/u8Mw2ExXuU//y8VD9V/injEOopRASFMuqrMK7HxHTaOmP/xit4Cqix2MkaY0F09UvH8Y6U7089Y6Ja0d4IPjEsrBLA= 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=GQWXV0J6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=O3OxtACM; 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="GQWXV0J6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="O3OxtACM" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327123; 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=6DHZsBE2j+R28AiO1hj+mYuIqcl/xch2HSM3caLWC0A=; b=GQWXV0J6l05koDcl1JxGmNYe0jpNk5jswVeHUbna3hBBAlLaa+XqPI6KcElYHAnDdnAwEh p99l5nYzob3nsAciL/di46L7pJJxzs1akBf5NyK0K+IZOv6Qzb26nSSb1OXXcZAlwXWR0q Nabq4gKwgHlzWAoXZamE0RuEIhZgHeE4uU/vU4J6GbGTrVJthvAPqcJDuWdqZ56QQSmVGF AUU+78nhkg87W8t0/42UxVVMH644XsJZr8wuQ2BupgtIlpDEJ3deeBM2M3uLLojw40G+PX bscUr6ciY7wH3YS+Lk+QWditFk27817EqBFCKZFANo4omYQVYLqre1CNz/H3Mw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327123; 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=6DHZsBE2j+R28AiO1hj+mYuIqcl/xch2HSM3caLWC0A=; b=O3OxtACMlaGcqbdSTLxi90qIr9EB39NUIgOmqjCGHTRioyVg8lJRlhn/rs2FQMpnDDo336 Osxz7tT8Dor1cjBw== 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 v3 24/28] jump_label: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:53 +0100 Message-ID: <20250108090457.512198-25-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930362 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 307761F9420; Wed, 8 Jan 2025 09:05:26 +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=1736327128; cv=none; b=gtO8456BIoKB8MfFGnXFgh/MD8pifedZY0NvLjdYPrwYs/WIPnYK4FJPi5+jXNaAW5WTV+ViM9KnFrXBBL3/d8oyEOZp4XMVnpjoCwrkoYBM8c1U35N1LaxztsAnQ25MCUwZQUWY/PKxxE7HOPUML3y5GJHu4vfS9kSrg/I/b5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327128; c=relaxed/simple; bh=Rfno/WDBaQo6Megi5n9CLWuW+Sf5W7R4mY0Et7Ub/lI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WMYzjwuoNmJyU+XpLsWNpZx3IEhLvlOWTFKZBHJ37ZjreyakRmIM44cduHc2r3cty5PSKzvwgvxzKBzQ4J70wZP46KxEUb9WXBtII66UfeFR7pJgY94yy+TAVwzCqLBJN7SuxhLl+CBRV8nC3tJ0vh+n1hyrZP2+nXx1qc+GDcM= 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=OlQxyPTc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Pi0E5pkC; 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="OlQxyPTc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Pi0E5pkC" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327124; 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=aWZxQxOJaEGd9SElXjI4Z9tZyIiipQdtqCaCraspLAk=; b=OlQxyPTc4KXCBeZGT3TJa+bbkReub6yPnM2lqBeJYit76X+ZTMq2yA0QoY08+401skoxFX dYJ40n67dA+bywAEOToIEQlia/tRRCRY8AbYUF7kOK5dgWaih7fk9FejvNIjyGgDX/rkYS fZCnagS96iMzk5UG0V+o/n5m7OGktAptW2Uhze9UoCeKXif7Csjsohks9L1nt6Zi0Bi0uR Skw19b5vmyf7Fk/A6MPJM4Zs4OpVPjdt5+xI+/8/7gh5esgz0OslIDcPrgbTRWeDurLemF O9SxQ7WM65wZHD2m54kgPfWgHyupWGbr3mY+3/23khr8bWuCp8a6bkqx2y7Y9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327124; 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=aWZxQxOJaEGd9SElXjI4Z9tZyIiipQdtqCaCraspLAk=; b=Pi0E5pkCHo/POaYqtA2D8zPpOtGjm4FDBWb3u3Jd9uYvwb5+wePI0na9fXkwzIO4roKQ81 vwjUMv0cYkSEvMDg== 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 v3 25/28] bpf: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:54 +0100 Message-ID: <20250108090457.512198-26-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) Signed-off-by: Sebastian Andrzej Siewior Acked-by: Alexei Starovoitov --- 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 Wed Jan 8 09:04:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930364 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 DA87E1F9F64; Wed, 8 Jan 2025 09:05:26 +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=1736327129; cv=none; b=nSDexZm1ANaz3f9MqqPBXdvoTlysxhCGD2gIns59sqaFjNPE3hxHnvypWwuS/xifV3kJqIyGngqhTKOnO0l1FxUscZ76xtXVaCQ6OAEmE+tW6OOAXfnEQJYs3bfknig7xgsh+dtOh5l+xohxTLrU7WDNPOu78wSfWTV5X4uOr9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327129; c=relaxed/simple; bh=zhuCTsrhq1sNrdJmokFlAoIEp1UlB8V4GeZJTffN1ts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BUC8DgVu/KapgBzlnnR02PNx7VM27+OZQ1AYJUn/mUm53Tv2E82pnqKlPNInSs3gkaEG1rFzZJ3IuoJNhTZcuyXVWFWzYisZU7wL5uljj3S+nRHCbWVZg/EVkHAW4FZKKtZD2CKFu/YKRXWLCjp3PIhDQo+TWVcBBzYQ+GySUoY= 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=kZCak5YE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cN/CNFCB; 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="kZCak5YE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cN/CNFCB" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327124; 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=VX0vljVHwWLPf6RRFuZ5ON1QvJx256zYGCAz24C+oI8=; b=kZCak5YES3w/CPS981gos2Cz1VvOvyEDTa+/ua2GkecyY2LbWcSr52H9Q3Vo3eDRBkgO2F 7qRqZn9GBRZOXpBIeikBTqwBhbEYqYw+OQ/Wb5JW8wbpwZfgfRX8y7wSOXIkJNqmfEZAaB 2zdBrO7hM7PuXbRg49MKpyWjJLYEmx0IRbM9R6D9LKfMaWfmYvtXFNeMWpSvzyV6rFlVTR 0pvLewAQZN0GcNJsZQ42vnwYQNMT2b93+IjaDepIVo050iVG1uR/kN2JOjqNEJ2ukjH091 6DC8fhtjbqnwcQhWI2WQOiz8kKGNheNdOA+x4O3mRu8nOgqkfZpIGjZkuGQmrQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327124; 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=VX0vljVHwWLPf6RRFuZ5ON1QvJx256zYGCAz24C+oI8=; b=cN/CNFCBJOLmcq/uSXT6xcI9WzcQe8fkL1ve5n6I/VoNQPGKWOJpjQcPHxg0GJIaJxbT+M Jg4LK4/ad0fzs0Dw== 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 v3 26/28] kprobes: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:55 +0100 Message-ID: <20250108090457.512198-27-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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 Wed Jan 8 09:04:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930363 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 C3E461F9F4B; Wed, 8 Jan 2025 09:05:26 +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=1736327128; cv=none; b=in7H8NqhYWQRFO1VsM7PVbFAD5ao7fs0Lq4a6r95eIt8UwbttxiUqscFMgP8Ub6PMgujkxeeP9UxS7vqF4QlvMzHny/lSUo99TDFrVfyE2DTB/gVemVOD+b5mI+w0qcYn69hH7kgLPL/WsKP11K2nP4aQEGUPQsmFKfSyyeFUeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327128; c=relaxed/simple; bh=SWUj/yhWok0jltP13k4QR36kJUgakop4QNztiZCnCiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XO2UBkqQI/sDlOHegamRghSwI8wr53uEBnlX/ecvDJTwoo/EwIoeiD4tB6wN0o3OWXfVZJV8zud5opXd72Jqgqsin7ge51E6Pt32R3Y/Dxo78z+1oy23UQ5UCS0snASeXN1XZN0DpvkCoE7fZkyE00JFkAoxgr+1MJ8CVz61PGw= 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=l6Xaa3Zk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EH4h1WB8; 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="l6Xaa3Zk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EH4h1WB8" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327125; 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=sk+WapeZw3AyhQlyz/y1GT+qnQ8et4haJZXe3SpiSPM=; b=l6Xaa3ZkuhLoLRb3L6QHEEtslE0cbJtrTLx++mukG7hdl/wlrUasaWxUbqZRljO/bEkIk5 7E44spQtMQ7BO8CzrWoqNY7R8LFlA/eLrFVt/3ExR1wz/dnF8ypsZRaiSDy5ppKflGeK+f dM3O2ocYj3/0lvoNC2bFfPRa/X37RVFGyn9JR/aejP+YCSAE8vIp8zmpDbpUoggR88OsBa ZG5/2zfFPMQL9IqBggckIU8tDzEigNP7khCkJ3k3K7O5O3/pZ/O0uw0XGDbAHp6WnDbHb0 hcFHw3NP2Xf/DGjO60ymRk4ptJ/LaiK3aemUk+SWzmtuVvyvZ4mKuKC5eI4M6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327125; 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=sk+WapeZw3AyhQlyz/y1GT+qnQ8et4haJZXe3SpiSPM=; b=EH4h1WB8+5vUrKERLEa4IhKQK955bSJDwtWd0t1bpuUqaDt4xU7l+k19U0ExI84Kgc5KPX zl5TqptJCoav67DQ== 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 v3 27/28] static_call: Use RCU in all users of __module_text_address(). Date: Wed, 8 Jan 2025 10:04:56 +0100 Message-ID: <20250108090457.512198-28-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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. Acked-by: Peter Zijlstra (Intel) 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 bb7d066a7c397..c2c59e6ef35d0 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 Wed Jan 8 09:04:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Sewior X-Patchwork-Id: 13930366 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 922CE1FA8E0; Wed, 8 Jan 2025 09:05:27 +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=1736327132; cv=none; b=ESAOr4E5eudUptLafAIY0a4pZDK9fFG0KdthqS+xIWxdY1IXWLQRj4LwSu39hRnx1T15WOUX5teRHHi50OYE/IGcd2+i1O6MnEvbibwGdIB6Vbg/NYbJdZAodW9q/CSESt4Y87EX7mwXxYFPi5J6Y8q9N1ecLb/MU/azFfv8Z44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736327132; c=relaxed/simple; bh=yb3mAfmVt1ym08Th8qD0bMdwyMmjhVwma+uBB5OZTMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N6UYkUFmVBXmb1Vpx9dXgCFUvvUE6VRfDIybQ7ueHzQFkOBi1Z/KeOFwebZAt71cSF8SaBUYCBi5HPfbn/JX+e1L0a7G+KoxikZxvR3dV0Twc4dBrGPyZ68GO3FYL7iU6mFVdXssoa9RK0ObjYuwzHr+PtIEs9vZF+/UsozfZlk= 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=EWuPgHkE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LwlX8T/q; 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="EWuPgHkE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LwlX8T/q" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736327125; 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=a9XnkkLLzmldxKAiZSOAAcLDr6gIVFvwHETvbCBha7k=; b=EWuPgHkE/wfR/74Pgd6Psf84g+9QOJANh7FieE9X6rdnxnILCuA3/4FJqDT9XZserXTDEW x/i7x8vabyoJv3szBlm8qqI1TUIuV5G4qtlcpnRk5Hft3x2O0zBZDshHZOSgV5E5TfHVfA FjJ/yIDSHwUf2e9rD/nMEeIRpVtlvqZYyAgQBWYQKKZntaWrSkVKty3tHnj2cIsnPr2GIH PT5INk63a34LNMVvXbNSLgqAqqD6o/LOPuFqqSMpO6JMj5ktb/Hp94QeAJddVmIXAmv7ez kvQeZX0CaRmKHnJ5fmhROnJbKRyhhGzIAJpyaDhDSD+ASqZbYYGUIYw/S8bQyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736327125; 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=a9XnkkLLzmldxKAiZSOAAcLDr6gIVFvwHETvbCBha7k=; b=LwlX8T/qNESEGTPLAofvaGNYw0U5DyLl9ErT9p48z8cobSLz20N47NKD/oBsguoiB0A7r1 pu6dPNdShJBQbvBw== 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 v3 28/28] bug: Use RCU instead RCU-sched to protect module_bug_list. Date: Wed, 8 Jan 2025 10:04:57 +0100 Message-ID: <20250108090457.512198-29-bigeasy@linutronix.de> In-Reply-To: <20250108090457.512198-1-bigeasy@linutronix.de> References: <20250108090457.512198-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 Acked-by: Peter Zijlstra (Intel) 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);