public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Doug Anderson <dianders@chromium.org>
Cc: Michael Turquette <mturquette@baylibre.com>,
	linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org,
	patches@lists.linux.dev, linux-arm-msm@vger.kernel.org,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: [PATCH 4/5] clk: Get runtime PM before walking tree during disable_unused
Date: Mon, 25 Mar 2024 10:06:08 -0700	[thread overview]
Message-ID: <42ae624ca2289fb82e00f3ac8938d05e.sboyd@kernel.org> (raw)
In-Reply-To: <CAD=FV=Ws-LYcpiitibPBPRhqrbS8rTo_7xtPPw2kA+qBzybOxQ@mail.gmail.com>

Quoting Doug Anderson (2024-03-25 09:19:37)
> Hi,
> 
> On Sun, Mar 24, 2024 at 10:44 PM Stephen Boyd <sboyd@kernel.org> wrote:
> >
> > Introduce a list of clk_core structures that have been registered, or
> > are in the process of being registered, that require runtime PM to
> > operate. Iterate this list and call clk_pm_runtime_get() on each of them
> > without holding the prepare_lock during clk_disable_unused(). This way
> > we can be certain that the runtime PM state of the devices will be
> > active and resumed so we can't schedule away while walking the clk tree
> > with the prepare_lock held. Similarly, call clk_pm_runtime_put() without
> > the prepare_lock held to properly drop the runtime PM reference.
> 
> There's a part of me that worries about the fact that we'll now be
> doing a pm_runtime get() on _all clocks_ (even those that are used) at
> bootup now. I worry that some device out there will be unhappy about
> it. ...but I guess the device passed in here is already documented to
> be one that the clock framework can get/put whenever it needs to
> prepare the clock, so that makes me feel like it should be fine.
> 
> Anyway, no action item, just documenting my thoughts...
> 
> Oh, funny. After reading the next patch, I guess I'm even less
> concerned. I guess we were already grabbing the pm_runtime state for
> all clocks while printing the clock summary. While that's a debugfs
> function, it's still something that many people have likely exercised
> and it's likely not going to introduce random/long tail problems.
> 
> 
> > +/*
> > + * Call clk_pm_runtime_get() on all runtime PM enabled clks in the clk tree so
> > + * that disabling unused clks avoids a deadlock where a device is runtime PM
> > + * resuming/suspending and the runtime PM callback is trying to grab the
> > + * prepare_lock for something like clk_prepare_enable() while
> > + * clk_disable_unused_subtree() holds the prepare_lock and is trying to runtime
> > + * PM resume/suspend the device as well.
> > + */
> > +static int clk_pm_runtime_get_all(void)
> 
> nit: It'd be nice if this documented that it acquired / held the lock.
> Could be in comments, or, might as well use the syntax like this (I
> think):
> 
> __acquires(&clk_rpm_list_lock);
> 
> ...similar with the put function.

I had that but removed it because on the error path we drop the lock and
sparse complains. I don't know how to signal that the lock is held
unless an error happens, but I'm a little out of date on sparse now.

> 
> 
> > +       /*
> > +        * Runtime PM "get" all the devices that are needed for the clks
> > +        * currently registered. Do this without holding the prepare_lock, to
> > +        * avoid the deadlock.
> > +        */
> > +       hlist_for_each_entry(core, &clk_rpm_list, rpm_node) {
> > +               ret = clk_pm_runtime_get(core);
> > +               if (ret) {
> > +                       failed = core;
> > +                       pr_err("clk: Failed to runtime PM get '%s' for clk '%s'\n",
> > +                              failed->name, dev_name(failed->dev));
> 
> If I'm reading this correctly, the strings are backward in your error
> print. Right now you're printing:
> 
> clk: Failed to runtime PM get '<clk_name>' for clk '<dev_name>'

Good catch. Thanks!

> 
> With the printout fixed and some type of documentation that
> clk_pm_runtime_get_all() and clk_pm_runtime_put_all() grab/release the
> mutex:
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>

  reply	other threads:[~2024-03-25 17:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25  5:43 [PATCH 0/5] Fix a deadlock with clk_pm_runtime_get() Stephen Boyd
2024-03-25  5:43 ` [PATCH 1/5] clk: Remove prepare_lock hold assertion in __clk_release() Stephen Boyd
2024-03-25 16:18   ` Doug Anderson
2024-03-25  5:43 ` [PATCH 2/5] clk: Don't hold prepare_lock when calling kref_put() Stephen Boyd
2024-03-25 16:19   ` Doug Anderson
2024-03-25  5:44 ` [PATCH 3/5] clk: Initialize struct clk_core kref earlier Stephen Boyd
2024-03-25 16:19   ` Doug Anderson
2024-03-25  5:44 ` [PATCH 4/5] clk: Get runtime PM before walking tree during disable_unused Stephen Boyd
2024-03-25 16:19   ` Doug Anderson
2024-03-25 17:06     ` Stephen Boyd [this message]
2024-03-25 17:15       ` Doug Anderson
2024-03-25  5:44 ` [PATCH 5/5] clk: Get runtime PM before walking tree for clk_summary Stephen Boyd
2024-03-25 16:19   ` Doug Anderson
2024-03-25 17:09     ` Stephen Boyd
2024-09-13 19:32 ` [PATCH 0/5] Fix a deadlock with clk_pm_runtime_get() Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42ae624ca2289fb82e00f3ac8938d05e.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=dianders@chromium.org \
    --cc=krzk@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mturquette@baylibre.com \
    --cc=patches@lists.linux.dev \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox