iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [RESEND  PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
@ 2023-06-06 13:05 gaoxu
  0 siblings, 0 replies; 3+ messages in thread
From: gaoxu @ 2023-06-06 13:05 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski
  Cc: Robin Murphy, iommu, linux-kernel, Suren Baghdasaryan,
	yipengxiang, wangbintian(BintianWang)

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. 

Call trace:
[14977.928623] qcrosvm: page allocation failure: order:5, mode:0x40cc0
[14977.928638] dump_backtrace.cfi_jt+0x0/0x8
[14977.928647] dump_stack_lvl+0x80/0xb8
[14977.928652] warn_alloc+0x164/0x200
[14977.928657] __alloc_pages_slowpath+0x9f0/0xb4c
[14977.928660] __alloc_pages+0x21c/0x39c
[14977.928662] kmalloc_order+0x48/0x108
[14977.928666] kmalloc_order_trace+0x34/0x154
[14977.928668] __kmalloc+0x548/0x7e4
[14977.928673] dma_direct_alloc+0x11c/0x4f8
[14977.928678] dma_alloc_attrs+0xf4/0x138
[14977.928680] gh_vm_ioctl_set_fw_name+0x3c4/0x610 [gunyah]
[14977.928698] gh_vm_ioctl+0x90/0x14c [gunyah]
[14977.928705] __arm64_sys_ioctl+0x184/0x210

work around by doing kvmalloc_array instead.

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

* Re: [RESEND  PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
  2023-06-06 12:47 gaoxu
@ 2023-06-07 13:07 ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2023-06-07 13:07 UTC (permalink / raw)
  To: gaoxu
  Cc: Christoph Hellwig, Marek Szyprowski, Robin Murphy, iommu,
	linux-kernel, Suren Baghdasaryan, yipengxiang,
	wangbintian(BintianWang)

Thanks,

applied to for-next.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RESEND  PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap
@ 2023-06-06 12:47 gaoxu
  2023-06-07 13:07 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: gaoxu @ 2023-06-06 12:47 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski
  Cc: Robin Murphy, iommu, linux-kernel, Suren Baghdasaryan,
	yipengxiang, wangbintian(BintianWang)

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. 

Call trace:
[14977.928623] qcrosvm: page allocation failure: order:5, mode:0x40cc0
[14977.928638] dump_backtrace.cfi_jt+0x0/0x8
[14977.928647] dump_stack_lvl+0x80/0xb8
[14977.928652] warn_alloc+0x164/0x200
[14977.928657] __alloc_pages_slowpath+0x9f0/0xb4c
[14977.928660] __alloc_pages+0x21c/0x39c
[14977.928662] kmalloc_order+0x48/0x108
[14977.928666] kmalloc_order_trace+0x34/0x154
[14977.928668] __kmalloc+0x548/0x7e4
[14977.928673] dma_direct_alloc+0x11c/0x4f8
[14977.928678] dma_alloc_attrs+0xf4/0x138
[14977.928680] gh_vm_ioctl_set_fw_name+0x3c4/0x610 [gunyah]
[14977.928698] gh_vm_ioctl+0x90/0x14c [gunyah]
[14977.928705] __arm64_sys_ioctl+0x184/0x210

work around by doing kvmalloc_array instead.

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-06-07 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06 13:05 [RESEND PATCH] dma-remap: Use kvmalloc_array/kvfree for larger dma memory remap gaoxu
  -- strict thread matches above, loose matches on Subject: below --
2023-06-06 12:47 gaoxu
2023-06-07 13:07 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).