2019-10-22 06:59:46

by Omer Shpigelman

[permalink] [raw]
Subject: [PATCH v2 2/2] habanalabs: handle large memory on MMU

This patch changes the allocation of the host memory pages array to use
vmalloc if needed. This in order to support mapping of large memory
chunks.

Signed-off-by: Omer Shpigelman <[email protected]>
---
drivers/misc/habanalabs/memory.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/habanalabs/memory.c b/drivers/misc/habanalabs/memory.c
index 552a47126567..ed3976f2198d 100644
--- a/drivers/misc/habanalabs/memory.c
+++ b/drivers/misc/habanalabs/memory.c
@@ -1228,7 +1228,7 @@ static int init_sg_list_for_vmalloc_memory(struct hl_device *hdev, u64 addr,
u64 tmp_addr;
int i, rc;

- pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
+ pages = kvmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
if (!pages)
return -ENOMEM;

@@ -1249,17 +1249,11 @@ static int init_sg_list_for_vmalloc_memory(struct hl_device *hdev, u64 addr,

rc = sg_alloc_table_from_pages(sgt, pages, npages, offset, size,
GFP_KERNEL);
- if (rc < 0) {
+ if (rc < 0)
dev_err(hdev->dev, "failed to create SG table from pages\n");
- goto free_pages;
- }
-
- kfree(pages);
-
- return 0;

free_pages:
- kfree(pages);
+ kvfree(pages);
return rc;
}

--
2.17.1