Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Manaf Meethalavalappu Pallikunhi" <manaf.pallikunhi@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver
Date: Sun, 06 Dec 2026 12:13:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-252407@kernel.org> (raw)
In-Reply-To: <20261206-qcom_spel_driver_upstream-v4-2-168697736e95@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] powercap: qcom: spel_get_max_energy_counter() returns U64_MAX,
  printing -1
- [Medium] powercap: qcom: unpolled 32-bit energy wraps missed and
  hidden by U64_MAX
- [Medium] powercap: qcom: spel_get_domain_limits() forces PL1 on all
  domains
- [Medium] powercap: qcom: spel_write_pl_data() disables limit on small
  non-zero values
- [Medium] powercap: qcom: spel_read_pl_data() ignores
  POWER_LIMIT_ENABLE bit
- [Low] powercap: qcom: commit message omits driver architecture context
--

commit 27c9fc242efc3e52d0b94409cc2a59891fe940ac
Author: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>

> powercap: qcom: Add SPEL powercap driver
>
> The Qualcomm SoC Power and Electrical Limits (SPEL) provides hardware
> based power monitoring and limiting capabilities for various power
> domains including System, SoC, CPU clusters, GPU, and various other
> subsystems.
>
> The driver integrates with the Linux powercap framework, exposing SPEL
> capabilities through powercap sysfs interfaces.
>
> Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>

[Severity: Low]
As reported by Daniel Lezcano on v3 [1], could the commit message be
expanded to describe the driver's architecture?

This adds a 949-line driver, yet the changelog omits the three MMIO
regions (config, constraints, nodes), unit exponent scaling, the Glymur
hierarchy, PL1-PL4 capability discovery, firmware notification on
time-window updates, 32-bit wraparound tracking, and hibernation support.

> diff --git a/drivers/powercap/qcom/spel.c b/drivers/powercap/qcom/spel.c
> new file mode 100644
> index 0000000000000..56cf98bc54669
> --- /dev/null
> +++ b/drivers/powercap/qcom/spel.c

[ ... ]

> +	reg_addr = sp->constraint_base + offset;
> +	value = readl(reg_addr);
> +
> +	switch (pl_op) {
> +	case PL_LIMIT:
> +		value = FIELD_GET(POWER_LIMIT_MASK, value);
> +		if (xlate)
> +			*data = spel_unit_xlate(sd, POWER_UNIT, value, 0);
> +		else
> +			*data = value;
> +		break;

[Severity: Medium]
Should spel_read_pl_data() check POWER_LIMIT_ENABLE before returning the
power limit?

zone_ops omits get_enable (so sysfs always reports enabled as 1), and
spel_write_pl_data() uses 0 to disable and non-zero to enable.  If
POWER_LIMIT_ENABLE is clear while POWER_LIMIT_MASK is non-zero, reads
report an active limit and saving/restoring it enables the constraint.

Returning 0 when !(value & POWER_LIMIT_ENABLE) would keep reads
consistent with writes.

[ ... ]

> +	switch (pl_op) {
> +	case PL_LIMIT:
> +		new_val = spel_unit_xlate(sd, POWER_UNIT, value, 1);
> +		if (new_val > FIELD_MAX(POWER_LIMIT_MASK))
> +			return -EINVAL;
> +
> +		FIELD_MODIFY(POWER_LIMIT_MASK, &reg_val, new_val);
> +
> +		/*
> +		 * Enable/Disable PL based on the value:
> +		 * - If value is 0, disable the PL (clear enable bit)
> +		 * - If value is non-zero, enable the PL (set enable bit)
> +		 */
> +		FIELD_MODIFY(POWER_LIMIT_ENABLE, &reg_val, !!new_val);
> +
> +		writel(reg_val, reg_addr);
> +		return 0;

[Severity: Medium]
Can a small non-zero power limit silently disable hardware limiting here?

spel_unit_xlate() uses DIV_ROUND_CLOSEST_ULL(), so any non-zero microwatt
value below half of one hardware quantum rounds down to new_val == 0.
FIELD_MODIFY(POWER_LIMIT_ENABLE, &reg_val, !!new_val) then clears the
enable bit and returns 0, removing the power cap instead of applying one.

When value is non-zero and new_val rounds to 0, returning -EINVAL or
clamping new_val to 1 would avoid disabling the limit.

[ ... ]

> +static void spel_domain_sync_energy(struct spel_domain *sd)
> +{
> +	u32 value = readl(sd->status_reg);
> +
> +	/* The 32-bit counter wrapped since the last read; fold a full range in. */
> +	if (value < sd->last_raw)
> +		sd->cumulative_energy_uj +=
> +			spel_unit_xlate(sd, ENERGY_UNIT, ENERGY_STATUS_MASK + 1ULL, 0);
> +
> +	sd->last_raw = value;
> +}

[Severity: Medium]
Can 32-bit energy counter wraps be silently dropped between reads?

Wrap detection only runs on demand during energy_uj reads or hibernation
freeze, with no periodic polling.  If reads are spaced further apart than
one 32-bit hardware wrap period, the missed wraps are permanently lost
from cumulative_energy_uj.

Because spel_get_max_energy_counter() reports U64_MAX instead of the
translated 32-bit hardware range, userspace pollers also cannot tell how
often they need to sample to avoid missing wraps.

[ ... ]

> +static int spel_get_max_energy_counter(struct powercap_zone *pcd_dev, u64 *energy)
> +{
> +	/*
> +	 * energy_raw is a software accumulator that never wraps at the
> +	 * hardware's 32-bit range; report the true u64 range instead of the
> +	 * hardware wrap boundary.
> +	 */
> +	*energy = U64_MAX;
> +
> +	return 0;
> +}

[Severity: High]
Will returning U64_MAX make max_energy_range_uj print -1 to userspace?

powercap_sys.c formats the u64 result as a signed 64-bit integer:

drivers/powercap/powercap_sys.c:define_power_zone_show() {
	...
	if (power_zone->ops->get_##_attr) {
		if (!power_zone->ops->get_##_attr(power_zone, &value))
			len = sysfs_emit(buf, "%lld\n", value);
	}
	...
}

Because U64_MAX has bit 63 set, every read of max_energy_range_uj emits
"-1\n", breaking tools that parse it as an unsigned range.  Either
powercap_sys.c needs to use %llu first, or this should return a value
within S64_MAX (such as the translated 32-bit hardware range).

[ ... ]

> +static int spel_get_domain_limits(struct spel_system *sp, enum spel_domain_type domain_id)
> +{
> +	/* Enable minimum one constraint, detect the rest from hardware capabilities. */
> +	int limits = BIT(POWER_LIMIT1);
> +
> +	for (int i = 0; i < ARRAY_SIZE(constraints); i++) {
> +		const struct spel_constraint_info *ci = &constraints[i];
> +
> +		if (ci->domain_id == domain_id && sp->pl_capabilities & ci->supported_mask)
> +			limits |= BIT(ci->pl_id);
> +	}
> +
> +	return limits;
> +}

[Severity: Medium]
Why is POWER_LIMIT1 unconditionally enabled on every domain?

constraints[] only defines registers for SPEL_DOMAIN_SYS and
SPEL_DOMAIN_SOC, so forcing BIT(POWER_LIMIT1) exposes broken constraint_0
(pl1) sysfs attributes on all 11 monitoring-only domains, where every
read or write fails in get_pl_ops_offset() with -EOPNOTSUPP (-ENODATA).

For SPEL_DOMAIN_SYS and SPEL_DOMAIN_SOC, it also bypasses the BIT(0) and
BIT(4) capability checks, causing sysfs handlers and hibernation
freeze/restore to access PL1 registers even if hardware leaves those
bits clear.

Initializing limits to 0 is supported by powercap_register_zone() when
&constraint_ops is passed.

[1] https://lore.kernel.org/r/92397fd7-e149-432c-9ec8-b2cd31af7f04@oss.qualcomm.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-qcom_spel_driver_upstream-v4-0-168697736e95@oss.qualcomm.com?part=2

  reply	other threads:[~2026-12-06 12:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 11:56 [PATCH v4 0/3] Add Qualcomm SPEL powercap driver Manaf Meethalavalappu Pallikunhi
2026-12-06 11:56 ` [PATCH v4 1/3] dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware Manaf Meethalavalappu Pallikunhi
2026-12-06 11:56 ` [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver Manaf Meethalavalappu Pallikunhi
2026-12-06 12:13   ` sashiko-bot [this message]
2026-12-06 11:56 ` [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable " Manaf Meethalavalappu Pallikunhi
2026-12-06 12:04   ` sashiko-bot

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-252407@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=manaf.pallikunhi@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --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