Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp224976iob; Mon, 2 May 2022 17:45:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWUqnLQYD8AeZxDnCwAVGCWqPHsX2Jfhja4uV8XsoAvR9koDaCb66VhA51MiZSxzM3+fbI X-Received: by 2002:a05:6a00:1695:b0:4f7:decc:506b with SMTP id k21-20020a056a00169500b004f7decc506bmr13704444pfc.7.1651538731857; Mon, 02 May 2022 17:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651538731; cv=none; d=google.com; s=arc-20160816; b=bZrhVz0TmqqKxtVVJ7M5lM7n0xs3B1M56sZSLCy1TKBFVK2d0qwQ6eM5P6ixmypIMo 3MDjBPWHOEmPO3kcu8yfLZSGZfHpMv1fTk1H7I2jvh3yuwtg6SFojdqBTkiTY+StoA4Q ueQkC01RqbKV3YdynwtDXzr+Hu6WeqkH5Gcdk95rvERyrKYxRLvgPxOoub/3V4buHTnw tu3bfa8sLXr1/cTMmXDPG3cbb0p/6AFA3BDrSrs4/jurh+tBD0NN6gInplnUbAKmv+ai jLylwJDfHu1ATrQrnvj6SVoA2Or5g47XwYyZpqmtp2N1ukK57ntWMf1+PLp7jWiUavuP zkBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4h1dixR9eiaKlLpS2tXl3Shj/NSz1oqvMbSXijXo1+c=; b=PUtOd9WY38su+aYHhosYvk/01U5gLtdLUP24a9NrFdWlmpWLkx9ufbm/FzA4WX+5Zu bh1JfW1YqUwSfStS/RKMNZ8aDytQiA/cn5mtuAAxAHvi6BJGT2tFEopWx4bQwgKvnlTx akM9tMSZDCvsHi49/q7BoHMV4UK4AwoVrP1XXib8t8CwXHgth/E6lAbiwlEL3t7gIFoY wXdcZqHLkNz//OQGUR0O0yYcfp5e8GJy99pV1NW2wnQvFkzKEwe0nvMG1dJIFBVVsXSP Cm5Q57vQAMTYF2PzLZ61IVeAXmdEKAU9Ei9Lv3q1JxDuTFrCmLiQWY4AO2afqm7Ssnh7 xxtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TyS89al3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q15-20020a17090311cf00b0015819f5edc5si17014789plh.426.2022.05.02.17.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:45:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TyS89al3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE87F38BD5; Mon, 2 May 2022 17:34:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357498AbiD2Kj0 (ORCPT + 99 others); Fri, 29 Apr 2022 06:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234735AbiD2KjX (ORCPT ); Fri, 29 Apr 2022 06:39:23 -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 675413BF88; Fri, 29 Apr 2022 03:36:05 -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 0186B622EB; Fri, 29 Apr 2022 10:36:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D111EC385A7; Fri, 29 Apr 2022 10:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651228564; bh=o0zBJ+SKkAUN56ZqpQtuEIJ6OIeAS93jNqU6+Q7RUSQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TyS89al3T0t01lxOPzBl9fvatdfcb1LWSvxIeOjSVrOuF9nslLxBiLa7EwhRJucUm o2SWD8uZu9cadtPMyh6cgSPl90t/Fw9//GdIx++e5pvK+npqLM0rVQcxsGJpkxe/Ly nc7TSC40HfxNg/LD+Y7/D4gsxOjIcDxqhwJgEg9A= Date: Fri, 29 Apr 2022 12:36:01 +0200 From: Greg KH To: Mauro Carvalho Chehab Cc: Daniel Vetter , Luis Chamberlain , mauro.chehab@intel.com, Kai Vehmanen , Lucas De Marchi , Pierre-Louis Bossart , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, David Airlie , Dan Williams Subject: Re: [PATCH 1/2] module: add a function to add module references Message-ID: References: <20220429090757.1acb943a@sal.lan> <20220429101503.4048db5b@sal.lan> <20220429112351.0e044950@sal.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220429112351.0e044950@sal.lan> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 On Fri, Apr 29, 2022 at 11:23:51AM +0100, Mauro Carvalho Chehab wrote: > Em Fri, 29 Apr 2022 12:10:07 +0200 > Greg KH escreveu: > > > On Fri, Apr 29, 2022 at 10:15:03AM +0100, Mauro Carvalho Chehab wrote: > > > HI Greg, > > > > > > Em Fri, 29 Apr 2022 10:30:33 +0200 > > > Greg KH escreveu: > > > > > > > On Fri, Apr 29, 2022 at 09:07:57AM +0100, Mauro Carvalho Chehab wrote: > > > > > Hi Daniel, > > > > > > > > > > Em Fri, 29 Apr 2022 09:54:10 +0200 > > > > > Daniel Vetter escreveu: > > > > > > > > > > > On Fri, Apr 29, 2022 at 07:31:15AM +0100, Mauro Carvalho Chehab wrote: > > > > > > > Sometimes, device drivers are bound using indirect references, > > > > > > > which is not visible when looking at /proc/modules or lsmod. > > > > > > > > > > > > > > Add a function to allow setting up module references for such > > > > > > > cases. > > > > > > > > > > > > > > Reviewed-by: Dan Williams > > > > > > > Signed-off-by: Mauro Carvalho Chehab > > > > > > > > > > > > This sounds like duct tape at the wrong level. We should have a > > > > > > device_link connecting these devices, and maybe device_link internally > > > > > > needs to make sure the respective driver modules stay around for long > > > > > > enough too. But open-coding this all over the place into every driver that > > > > > > has some kind of cross-driver dependency sounds terrible. > > > > > > > > > > > > Or maybe the bug is that the snd driver keeps accessing the hw/component > > > > > > side when that is just plain gone. Iirc there's still fundamental issues > > > > > > there on the sound side of things, which have been attempted to paper over > > > > > > by timeouts and stuff like that in the past instead of enforcing a hard > > > > > > link between the snd and i915 side. > > > > > > > > > > I agree with you that the device link between snd-hda and the DRM driver > > > > > should properly handle unbinding on both directions. This is something > > > > > that require further discussions with ALSA and DRM people, and we should > > > > > keep working on it. > > > > > > > > > > Yet, the binding between those drivers do exist, but, despite other > > > > > similar inter-driver bindings being properly reported by lsmod, this one > > > > > is invisible for userspace. > > > > > > > > > > What this series does is to make such binding visible. As simple as that. > > > > > > > > It also increases the reference count, and creates a user/kernel api > > > > with the symlinks, right? Will the reference count increase prevent the > > > > modules from now being unloadable? > > > > > > > > This feels like a very "weak" link between modules that should not be > > > > needed if reference counting is implemented properly (so that things are > > > > cleaned up in the correct order.) > > > > > > The refcount increment exists even without this patch, as > > > hda_component_master_bind() at sound/hda/hdac_component.c uses > > > try_module_get() when it creates the device link. > > > > Ok, then why shouldn't try_module_get() be creating this link instead of > > having to manually do it this way again? You don't want to have to go > > around and add this call to all users of that function, right? > > Works for me, but this is not a too trivial change, as the new > try_module_get() function will require two parameters, instead of one: > > - the module to be referenced; > - the module which will reference it. > > On trivial cases, one will be THIS_MODULE, but, in the specific case > of snd_hda, the binding is done via an ancillary routine under > snd_hda_core, but the actual binding happens at snd_hda_intel. For calls that want to increment a module reference on behalf of a different code segment than is calling it, create a new function so we can audit-the-heck out of those code paths as odds are, they are unsafe. For the normal code path, just turn try_module_get() into a macro that includes THIS_MODULE as part of it like we do for the driver register functions (see usb_register_driver() in include/linux/usb.h as an example of how to do that.) > Ok, we could add a __try_module_get() (or whatever other name that > would properly express what it does) with two parameters, and then > define try_module_get() as: > > #define try_module_get(mod) __try_module_get(mod, THIS_MODULE) Yes, that's the way forward. thanks, greg k-h