From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E2AAC433E0 for ; Thu, 21 Jan 2021 20:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 638AD23A54 for ; Thu, 21 Jan 2021 20:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727153AbhAUUWd (ORCPT ); Thu, 21 Jan 2021 15:22:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727217AbhAUHyj (ORCPT ); Thu, 21 Jan 2021 02:54:39 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD727C061757; Wed, 20 Jan 2021 23:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=CBn0nIvzF4lsJIlmcNwvI6PwAlNBtY57zO+JFTdIDBA=; b=wILKHrE7zJ5ukZC9RHuI0Uk3fe EiDCI/52xf99CaCWMXlzY0E74cAz6IXo4v2Mu6qm6hpykxhDEoPz4TqKYKZxGxXpznewjH7NJXIhm 3wwDBW9PxX/8Ls3odBp8+swR/7BGL44uzxP4UCWiIBU1t0Gniwi5nL/pVazEPwP3ucRVGnz8LH3JS aRn0VX7Ip3Hx9YvdI1cdwznnGnyhpjrLbdLbHLOnDc49Eu3Mc+6a4xIuxYiCHUjyxDVBBBE+HRSZD MI38XZRZXTIz9bbpTPfhcUyG6pEQ08XubgPMvqPcgIgikuuTk5lY4R3EhePGY35H1ubDwdprJFg10 D6cBk3ag==; Received: from [2001:4bb8:188:1954:d5b3:2657:287:e45f] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1l2UmN-00Gm5Z-VJ; Thu, 21 Jan 2021 07:53:25 +0000 From: Christoph Hellwig To: Frederic Barrat , Andrew Donnellan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jessica Yu , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence Cc: Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, dri-devel@lists.freedesktop.org, live-patching@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH 02/13] module: add a module_loaded helper Date: Thu, 21 Jan 2021 08:49:48 +0100 Message-Id: <20210121074959.313333-3-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210121074959.313333-1-hch@lst.de> References: <20210121074959.313333-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper that takes modules_mutex and uses find_module to check if a given module is loaded. This provides a better abstraction for the two callers, and allows to unexport modules_mutex and find_module. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/drm_fb_helper.c | 7 +------ include/linux/module.h | 3 +++ kernel/module.c | 14 ++++++++++++-- kernel/trace/trace_kprobe.c | 4 +--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 4b81195106875d..ce6d63ca75c32a 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -2508,13 +2508,8 @@ int __init drm_fb_helper_modinit(void) { #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT) const char name[] = "fbcon"; - struct module *fbcon; - mutex_lock(&module_mutex); - fbcon = find_module(name); - mutex_unlock(&module_mutex); - - if (!fbcon) + if (!module_loaded(name)) request_module_nowait(name); #endif return 0; diff --git a/include/linux/module.h b/include/linux/module.h index 7a0bcb5b1ffccd..b4654f8a408134 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -589,6 +589,9 @@ static inline bool within_module(unsigned long addr, const struct module *mod) /* Search for module by name: must hold module_mutex. */ struct module *find_module(const char *name); +/* Check if a module is loaded. */ +bool module_loaded(const char *name); + struct symsearch { const struct kernel_symbol *start, *stop; const s32 *crcs; diff --git a/kernel/module.c b/kernel/module.c index 4bf30e4b3eaaa1..619ea682e64cd1 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -88,7 +88,6 @@ * (delete and add uses RCU list operations). */ DEFINE_MUTEX(module_mutex); -EXPORT_SYMBOL_GPL(module_mutex); static LIST_HEAD(modules); /* Work queue for freeing init sections in success case */ @@ -672,7 +671,18 @@ struct module *find_module(const char *name) module_assert_mutex(); return find_module_all(name, strlen(name), false); } -EXPORT_SYMBOL_GPL(find_module); + +bool module_loaded(const char *name) +{ + bool ret; + + mutex_lock(&module_mutex); + ret = !!find_module(name); + mutex_unlock(&module_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(module_loaded); #ifdef CONFIG_SMP diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index e6fba1798771b4..c2e453f88bce70 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -124,9 +124,7 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) if (!p) return true; *p = '\0'; - mutex_lock(&module_mutex); - ret = !!find_module(tk->symbol); - mutex_unlock(&module_mutex); + ret = module_loaded(tk->symbol); *p = ':'; return ret; -- 2.29.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47F22C433E0 for ; Thu, 21 Jan 2021 07:59:51 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 70870238E2 for ; Thu, 21 Jan 2021 07:59:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70870238E2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DLvtq65rCzDqnF for ; Thu, 21 Jan 2021 18:59:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=casper.srs.infradead.org (client-ip=2001:8b0:10b:1236::1; helo=casper.infradead.org; envelope-from=batv+5b2bf2cc950c4867fd89+6360+infradead.org+hch@casper.srs.infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=wILKHrE7; dkim-atps=neutral Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4DLvm4550JzDqvR for ; Thu, 21 Jan 2021 18:53:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=CBn0nIvzF4lsJIlmcNwvI6PwAlNBtY57zO+JFTdIDBA=; b=wILKHrE7zJ5ukZC9RHuI0Uk3fe EiDCI/52xf99CaCWMXlzY0E74cAz6IXo4v2Mu6qm6hpykxhDEoPz4TqKYKZxGxXpznewjH7NJXIhm 3wwDBW9PxX/8Ls3odBp8+swR/7BGL44uzxP4UCWiIBU1t0Gniwi5nL/pVazEPwP3ucRVGnz8LH3JS aRn0VX7Ip3Hx9YvdI1cdwznnGnyhpjrLbdLbHLOnDc49Eu3Mc+6a4xIuxYiCHUjyxDVBBBE+HRSZD MI38XZRZXTIz9bbpTPfhcUyG6pEQ08XubgPMvqPcgIgikuuTk5lY4R3EhePGY35H1ubDwdprJFg10 D6cBk3ag==; Received: from [2001:4bb8:188:1954:d5b3:2657:287:e45f] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1l2UmN-00Gm5Z-VJ; Thu, 21 Jan 2021 07:53:25 +0000 From: Christoph Hellwig To: Frederic Barrat , Andrew Donnellan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jessica Yu , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence Subject: [PATCH 02/13] module: add a module_loaded helper Date: Thu, 21 Jan 2021 08:49:48 +0100 Message-Id: <20210121074959.313333-3-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210121074959.313333-1-hch@lst.de> References: <20210121074959.313333-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Marek , linux-kbuild@vger.kernel.org, Masahiro Yamada , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, live-patching@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add a helper that takes modules_mutex and uses find_module to check if a given module is loaded. This provides a better abstraction for the two callers, and allows to unexport modules_mutex and find_module. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/drm_fb_helper.c | 7 +------ include/linux/module.h | 3 +++ kernel/module.c | 14 ++++++++++++-- kernel/trace/trace_kprobe.c | 4 +--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 4b81195106875d..ce6d63ca75c32a 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -2508,13 +2508,8 @@ int __init drm_fb_helper_modinit(void) { #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT) const char name[] = "fbcon"; - struct module *fbcon; - mutex_lock(&module_mutex); - fbcon = find_module(name); - mutex_unlock(&module_mutex); - - if (!fbcon) + if (!module_loaded(name)) request_module_nowait(name); #endif return 0; diff --git a/include/linux/module.h b/include/linux/module.h index 7a0bcb5b1ffccd..b4654f8a408134 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -589,6 +589,9 @@ static inline bool within_module(unsigned long addr, const struct module *mod) /* Search for module by name: must hold module_mutex. */ struct module *find_module(const char *name); +/* Check if a module is loaded. */ +bool module_loaded(const char *name); + struct symsearch { const struct kernel_symbol *start, *stop; const s32 *crcs; diff --git a/kernel/module.c b/kernel/module.c index 4bf30e4b3eaaa1..619ea682e64cd1 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -88,7 +88,6 @@ * (delete and add uses RCU list operations). */ DEFINE_MUTEX(module_mutex); -EXPORT_SYMBOL_GPL(module_mutex); static LIST_HEAD(modules); /* Work queue for freeing init sections in success case */ @@ -672,7 +671,18 @@ struct module *find_module(const char *name) module_assert_mutex(); return find_module_all(name, strlen(name), false); } -EXPORT_SYMBOL_GPL(find_module); + +bool module_loaded(const char *name) +{ + bool ret; + + mutex_lock(&module_mutex); + ret = !!find_module(name); + mutex_unlock(&module_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(module_loaded); #ifdef CONFIG_SMP diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index e6fba1798771b4..c2e453f88bce70 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -124,9 +124,7 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) if (!p) return true; *p = '\0'; - mutex_lock(&module_mutex); - ret = !!find_module(tk->symbol); - mutex_unlock(&module_mutex); + ret = module_loaded(tk->symbol); *p = ':'; return ret; -- 2.29.2