Skip to content

Commit 9620cfb

Browse files
author
Christoph Hellwig
committed
nvme-pci: propagate (some) errors from host memory buffer setup
We want to catch command execution errors when resetting the device, so propagate errors from the Set Features when setting up the host memory buffer. We keep ignoring memory allocation failures, as the spec clearly says that the controller must work without a host memory buffer. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Cc: [email protected]
1 parent 30f92d6 commit 9620cfb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/nvme/host/pci.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,20 +1693,21 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
16931693
return -ENOMEM;
16941694
}
16951695

1696-
static void nvme_setup_host_mem(struct nvme_dev *dev)
1696+
static int nvme_setup_host_mem(struct nvme_dev *dev)
16971697
{
16981698
u64 max = (u64)max_host_mem_size_mb * SZ_1M;
16991699
u64 preferred = (u64)dev->ctrl.hmpre * 4096;
17001700
u64 min = (u64)dev->ctrl.hmmin * 4096;
17011701
u32 enable_bits = NVME_HOST_MEM_ENABLE;
1702+
int ret = 0;
17021703

17031704
preferred = min(preferred, max);
17041705
if (min > max) {
17051706
dev_warn(dev->ctrl.device,
17061707
"min host memory (%lld MiB) above limit (%d MiB).\n",
17071708
min >> ilog2(SZ_1M), max_host_mem_size_mb);
17081709
nvme_free_host_mem(dev);
1709-
return;
1710+
return 0;
17101711
}
17111712

17121713
/*
@@ -1723,16 +1724,18 @@ static void nvme_setup_host_mem(struct nvme_dev *dev)
17231724
if (nvme_alloc_host_mem(dev, min, preferred)) {
17241725
dev_warn(dev->ctrl.device,
17251726
"failed to allocate host memory buffer.\n");
1726-
return;
1727+
return 0; /* controller must work without HMB */
17271728
}
17281729

17291730
dev_info(dev->ctrl.device,
17301731
"allocated %lld MiB host memory buffer.\n",
17311732
dev->host_mem_size >> ilog2(SZ_1M));
17321733
}
17331734

1734-
if (nvme_set_host_mem(dev, enable_bits))
1735+
ret = nvme_set_host_mem(dev, enable_bits);
1736+
if (ret)
17351737
nvme_free_host_mem(dev);
1738+
return ret;
17361739
}
17371740

17381741
static int nvme_setup_io_queues(struct nvme_dev *dev)
@@ -2176,8 +2179,11 @@ static void nvme_reset_work(struct work_struct *work)
21762179
"unable to allocate dma for dbbuf\n");
21772180
}
21782181

2179-
if (dev->ctrl.hmpre)
2180-
nvme_setup_host_mem(dev);
2182+
if (dev->ctrl.hmpre) {
2183+
result = nvme_setup_host_mem(dev);
2184+
if (result < 0)
2185+
goto out;
2186+
}
21812187

21822188
result = nvme_setup_io_queues(dev);
21832189
if (result)

0 commit comments

Comments
 (0)