hwmon: fix jiffies wraparound in one-shot ready checks
Status from this message: Applied.
Get series with b4
b4 am [email protected]Versions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | hwmon: (tmp102) Fix jiffies wraparound in conversion-ready checkdrivers/ | +4 | 1 reply | |
| 2/3 | hwmon: (tmp108) Fix jiffies wraparound in conversion-ready checkdrivers/ | +4 | 1 reply | |
| 3/3 | hwmon: (sht4x) Fix jiffies wraparound in heater-ready checkdrivers/ | +9 | 3 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/3] hwmon: fix jiffies wraparound in one-shot ready checks
Several hwmon drivers store a one-shot jiffies deadline that is set once and never refreshed, then compare it against the current time with time_before() on every access. time_before() only interprets the signed difference of two jiffies values correctly while they are within LONG_MAX jiffies of each other. Because the deadline is frozen while jiffies keeps advancing, the difference eventually flips sign: after 2^31 jiffies (~248.5 days of uptime on a 32-bit HZ=100 kernel) the check inverts and stays wrong for the next ~248.5 days.
The consequences differ per driver:
- tmp102, tmp108: every temperature read then returns -EAGAIN without ever touching the sensor, until the machine is rebooted. This has been observed in the field on 32-bit systems that had been up for ~248 days.
- sht4x: the read path instead concludes the heater is still active and calls msleep() with a bogus, huge delta, blocking the read for a very long time.
Each is fixed the same minimal way: store the deadline in a u64 jiffies value and compare it with get_jiffies_64()/time_before64(), which does not wrap in any realistic uptime. No functional change on the hot path other than removing the false-positive after the wrap point.
The other hwmon time_before(jiffies, ...) users I looked at are not
affected: they either re-stamp last_updated on every update (the usual cache pattern, e.g. tmp421, tmp464, tc654, g762, ibmpex, w83792d) or use a freshly computed local timeout (pmbus/ltc2978), so their two operands never drift apart.
The failure itself takes ~248 days of uptime to reproduce and follows directly from the time_before() semantics; it was traced from a field report of a 32-bit board stuck returning -EAGAIN after ~248 days.
Build-tested on x86-64 and cross-compiled for 32-bit ARM (Cortex-A7, arm-linux-gnueabi) with make W=1; all three objects build cleanly with no new warnings. 32-bit ARM is the configuration in which the bug actually manifests.
Tom Verdonck (3):
hwmon: (tmp102) Fix jiffies wraparound in conversion-ready check
hwmon: (tmp108) Fix jiffies wraparound in conversion-ready check
hwmon: (sht4x) Fix jiffies wraparound in heater-ready check
drivers/hwmon/sht4x.c | 18 +++++++++--------- drivers/hwmon/tmp102.c | 8 ++++---- drivers/hwmon/tmp108.c | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-)
Signature · 1 line
2.53.0