Skip to content

Commit 4cc47e8

Browse files
committed
clk: qcom: gdsc: Remove direct runtime PM calls
We shouldn't be calling runtime PM APIs from within the genpd enable/disable path for a couple reasons. First, this causes an AA lockdep splat[1] because genpd can call into genpd code again while holding the genpd lock. WARNING: possible recursive locking detected 5.19.0-rc2-lockdep+ #7 Not tainted -------------------------------------------- kworker/2:1/49 is trying to acquire lock: ffffffeea0370788 (&genpd->mlock){+.+.}-{3:3}, at: genpd_lock_mtx+0x24/0x30 but task is already holding lock: ffffffeea03710a8 (&genpd->mlock){+.+.}-{3:3}, at: genpd_lock_mtx+0x24/0x30 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&genpd->mlock); lock(&genpd->mlock); *** DEADLOCK *** May be due to missing lock nesting notation 3 locks held by kworker/2:1/49: #0: 74ffff80811a5748 ((wq_completion)pm){+.+.}-{0:0}, at: process_one_work+0x320/0x5fc #1: ffffffc008537cf8 ((work_completion)(&genpd->power_off_work)){+.+.}-{0:0}, at: process_one_work+0x354/0x5fc #2: ffffffeea03710a8 (&genpd->mlock){+.+.}-{3:3}, at: genpd_lock_mtx+0x24/0x30 stack backtrace: CPU: 2 PID: 49 Comm: kworker/2:1 Not tainted 5.19.0-rc2-lockdep+ #7 Hardware name: Google Lazor (rev3 - 8) with KB Backlight (DT) Workqueue: pm genpd_power_off_work_fn Call trace: dump_backtrace+0x1a0/0x200 show_stack+0x24/0x30 dump_stack_lvl+0x7c/0xa0 dump_stack+0x18/0x44 __lock_acquire+0xb38/0x3634 lock_acquire+0x180/0x2d4 __mutex_lock_common+0x118/0xe30 mutex_lock_nested+0x70/0x7c genpd_lock_mtx+0x24/0x30 genpd_runtime_suspend+0x2f0/0x414 __rpm_callback+0xdc/0x1b8 rpm_callback+0x4c/0xcc rpm_suspend+0x21c/0x5f0 rpm_idle+0x17c/0x1e0 __pm_runtime_idle+0x78/0xcc gdsc_disable+0x24c/0x26c _genpd_power_off+0xd4/0x1c4 genpd_power_off+0x2d8/0x41c genpd_power_off_work_fn+0x60/0x94 process_one_work+0x398/0x5fc worker_thread+0x42c/0x6c4 kthread+0x194/0x1b4 ret_from_fork+0x10/0x20 Second, this confuses runtime PM on CoachZ for the camera devices by causing the camera clock controller's runtime PM usage_count to go negative after resuming from suspend. This is because runtime PM is being used on the clock controller while runtime PM is disabled for the device. The reason for the negative count is because a GDSC is represented as a genpd and each genpd that is attached to a device is resumed during the noirq phase of system wide suspend/resume (see the noirq suspend ops assignment in pm_genpd_init() for more details). The camera GDSCs are attached to camera devices with the 'power-domains' property in DT. Every device has runtime PM disabled in the late system suspend phase via __device_suspend_late(). Runtime PM is not usable until runtime PM is enabled in device_resume_early(). The noirq phases run after the 'late' and before the 'early' phase of suspend/resume. When the genpds are resumed in genpd_resume_noirq(), we call down into gdsc_enable() that calls pm_runtime_resume_and_get() and that returns -EACCES to indicate failure to resume because runtime PM is disabled for all devices. Upon closer inspection, calling runtime PM APIs like this in the GDSC driver doesn't make sense. It was intended to make sure the GDSC for the clock controller providing other GDSCs was enabled, specifically the MMCX GDSC for the display clk controller on SM8250 (sm8250-dispcc), so that GDSC register accesses succeeded. That will already happen because we make the 'dev->pm_domain' a parent domain of each GDSC we register in gdsc_register() via pm_genpd_add_subdomain(). When any of these GDSCs are accessed, we'll enable the parent domain (in this specific case MMCX). We also remove any getting of runtime PM during registration, because when a genpd is registered it increments the count on the parent if the genpd itself is already enabled. Cc: Dmitry Baryshkov <[email protected]> Cc: Johan Hovold <[email protected]> Cc: Ulf Hansson <[email protected]> Cc: Taniya Das <[email protected]> Cc: Satya Priya <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Tested-by: Douglas Anderson <[email protected]> Cc: Matthias Kaehlcke <[email protected]> Reported-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/CAE-0n52xbZeJ66RaKwggeRB57fUAwjvxGxfFMKOKJMKVyFTe+w@mail.gmail.com [1] Fixes: 1b77183 ("clk: qcom: gdsc: enable optional power domain support") Signed-off-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Johan Hovold <[email protected]> Reviewed-by: Johan Hovold <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent ffa20aa commit 4cc47e8

File tree

2 files changed

+6
-57
lines changed

2 files changed

+6
-57
lines changed

drivers/clk/qcom/gdsc.c

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/kernel.h>
1212
#include <linux/ktime.h>
1313
#include <linux/pm_domain.h>
14-
#include <linux/pm_runtime.h>
1514
#include <linux/regmap.h>
1615
#include <linux/regulator/consumer.h>
1716
#include <linux/reset-controller.h>
@@ -56,22 +55,6 @@ enum gdsc_status {
5655
GDSC_ON
5756
};
5857

59-
static int gdsc_pm_runtime_get(struct gdsc *sc)
60-
{
61-
if (!sc->dev)
62-
return 0;
63-
64-
return pm_runtime_resume_and_get(sc->dev);
65-
}
66-
67-
static int gdsc_pm_runtime_put(struct gdsc *sc)
68-
{
69-
if (!sc->dev)
70-
return 0;
71-
72-
return pm_runtime_put_sync(sc->dev);
73-
}
74-
7558
/* Returns 1 if GDSC status is status, 0 if not, and < 0 on error */
7659
static int gdsc_check_status(struct gdsc *sc, enum gdsc_status status)
7760
{
@@ -271,8 +254,9 @@ static void gdsc_retain_ff_on(struct gdsc *sc)
271254
regmap_update_bits(sc->regmap, sc->gdscr, mask, mask);
272255
}
273256

274-
static int _gdsc_enable(struct gdsc *sc)
257+
static int gdsc_enable(struct generic_pm_domain *domain)
275258
{
259+
struct gdsc *sc = domain_to_gdsc(domain);
276260
int ret;
277261

278262
if (sc->pwrsts == PWRSTS_ON)
@@ -328,22 +312,11 @@ static int _gdsc_enable(struct gdsc *sc)
328312
return 0;
329313
}
330314

331-
static int gdsc_enable(struct generic_pm_domain *domain)
315+
static int gdsc_disable(struct generic_pm_domain *domain)
332316
{
333317
struct gdsc *sc = domain_to_gdsc(domain);
334318
int ret;
335319

336-
ret = gdsc_pm_runtime_get(sc);
337-
if (ret)
338-
return ret;
339-
340-
return _gdsc_enable(sc);
341-
}
342-
343-
static int _gdsc_disable(struct gdsc *sc)
344-
{
345-
int ret;
346-
347320
if (sc->pwrsts == PWRSTS_ON)
348321
return gdsc_assert_reset(sc);
349322

@@ -388,18 +361,6 @@ static int _gdsc_disable(struct gdsc *sc)
388361
return 0;
389362
}
390363

391-
static int gdsc_disable(struct generic_pm_domain *domain)
392-
{
393-
struct gdsc *sc = domain_to_gdsc(domain);
394-
int ret;
395-
396-
ret = _gdsc_disable(sc);
397-
398-
gdsc_pm_runtime_put(sc);
399-
400-
return ret;
401-
}
402-
403364
static int gdsc_init(struct gdsc *sc)
404365
{
405366
u32 mask, val;
@@ -447,26 +408,21 @@ static int gdsc_init(struct gdsc *sc)
447408
return ret;
448409
}
449410

450-
/* ...and the power-domain */
451-
ret = gdsc_pm_runtime_get(sc);
452-
if (ret)
453-
goto err_disable_supply;
454-
455411
/*
456412
* Votable GDSCs can be ON due to Vote from other masters.
457413
* If a Votable GDSC is ON, make sure we have a Vote.
458414
*/
459415
if (sc->flags & VOTABLE) {
460416
ret = gdsc_update_collapse_bit(sc, false);
461417
if (ret)
462-
goto err_put_rpm;
418+
goto err_disable_supply;
463419
}
464420

465421
/* Turn on HW trigger mode if supported */
466422
if (sc->flags & HW_CTRL) {
467423
ret = gdsc_hwctrl(sc, true);
468424
if (ret < 0)
469-
goto err_put_rpm;
425+
goto err_disable_supply;
470426
}
471427

472428
/*
@@ -496,13 +452,10 @@ static int gdsc_init(struct gdsc *sc)
496452

497453
ret = pm_genpd_init(&sc->pd, NULL, !on);
498454
if (ret)
499-
goto err_put_rpm;
455+
goto err_disable_supply;
500456

501457
return 0;
502458

503-
err_put_rpm:
504-
if (on)
505-
gdsc_pm_runtime_put(sc);
506459
err_disable_supply:
507460
if (on && sc->rsupply)
508461
regulator_disable(sc->rsupply);
@@ -541,8 +494,6 @@ int gdsc_register(struct gdsc_desc *desc,
541494
for (i = 0; i < num; i++) {
542495
if (!scs[i])
543496
continue;
544-
if (pm_runtime_enabled(dev))
545-
scs[i]->dev = dev;
546497
scs[i]->regmap = regmap;
547498
scs[i]->rcdev = rcdev;
548499
ret = gdsc_init(scs[i]);

drivers/clk/qcom/gdsc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ struct reset_controller_dev;
3030
* @resets: ids of resets associated with this gdsc
3131
* @reset_count: number of @resets
3232
* @rcdev: reset controller
33-
* @dev: the device holding the GDSC, used for pm_runtime calls
3433
*/
3534
struct gdsc {
3635
struct generic_pm_domain pd;
@@ -74,7 +73,6 @@ struct gdsc {
7473

7574
const char *supply;
7675
struct regulator *rsupply;
77-
struct device *dev;
7876
};
7977

8078
struct gdsc_desc {

0 commit comments

Comments
 (0)