Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3622742iob; Mon, 2 May 2022 00:58:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz13T0t4f/kOE45JwpbdfKm6HZcQ5i4IO+KiAX48zi66wLYRDXuVA8xKf+MeCsGFj1JN4aF X-Received: by 2002:a05:651c:19a8:b0:24f:4ff5:3a85 with SMTP id bx40-20020a05651c19a800b0024f4ff53a85mr4709529ljb.457.1651478298617; Mon, 02 May 2022 00:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651478298; cv=none; d=google.com; s=arc-20160816; b=AylU92KNISW6HqELrqmusLcATOgec1uQL+IU6gTVwZnmT61Evl+WAqKZlI8E1BszWH WT/pNdjoHMoENg075/edHExqU7yVLvA623ARHpyzk2Lqf4Kxs8AWfBnLssFGp0bLaPu/ P1ijvufI56pr50vGyTmaHiOyspR3f+ME0NxGiybwLsbk/jv0+a7Xs8mSqK7foFEWeYC+ jaszE+TM4LqYO/IG4Z/qCE+Td3jXDRSUHdkI6ZnJlfPwF/i9WZQWSAE8S+IKP9bVGFGm osWQYwEjIcNtC24vOCyFCsphxv0jjl7fUC0jsxM92/+Nn/fBDwX6DfcaEqjpqbdqDQig Px0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AccwMZeZU4VT8RW/XJky4i744IrrJHGK92fmF0m5Ypg=; b=e742ZQMfRYQOpzDqhOeGto4gvKC1YvExX8PLeuJTpEW0eagCai/vINGlfsoAuTu08B ac7ymfnDarmxOwKl4+weR1OjhUpwei5wWn0q03cGMMV8cmV6jrgn0aPoFv31mDfRjwtk A8B/AttHIzsZtyzDeQnFcNG54z9NtRze5BFA7mWE6TGPWa4geGFNDOX/RqkfIg7qg+83 vF7Tm2aDmhjvdjUwhXGalNAMQueG6uwWi3nqQH/hiry57/+5SWFGTNekH/ulP7+D7mQO c5dZnFe0gQmcVBIljF+IW/mcHXMkoV5L28U7brhtOimlPVw0rku8cwYybg136rGZU00w D2sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qVpIF9zg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a2e7e03000000b0024c84945707si13684826ljc.96.2022.05.02.00.57.52; Mon, 02 May 2022 00:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qVpIF9zg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243548AbiD3ROY (ORCPT + 99 others); Sat, 30 Apr 2022 13:14:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243340AbiD3ROR (ORCPT ); Sat, 30 Apr 2022 13:14:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6AAEFD1E; Sat, 30 Apr 2022 10:10:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 60DF5B8077F; Sat, 30 Apr 2022 17:10:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4B57C385AA; Sat, 30 Apr 2022 17:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651338651; bh=+7jXUBzEVdqXeKK0kRGylvrQWUjmQVZ+Zn0af0572r8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVpIF9zgxN+mEB1kPhL20QKtJOhUYkRQXxspTz+YCJo/Visor8+j9kSGZBHe5n5lC SFb3ov6YLrToFcPP6+5ehM6JsPZlDeeNuMreJUsbQhysuuOeH6Q2E2ZR/onoOID7Dd NpCvM9cJvqH8tcUF7v7CFccdyelfl4XXSugyuZ7u7FUfCZlT5Lq0dtvoL5PIfC9Prx 0pEy6P9aujZUU3Sp7Zu8YvliLi5Pa8cfQKWGbKE4h4toHtw/Xu5J/RSSdeSo4mX0Z6 +67KNMfJzrTEhb95OH3MuM0dxwiIkg9Zi+I+qlucsbWBwkcpzfJ3+MDCFkAuDG2hb1 oGjdwBvvwf/TA== Received: from mchehab by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1nkqcJ-001tIJ-CM; Sat, 30 Apr 2022 18:10:47 +0100 From: Mauro Carvalho Chehab To: Luis Chamberlain Cc: Mauro Carvalho Chehab , "Daniel Vetter" , "David Airlie" , "Greg KH" , "Jaroslav Kysela" , "Kai Vehmanen" , "Lucas De Marchi" , "Pierre-Louis Bossart" , "Takashi Iwai" , alsa-devel@alsa-project.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, mauro.chehab@linux.intel.com, Dan Williams Subject: [PATCH v4 1/2] module: update dependencies at try_module_get() Date: Sat, 30 Apr 2022 18:10:45 +0100 Message-Id: <6121371a6f701e1c03a5363bf4738bd446324c05.1651338466.git.mchehab@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes, device drivers are bound into each other via try_module_get(), making such references invisible when looking at /proc/modules or lsmod. Add a function to allow setting up module references for such cases, and call it when try_module_get() is used. Reviewed-by: Dan Williams Reviewed-by: Greg Kroah-Hartman Signed-off-by: Mauro Carvalho Chehab --- See [PATCH v4 0/2] at: https://lore.kernel.org/all/cover.1651338466.git.mchehab@kernel.org/ include/linux/module.h | 8 +++++--- kernel/module/main.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 46d4d5f2516e..3b67720faf3b 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -620,12 +620,12 @@ extern void __module_get(struct module *module); /* This is the Right Way to get a module: if it fails, it's being removed, * so pretend it's not there. */ -extern bool try_module_get(struct module *module); +extern bool __try_module_get(struct module *module, struct module *this); extern void module_put(struct module *module); #else /*!CONFIG_MODULE_UNLOAD*/ -static inline bool try_module_get(struct module *module) +static inline bool __try_module_get(struct module *module, struct module *this) { return !module || module_is_live(module); } @@ -740,7 +740,7 @@ static inline void __module_get(struct module *module) { } -static inline bool try_module_get(struct module *module) +static inline bool __try_module_get(struct module *module, struct module *this) { return true; } @@ -875,6 +875,8 @@ static inline bool module_sig_ok(struct module *module) } #endif /* CONFIG_MODULE_SIG */ +#define try_module_get(mod) __try_module_get(mod, THIS_MODULE) + int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, unsigned long), void *data); diff --git a/kernel/module/main.c b/kernel/module/main.c index 05a42d8fcd7a..d63ebf52392b 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -631,6 +631,33 @@ static int ref_module(struct module *a, struct module *b) return 0; } +static int ref_module_dependency(struct module *mod, struct module *this) +{ + int ret; + + if (!this || !this->name) + return -EINVAL; + + if (mod == this) + return 0; + + mutex_lock(&module_mutex); + + ret = ref_module(this, mod); + +#ifdef CONFIG_MODULE_UNLOAD + if (ret) + goto ret; + + ret = sysfs_create_link(mod->holders_dir, + &this->mkobj.kobj, this->name); +#endif + +ret: + mutex_unlock(&module_mutex); + return ret; +} + /* Clear the unload stuff of the module. */ static void module_unload_free(struct module *mod) { @@ -841,7 +868,7 @@ void __module_get(struct module *module) } EXPORT_SYMBOL(__module_get); -bool try_module_get(struct module *module) +bool __try_module_get(struct module *module, struct module *this) { bool ret = true; @@ -856,9 +883,11 @@ bool try_module_get(struct module *module) preempt_enable(); } + if (ret) + ref_module_dependency(module, this); return ret; } -EXPORT_SYMBOL(try_module_get); +EXPORT_SYMBOL(__try_module_get); void module_put(struct module *module) { -- 2.35.1