From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796559206; b=X/fuRfRnrw5pKGh6OUbYhzwpEf7F69SRVWspNLYaMRqvNBYex5Pv/+HbeJdOvXaZA/Nd GS3OLvJuHnMngiG/HbzPkFpHmQK4w7fnFGBZp7sxXhcvFz819tII4Ql9QPdcIhMUHMfJr D6kIJ4LHXe1AtKJAPHtgVJZYV9aknaAWBZp4295nsvTriZ4mNQDKXFpvS6Jo48BvNiQYk tcJQQ3zF5vm1DCP+OwnbDcg4GT45NaFIj4WrLHuP+6vpNtj7jR1/FbGWF+druAXJDKHBq GwHFBAHFpiiuMplyrs3vD4ykOE6Zw+UFJ85nKNJRGkDiNaGy7/t8IThAGS/PxVoA30Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796559206; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=XrVd0Bn16b8DZvQ8v82j9edesaYOcC5pDxFTV7t+P+M=; b=fDeyyEY65EwPU1JTO9x+VnGU5G4Abcf9x9ZrVNF0IDzFvtmdMptvKec/roMvJTOLkxGJ 8oBF0wooLbpNfIb4bZTtt++PzNTCfkCPEKhqKDYM1TOujxjgYji2UktOyR2KJcmt8s82n by4UaL8rPgSbxY9UvhQZ3nfiBHYUEmILMfRfvCQtQ18uNuU4A2hGPpgb1/9CBkZssj1ps yT1v7gfXVbkEahllTzTkm02ErcUyDeXERKctEuIPaKwRZwrCjAX9kImQg1Z40vnk+i52C 5jpw7S7k/ezdfSCvSlUPVhpdI4iyVxxrppbcH+ZJGnDD7CWTcg191Os70jyLIAjgqxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Dc/DGGpC"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DBC1606A31F for ; Sun, 6 Dec 2026 12:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Dc/DGGpC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F14F1F0092B; Sun, 6 Dec 2026 12:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796559206; bh=XrVd0Bn16b8DZvQ8v82j9edesaYOcC5pDxFTV7t+P+M=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Dc/DGGpCFvF6eqlBW5bXOfjBxcWsJ8ne3ZHXjvq4XCuXRaVCCg8ArQJ5XPGCK49+6 loSxb7XlpF+lH20UeHqaE7T16qkT6GiU3ur6rJHq2Se1gSzQCX15hZamvk+24GQimI Y6FKJioa1EZdOcDEs0BIRBjD5JKWmmBDPbfDD0fcDeJFwuMAwiQD01SqLaOBGWRXL/ FM/VgWc/m1D4ZYNBXHnsA8GFyncjFemTIBvWW+v7V88PeMqSJs2YYWCwueLeCsHCvk qs26idh+Cc54LfekcQHtVok6oxAbl3Y4e8U4icMBiMJJ8FOTwR938VZwFowtuXFFRg b0xCC+JALjRIw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver Reply-To: sashiko-reviews@lists.linux.dev To: "Manaf Meethalavalappu Pallikunhi" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261206-qcom_spel_driver_upstream-v4-2-168697736e95@oss.qualcomm.com> References: <20261206-qcom_spel_driver_upstream-v4-0-168697736e95@oss.qualcomm.com> <20261206-qcom_spel_driver_upstream-v4-2-168697736e95@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 12:13:25 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 [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 =3D sp->constraint_base + offset; > + value =3D readl(reg_addr); > + > + switch (pl_op) { > + case PL_LIMIT: > + value =3D FIELD_GET(POWER_LIMIT_MASK, value); > + if (xlate) > + *data =3D spel_unit_xlate(sd, POWER_UNIT, value, 0); > + else > + *data =3D 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 =3D spel_unit_xlate(sd, POWER_UNIT, value, 1); > + if (new_val > FIELD_MAX(POWER_LIMIT_MASK)) > + return -EINVAL; > + > + FIELD_MODIFY(POWER_LIMIT_MASK, ®_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, ®_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 =3D=3D 0. FIELD_MODIFY(POWER_LIMIT_ENABLE, ®_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 =3D 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 +=3D > + spel_unit_xlate(sd, ENERGY_UNIT, ENERGY_STATUS_MASK + 1ULL, 0); > + > + sd->last_raw =3D 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, u6= 4 *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 =3D 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 =3D 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_doma= in_type domain_id) > +{ > + /* Enable minimum one constraint, detect the rest from hardware capabil= ities. */ > + int limits =3D BIT(POWER_LIMIT1); > + > + for (int i =3D 0; i < ARRAY_SIZE(constraints); i++) { > + const struct spel_constraint_info *ci =3D &constraints[i]; > + > + if (ci->domain_id =3D=3D domain_id && sp->pl_capabilities & ci->suppor= ted_mask) > + limits |=3D 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.qual= comm.com --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-qcom_spel_= driver_upstream-v4-0-168697736e95@oss.qualcomm.com?part=3D2