* [PATCH] nvme/pci: Fix HMB size calculation
@ 2017-07-17 23:45 Keith Busch
2017-07-17 23:47 ` Keith Busch
2017-07-18 17:39 ` Christoph Hellwig
0 siblings, 2 replies; 4+ messages in thread
From: Keith Busch @ 2017-07-17 23:45 UTC (permalink / raw)
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.
Signed-off-by: Keith Busch <keith.busch at intel.com>
---
drivers/nvme/host/pci.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index d321597..e22ffda 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -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++;
--
2.5.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] nvme/pci: Fix HMB size calculation
2017-07-17 23:45 [PATCH] nvme/pci: Fix HMB size calculation Keith Busch
@ 2017-07-17 23:47 ` Keith Busch
2017-07-18 17:39 ` Christoph Hellwig
1 sibling, 0 replies; 4+ messages in thread
From: Keith Busch @ 2017-07-17 23:47 UTC (permalink / raw)
On Mon, Jul 17, 2017@07:45:39PM -0400, Keith Busch wrote:
> 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.
>
> Signed-off-by: Keith Busch <keith.busch at intel.com>
Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
> ---
> drivers/nvme/host/pci.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index d321597..e22ffda 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -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++;
> --
> 2.5.5
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] nvme/pci: Fix HMB size calculation
2017-07-17 23:45 [PATCH] nvme/pci: Fix HMB size calculation Keith Busch
2017-07-17 23:47 ` Keith Busch
@ 2017-07-18 17:39 ` Christoph Hellwig
2017-07-18 18:04 ` Keith Busch
1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2017-07-18 17:39 UTC (permalink / raw)
On Mon, Jul 17, 2017@07:45:39PM -0400, Keith Busch wrote:
> 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.
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] nvme/pci: Fix HMB size calculation
2017-07-18 17:39 ` Christoph Hellwig
@ 2017-07-18 18:04 ` Keith Busch
0 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2017-07-18 18:04 UTC (permalink / raw)
On Tue, Jul 18, 2017@07:39:54PM +0200, Christoph Hellwig wrote:
> On Mon, Jul 17, 2017@07:45:39PM -0400, Keith Busch wrote:
> > 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.
>
> 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.
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-18 18:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-17 23:45 [PATCH] nvme/pci: Fix HMB size calculation Keith Busch
2017-07-17 23:47 ` Keith Busch
2017-07-18 17:39 ` Christoph Hellwig
2017-07-18 18:04 ` Keith Busch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.