Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mediatek: Do a runtime PM get on controllers during probe

mt8183-mfgcfg has a mutual dependency with genpd during the probing
stage, which leads to a deadlock in the following call stack:

CPU0: genpd_lock --> clk_prepare_lock
genpd_power_off_work_fn()
genpd_lock()
generic_pm_domain::power_off()
clk_unprepare()
clk_prepare_lock()

CPU1: clk_prepare_lock --> genpd_lock
clk_register()
__clk_core_init()
clk_prepare_lock()
clk_pm_runtime_get()
genpd_lock()

Do a runtime PM get at the probe function to make sure clk_register()
won't acquire the genpd lock. Instead of only modifying mt8183-mfgcfg,
do this on all mediatek clock controller probings because we don't
believe this would cause any regression.

Verified on MT8183 and MT8192 Chromebooks.

Fixes: acddfc2c261b ("clk: mediatek: Add MT8183 clock support")
Signed-off-by: Pin-yen Lin <treapking@chromium.org>

Link: https://lore.kernel.org/r/20240312115249.3341654-1-treapking@chromium.org
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Pin-yen Lin and committed by
Stephen Boyd
2f7b1d8b 754e5287

+15
+15
drivers/clk/mediatek/clk-mtk.c
··· 13 13 #include <linux/of.h> 14 14 #include <linux/of_address.h> 15 15 #include <linux/platform_device.h> 16 + #include <linux/pm_runtime.h> 16 17 #include <linux/slab.h> 17 18 18 19 #include "clk-mtk.h" ··· 495 494 return IS_ERR(base) ? PTR_ERR(base) : -ENOMEM; 496 495 } 497 496 497 + 498 + devm_pm_runtime_enable(&pdev->dev); 499 + /* 500 + * Do a pm_runtime_resume_and_get() to workaround a possible 501 + * deadlock between clk_register() and the genpd framework. 502 + */ 503 + r = pm_runtime_resume_and_get(&pdev->dev); 504 + if (r) 505 + return r; 506 + 498 507 /* Calculate how many clk_hw_onecell_data entries to allocate */ 499 508 num_clks = mcd->num_clks + mcd->num_composite_clks; 500 509 num_clks += mcd->num_fixed_clks + mcd->num_factor_clks; ··· 585 574 goto unregister_clks; 586 575 } 587 576 577 + pm_runtime_put(&pdev->dev); 578 + 588 579 return r; 589 580 590 581 unregister_clks: ··· 617 604 free_base: 618 605 if (mcd->shared_io && base) 619 606 iounmap(base); 607 + 608 + pm_runtime_put(&pdev->dev); 620 609 return r; 621 610 } 622 611