Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3724687iob; Mon, 2 May 2022 04:13:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqpHiBjKnVnElNdbsuyuTl2Y5EXYMgSZ0cH5e1sPfvZZM0/peVvCdDMCno+ptKEL182J6w X-Received: by 2002:aa7:8605:0:b0:50d:46d4:a1ad with SMTP id p5-20020aa78605000000b0050d46d4a1admr10937374pfn.66.1651490019235; Mon, 02 May 2022 04:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651490019; cv=none; d=google.com; s=arc-20160816; b=w3FoNWQmLogiuueTsI8FkRsz7DV8VpUuCmiC7vR2ZDzXNZ+cdU+9ZeLvRKg0UgwY2i dH/1YKKvBhdY3md9xFYGkvWTSFxL7azNlrSMpaYvMxGvfDmf/6R79KShen4284jT8X2j To7hGwL46AzbUsycNFIPPGzmo3OkJUVm83lo8p2PvLbalrcwrfAGRRHoY9XXzLZJIi1D BXJsBmqv4EQJElfsmQOv2J39gf5jek8IIX0kyg0DlGP0SEJevi6XTfk4Pjgxq/bVEXq4 Lb5IUfwxaJGKFQPRzoMGZzYd1yGPNYztZq2k3pOwrwK9I/6X+Gw0tfvEglw1BchfD9uB pj3w== 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=bdErFuTzE+OzmPLVeZqojHAJtE6S6FI1UiYRZF8fI7w=; b=rqtjt761d1CmKnQdDEeHoQj1FqFBpS+yt2sIXoBSRtNgD6voD0+bhMsbt5k1o0GJT/ yWaUgum50FfuXkO5LdtDRL9zbA0miBPc3d+1oNHkP5z76r9l3/EkQkPtV96Lj5FzWk3S /FLkVeK9T5DoD7w/ClNXra9xBqfFWfrRYQlC2NK3ATmyb9844NjfPJRW+uU4b7uhxRKE xavLR9taf0OjA/PPk7lBLAR0udi41Y6n+SfRLPzz27ZAmd1eeBQpTr9q7/+ewEpCLK2P X424QVxJYre2fgXOitlrXEPeEBh2iSLubC4g7SogVLlmPhJC1M+r/20XnGY+66C8oG3w 5c+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ny+p08Hj; 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 c33-20020a634e21000000b003aa663f5451si13376898pgb.744.2022.05.02.04.13.24; Mon, 02 May 2022 04:13:39 -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=Ny+p08Hj; 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 S242229AbiD3NpY (ORCPT + 99 others); Sat, 30 Apr 2022 09:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241973AbiD3NpR (ORCPT ); Sat, 30 Apr 2022 09:45:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7AB3A1BB; Sat, 30 Apr 2022 06:41:55 -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 AB3DE60EC6; Sat, 30 Apr 2022 13:41:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EC8AC385AF; Sat, 30 Apr 2022 13:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651326114; bh=oRIo74EBIqUQt2BggP6GLMLLkw6dNMctIDHE7rupAZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ny+p08HjVrXxoTDUZsW9vWR6yDP5UI/lSctNfXWbp1Rhg+wveY5qplOs0xpXmNQ1A w3rfevmi69mgOEg8ROfY2XM+HhncElbV8+tCkayjBgt+aTYby2w86hvVOpqxJZZARO TWjBLOkOW9YZLxTLDEyIl9qwxDv3QqTqg7BJmIEkoIxGul2OD4r2bfsJCwbf2IgF1l LI3TKJknogTfaGiwRZPXXQaNl+b8cfmcESGGL83Lip61CDAQ9Z2TV3/ofU4nWqmlda yI/0gc/O2cG+ThIPEkRr6iBNi09adk5E55LdRxZDq6WzOIYlnwfQxZT7VlIkzp3rHy PGgzxtBbGPo8Q== Received: from mchehab by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1nknM6-001nsg-Is; Sat, 30 Apr 2022 14:41:50 +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 v3 1/2] module: update dependencies at try_module_get() Date: Sat, 30 Apr 2022 14:41:47 +0100 Message-Id: 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 Signed-off-by: Mauro Carvalho Chehab --- See [PATCH v3 0/2] at: https://lore.kernel.org/all/cover.1651326000.git.mchehab@kernel.org/ include/linux/module.h | 4 +++- kernel/module/main.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 34 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..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