Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp234367iob; Mon, 2 May 2022 18:02:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO+VlWHX/6NZM36L5t9rRkRMvIY3oXVyBOXfWEABtG01RfbAoXAl6j6g6Vth6oS1EF+UnH X-Received: by 2002:a63:e70f:0:b0:380:d919:beb with SMTP id b15-20020a63e70f000000b00380d9190bebmr11792994pgi.58.1651539748062; Mon, 02 May 2022 18:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651539748; cv=none; d=google.com; s=arc-20160816; b=hs1ojgnuowPgaEd+/0xMoTanipRr6DpBGy8TJFFrelkxBrsRTp2V3v4MISMzzN8tCm u9sJieRMNnMc2yaWmaZCyOTdVKgtVcoA3ImxVcDYq9hqYPKt/587Sn1Fm2aHMhUgxTYf noe90sh9HiWJ4xAZ9I8DYEnjJ3m3DmwtVqH2sNyO/zWD/O7NRAp8oeeu5HLctN74XBwM yiAX2Q15u2KlvcYUKs+GYdFJmMR47ridgXRMbmokOssCirb4otGfWab5X8VpYxSTmhzQ IcPUjD3oWXlpok+cETFxnfpXaLSLhD2POTAi8pYmMSMwMgtDRWw9xKt39bzZGII3Uc0K DEKQ== 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=jYYAGJKcgW1ysPkqexul3bzI90bBXaT6xf5bGJiJbbM=; b=dIg0pw1hB/yQH14/DuhGCZ6p2D2cuePlfghcOrfNGdFtYiTSmVS++T3fqmwEZOTmeJ bmUT3YmDsZdYhRrrGgC4fN+uwFCtZ0ZWTgTH/QG2JzZednZ+skucYmUbaHO99cT6lsKk Vp7HtuzQJrIwUrOawEgNenIDPWJladhagVrL5bbSinOMJOr/pqw8drfNwJ0bJ/l2Nve7 5n3eGm5CyJv22dWkYZM3lknVCFUOvEKyUS0bCbUlZGhVJLy8q2xPXq2R/8ykRu0ATcjm 8zs5kDZYWmsXG+YC+8HQ2AGBbSZuOukrr57Pf/EQwQ0ZMxnbkQVmWzQ0mZqS3/kGnBQr EJcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gAOGtCXn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id iy13-20020a17090b16cd00b001cd658e7640si728941pjb.43.2022.05.02.18.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 18:02:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gAOGtCXn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD62F56214; Mon, 2 May 2022 17:46:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382588AbiD3Kei (ORCPT + 99 others); Sat, 30 Apr 2022 06:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241493AbiD3Kee (ORCPT ); Sat, 30 Apr 2022 06:34:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 767AA44A09; Sat, 30 Apr 2022 03:31:09 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4897A60F76; Sat, 30 Apr 2022 10:31:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B45AC385B0; Sat, 30 Apr 2022 10:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651314668; bh=5a3g5n+qmEd88ekG2DL7ECt9MM1yHMe0jnzyEtuLpqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gAOGtCXn9lgpRzyoj/fqa0aPc3jhw1Jqo+MSKNxwVE+IUgMVRpGTf4OVtLZdSeZqd wzjmUKJAtT22aRbMgAPxuz9GQUEYery/ELlun2DLAoz4nAWVKdJoKcandelji+33q4 fGaWOQOJcG0O89lfSGUZjTc7SB2nVxzbJbHQxYaFjuqGCSAznmzGifz9TAn5SMrf1Q PI8UwQorA626qDLrprZknbQa7iTyKQ7iF9pfgpqLHiLM4Tdq5yUXcJXxaai4gr4NhE xnFMc7czngQdUywPIYRNYuvNTjBhiiPK+QP50B9IVurAYM35wbS13rciykpn4LD+UZ xIGETWKHKhZwA== Received: from mchehab by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1nkkNQ-001lBO-G4; Sat, 30 Apr 2022 11:31:00 +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 v2 1/2] module: update dependencies at try_module_get() Date: Sat, 30 Apr 2022 11:30:58 +0100 Message-Id: <3c7547d551558c9da02038dda45992f91b1f5141.1651314499.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=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Signed-off-by: Mauro Carvalho Chehab --- See [PATCH v2 0/2] at: https://lore.kernel.org/all/cover.1651314499.git.mchehab@kernel.org/ include/linux/module.h | 4 +++- kernel/module/main.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 46d4d5f2516e..836851baaad4 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -620,7 +620,9 @@ 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); + +#define try_module_get(mod) __try_module_get(mod, THIS_MODULE) extern void module_put(struct module *module); diff --git a/kernel/module/main.c b/kernel/module/main.c index 05a42d8fcd7a..9f4416381e65 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -631,6 +631,35 @@ 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 +870,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 +885,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