Re: [PATCH v4 1/3] hwmon: (pmbus) add spinlock to protect 64-bit timestamp
From: Guenter Roeck
Date: Fri Mar 20 2026 - 08:50:39 EST
On 3/19/26 16:50, Pradhan, Sanman wrote:
From: Sanman Pradhan <psanman@xxxxxxxxxxx>
The next_access_backoff variable is a 64-bit ktime_t. On 32-bit
architectures, accesses to 64-bit variables are not atomic, which can
result in "torn" reads or writes if accessed concurrently from
different subsystems (e.g., hwmon sysfs reads vs. regulator updates).
Introduce a spinlock in struct pmbus_data to protect accesses to
next_access_backoff and prevent torn reads/writes on 32-bit systems.
This change addresses atomicity of the timestamp field itself as the
timing helpers become callable from more paths, including PMBus chip
drivers using the exported helpers.
This does not attempt to serialize the full wait/transfer/update
sequence across concurrent callers; it only protects the timestamp
field from torn access.
Signed-off-by: Sanman Pradhan <psanman@xxxxxxxxxxx>
---
v4:
- New patch in the series. Introduces a spinlock to protect the 64-bit
next_access_backoff timestamp from torn reads/writes on 32-bit
architectures.
Unfortunately that makes timestamp handling very expensive, even for
architectures not needing it.
We'll have to make sure that all accesses (sysfs, thermal, and regulator)
are serialized instead. I just browsed through the core code. Most of
the accesses are already serialized, but I think the locking is missing
in the regulator operations. We'll need to add the missing locks there.
Thanks,
Guenter