Skip to contentSkip to conversation

nvme-pci: shut down the controller if disabling the HMB fails on suspend

PATCH Applied Yuho Choi 3 participants 3 messages Oct 22 – Nov 6 NVMe

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 nvme-pci: shut down the controller if disabling the HMB fails on suspend

nvme_suspend() disables the host memory buffer before it moves the controller to a non-operational power state, as host memory access may not work in a system suspend state. It only treats a negative return from nvme_set_host_mem() as a failure, though. If the controller fails the Set Features command with an NVMe status, the HMB stays enabled and the controller is suspended with it in use.

On resume, nvme_setup_host_mem() then tries to enable the buffer again. If the controller rejects that, the buffer is freed while the controller can still access it, and the reset that nvme_resume() falls back to is not scheduled, as the controller is still LIVE.

Handle a positive status like the power state change below does: shut the controller down, so that it no longer accesses the buffer and is reset on resume.

Fixes e5ad96f388b7 ("nvme-pci: disable hmb on idle suspend")
Assisted-by LLM

---
This was found by code inspection as part of ongoing, not yet published research. It has not been reproduced on hardware. Compile-tested only (x86_64 defconfig with BLK_DEV_NVME=y, W=1).

 drivers/nvme/host/pci.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/nvme/host/pci.c +8 -0
index 77317e5d00f9..268d8fe0ac90 100644
@@ -3997,6 +3997,14 @@ static int nvme_suspend(struct device *dev)
 		ret = nvme_set_host_mem(ndev, 0);
 		if (ret < 0)
 			goto unfreeze;
+		if (ret) {
+			/*
+			 * The controller may still access the HMB. Shut it
+			 * down instead, which forces a reset on resume.
+			 */
+			ret = nvme_disable_prepare_reset(ndev, true);
+			goto unfreeze;
+		}
 	}
 
 	ret = nvme_get_power_state(ctrl, &ndev->last_ps);

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Yuho Choi

This was found by code inspection as part of ongoing, not yet published research. It has not been reproduced on hardware. Compile-tested only (x86_64 defconfig with BLK_DEV_NVME=y, W=1).

Yeah, the only way this really should happen is a communication failure. But your handling looks correct, so:

maintainer Applied
#2 lore raw
In reply to Yuho Choi
Quoted 8 lines · Yuho Choi

nvme_suspend() disables the host memory buffer before it moves the controller to a non-operational power state, as host memory access may not work in a system suspend state. It only treats a negative return from nvme_set_host_mem() as a failure, though. If the controller fails the Set Features command with an NVMe status, the HMB stays enabled and the controller is suspended with it in use.

[...]

Thanks, applied to nvme-7.4.

[1/1] nvme-pci: shut down the controller if disabling the HMB fails on suspend

      commit: 82dd68297483afdc3be48e9d77f2dc4adb7a6941

--
Keith Busch <[email protected]>