Skip to contentSkip to conversation

hwmon: (spd5118) support write protected devices

PATCH In review Kean Ren 3 participants 5 messages Sep 20 – Sep 22

Subsystems (2)
lore
Share & tools
lore

Kean Ren

author
#0 lore raw

PATCH 1/1 hwmon: (spd5118) support write protected devices

Some systems do not allow writes to SPD devices. On the i801 SMBus controller family this happens when the BIOS sets SPD Write Disable, in which case the controller refuses writes to addresses 0x50-0x57; other platforms may enforce the same in firmware. There is no way for the driver to query this.

spd5118 assumes that it can write to the device, which does not hold on such systems:

- writes to the hwmon attributes always fail with -ENXIO
- the temperature sensor disable in spd5118_suspend() fails silently
- spd5118_resume() fails in regcache_sync(), and the system reports

spd5118 0-0050: Failed to write b = 0: -6 spd5118 0-0050: PM: failed to resume async: error -6

Register 0xb in that message is the page selector register, which regmap writes back from its cache at the end of regcache_sync(). The write of the saved configuration register before that fails as well, but the cache code does not report that error.

Detect write protection once at probe time by writing the page selector register back with the value just read from it. This is a no-op on a device which accepts writes, and it fails if writes are blocked.

If writes are not possible, run the device read-only: drop the register cache so that regcache_sync() cannot attempt any write, skip the writes in the suspend and resume callbacks, and make the writable attributes read only. Alarm attributes are read only already; stop clearing a latched status from them, since that requires a write, and report the condition as the device presents it.

Reading the SPD NVRAM beyond the first page requires switching pages, which is itself a write. Restrict the 'eeprom' attribute to the page which can be read in that case, instead of returning errors for the accessible part.

The temperature sensor remains fully usable; only its configuration becomes read-only. Document that, and leave the shared regmap configuration alone by selecting a separate one without a register cache.

---
 Documentation/hwmon/spd5118.rst |  10 ++++
 drivers/hwmon/spd5118.c         | 110 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 108 insertions(+), 12 deletions(-)
Documentation/hwmon/spd5118.rst +10 -0
index ef7338f46575..dc5a464372d7 100644
@@ -54,6 +54,12 @@ temp1_crit_alarm	Temperature critical alarm
 Alarm attributes are sticky until read and will be cleared afterwards
 unless the alarm condition still applies.
 
+If the chip cannot be written to, for example because the SMBus controller has
+SPD Write Disable set or because the firmware protects the SPD, the driver runs
+the chip read-only. The writable attributes listed above are read-only then, and
+latched alarm conditions are reported as presented by the chip because clearing
+them requires a write.
+
 
 SPD (Serial Presence Detect) support
 ------------------------------------
@@ -61,3 +67,7 @@ SPD (Serial Presence Detect) support
 The driver also supports reading the SPD NVRAM on SPD5118 compatible chips.
 SPD data is available from the 'eeprom' binary attribute file attached to the
 chip's I2C device.
+
+On write protected chips only the first SPD page can be read, because selecting
+another page requires a write. The 'eeprom' attribute is limited to that page in
+this case.
drivers/hwmon/spd5118.c +98 -12

225 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#1 lore raw

cover hwmon: (spd5118) support write protected devices

This patch makes the spd5118 driver usable on systems that do not allow writes to SPD devices, while keeping the temperature sensor available.

Problem
=======
On many systems the SMBus controller is configured to block writes to SPD addresses 0x50-0x57. On the i801 family this is SPD Write Disable (SMBHSTCFG bit 4), set by the BIOS; reads are unaffected. There is no way for a driver to query this.

The driver assumes that it can write to the device, which does not hold on such systems:

- writes to the hwmon attributes always fail with -ENXIO
- the temperature sensor disable in spd5118_suspend() fails silently
- spd5118_resume() fails in regcache_sync(), and the kernel reports a device resume failure:

     spd5118 0-0050: Failed to write b = 0: -6
     spd5118 0-0050: PM: failed to resume async: error -6

Register 0xb in that message is the page selector register, which regmap writes back from its cache at the end of regcache_sync(). The write of the saved configuration register before that fails as well, but the cache code does not report that error.

What the patch does
===================
Detect write protection once at probe time by writing the page selector register back with the value just read from it. This is a no-op on a device which accepts writes, and it fails if writes are blocked. If writes are not possible, run the device read-only:

- drop the register cache (REGCACHE_NONE), so that regcache_sync() cannot attempt any write; this is what makes resume work
- skip the writes in the suspend and resume callbacks
- expose the writable attributes as 0444
- do not clear a latched alarm status from the alarm read path, as that requires a write
- limit the nvmem 'eeprom' attribute to the currently selected page, instead of returning errors for pages that cannot be reached

What is kept
============
The temperature sensor remains usable. For a chip which is already on page 0 - the normal case - reading the temperature and the temperature limits does not need any write: regmap only writes the page selector when the selected page actually changes.

What is not available on such systems
=====================================
- the temperature limits cannot be configured
- the sensor cannot be disabled during suspend, so it keeps running
- SPD EEPROM pages 1..7 are not readable, because selecting a page is itself a write (the attribute is limited accordingly)
- a chip which reports a non-zero page and needs the page reset in spd5118_i2c_init() is still rejected at probe, since that reset is also a write

Relation to earlier proposals
=============================
Two other approaches were posted for the same problem:

1) Make the driver read-only as well, and additionally avoid instantiating it on an i801 adapter when SPD writes are disabled:

hwmon: (spd5118) restrict writes under SPD write protection
https://lore.kernel.org/all/20250416-for-upstream-spd5118-spd-write-prot-detect-v1-2-8b3bcafe9dad@canonical.com/

i2c: i801: don't instantiate spd5118 under SPD Write Disable
https://lore.kernel.org/all/20250430-for-upstream-i801-spd5118-no-instantiate-v2-2f54d91ae2c7@canonical.com/

2) Expose the restriction as an adapter quirk and have spd5118 fail probe, on the grounds that write access is mandatory (including a follow-up suggestion to skip SPD instantiation on such adapters):

i2c: i801: Detect SPD Write Disable and expose as adapter quirk
https://lore.kernel.org/all/[email protected]/

This patch is deliberately limited to the driver side. It is complementary to gating instantiation on the adapter side rather than competing with it:
not instantiating avoids probing a driver which cannot work on a given bus, while tolerating a write protected device keeps the driver correct when it is instantiated anyway - from devicetree, from userspace via new_device, or on a controller which blocks SPD writes without the adapter driver knowing about it.

The trade-off this patch makes is that DDR5 memory temperature monitoring keeps working on affected systems, instead of not being available at all.

Testing
=======
Tested on a Lenovo ThinkPad P1 Gen 9 (DDR5), with SPD Write Disable set by the BIOS:

- before: suspend-to-idle woke immediately; suspend_stats.failed_resume incremented on every cycle (14 times) and last_failed_dev was "0-0050"
- after: 10 suspend/resume cycles with failed_resume and failed_suspend remaining 0
- the chip is still detected and reports its temperature; the writable attributes are 0444

Kean Ren (1):
hwmon: (spd5118) support write protected devices

 Documentation/hwmon/spd5118.rst |  10 ++++
 drivers/hwmon/spd5118.c         | 110 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 108 insertions(+), 12 deletions(-)
Signature · 1 line
2.53.0
#2 lore raw
In reply to Kean Ren
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 13 lines

Some systems do not allow writes to SPD devices. On the i801 SMBus controller family this happens when the BIOS sets SPD Write Disable, in which case the controller refuses writes to addresses 0x50-0x57; other platforms may enforce the same in firmware. There is no way for the driver to query this.

spd5118 assumes that it can write to the device, which does not hold on such systems:

- writes to the hwmon attributes always fail with -ENXIO
- the temperature sensor disable in spd5118_suspend() fails silently
- spd5118_resume() fails in regcache_sync(), and the system reports

Quoted 8 lines

spd5118 0-0050: Failed to write b = 0: -6
spd5118 0-0050: PM: failed to resume async: error -6
[ ... ]
becomes read-only. Document that, and leave the shared regmap configuration alone by selecting a separate one without a register cache.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw
In reply to Kean Ren
Quoted 32 lines · Kean Ren

Some systems do not allow writes to SPD devices. On the i801 SMBus controller family this happens when the BIOS sets SPD Write Disable, in which case the controller refuses writes to addresses 0x50-0x57; other platforms may enforce the same in firmware. There is no way for the driver to query this.

spd5118 assumes that it can write to the device, which does not hold on such systems:

- writes to the hwmon attributes always fail with -ENXIO
- the temperature sensor disable in spd5118_suspend() fails silently
- spd5118_resume() fails in regcache_sync(), and the system reports

spd5118 0-0050: Failed to write b = 0: -6 spd5118 0-0050: PM: failed to resume async: error -6

Register 0xb in that message is the page selector register, which regmap writes back from its cache at the end of regcache_sync(). The write of the saved configuration register before that fails as well, but the cache code does not report that error.

Detect write protection once at probe time by writing the page selector register back with the value just read from it. This is a no-op on a device which accepts writes, and it fails if writes are blocked.

If writes are not possible, run the device read-only: drop the register cache so that regcache_sync() cannot attempt any write, skip the writes in the suspend and resume callbacks, and make the writable attributes read only. Alarm attributes are read only already; stop clearing a latched status from them, since that requires a write, and report the condition as the device presents it.

Quoted 4 lines

Reading the SPD NVRAM beyond the first page requires switching pages, which is itself a write. Restrict the 'eeprom' attribute to the page which can be read in that case, instead of returning errors for the accessible part.

It doesn't add value to only return page 0 of NVMEM.

Quoted 5 lines

The temperature sensor remains fully usable; only its configuration becomes read-only. Document that, and leave the shared regmap configuration alone by selecting a separate one without a register cache.

I had thought about implementing read-only mode, but there is no guarantee that the BIOS doesn't select a different page during a suspend/resume cycle. For that reason, the read-only mode can not be supported. Sorry, I am not going to apply this patch.

Thanks,
Guenter

author
#4 lore raw

From: Kean Ren <[email protected]>

Hi Guenter,

Thanks for the review and for the detailed explanation. I agree that read-only mode cannot be supported reliably if the BIOS can change the page selector across suspend/resume, and that exposing only page 0 of the NVMEM is not useful. I'll drop this patch.

Sorry for the noise.

Thanks,
Kean