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=1796315565; b=jU7C7d5eunN4h3pvbJMU4tu30tfLVKd1WwojDhuTkgLrZuu5bE8DKcZ66BnNTn2NFd8Z NgQWWTbZxX+bb3IVggOmckL+2rOhym3rZkD3PgWX5h5XBiJNVraZAok7M4Zc9nldfd2R5 KjleISpFrm/VFzSvWKr0zbZXzfLeURvl9evZCHEIPAjo2ql5cRb5ButMJd/RH82aR2IBy GkeGiSKWRvHOTZpkkpsMlwiq55NDm3qt42p+MUxIjWtMg/pMDrM0vDm4icSYhkVXyN+Bu wr05Orno/5xeT7MqLyxwCXrQNmauKIEGtIzfBuw+zzZJA83AZt0Lux35diVLa3MqSsQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796315565; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=VONj38JFGiC6DlDYt6cMcOeeh1xzPgMAu9T/1c4739I=; b=4jiNAV57DaWXqByiZjjqghvgrKdZYjpMw/Co2OJX0xAG2fdL0mMsVnQ95fW3e12mUA1v vKs9ZAP58n+CtVhwFWjeDnQk4hPRvY1F25aR4ndVLiYcuCz2aw/ftJFBxgEXVxTdCWDKL JDTPOxGWuxB0Sn5NrSKRqP5ITZl4zYZAUljBd/OvhioeLeNN+hFkR0mcVCmcmvOOsnFiS ifmN0UfbvHZTfKB4YbEGl98DApXRkbnl+KhrPuS3aHuw9Dslihg9bHecxXXzJB6/NINcO iphJTJKi3ZKEfXwpFRR+xw5h4TdviW+9pdPmn1s0dQNcvCYmnUxPeBVoYmJNKq2/Zlg== 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=RxSPUeHe; 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 D1A8E606A322 for ; Thu, 3 Dec 2026 16:32:45 +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=RxSPUeHe Received: by smtp.kernel.org (Postfix) with ESMTPSA id 517A81F000C1; Thu, 3 Dec 2026 16:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796315565; bh=VONj38JFGiC6DlDYt6cMcOeeh1xzPgMAu9T/1c4739I=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=RxSPUeHe4oRd7xWcS40xFbxM7QoP4cpbS6QQTdNYNF2vjpaL/QxhvOvPzRMh+37B9 YJ4vP5sYxHZtTuZDrRJ9V9Q7Bpy4U2NM2KPm00DENY/AelpYNx98HKsj51qS7+rS0K Lt7x5I8sY1Lk87oZnUOKfRUfrSWCRTrg9PFHSpU6XJHy/t/hqmhJMHmyCY0d85e8WT SZOpe2sEyQzzvs3sT9doXeFnPD8/AKm99T0tcSj1k6fvheAbogqOUewgLqOgmhmsgn zr6fEYOuQUE1U7MzElDJTLsJ+oD9LiQa5bTQFzQfrcKVp6v7uXPxgrXr9UffMUz3oY NC8+LlqM3oIIw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver Reply-To: sashiko-reviews@lists.linux.dev To: "Jeroen Trappers" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203155600.3911447-3-jeroen.trappers@gmail.com> References: <20261203155600.3911447-1-jeroen.trappers@gmail.com> <20261203155600.3911447-3-jeroen.trappers@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 16:32:42 +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 3 potential issues to consider: - [High] thermal: rate-limit bypass and accumulator starvation in t7000_get_temp() - [Medium] thermal: unbounded stale temp masking and disabled restart in t7000_sample() - [Medium] thermal: unused sensors started and stopped in t7000_thermal_probe() -- commit e51c3a5c5a92b6f8f1aba9692e7009a4e0f3f77d Author: Jeroen Trappers thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver This commit adds a thermal zone driver for the Apple T7000 (A8) on-die temperature sensors, reading accumulated samples from the boot-calibrated SoC and CPU complex register pages and exposing them through thermal zones and hwmon. > diff --git a/drivers/thermal/apple_t7000_thermal.c b/drivers/thermal/appl= e_t7000_thermal.c > new file mode 100644 > index 0000000000000..7d80ddf6e2f56 > --- /dev/null > +++ b/drivers/thermal/apple_t7000_thermal.c [ ... ] > +static int t7000_sample(struct t7000_sensor *s) > +{ > + const struct t7000_sensor_desc *d =3D s->desc; > + u32 ctl, bk, count; > + int temp; > + > + writel(T7000_CTL0_ACCUMULATE, s->base + d->ctl_clear); > + ctl =3D readl(s->base + d->ctl_set); > + bk =3D readl(s->base + d->bk); > + count =3D readl(s->base + d->count); > + writel(T7000_CTL0_ACCUMULATE, s->base + d->ctl_set); > + > + if (!(ctl & T7000_CTL0_ENABLE) || !(bk & T7000_BK_VALID) || !count) > + return -EAGAIN; > + > + temp =3D DIV_ROUND_CLOSEST(sign_extend32(bk, d->sign_bit) * 1000, 64); > + /* An impossible code is a glitch; iOS substitutes 30 C instead. */ > + if (temp < -40000 || temp > 150000) > + return -EAGAIN; > + > + s->temp =3D temp; > + s->sampled =3D jiffies; > + s->valid =3D true; > + return 0; > +} > + > +static int t7000_get_temp(struct thermal_zone_device *tz, int *temp) > +{ > + struct t7000_sensor *s =3D thermal_zone_device_priv(tz); > + int ret =3D 0; > + > + if (!s->valid || > + time_after_eq(jiffies, s->sampled + msecs_to_jiffies(T7000_MIN_INTE= RVAL_MS))) > + ret =3D t7000_sample(s); [Severity: High] Can rapid reads bypass T7000_MIN_INTERVAL_MS and starve the accumulator? t7000_sample() always freezes and restarts T7000_CTL0_ACCUMULATE, but skips updating s->sampled on -EAGAIN. An unprivileged user polling /sys/class/thermal/thermal_zone*/temp faster than ~2.5 ms can therefore keep resetting the accumulator with count =3D=3D 0. At probe, t7000_thermal_probe() starts accumulation without setting s->sampled, and !s->valid skips T7000_MIN_INTERVAL_MS, so rapid polling kee= ps s->valid false. After any runtime -EAGAIN, s->sampled stays expired and t7000_get_temp() returns stale s->temp forever, blocking thermal trips. Updating s->sampled =3D jiffies whenever ctl_set is written (in probe and unconditionally in t7000_sample()) and enforcing T7000_MIN_INTERVAL_MS befo= re s->valid is set would prevent starvation. > + /* No new sample (an interval without one, or a glitch): keep the last = one. */ > + if (ret =3D=3D -EAGAIN && s->valid) > + ret =3D 0; > + if (!ret) > + *temp =3D s->temp; [Severity: Medium] Should a disabled or persistently failing sensor be masked behind stale s->temp forever? Once s->valid is true, t7000_get_temp() turns every -EAGAIN into 0 with no staleness limit or retry bound. Since t7000_sample() only returns 0 or -EAGAIN, thermal_core never sees a hard error to trigger thermal_zone_broken_disable(), leaving thermal trips on frozen data. t7000_sample() also writes ctl_set before checking T7000_CTL0_ENABLE, restarting accumulation on a disabled sensor. Returning -ENODEV or -EIO without writing ctl_set when disabled, and expiring s->valid after bounded failures or age, would let thermal_core detect a broken sensor. [ ... ] > + /* Start accumulating, as iOS does, before the zone's first read. */ > + writel(T7000_CTL0_ACCUMULATE, s->base + d->ctl_set); > + ret =3D devm_add_action_or_reset(dev, t7000_sensor_stop, s); > + if (ret) > + return ret; > + > + tz =3D devm_thermal_of_zone_register(dev, i, s, &t7000_thermal_ops); > + if (IS_ERR(tz)) { > + /* No zone uses this sensor: leave it alone. */ > + if (PTR_ERR(tz) =3D=3D -ENODEV) { > + devm_release_action(dev, t7000_sensor_stop, s); > + continue; > + } [Severity: Medium] Does writing ctl_set before devm_thermal_of_zone_register() disturb sensors that no thermal zone uses? When a boot-enabled sensor has no thermal zone, devm_thermal_of_zone_register() returns -ENODEV and devm_release_action() runs t7000_sensor_stop(). That writes ctl_set then ctl_clear, clearing T7000_CTL0_ACCUMULATE even if firmware left it running. Registering t7000_sensor_stop() without pre-writing ctl_set, starting accumulation only after registration succeeds, and calling devm_remove_action() on -ENODEV would keep unbind order while leaving unused sensors untouched. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203155600.3911= 447-1-jeroen.trappers@gmail.com?part=3D2