[PATCH] dma-buf: dma-heap: Add a size limitation for allocation
guangming.cao at mediatek.com
guangming.cao at mediatek.com
Fri Dec 17 01:41:04 PST 2021
From: Guangming <Guangming.Cao at mediatek.com>
Currently, there is no size check for allocation.
If the alloc size is larger than DRAM, it will cause OOM issue.
Besides, if it runs on a process that won't be killed by OOM flow, it will
cause a kernel exception finally, and we couldn't find the correct
memory usage by dma-buf dump api such as "dma_buf_debug_show" since the
allocation is still on going and the corresponding dmabuf is not exported.
However, it sounds not simple enough to adding a count to count how many
pages has been allocated before allocating done.
So adding a size limitation here to prevent this case.
Signed-off-by: Guangming <Guangming.Cao at mediatek.com>
Signed-off-by: jianjiao zeng <jianjiao.zeng at mediatek.com>
---
drivers/dma-buf/dma-heap.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
index 56bf5ad01ad5..8b75998a106c 100644
--- a/drivers/dma-buf/dma-heap.c
+++ b/drivers/dma-buf/dma-heap.c
@@ -107,6 +107,9 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data)
if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS)
return -EINVAL;
+ if (heap_allocation->len / PAGE_SIZE > totalram_pages() / 2)
+ return -EINVAL;
+
fd = dma_heap_buffer_alloc(heap, heap_allocation->len,
heap_allocation->fd_flags,
heap_allocation->heap_flags);
--
2.17.1
More information about the Linux-mediatek
mailing list