Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sarath Ganapathiraju" <sarath.ganapathiraju@oss.qualcomm.com>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v16 2/2] clk: qcom: Add LPASS VA CSR heartbeat pulse clock
Date: Thu, 03 Dec 2026 18:57:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-248447@kernel.org> (raw)
In-Reply-To: <20261203-master-v16-2-f946e4c2686a@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] clk: qcom: AB-BA deadlock between prepare_lock and lpass-va-csr
  runtime PM
- [Medium] clk: qcom: missing NULL check on match data in
  lpass_va_csr_probe()
- [Medium] clk: qcom: unsynchronized hb_enabled race in
  lpass_va_csr_runtime_resume()
- [Low] clk: qcom: unguarded regmap debugfs MMIO reads in lpass-va-csr
--

commit 6181a29fe3667ab7db1605811f8d478d055d71b8
Author: Sarath Ganapathiraju <sarath.ganapathiraju@oss.qualcomm.com>

clk: qcom: Add LPASS VA CSR heartbeat pulse clock

This commit adds the Qualcomm LPASS VA CSR driver that models the
heartbeat pulse rate generator as a common clock provider, using runtime
PM and PM clocks to manage the vote clocks and restore register state
across suspend and resume.

> diff --git a/drivers/clk/qcom/lpass-va-csr.c b/drivers/clk/qcom/lpass-va-csr.c
> new file mode 100644
> index 0000000000000..7c6301311575f
> --- /dev/null
> +++ b/drivers/clk/qcom/lpass-va-csr.c
> @@ -0,0 +1,209 @@

[ ... ]

> +static const struct regmap_config lpass_rate_gen_regmap_config = {
> +	.name = "lpass_rate_gen",
> +	.reg_bits = 32,
> +	.val_bits = 32,
> +	.reg_stride = 4,
> +	.max_register = LPASS_RATE_GEN_MAX_REG,
> +};

[Severity: Low]
Can reading the regmap debugfs registers file trigger unclocked MMIO reads
while the device is runtime-suspended?

lpass_rate_gen_regmap_config leaves readable_reg and rd_table unset, and
lpass_va_csr_runtime_suspend() calls pm_clk_suspend() without putting the
regmap into cache-only mode.  Reading
/sys/kernel/debug/regmap/<dev>-lpass_rate_gen/registers calls
regmap_read_debugfs() without resuming runtime PM, issuing raw MMIO readl()
accesses across 0x0000..0xd010 with the LPASS vote clocks disabled, which
can cause bus errors, SErrors, or hangs (and even when clocked, reads
unrelated VA CSR offsets outside the three rate generator registers).

Restricting readable registers with readable_reg or rd_table and toggling
regcache_cache_only() in runtime suspend and resume would prevent this.

[ ... ]

> +	ret = regmap_write(csr->hb.regmap, LPASS_RATE_GEN_COUNTER_0,
> +			   data->counter_0);
> +	if (ret)
> +		goto err_pm_clk_suspend;
> +
> +	ret = regmap_write(csr->hb.regmap, LPASS_RATE_GEN_DELAY, data->delay);
> +	if (ret)
> +		goto err_pm_clk_suspend;
> +
> +	if (csr->hb_enabled) {
> +		ret = regmap_update_bits(csr->hb.regmap, LPASS_RATE_GEN_CTRL,
> +					 LPASS_RG_CTRL_EN, LPASS_RG_CTRL_EN);
> +		if (ret)
> +			goto err_pm_clk_suspend;
> +	}

[Severity: Medium]
Can csr->hb_enabled and the rate generator register restore race with
atomic clk_enable() or clk_disable() during system resume?

DEFINE_RUNTIME_DEV_PM_OPS() hooks pm_runtime_force_resume() into regular
.resume, which runs after device IRQs and secondary CPUs are already
re-enabled.  If a consumer kept the clock prepared across suspend, an
atomic clk_disable() can interleave with lpass_va_csr_runtime_resume():

CPU0                                CPU1 (or <hardirq>)
lpass_va_csr_runtime_resume()
  if (csr->hb_enabled)  /* true */
                                    clk_disable()
                                      lpass_va_csr_hb_disable()
                                        clk_disable_regmap()
                                        csr->hb_enabled = false
  regmap_update_bits(...CTRL_EN)    <-- re-enables disabled clock

This leaves LPASS_RG_CTRL_EN set in hardware while csr->hb_enabled is
false and the clock framework considers it disabled.  Similarly, a
concurrent clk_enable() after pm_clk_resume() can set LPASS_RG_CTRL_EN
before COUNTER_0 and DELAY are restored.

Protecting csr->hb_enabled and the register updates in
lpass_va_csr_hb_enable(), lpass_va_csr_hb_disable(), and the post-resume
restore path with a spinlock using spin_lock_irqsave() would close this
race.

[ ... ]

> +	data = of_device_get_match_data(dev);

[Severity: Medium]
Should data be checked for NULL here?

If the driver is bound via sysfs driver_override to a non-matching DT
platform device that has an MMIO resource and a clocks property,
of_device_get_match_data() returns NULL and lpass_va_csr_runtime_resume()
dereferences data->counter_0 during pm_runtime_resume_and_get(), causing a
NULL pointer dereference.

[ ... ]

> +	ret = devm_pm_runtime_enable(dev);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to enable PM runtime\n");
> +
> +	ret = pm_runtime_resume_and_get(dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_clk_register_regmap(dev, &csr->hb);
> +	if (ret)
> +		goto err_pm_runtime_put;
> +
> +	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &csr->hb.hw);
> +	if (ret)
> +		goto err_pm_runtime_put;
> +
> +	pm_runtime_put_sync(dev);

[Severity: High]
Does enabling runtime PM before devm_clk_register_regmap() create an ABBA
deadlock between the clock framework's global prepare_lock and this
device's runtime PM transitions?

Because runtime PM is enabled when devm_clk_register_regmap() runs, the
clock core sets core->rpm_enabled = true and calls
pm_runtime_resume_and_get() and pm_runtime_put_sync() while holding
prepare_lock in clk_core_prepare() and clk_core_unprepare().  At the same
time, the DT vote clocks attached via of_pm_clk_add_clks()
(clk_vote_q6dsp_ops) implement only .prepare and .unprepare, so
pm_clk_resume() and pm_clk_suspend() call clk_prepare_enable() and
clk_disable_unprepare(), which acquire prepare_lock from inside the
runtime PM callbacks.

Any runtime PM transition started outside prepare_lock, such as
pm_runtime_put_sync(dev) here after devm_of_clk_add_hw_provider() has
published the clock, can deadlock against a concurrent clk_prepare():

CPU0                                CPU1
----                                ----
rpm_suspend() [RPM_SUSPENDING]
                                    lock(&prepare_lock)
  pm_clk_suspend()
    clk_disable_unprepare()
      lock(&prepare_lock)
                                    rpm_resume() [waits on RPM_SUSPENDING]

 *** DEADLOCK ***

CPU0: lpass_va_csr_probe() -> pm_runtime_put_sync() ->
      lpass_va_csr_runtime_suspend() -> pm_clk_suspend() ->
      clk_disable_unprepare()
CPU1: clk_prepare() -> clk_core_prepare() -> clk_pm_runtime_get() ->
      rpm_resume()

Once this hits, both threads hang permanently along with all clock
prepare, unprepare, set_rate, and registration operations kernel-wide.

Registering the clock with core->rpm_enabled = true also causes
clk_summary, clk_dump, and clk_disable_unused to perform unnecessary
synchronous ADSP GPR IPC wakeups and register writes on this device.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-master-v16-0-f946e4c2686a@oss.qualcomm.com?part=2

      reply	other threads:[~2026-12-03 18:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:55 [PATCH v16 0/2] Add LPASS VA CSR HeartBeat pulse clock support Sarath Ganapathiraju via B4 Relay
2026-12-03 17:55 ` [PATCH v16 1/2] dt-bindings: clock: qcom: Add LPASS VA CSR HeartBeat pulse clock Sarath Ganapathiraju via B4 Relay
2026-12-03 17:55 ` [PATCH v16 2/2] clk: qcom: Add LPASS VA CSR heartbeat " Sarath Ganapathiraju via B4 Relay
2026-12-03 18:57   ` sashiko-bot [this message]

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=sashiko-outbox-248447@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sarath.ganapathiraju@oss.qualcomm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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