Skip to contentSkip to conversation

nvme-pci: another 64-bit division for the host memory buffer code

PATCH New Christoph Hellwig 3 participants 4 messages Jun 13, 2017 – Jun 15, 2017 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme-pci: another 64-bit division for the host memory buffer code

[to be folded into "nvme-pci: implement host memory buffer support"]

Signed-off-by Christoph Hellwig <hch at lst.de>

---

Now tested with a full i386 build, sigh..

---
 drivers/nvme/host/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +4 -2
index 788bb2c479d0..4b50fef1fa1b 100644
@@ -1591,12 +1591,14 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
 	struct nvme_host_mem_buf_desc *descs;
 	u32 chunk_size, max_entries, i = 0;
 	void **bufs;
-	u64 size;
+	u64 size, tmp;
 
 	/* start big and work our way down */
 	chunk_size = min(preferred, (u64)PAGE_SIZE << MAX_ORDER);
 retry:
-	max_entries = DIV_ROUND_UP(preferred, chunk_size);
+	tmp = (preferred + chunk_size - 1);
+	do_div(tmp, chunk_size);
+	max_entries = tmp;
 	descs = kcalloc(max_entries, sizeof(*descs), GFP_KERNEL);
 	if (!descs)
 		goto out;
Signature · 1 line
2.11.0
maintainer
#1 lore raw

PATCH 1/1 nvme-pci: another 64-bit division for the host memory buffer code

This looks fine, but is there a good reason why shouldn't DIV_ROUND_UP take care of that instead of you open-coding it?

Reviewed-by Sagi Grimberg <sagi at rimberg.me>
Quoted 33 lines · Christoph Hellwig

[to be folded into "nvme-pci: implement host memory buffer support"]

Signed-off-by Christoph Hellwig <hch at lst.de>

---

Now tested with a full i386 build, sigh..

---
  drivers/nvme/host/pci.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +4 -2
index 788bb2c479d0..4b50fef1fa1b 100644
@@ -1591,12 +1591,14 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
  	struct nvme_host_mem_buf_desc *descs;
  	u32 chunk_size, max_entries, i = 0;
  	void **bufs;
-	u64 size;
+	u64 size, tmp;
 
  	/* start big and work our way down */
  	chunk_size = min(preferred, (u64)PAGE_SIZE << MAX_ORDER);
  retry:
-	max_entries = DIV_ROUND_UP(preferred, chunk_size);
+	tmp = (preferred + chunk_size - 1);
+	do_div(tmp, chunk_size);
+	max_entries = tmp;
  	descs = kcalloc(max_entries, sizeof(*descs), GFP_KERNEL);
  	if (!descs)
  		goto out;
author maintainer
#2 lore raw

PATCH 1/1 nvme-pci: another 64-bit division for the host memory buffer code

Quoted 3 lines · Sagi Grimberg

This looks fine, but is there a good reason why shouldn't DIV_ROUND_UP take care of that instead of you open-coding it?

Because it uses a plain division, and Linux on most 32-bit architectures doesn't support that, as Linus doesn't want the required libgcc helpers in the kernel.

#3 lore raw

PATCH 1/1 nvme-pci: another 64-bit division for the host memory buffer code

In reply to Christoph Hellwig

Looks fine.

Reviewed-by Keith Busch <keith.busch at intel.com>
Quoted 35 lines · Christoph Hellwig

[to be folded into "nvme-pci: implement host memory buffer support"]

Signed-off-by Christoph Hellwig <hch at lst.de>

---

Now tested with a full i386 build, sigh..

---
 drivers/nvme/host/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +4 -2
index 788bb2c479d0..4b50fef1fa1b 100644
@@ -1591,12 +1591,14 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
 	struct nvme_host_mem_buf_desc *descs;
 	u32 chunk_size, max_entries, i = 0;
 	void **bufs;
-	u64 size;
+	u64 size, tmp;
 
 	/* start big and work our way down */
 	chunk_size = min(preferred, (u64)PAGE_SIZE << MAX_ORDER);
 retry:
-	max_entries = DIV_ROUND_UP(preferred, chunk_size);
+	tmp = (preferred + chunk_size - 1);
+	do_div(tmp, chunk_size);
+	max_entries = tmp;
 	descs = kcalloc(max_entries, sizeof(*descs), GFP_KERNEL);
 	if (!descs)
 		goto out;
Signature · 1 line
2.11.0