Skip to content

nvme: make SMART / Health Status AENs reach hwmon alarms

Guixin Liu linux-nvme 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest1 patch 1 replyIn review
  2. v21 patch 2 repliesSuperseded
  3. v12 patches 1 replySuperseded

Changes in v3 from the cover letter

- exclude transports that do not implement asynchronous event requests from the subscription: apple-nvme reports no OAES support but registers hwmon, which would have queued the async event work and dereferenced a NULL submit_async_event callback (sashiko)
- embed the SMART work in nvme_ctrl and only queue it while the controller is live, so that a work item left over from before a reset does not issue a blocking admin command against a quiesced queue, and the work memory is tied to the controller lifetime (sashiko)
- only notify temp1_alarm when the re-read SMART log has the temperature critical warning set, so non-temperature events enabled through passthrough do not produce false alarms (sashiko)
- fall back to the notice-only Asynchronous Event Configuration when the controller rejects the critical warning subscription with Invalid Field in Command -- the SHCW bits have no capability field to probe, so the subscription itself is the only probe -- and return early when the reduced mask is empty, so the notice events are not lost with the subscription (sashiko)
- drain the SMART work before freeing its data during controller teardown, so that a late asynchronous event completion cannot dereference freed memory (sashiko)

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1nvme-hwmon: notify hwmon alarms on the SMART / Health Status AENdrivers/nvme/host/core.c drivers/nvme/host/hwmon.c drivers/nvme/host/nvme.h+73 -11 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/1] nvme: make SMART / Health Status AENs reach hwmon alarms

The NVMe hwmon support exposes the temperature alarm as a plain sysfs attribute, so monitoring tools have to poll temp1_alarm to learn about a critical temperature condition. The device does send a SMART / Health Status asynchronous event when a critical warning is raised, but the host never enables it in the Asynchronous Event Configuration, and the completion path silently drops the event.

The temperature warning is subscribed unconditionally when hwmon is present (it has no OAES capability bit), a work item embedded in nvme_ctrl re-reads the SMART log to clear the latched event -- the same shape as the namespace scan reading the changed namespace list -- and the alarm is announced with hwmon_notify_event(), which also feeds the registered thermal zone.

Testing: verified end to end against QEMU's nvme emulation: injecting smart_critical_warning over QMP delivers the AEN, poll(2) on temp1_alarm wakes immediately with EPOLLERR|EPOLLPRI and reads alarm=1; clearing the warning produces no event and no spurious wake; re-injecting the bit wakes again; enabling the spare-block warning through an admin passthrough delivers the AEN without waking the temperature alarm; a controller modeled to reject the critical warning subscription with Invalid Field in Command falls back to the notice-only mask, which a Get Features of the Asynchronous Event Configuration confirms.

Changes since v2:

- exclude transports that do not implement asynchronous event requests from the subscription: apple-nvme reports no OAES support but registers hwmon, which would have queued the async event work and dereferenced a NULL submit_async_event callback (sashiko)
- embed the SMART work in nvme_ctrl and only queue it while the controller is live, so that a work item left over from before a reset does not issue a blocking admin command against a quiesced queue, and the work memory is tied to the controller lifetime (sashiko)
- only notify temp1_alarm when the re-read SMART log has the temperature critical warning set, so non-temperature events enabled through passthrough do not produce false alarms (sashiko)
- fall back to the notice-only Asynchronous Event Configuration when the controller rejects the critical warning subscription with Invalid Field in Command -- the SHCW bits have no capability field to probe, so the subscription itself is the only probe -- and return early when the reduced mask is empty, so the notice events are not lost with the subscription (sashiko)
- drain the SMART work before freeing its data during controller teardown, so that a late asynchronous event completion cannot dereference freed memory (sashiko)

Changes since v1:

- drop the uapi patch defining an OAES bit for the SMART event: OAES bits 7:0 are reserved; the warning is configured through the SMART / Health Critical Warnings field of the Asynchronous Event Configuration feature (sashiko)
- subscribe to the temperature warning unconditionally when hwmon is present, instead of masking against ctrl->oaes (sashiko)
- re-read the SMART log in the deferred work to clear the latched event, like the namespace scan does for the changed namespace list (sashiko)
- call hwmon_notify_event() instead of sysfs_notify(), so the thermal zone registered with HWMON_C_REGISTER_TZ is fed as well (sashiko)
- correct the cover letter: temp1_alarm reflects the temperature warning only, not the spare-block condition

Guixin Liu (1):
nvme-hwmon: notify hwmon alarms on the SMART / Health Status AEN

 drivers/nvme/host/core.c  | 26 +++++++++++++++++++++++++-
 drivers/nvme/host/hwmon.c | 32 ++++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h  | 16 +++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)

--
2.43.7