[RFC PATCH 0/2] clk: Avoid potential deadlock when disabling unused clocks

From: Douglas Anderson
Date: Thu Sep 22 2022 - 11:45:03 EST


These two patches together fix a deadlock that I seem to be hitting
every time with my particular setup (a sc7280-herobrine board running
the downstream chromeos-5.15 kernel).

FWIW:
* Others tried with the very a similar setup to me and they didn't
reproduce the hang, which makes sense after the analysis in the
commit message of the clock patch. To hit this you just need to be
lucky.
* I bisected this in our tree and landed on a cherry-pick of commit
1b771839de05 ("clk: qcom: gdsc: enable optional power domain
support") as the first one where I saw the hang (and the "fix" of
that commit upstream didn't change things). Nothing about that patch
was directly touching the code paths that my analysis showed so I
can only assume it changed the timing in a way to make this happen
reliably for me.

While the solution proposed in this patch series doesn't seem too
terrible to me, it's still not exactly elegant. This is why I'm
marking it as an RFC. If someone wants to send out patches that solve
this in a better way then I'd be more than happy.

NOTE also that at the same time I started getting the deadlock I also
started getting a lockdep warning talking about similar locks.
Unfortunately, the lockdep warning seems to be unrelated. This fix
handles the deadlock but the lockdep still shows up. I can also fix
the lockdep without fixing the deadlock. I'll send a separate patch
about the lockdep.


Douglas Anderson (2):
PM: runtime: Add pm_runtime_try_put_sync() and
pm_runtime_try_get_sync()
clk: core: Avoid potential deadlock when disabling unused clocks

drivers/base/power/runtime.c | 7 +-
drivers/clk/clk.c | 137 ++++++++++++++++++++++++++++-------
include/linux/pm_runtime.h | 28 +++++++
3 files changed, 143 insertions(+), 29 deletions(-)

--
2.37.3.968.ga6b4b080e4-goog