Skip to contentSkip to conversation

net: ethernet: mellanox: correct page conversion

PATCH In review [email protected] 2 participants 2 messages Feb 26, 2015 – Mar 15, 2015 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ethernet: mellanox: correct page conversion

From: Sinan Kaya <[email protected]>

Current code is assuming that the addresses returned by dma_alloc_coherent is a logical address. This is not true on ARM/ARM64 systems. This patch uses dma_to_phys API to reach to the actual physical address and then convert to the page pointer.

---
 drivers/net/ethernet/mellanox/mlx4/alloc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/alloc.c +7 -2
index 963dd7e..8eca66a 100644
@@ -634,8 +634,13 @@ int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
 			pages = kmalloc(sizeof *pages * buf->nbufs, gfp);
 			if (!pages)
 				goto err_free;
-			for (i = 0; i < buf->nbufs; ++i)
-				pages[i] = virt_to_page(buf->page_list[i].buf);
+			for (i = 0; i < buf->nbufs; ++i) {
+				phys_addr_t phys;
+
+				phys = dma_to_phys(&dev->pdev->dev,
+						   buf->page_list[i].map);
+				pages[i] = phys_to_page(phys);
+			}
 			buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
 			kfree(pages);
 			if (!buf->direct.buf)
Signature · 8 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1424977168-19523-1-git-send-email-timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org

#2 lore raw
Quoted 34 lines · On Thu, Feb 26, 2015 at 8:59 PM, <[email protected]…

From: Sinan Kaya <[email protected]>

Current code is assuming that the addresses returned by dma_alloc_coherent is a logical address. This is not true on ARM/ARM64 systems. This patch uses dma_to_phys API to reach to the actual physical address and then convert to the page pointer.

---
 drivers/net/ethernet/mellanox/mlx4/alloc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/alloc.c +7 -3
index 963dd7e..8eca66a 100644
@@ -634,8 +634,13 @@ int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
                        pages = kmalloc(sizeof *pages * buf->nbufs, gfp);
                        if (!pages)
                                goto err_free;
-                       for (i = 0; i < buf->nbufs; ++i)
-                               pages[i] = virt_to_page(buf->page_list[i].buf);
+                       for (i = 0; i < buf->nbufs; ++i) {
+                               phys_addr_t phys;
+
+                               phys = dma_to_phys(&dev->pdev->dev,
+                                                  buf->page_list[i].map);
+                               pages[i] = phys_to_page(phys);
+                       }
                        buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
                        kfree(pages);
                        if (!buf->direct.buf)
--
Quoted 4 lines

Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

This will not compile on non ARM arch. For example x86:

drivers/net/ethernet/mellanox/mlx4/alloc.c: In function ‘mlx4_buf_alloc’:
drivers/net/ethernet/mellanox/mlx4/alloc.c:642:5: error: implicit declaration of function ‘phys_to_page’ [-Werror=implicit-function-declaration]

     pages[i] = phys_to_page(phys);

Amir
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html