From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50B1123507B for ; Fri, 24 Jul 2026 15:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784908084; cv=none; b=ku+asXdYXfJvBeVGE105l2rFEhM14Kvz28US+PYkrPo7HJ55KQUhNqYC2UqdTgHFT5wxLNnStSd0zlqcRC5rHowW2i2/WmadRJx8QrPhLcX+wOw8RssvSNMMZlwbb7AZwjCcUKQ9gScy68IVZDpa21nDBLD/9WgSFF5bIBMGu08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784908084; c=relaxed/simple; bh=cn+x4dya5aJWGTuEtKwknI0NaktEbB4OB5mtal3SK1k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PVx4TrNbr8Su46plS7ZX+uSLcHirMLoX78Ry7ajx3T4OG+0Lh4XPD+IUiurxgZrNGPmjIhzO6I0VVwoeqCrrXJ4FA977EJxMYAJ1lGv9XyRYsWnftNgFOwvsmJVcZJXuW2ZFNBe79JDNxnzALaMevdu4CP18lYvrivJsxh2kW5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YLbDWYdx; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=YVZ745c+; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YLbDWYdx"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="YVZ745c+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784908081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4ffI7ELCJU7nRGshcHwyrN09W4Ca8x2m7UfWZqlGMYM=; b=YLbDWYdx+cHL6smdObAIFrxkUx4C753z+rtWyccWosDkR9RsqqNT1zuU1JTSmnyt2/Q9wN h/7wIz1+2mYrTAQv6x7ni1Ku4NxVV9nZdQ0fngISoutp0tF06ukMus4dyU35TwS+M+r1nD IAvIPJ2UznKEoQtb/SxkXija7eVuHiU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-8TVx8Q1yO1myyoVd1v3EBA-1; Fri, 24 Jul 2026 11:47:59 -0400 X-MC-Unique: 8TVx8Q1yO1myyoVd1v3EBA-1 X-Mimecast-MFC-AGG-ID: 8TVx8Q1yO1myyoVd1v3EBA_1784908079 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-930edb4362dso76993385a.3 for ; Fri, 24 Jul 2026 08:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784908079; x=1785512879; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=4ffI7ELCJU7nRGshcHwyrN09W4Ca8x2m7UfWZqlGMYM=; b=YVZ745c+aSt7+gGFACWJZgaHVwXyQWbU0w15c+0nV6mglhT/UMtJYhuuDFc3Dk1CWd B2OKZpyGiNRRnE5wR6XOdy6hSCxth3pYEU6DARxSZaLooHyVJvDQp70OKelG8L+jqAVV 9g/AW3sTGXo2fpHrpqBGF8f/DMzJKE4O9Z35w4F4vWo2Lch7IJe4LbFoWOQTARGObwJC r3Q71+EfX9sNAOu2VNcgRNCPyaZ+9SMdHRPF+2czn04b7yEdRtgSljPWCWrxrxA4Qvyx IviPAbDdvpkB13jnqmsDnvKnyzX7mUNKL3DA7dwWdn6vCc2C+JOy+7BFpRU8UT3ajNO+ fHvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784908079; x=1785512879; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4ffI7ELCJU7nRGshcHwyrN09W4Ca8x2m7UfWZqlGMYM=; b=T0c1jZjyvSL9YyWPiyalb1lKWkfporI3d4hOE8Zxr4ijq+mE0+VVVJlnhaAGyJ1f17 82Z6y9GA2g0Hr7IOikCwzTfDGQcwQzqerosEMUviEVoPkngT1zjajm2BYduyewcDe1mh L7Oz16qD/snee2ZLLBEcNlTmvXJuHlUj6oBGqPeBaucR9Qnuete4H8kSxzUhu+/9mxhG r+CSiE7tAUD+JOVMNidyOHURID//PPWE0snHewXJ9Z+DSCc6vumcEWTn7lTzcxZVCsCO owhRkVEsH2GTW2KWPWxqWzPEbdPmoUDu6sEfo7OrocA9dGd/XHcGwy9yC4lzxdwMytwD JS7A== X-Forwarded-Encrypted: i=1; AHgh+RrDAs3f3QP2nZWXR3Nkr9DqiWGJRP5IatcXBp5Et20fYIEBpEZ+BrjbsQKzgrEjpZ1tcpJ2pTEnPNXU2LI=@vger.kernel.org X-Gm-Message-State: AOJu0YzRCGaX8kCGbJwSxUiAXZ66p92VkBGJ7DDHiT7XWeo8XGz0v9FA ZDupUagLb8FlPsH6yyrbPYWa7bEeW+dGOwZfifRuz1rKQjWivMSIf3j3f34QiCWdf7zEswV1gsR rvy8lwt/2JQcHl4V8ye+7lB4SwhLWNQwpnlvelmjW+qBC6GkabZ3rnvAjnkR98Xkx6w== X-Gm-Gg: AR+sD11iTt6sf4CgnOF8H9p+2Es2pLCSarKK/IRxCoLNJPqLf7hURkG4D3SPs2iQCUs bS8mEFtnSWkbeoNgF62clucUlYIv+B3RBqc5WnNyqHtaUTiIIWpgbHgY0cDTPQKAxbvJbJjCyO1 NaifmTQXnAYyzeN5NkGRZt/9Lf421LND2d6Tubwav2anNuPKF6Wm0duULKp3dUHSFYDYCJcAd3O OqIfgYb0+uXPOkMmSICdHL2dWbNaUeA3XSpCtkVxwWPFKDpFAmANBCc6+g5I7BnRJHNPMPLmKAZ ePTsF3tg4OLHTqUORF3S0NBMKmHLxs6W9JxTdgsXdUzy2g1zuFubB1Ji+0A49LhyR4d2LzHgVT7 IfpSlAZmq5/uCF1C9tbt+CDbONyBfvmlTND8= X-Received: by 2002:a05:620a:4690:b0:930:b4f9:f327 with SMTP id af79cd13be357-931038a7d95mr809454785a.33.1784908079143; Fri, 24 Jul 2026 08:47:59 -0700 (PDT) X-Received: by 2002:a05:620a:4690:b0:930:b4f9:f327 with SMTP id af79cd13be357-931038a7d95mr809449885a.33.1784908078506; Fri, 24 Jul 2026 08:47:58 -0700 (PDT) Received: from redhat.com (c-73-183-53-213.hsd1.pa.comcast.net. [73.183.53.213]) by smtp.gmail.com with ESMTPSA id af79cd13be357-930f6ac3e5esm670750585a.47.2026.07.24.08.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 08:47:57 -0700 (PDT) Date: Fri, 24 Jul 2026 11:47:55 -0400 From: Brian Masney To: Jerome Brunet Cc: Michael Turquette , Stephen Boyd , Russell King , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2] clk: fix self-consuming provider module pinning Message-ID: References: <20260723-clk-provider-pinning-v2-1-8dad72eb79f0@baylibre.com> <1jbjbxd4fk.fsf@starbuckisacylon.baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1jbjbxd4fk.fsf@starbuckisacylon.baylibre.com> User-Agent: Mutt/2.4.0 (2026-06-19) On Thu, Jul 23, 2026 at 07:03:11PM +0200, Jerome Brunet wrote: > On jeu. 23 juil. 2026 at 10:40, Brian Masney wrote: > > > Hi Jerome, > > > > On Thu, Jul 23, 2026 at 03:00:51PM +0200, Jerome Brunet wrote: > >> clk_hw_get_clk() lets a provider get a struct clk for one of its own > >> struct clk_hw. > >> > >> When a struct clk is created, the module usage count of the provider > >> is unconditionally increased. For a self-consuming provider, this means > >> it pins itself and the module can never be unloaded. > >> > >> Increasing the module usage count should only be done when the consumer > >> lives in a different module from the provider. Use THIS_MODULE to > >> capture caller's module and increase the module usage count accordingly. > >> > >> It is OK for consumer-only APIs such as clk_get() or of_clk_get() to > >> pass a NULL owner. As a result, any provider module will get pinned, > >> same as before. > >> > >> Fixes: 30d6f8c15d2c ("clk: add api to get clk consumer from clk_hw") > >> Signed-off-by: Jerome Brunet > >> --- > >> This issue has been present for a while. Virtually all users of > >> clk_hw_get_clk() are affected. The majority are compiled as builtins > >> according to the defconfigs. It is not problem in this case but it is > >> if the configuration is changed to module. > >> > >> The following modules are using clk_hw_get_clk() and are compiled as > >> module with some shipped defconfigs: > >> * drivers/gpu/drm/msm/disp/mdp4/mdp4_lvds_pll.c > >> * drivers/phy/cadence/phy-cadence-sierra.c > >> * drivers/pwm/pwm-meson.c > >> * sound/soc/codecs/lpass-va-macro.c > >> > >> Currently those module cannot be unloaded once they have been loaded. > >> > >> """ > >> rmmod: ERROR: Module blabla-module is in use > >> """ > >> > >> With this applied, we can get back to removing the direct usage > >> of the struct clk in struct clk_hw and eventually remove this > >> struct member entirely. > >> --- > >> Changes in v2: > >> - Update comment in __clk_register() > >> - Add missing documention for the new parameter of clk_hw_create_clk() > >> - No functional change > >> - Link to v1: https://patch.msgid.link/20260721-clk-provider-pinning-v1-1-63db2e667993@baylibre.com > > > > Reviewed-by: Brian Masney > > > > This looks good to me. I'm planning to send Stephen a pull next week for > > content that I think is ready during this development cycle, however I'm > > not going to include this. I suspect he's going to want a kunit test for > > this and I know it's going to be complicated. My suggestion is to post > > some kind of rough test scenario for this, even if it's initially not in > > kunit. As I get some spare time at work, I can help you to see if we can > > get a kunit test together for this. > > > > Brian > > I understand but I'm not adding an new API, I'm fixing a real problem in > an existing one in the kernel now. The related API is already used in > some kunit, so there is some coverage already. > > The problem was known (as the comment in __clk_register() was showing) and > there was no kunit then ... so it is a bit strange to delay fixing the > problem because there is not kunit associated with it now. > > That said, I'll check was I can do. acutally loading and unloading > module in kunit does not really feasible. Maybe poking the owner > field with __clk_hw_get_clk(). This is not really supposed to used > directly (which is why I did not add the documentation around it) > and it's bit fake but I do not really a way around it. I agree that it's fixing a real problem, and also agree that a kunit test for this is likely going to be nasty and overly complicated. Let's wait and see what Stephen says. Personally I think we merge this right after -rc1 is released to give time for additional testing in -next. Brian