All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] staging: ion: Fix ion_cma_heap allocations
@ 2017-12-13 21:26 John Stultz
  2017-12-14  7:21 ` Greg KH
  2017-12-14  7:22 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: John Stultz @ 2017-12-13 21:26 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Laura Abbott, Sumit Semwal, Benjamin Gaignard,
	Archit Taneja, Greg KH, Daniel Vetter, Dmitry Shmidt, Todd Kjos,
	Amit Pundir

In trying to add support for drm_hwcomposer to HiKey,
I've needed to utilize the ION CMA heap, and I've noticed
problems with allocations on newer kernels failing.

It seems back with 204f672255c2 ("ion: Use CMA APIs directly"),
the ion_cma_heap code was modified to use the CMA API, but
kept the arguments as buffer lengths rather then number of pages.

This results in errors as we don't have enough pages in CMA to
satisfy the exaggerated requests.

This patch converts the ion_cma_heap CMA API usage to properly
request pages.

It also fixes a minor issue in the allocation where in the error
path, the cma_release is called with the buffer->size value which
hasn't yet been set.

Cc: Laura Abbott <labbott@redhat.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Cc: Archit Taneja <architt@codeaurora.org>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dmitry Shmidt <dimitrysh@google.com>
Cc: Todd Kjos <tkjos@google.com>
Cc: Amit Pundir <amit.pundir@linaro.org>
Fixes: 204f672255c2 ("staging: android: ion: Use CMA APIs directly")
Acked-by: Laura Abbott <labbott@redhat.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
v2: Fix build errors when CONFIG_CMA_ALIGNMENT isn't defined

 drivers/staging/android/ion/ion_cma_heap.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index dd5545d..ff405c7 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -31,6 +31,12 @@ struct ion_cma_heap {
 
 #define to_cma_heap(x) container_of(x, struct ion_cma_heap, heap)
 
+#ifdef CONFIG_CMA_ALIGNMENT
+ #define CMA_ALIGNMENT CONFIG_CMA_ALIGNMENT
+#else
+ #define CMA_ALIGNMNET 8
+#endif
+
 /* ION CMA heap operations functions */
 static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 			    unsigned long len,
@@ -39,9 +45,15 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 	struct ion_cma_heap *cma_heap = to_cma_heap(heap);
 	struct sg_table *table;
 	struct page *pages;
+	unsigned long size = PAGE_ALIGN(len);
+	unsigned long nr_pages = size >> PAGE_SHIFT;
+	unsigned long align = get_order(size);
 	int ret;
 
-	pages = cma_alloc(cma_heap->cma, len, 0, GFP_KERNEL);
+	if (align > CMA_ALIGNMENT)
+		align = CMA_ALIGNMENT;
+
+	pages = cma_alloc(cma_heap->cma, nr_pages, align, GFP_KERNEL);
 	if (!pages)
 		return -ENOMEM;
 
@@ -53,7 +65,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 	if (ret)
 		goto free_mem;
 
-	sg_set_page(table->sgl, pages, len, 0);
+	sg_set_page(table->sgl, pages, size, 0);
 
 	buffer->priv_virt = pages;
 	buffer->sg_table = table;
@@ -62,7 +74,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 free_mem:
 	kfree(table);
 err:
-	cma_release(cma_heap->cma, pages, buffer->size);
+	cma_release(cma_heap->cma, pages, nr_pages);
 	return -ENOMEM;
 }
 
@@ -70,9 +82,10 @@ static void ion_cma_free(struct ion_buffer *buffer)
 {
 	struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
 	struct page *pages = buffer->priv_virt;
+	unsigned long nr_pages = PAGE_ALIGN(buffer->size) >> PAGE_SHIFT;
 
 	/* release memory */
-	cma_release(cma_heap->cma, pages, buffer->size);
+	cma_release(cma_heap->cma, pages, nr_pages);
 	/* release sg table */
 	sg_free_table(buffer->sg_table);
 	kfree(buffer->sg_table);
-- 
2.7.4

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

* Re: [PATCH v2] staging: ion: Fix ion_cma_heap allocations
  2017-12-13 21:26 [PATCH v2] staging: ion: Fix ion_cma_heap allocations John Stultz
@ 2017-12-14  7:21 ` Greg KH
  2017-12-14  7:22 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2017-12-14  7:21 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Laura Abbott, Sumit Semwal, Benjamin Gaignard,
	Archit Taneja, Daniel Vetter, Dmitry Shmidt, Todd Kjos,
	Amit Pundir

On Wed, Dec 13, 2017 at 01:26:04PM -0800, John Stultz wrote:
> In trying to add support for drm_hwcomposer to HiKey,
> I've needed to utilize the ION CMA heap, and I've noticed
> problems with allocations on newer kernels failing.
> 
> It seems back with 204f672255c2 ("ion: Use CMA APIs directly"),
> the ion_cma_heap code was modified to use the CMA API, but
> kept the arguments as buffer lengths rather then number of pages.
> 
> This results in errors as we don't have enough pages in CMA to
> satisfy the exaggerated requests.
> 
> This patch converts the ion_cma_heap CMA API usage to properly
> request pages.
> 
> It also fixes a minor issue in the allocation where in the error
> path, the cma_release is called with the buffer->size value which
> hasn't yet been set.
> 
> Cc: Laura Abbott <labbott@redhat.com>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> Cc: Archit Taneja <architt@codeaurora.org>
> Cc: Greg KH <gregkh@linuxfoundation.org>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Dmitry Shmidt <dimitrysh@google.com>
> Cc: Todd Kjos <tkjos@google.com>
> Cc: Amit Pundir <amit.pundir@linaro.org>
> Fixes: 204f672255c2 ("staging: android: ion: Use CMA APIs directly")
> Acked-by: Laura Abbott <labbott@redhat.com>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
> v2: Fix build errors when CONFIG_CMA_ALIGNMENT isn't defined

As v1 is already in my tree, can you send me the diff so I can just
apply that instead of me having to revert the original and then add this
one?

thanks,

greg k-h

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

* Re: [PATCH v2] staging: ion: Fix ion_cma_heap allocations
  2017-12-13 21:26 [PATCH v2] staging: ion: Fix ion_cma_heap allocations John Stultz
  2017-12-14  7:21 ` Greg KH
@ 2017-12-14  7:22 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2017-12-14  7:22 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Laura Abbott, Sumit Semwal, Benjamin Gaignard,
	Archit Taneja, Daniel Vetter, Dmitry Shmidt, Todd Kjos,
	Amit Pundir

On Wed, Dec 13, 2017 at 01:26:04PM -0800, John Stultz wrote:
> In trying to add support for drm_hwcomposer to HiKey,
> I've needed to utilize the ION CMA heap, and I've noticed
> problems with allocations on newer kernels failing.
> 
> It seems back with 204f672255c2 ("ion: Use CMA APIs directly"),
> the ion_cma_heap code was modified to use the CMA API, but
> kept the arguments as buffer lengths rather then number of pages.
> 
> This results in errors as we don't have enough pages in CMA to
> satisfy the exaggerated requests.
> 
> This patch converts the ion_cma_heap CMA API usage to properly
> request pages.
> 
> It also fixes a minor issue in the allocation where in the error
> path, the cma_release is called with the buffer->size value which
> hasn't yet been set.
> 
> Cc: Laura Abbott <labbott@redhat.com>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> Cc: Archit Taneja <architt@codeaurora.org>
> Cc: Greg KH <gregkh@linuxfoundation.org>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Dmitry Shmidt <dimitrysh@google.com>
> Cc: Todd Kjos <tkjos@google.com>
> Cc: Amit Pundir <amit.pundir@linaro.org>
> Fixes: 204f672255c2 ("staging: android: ion: Use CMA APIs directly")
> Acked-by: Laura Abbott <labbott@redhat.com>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
> v2: Fix build errors when CONFIG_CMA_ALIGNMENT isn't defined

Wait, why would CONFIG_CMA_ALIGNMENT not be defined if we are using the
cma code?  Is that a Kconfig issue somehow?

thanks,

greg k-h

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

end of thread, other threads:[~2017-12-14  7:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-13 21:26 [PATCH v2] staging: ion: Fix ion_cma_heap allocations John Stultz
2017-12-14  7:21 ` Greg KH
2017-12-14  7:22 ` Greg KH

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.