Re: [RFC][PATCH 3/5 v2] dma-buf: heaps: Add system heap to dmabuf heaps

From: Christoph Hellwig
Date: Fri Mar 15 2019 - 05:07:17 EST


> + i = sg_alloc_table(table, npages, GFP_KERNEL);
> + if (i)
> + goto err1;
> + for_each_sg(table->sgl, sg, table->nents, i) {
> + struct page *page;
> +
> + page = alloc_page(GFP_KERNEL);
> + if (!page)
> + goto err2;
> + sg_set_page(sg, page, PAGE_SIZE, 0);
> + }

Given that one if not the primary intent here is to DMA map the memory
this is a bad idea, as it might require bounce buffering.

What we really want here is something like this:

http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/dma-noncoherent-allocator.3

And I wonder if the S/G building should also move into common code
instead of being duplicated everywhere.

> +static int system_heap_create(void)
> +{
> + struct system_heap *sys_heap;
> +
> + sys_heap = kzalloc(sizeof(*sys_heap), GFP_KERNEL);
> + if (!sys_heap)
> + return -ENOMEM;
> + sys_heap->heap.name = "system_heap";
> + sys_heap->heap.ops = &system_heap_ops;
> +
> + dma_heap_add(&sys_heap->heap);

Why is this dynamically allocated?