nvme/pci: Fix HMB size calculation
PATCH 1/1 nvme/pci: Fix HMB size calculation
It's possible the preferred HMB size may not be a multiple of the chunk_size. This patch will set the chunk_size to the descriptor's actual length so the last iteration doesn't cause the total size to exceed the allocated HMB size.
--- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +1 -0
@@ -1641,6 +1641,7 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)if (!bufs[i])break ; + chunk_size = len; descs[i].addr =cpu_to_le64 (dma_addr); descs[i].size =cpu_to_le32 (len / dev->ctrl.page_size); i++;
Signature · 1 line
2.5.5
PATCH 1/1 nvme/pci: Fix HMB size calculation
Quoted 6 lines · Keith Busch
It's possible the preferred HMB size may not be a multiple of the
chunk_size. This patch will set thechunk_sizeto the descriptor's actual length so the last iteration doesn't cause the total size to exceed the allocated HMB size.Signed-off-by Keith Busch <keith.busch at intel.com>
Quoted 19 lines
--- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+)drivers/nvme/host/pci.c +1
-0@@ -1641,6 +1641,7 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)if (!bufs[i])break ; + chunk_size = len; descs[i].addr =cpu_to_le64 (dma_addr); descs[i].size =cpu_to_le32 (len / dev->ctrl.page_size); i++;Signature · 1 line
2.5.5
Christoph Hellwig
maintainerPATCH 1/1 nvme/pci: Fix HMB size calculation
In reply to Keith BuschQuoted 4 lines · Keith Busch
It's possible the preferred HMB size may not be a multiple of the
chunk_size. This patch will set thechunk_sizeto the descriptor's actual length so the last iteration doesn't cause the total size to exceed the allocated HMB size.
This looks a little weird, and might do the wrong thing if we hit the retry loop after reducing chunk_size.
I suspect we just need to change to
for (size = 0; size < preferred; size += len) {and move len to function scope.
PATCH 1/1 nvme/pci: Fix HMB size calculation
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Keith Busch
It's possible the preferred HMB size may not be a multiple of the
chunk_size. This patch will set thechunk_sizeto the descriptor's actual length so the last iteration doesn't cause the total size to exceed the allocated HMB size.This looks a little weird, and might do the wrong thing if we hit the retry loop after reducing
chunk_size.
It may look weird when you consider the retry, but I'm pretty sure it isn't wrong. The only way you can get to the retry is if the for-loop breaks before the last interation, which means chunk_size will be unchanged. That's not immediately obvious, though, so maybe this implementation was trying to be too clever.
Quoted 5 lines
I suspect we just need to change to
for (size = 0; size < preferred; size += len) {and move len to function scope.
That's fine too.