* [PATCH] PM: clk: Fix false-positive recursive PM clock mutex locking
@ 2026-11-09 5:10 Daniel J Blueman
0 siblings, 0 replies; only message in thread
From: Daniel J Blueman @ 2026-11-09 5:10 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Pavel Machek, Len Brown, Greg Kroah-Hartman, Danilo Krummrich,
Johan Hovold, Konrad Dybcio, Mark Brown, Ajay Kumar Nandam,
Srinivas Kandagatla, linux-pm, driver-core, linux-kernel,
Daniel J Blueman
pm_clk_suspend() and pm_clk_resume() hold psd->clock_mutex across
clk_prepare() and clk_unprepare() for sleeping clocks, with every instance
sharing one lockdep class. If a PM clock is provided by a device that also
uses PM clocks, clk_prepare() resumes the provider, which takes its own
clock mutex, triggering a lockdep report.
This shows up on the Qualcomm X1 with the LPASS WSA/RX/TX macros and the
varargs macro providing the "fsgen" clock:
WARNING: possible recursive locking detected
...
pm_clk_resume
va_macro_runtime_resume [snd_soc_lpass_va_macro]
...
clk_prepare
pm_clk_resume
wsa_macro_runtime_resume [snd_soc_lpass_wsa_macro]
Lock ordering is always consumer -> provider, so this is false-positive,
resulting in lockdep being turned off.
Fix this by giving each pm_clk_create()/devm_pm_clk_create() call site its
own lock class.
Scenario analysis and patch development was assisted by Claude Opus 5.5
under my instruction; detection and validation was performed on my Lenovo
Slim 7x with a X1E80100.
Fixes: eb667d0fbdd3 ("ASoC: codecs: lpass-va-macro: Switch to PM clock framework for runtime PM")
Signed-off-by: Daniel J Blueman <daniel@quora.org>
---
drivers/base/power/clock_ops.c | 23 ++++++++++++++++-------
include/linux/pm_clock.h | 19 +++++++++++++++++--
2 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 3b8ba27802a8..94f2aa090ce1 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -398,17 +398,26 @@ void pm_clk_init(struct device *dev)
EXPORT_SYMBOL_GPL(pm_clk_init);
/**
- * pm_clk_create - Create and initialize a device's list of PM clocks.
+ * __pm_clk_create - Create and initialize a device's list of PM clocks.
* @dev: Device to create and initialize the list of PM clocks for.
+ * @key: Lockdep class key for the clock mutex.
*
* Allocate a struct pm_subsys_data object, initialize its lock and clock_list
* members and make the @dev's power.subsys_data field point to it.
*/
-int pm_clk_create(struct device *dev)
+int __pm_clk_create(struct device *dev, struct lock_class_key *key)
{
- return dev_pm_get_subsys_data(dev);
+ int ret;
+
+ ret = dev_pm_get_subsys_data(dev);
+ if (ret)
+ return ret;
+
+ lockdep_set_class_and_name(&dev_to_psd(dev)->clock_mutex, key,
+ "&psd->clock_mutex");
+ return 0;
}
-EXPORT_SYMBOL_GPL(pm_clk_create);
+EXPORT_SYMBOL_GPL(__pm_clk_create);
/**
* pm_clk_destroy - Destroy a device's list of power management clocks.
@@ -451,17 +460,17 @@ static void pm_clk_destroy_action(void *data)
pm_clk_destroy(data);
}
-int devm_pm_clk_create(struct device *dev)
+int __devm_pm_clk_create(struct device *dev, struct lock_class_key *key)
{
int ret;
- ret = pm_clk_create(dev);
+ ret = __pm_clk_create(dev, key);
if (ret)
return ret;
return devm_add_action_or_reset(dev, pm_clk_destroy_action, dev);
}
-EXPORT_SYMBOL_GPL(devm_pm_clk_create);
+EXPORT_SYMBOL_GPL(__devm_pm_clk_create);
/**
* pm_clk_suspend - Disable clocks in a device's PM clock list.
diff --git a/include/linux/pm_clock.h b/include/linux/pm_clock.h
index c3b46fa358d3..d54681547f58 100644
--- a/include/linux/pm_clock.h
+++ b/include/linux/pm_clock.h
@@ -37,7 +37,7 @@ static inline bool pm_clk_no_clocks(struct device *dev)
}
extern void pm_clk_init(struct device *dev);
-extern int pm_clk_create(struct device *dev);
+extern int __pm_clk_create(struct device *dev, struct lock_class_key *key);
extern void pm_clk_destroy(struct device *dev);
extern int pm_clk_add(struct device *dev, const char *con_id);
extern int pm_clk_add_clk(struct device *dev, struct clk *clk);
@@ -45,7 +45,22 @@ extern int of_pm_clk_add_clks(struct device *dev);
extern void pm_clk_remove_clk(struct device *dev, struct clk *clk);
extern int pm_clk_suspend(struct device *dev);
extern int pm_clk_resume(struct device *dev);
-extern int devm_pm_clk_create(struct device *dev);
+extern int __devm_pm_clk_create(struct device *dev, struct lock_class_key *key);
+
+/* Per-call-site lockdep class, as clock mutexes of different devices nest */
+#define pm_clk_create(dev) \
+({ \
+ static struct lock_class_key __key; \
+ \
+ __pm_clk_create(dev, &__key); \
+})
+
+#define devm_pm_clk_create(dev) \
+({ \
+ static struct lock_class_key __key; \
+ \
+ __devm_pm_clk_create(dev, &__key); \
+})
#else
static inline bool pm_clk_no_clocks(struct device *dev)
{
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-09 5:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 5:10 [PATCH] PM: clk: Fix false-positive recursive PM clock mutex locking Daniel J Blueman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®