linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [RFC] drivers: dma-coherent: pass struct dma_attrs to dma_alloc_from_coherent
@ 2016-12-09  5:05 Jaewon Kim
  2016-12-09  5:05 ` [PATCH] staging: android: ion: return -ENOMEM in ion_cma_heap allocation failure Jaewon Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Jaewon Kim @ 2016-12-09  5:05 UTC (permalink / raw)
  To: gregkh
  Cc: labbott, sumit.semwal, tixy, prime.zeng, tranmanphong,
	fabio.estevam, ccross, rebecca, benjamin.gaignard, arve,
	riandrews, linux-mm, linux-kernel, jaewon31.kim, Jaewon Kim

dma_alloc_from_coherent does not get struct dma_attrs information.
If dma_attrs information is passed to dma_alloc_from_coherent,
dma_alloc_from_coherent can do more jobs accodring to the information.
As a example I added DMA_ATTR_SKIP_ZEROING to skip zeroing. Accoring
to driver implementation ZEROING could be skipped or could be done later.

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 drivers/base/dma-coherent.c | 6 +++++-
 include/linux/dma-mapping.h | 7 ++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index 640a7e6..428eced 100644
--- a/drivers/base/dma-coherent.c
+++ b/drivers/base/dma-coherent.c
@@ -151,6 +151,7 @@ void *dma_mark_declared_memory_occupied(struct device *dev,
  * @dma_handle:	This will be filled with the correct dma handle
  * @ret:	This pointer will be filled with the virtual address
  *		to allocated area.
+ * @attrs:	dma_attrs to pass additional information
  *
  * This function should be only called from per-arch dma_alloc_coherent()
  * to support allocation from per-device coherent memory pools.
@@ -159,7 +160,8 @@ void *dma_mark_declared_memory_occupied(struct device *dev,
  * generic memory areas, or !0 if dma_alloc_coherent should return @ret.
  */
 int dma_alloc_from_coherent(struct device *dev, ssize_t size,
-				       dma_addr_t *dma_handle, void **ret)
+				       dma_addr_t *dma_handle, void **ret,
+				       struct dma_attrs *attrs)
 {
 	struct dma_coherent_mem *mem;
 	int order = get_order(size);
@@ -190,6 +192,8 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t size,
 	*ret = mem->virt_base + (pageno << PAGE_SHIFT);
 	dma_memory_map = (mem->flags & DMA_MEMORY_MAP);
 	spin_unlock_irqrestore(&mem->spinlock, flags);
+	if (dma_get_attr(DMA_ATTR_SKIP_ZEROING, attrs))
+		return 1;
 	if (dma_memory_map)
 		memset(*ret, 0, size);
 	else
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 08528af..737fd71 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -151,13 +151,14 @@ static inline int is_device_dma_capable(struct device *dev)
  * Don't use them in device drivers.
  */
 int dma_alloc_from_coherent(struct device *dev, ssize_t size,
-				       dma_addr_t *dma_handle, void **ret);
+				       dma_addr_t *dma_handle, void **ret,
+				       struct dma_attrs *attrs);
 int dma_release_from_coherent(struct device *dev, int order, void *vaddr);
 
 int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
 			    void *cpu_addr, size_t size, int *ret);
 #else
-#define dma_alloc_from_coherent(dev, size, handle, ret) (0)
+#define dma_alloc_from_coherent(dev, size, handle, ret, attrs) (0)
 #define dma_release_from_coherent(dev, order, vaddr) (0)
 #define dma_mmap_from_coherent(dev, vma, vaddr, order, ret) (0)
 #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
@@ -456,7 +457,7 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size,
 
 	BUG_ON(!ops);
 
-	if (dma_alloc_from_coherent(dev, size, dma_handle, &cpu_addr))
+	if (dma_alloc_from_coherent(dev, size, dma_handle, &cpu_addr, attrs))
 		return cpu_addr;
 
 	if (!arch_dma_alloc_attrs(&dev, &flag))
-- 
1.9.1

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

* [PATCH] staging: android: ion: return -ENOMEM in ion_cma_heap allocation failure
  2016-12-09  5:05 [PATCH] [RFC] drivers: dma-coherent: pass struct dma_attrs to dma_alloc_from_coherent Jaewon Kim
@ 2016-12-09  5:05 ` Jaewon Kim
  2016-12-13 16:04   ` Laura Abbott
  0 siblings, 1 reply; 4+ messages in thread
From: Jaewon Kim @ 2016-12-09  5:05 UTC (permalink / raw)
  To: gregkh
  Cc: labbott, sumit.semwal, tixy, prime.zeng, tranmanphong,
	fabio.estevam, ccross, rebecca, benjamin.gaignard, arve,
	riandrews, linux-mm, linux-kernel, jaewon31.kim, Jaewon Kim

Initial Commit 349c9e138551 ("gpu: ion: add CMA heap") returns -1 in allocation
failure. The returned value is passed up to userspace through ioctl. So user can
misunderstand error reason as -EPERM(1) rather than -ENOMEM(12).

This patch simply changed this to return -ENOMEM.

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 drivers/staging/android/ion/ion_cma_heap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index 6c7de74..22b9582 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -24,8 +24,6 @@
 #include "ion.h"
 #include "ion_priv.h"
 
-#define ION_CMA_ALLOCATE_FAILED -1
-
 struct ion_cma_heap {
 	struct ion_heap heap;
 	struct device *dev;
@@ -59,7 +57,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 
 	info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL);
 	if (!info)
-		return ION_CMA_ALLOCATE_FAILED;
+		return -ENOMEM;
 
 	info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
 						GFP_HIGHUSER | __GFP_ZERO);
@@ -88,7 +86,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
 	dma_free_coherent(dev, len, info->cpu_addr, info->handle);
 err:
 	kfree(info);
-	return ION_CMA_ALLOCATE_FAILED;
+	return -ENOMEM;
 }
 
 static void ion_cma_free(struct ion_buffer *buffer)
-- 
1.9.1

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

* Re: [PATCH] staging: android: ion: return -ENOMEM in ion_cma_heap allocation failure
  2016-12-09  5:05 ` [PATCH] staging: android: ion: return -ENOMEM in ion_cma_heap allocation failure Jaewon Kim
@ 2016-12-13 16:04   ` Laura Abbott
  2016-12-17 12:00     ` Jaewon Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Laura Abbott @ 2016-12-13 16:04 UTC (permalink / raw)
  To: Jaewon Kim, gregkh
  Cc: sumit.semwal, tixy, prime.zeng, tranmanphong, fabio.estevam,
	ccross, rebecca, benjamin.gaignard, arve, riandrews, linux-mm,
	linux-kernel, jaewon31.kim

On 12/08/2016 09:05 PM, Jaewon Kim wrote:
> Initial Commit 349c9e138551 ("gpu: ion: add CMA heap") returns -1 in allocation
> failure. The returned value is passed up to userspace through ioctl. So user can
> misunderstand error reason as -EPERM(1) rather than -ENOMEM(12).
> 
> This patch simply changed this to return -ENOMEM.
> 
> Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
> ---
>  drivers/staging/android/ion/ion_cma_heap.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
> index 6c7de74..22b9582 100644
> --- a/drivers/staging/android/ion/ion_cma_heap.c
> +++ b/drivers/staging/android/ion/ion_cma_heap.c
> @@ -24,8 +24,6 @@
>  #include "ion.h"
>  #include "ion_priv.h"
>  
> -#define ION_CMA_ALLOCATE_FAILED -1
> -
>  struct ion_cma_heap {
>  	struct ion_heap heap;
>  	struct device *dev;
> @@ -59,7 +57,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>  
>  	info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL);
>  	if (!info)
> -		return ION_CMA_ALLOCATE_FAILED;
> +		return -ENOMEM;
>  
>  	info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
>  						GFP_HIGHUSER | __GFP_ZERO);
> @@ -88,7 +86,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>  	dma_free_coherent(dev, len, info->cpu_addr, info->handle);
>  err:
>  	kfree(info);
> -	return ION_CMA_ALLOCATE_FAILED;
> +	return -ENOMEM;
>  }
>  
>  static void ion_cma_free(struct ion_buffer *buffer)
> 

Happy to see cleanup

Acked-by: Laura Abbott <labbott@redhat.com>

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

* Re: [PATCH] staging: android: ion: return -ENOMEM in ion_cma_heap allocation failure
  2016-12-13 16:04   ` Laura Abbott
@ 2016-12-17 12:00     ` Jaewon Kim
  0 siblings, 0 replies; 4+ messages in thread
From: Jaewon Kim @ 2016-12-17 12:00 UTC (permalink / raw)
  To: Laura Abbott
  Cc: Jaewon Kim, gregkh, sumit.semwal, tixy, prime.zeng, tranmanphong,
	fabio.estevam, ccross, rebecca, benjamin.gaignard, arve,
	riandrews, linux-mm, linux-kernel

2016-12-14 1:04 GMT+09:00 Laura Abbott <labbott@redhat.com>:
> On 12/08/2016 09:05 PM, Jaewon Kim wrote:
>> Initial Commit 349c9e138551 ("gpu: ion: add CMA heap") returns -1 in allocation
>> failure. The returned value is passed up to userspace through ioctl. So user can
>> misunderstand error reason as -EPERM(1) rather than -ENOMEM(12).
>>
>> This patch simply changed this to return -ENOMEM.
>>
>> Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
>> ---
>>  drivers/staging/android/ion/ion_cma_heap.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
>> index 6c7de74..22b9582 100644
>> --- a/drivers/staging/android/ion/ion_cma_heap.c
>> +++ b/drivers/staging/android/ion/ion_cma_heap.c
>> @@ -24,8 +24,6 @@
>>  #include "ion.h"
>>  #include "ion_priv.h"
>>
>> -#define ION_CMA_ALLOCATE_FAILED -1
>> -
>>  struct ion_cma_heap {
>>       struct ion_heap heap;
>>       struct device *dev;
>> @@ -59,7 +57,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>>
>>       info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL);
>>       if (!info)
>> -             return ION_CMA_ALLOCATE_FAILED;
>> +             return -ENOMEM;
>>
>>       info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
>>                                               GFP_HIGHUSER | __GFP_ZERO);
>> @@ -88,7 +86,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>>       dma_free_coherent(dev, len, info->cpu_addr, info->handle);
>>  err:
>>       kfree(info);
>> -     return ION_CMA_ALLOCATE_FAILED;
>> +     return -ENOMEM;
>>  }
>>
>>  static void ion_cma_free(struct ion_buffer *buffer)
>>
>
> Happy to see cleanup
>
> Acked-by: Laura Abbott <labbott@redhat.com>

Thank you Laura Abbott. I'm honored to get Ack from you. I looked many
patches of you.
I hope this patch to be mainlined.

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

end of thread, other threads:[~2016-12-17 12:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-09  5:05 [PATCH] [RFC] drivers: dma-coherent: pass struct dma_attrs to dma_alloc_from_coherent Jaewon Kim
2016-12-09  5:05 ` [PATCH] staging: android: ion: return -ENOMEM in ion_cma_heap allocation failure Jaewon Kim
2016-12-13 16:04   ` Laura Abbott
2016-12-17 12:00     ` Jaewon Kim

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).