* [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
@ 2023-05-06 7:33 gaoxu 00016977
2023-05-15 6:59 ` gaoxu
2023-05-16 19:41 ` Suren Baghdasaryan
0 siblings, 2 replies; 3+ messages in thread
From: gaoxu 00016977 @ 2023-05-06 7:33 UTC (permalink / raw)
To: hch, m.szyprowski
Cc: robin.murphy, iommu, linux-kernel, surenb, yipengxiang 00013268,
wangbintian 00013160, hanfeng 00012985
If dma_direct_alloc() alloc memory in size of 64MB, the inner function
dma_common_contiguous_remap() will allocate 128KB memory by invoking
the function kmalloc_array(). and the kmalloc_array seems to fail to try to
allocate 128KB mem. work around by doing kvmalloc_array instead.
Signed-off-by: Gao Xu <gaoxu2@hihonor.com>
---
kernel/dma/remap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index b45266680..27596f3b4 100644
--- a/kernel/dma/remap.c
+++ b/kernel/dma/remap.c
@@ -43,13 +43,13 @@ void *dma_common_contiguous_remap(struct page *page, size_t size,
void *vaddr;
int i;
- pages = kmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
+ pages = kvmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
if (!pages)
return NULL;
for (i = 0; i < count; i++)
pages[i] = nth_page(page, i);
vaddr = vmap(pages, count, VM_DMA_COHERENT, prot);
- kfree(pages);
+ kvfree(pages);
return vaddr;
}
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
2023-05-06 7:33 [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap gaoxu 00016977
@ 2023-05-15 6:59 ` gaoxu
2023-05-16 19:41 ` Suren Baghdasaryan
1 sibling, 0 replies; 3+ messages in thread
From: gaoxu @ 2023-05-15 6:59 UTC (permalink / raw)
To: hch, m.szyprowski
Cc: robin.murphy, iommu, linux-kernel, surenb, yipengxiang,
wangbintian 00013160
Please help to review, thanks.
-----Original Message-----
From: gaoxu 00016977
Sent: 2023年5月6日 15:34
To: 'hch@lst.de' <hch@lst.de>; 'm.szyprowski@samsung.com' <m.szyprowski@samsung.com>
Cc: 'robin.murphy@arm.com' <robin.murphy@arm.com>; 'iommu@lists.linux.dev' <iommu@lists.linux.dev>; 'linux-kernel@vger.kernel.org' <linux-kernel@vger.kernel.org>; 'surenb@google.com' <surenb@google.com>; yipengxiang 00013268 <yipengxiang@hihonor.com>; wangbintian 00013160 <bintian.wang@hihonor.com>; hanfeng 00012985 <feng.han@hihonor.com>
Subject: [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
If dma_direct_alloc() alloc memory in size of 64MB, the inner function
dma_common_contiguous_remap() will allocate 128KB memory by invoking the function kmalloc_array(). and the kmalloc_array seems to fail to try to allocate 128KB mem. work around by doing kvmalloc_array instead.
Signed-off-by: Gao Xu <gaoxu2@hihonor.com>
---
kernel/dma/remap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index b45266680..27596f3b4 100644
--- a/kernel/dma/remap.c
+++ b/kernel/dma/remap.c
@@ -43,13 +43,13 @@ void *dma_common_contiguous_remap(struct page *page, size_t size,
void *vaddr;
int i;
- pages = kmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
+ pages = kvmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
if (!pages)
return NULL;
for (i = 0; i < count; i++)
pages[i] = nth_page(page, i);
vaddr = vmap(pages, count, VM_DMA_COHERENT, prot);
- kfree(pages);
+ kvfree(pages);
return vaddr;
}
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
2023-05-06 7:33 [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap gaoxu 00016977
2023-05-15 6:59 ` gaoxu
@ 2023-05-16 19:41 ` Suren Baghdasaryan
1 sibling, 0 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2023-05-16 19:41 UTC (permalink / raw)
To: gaoxu 00016977
Cc: hch, m.szyprowski, robin.murphy, iommu, linux-kernel,
yipengxiang 00013268, wangbintian 00013160, hanfeng 00012985
On Sat, May 6, 2023 at 12:33 AM gaoxu 00016977 <gaoxu2@hihonor.com> wrote:
>
> If dma_direct_alloc() alloc memory in size of 64MB, the inner function
> dma_common_contiguous_remap() will allocate 128KB memory by invoking
> the function kmalloc_array(). and the kmalloc_array seems to fail to try to
> allocate 128KB mem. work around by doing kvmalloc_array instead.
On systems like Android it's not unusual for order 5 allocation to
fail. The change seems safe to me with no downside since kvmalloc will
try kmalloc first.
>
> Signed-off-by: Gao Xu <gaoxu2@hihonor.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
> ---
> kernel/dma/remap.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index b45266680..27596f3b4 100644
> --- a/kernel/dma/remap.c
> +++ b/kernel/dma/remap.c
> @@ -43,13 +43,13 @@ void *dma_common_contiguous_remap(struct page *page, size_t size,
> void *vaddr;
> int i;
>
> - pages = kmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
> + pages = kvmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
> if (!pages)
> return NULL;
> for (i = 0; i < count; i++)
> pages[i] = nth_page(page, i);
> vaddr = vmap(pages, count, VM_DMA_COHERENT, prot);
> - kfree(pages);
> + kvfree(pages);
>
> return vaddr;
> }
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-16 19:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-06 7:33 [PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap gaoxu 00016977
2023-05-15 6:59 ` gaoxu
2023-05-16 19:41 ` Suren Baghdasaryan
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.