From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Hellwig Subject: Re: [RFC][PATCH 3/5 v2] dma-buf: heaps: Add system heap to dmabuf heaps Date: Fri, 15 Mar 2019 02:06:49 -0700 Message-ID: <20190315090649.GD4470@infradead.org> References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-4-git-send-email-john.stultz@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1551819273-640-4-git-send-email-john.stultz@linaro.org> Sender: linux-kernel-owner@vger.kernel.org To: John Stultz Cc: lkml , Laura Abbott , Benjamin Gaignard , Greg KH , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Chenbo Feng , Alistair Strachan , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org > + 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?