Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1324967 > unrolled thread
| Started by | "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com> |
|---|---|
| First post | 2016-02-03 07:50 +0100 |
| Last post | 2016-02-04 06:20 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCHv2] staging: android: ion: use the manged version of DMA memory allocation "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com> - 2016-02-03 07:50 +0100
Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation Robin Murphy <robin.murphy@arm.com> - 2016-02-03 13:10 +0100
Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation Laura Abbott <labbott@redhat.com> - 2016-02-03 19:20 +0100
Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com> - 2016-02-04 06:20 +0100
| From | "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com> |
|---|---|
| Date | 2016-02-03 07:50 +0100 |
| Subject | [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation |
| Message-ID | <qXZqi-6Mx-13@gated-at.bofh.it> |
From: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
Use the managed version of the dma_alloc_coherent() i.e. the
dmam_alloc_coherent() & accordingly cleanup the error handling
part.Also,remove the references to dma_free_coherent
Signed-off-by: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
---
v2:kbuild test robot reported warnings on ununsed
variables.Those warnings are fixed.
---
drivers/staging/android/ion/ion_cma_heap.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index a3446da..8cd720b 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -61,7 +61,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
if (!info)
return ION_CMA_ALLOCATE_FAILED;
- info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
+ info->cpu_addr = dmam_alloc_coherent(dev, len, &(info->handle),
GFP_HIGHUSER | __GFP_ZERO);
if (!info->cpu_addr) {
@@ -71,7 +71,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
if (!info->table)
- goto free_mem;
+ goto err;
if (dma_get_sgtable(dev, info->table, info->cpu_addr, info->handle,
len))
@@ -83,8 +83,6 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
free_table:
kfree(info->table);
-free_mem:
- dma_free_coherent(dev, len, info->cpu_addr, info->handle);
err:
kfree(info);
return ION_CMA_ALLOCATE_FAILED;
@@ -92,13 +90,8 @@ err:
static void ion_cma_free(struct ion_buffer *buffer)
{
- struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
- struct device *dev = cma_heap->dev;
struct ion_cma_buffer_info *info = buffer->priv_virt;
- dev_dbg(dev, "Release buffer %p\n", buffer);
- /* release memory */
- dma_free_coherent(dev, buffer->size, info->cpu_addr, info->handle);
/* release sg table */
sg_free_table(info->table);
kfree(info->table);
--
1.9.1
[toc] | [next] | [standalone]
| From | Robin Murphy <robin.murphy@arm.com> |
|---|---|
| Date | 2016-02-03 13:10 +0100 |
| Subject | Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation |
| Message-ID | <qY4pY-1KZ-19@gated-at.bofh.it> |
| In reply to | #1324967 |
On 03/02/16 06:49, Gujulan Elango, Hari Prasath (H.) wrote:
> From: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
>
> Use the managed version of the dma_alloc_coherent() i.e. the
> dmam_alloc_coherent() & accordingly cleanup the error handling
> part.Also,remove the references to dma_free_coherent
That last aspect looks a bit off to me - the heaps don't seem to be
something that exist for the lifetime of the ION "device", given that
these are specific runtime alloc and free calls, rather than the probe
and remove routines. I don't know if CMA heaps are among those which ION
creates and destroys frequently (enough that it apparently kicks off a
whole background thread to manage the freeing), but this looks like a
recipe for leaks. If the free call doesn't actually free the buffer,
it's going to remain hanging around consuming precious CMA area until
the ION device itself is torn down, which is likely never.
I wouldn't say it's necessarily inappropriate to use managed DMA
resources here to cover unexpected failure cases for the ION device
itself (I see the comment in ion_device_remove()), but that means still
using dmam_free_coherent() when naturally releasing allocations for
other reasons (i.e. both cases here). Think Java finalisers, rather than
C++ destructors.
Robin.
> Signed-off-by: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
> ---
> v2:kbuild test robot reported warnings on ununsed
> variables.Those warnings are fixed.
> ---
> drivers/staging/android/ion/ion_cma_heap.c | 11 ++---------
> 1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
> index a3446da..8cd720b 100644
> --- a/drivers/staging/android/ion/ion_cma_heap.c
> +++ b/drivers/staging/android/ion/ion_cma_heap.c
> @@ -61,7 +61,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
> if (!info)
> return ION_CMA_ALLOCATE_FAILED;
>
> - info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
> + info->cpu_addr = dmam_alloc_coherent(dev, len, &(info->handle),
> GFP_HIGHUSER | __GFP_ZERO);
>
> if (!info->cpu_addr) {
> @@ -71,7 +71,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>
> info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
> if (!info->table)
> - goto free_mem;
> + goto err;
>
> if (dma_get_sgtable(dev, info->table, info->cpu_addr, info->handle,
> len))
> @@ -83,8 +83,6 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>
> free_table:
> kfree(info->table);
> -free_mem:
> - dma_free_coherent(dev, len, info->cpu_addr, info->handle);
> err:
> kfree(info);
> return ION_CMA_ALLOCATE_FAILED;
> @@ -92,13 +90,8 @@ err:
>
> static void ion_cma_free(struct ion_buffer *buffer)
> {
> - struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
> - struct device *dev = cma_heap->dev;
> struct ion_cma_buffer_info *info = buffer->priv_virt;
>
> - dev_dbg(dev, "Release buffer %p\n", buffer);
> - /* release memory */
> - dma_free_coherent(dev, buffer->size, info->cpu_addr, info->handle);
> /* release sg table */
> sg_free_table(info->table);
> kfree(info->table);
>
[toc] | [prev] | [next] | [standalone]
| From | Laura Abbott <labbott@redhat.com> |
|---|---|
| Date | 2016-02-03 19:20 +0100 |
| Subject | Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation |
| Message-ID | <qYac2-5uj-27@gated-at.bofh.it> |
| In reply to | #1325311 |
On 02/03/2016 04:03 AM, Robin Murphy wrote:
> On 03/02/16 06:49, Gujulan Elango, Hari Prasath (H.) wrote:
>> From: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
>>
>> Use the managed version of the dma_alloc_coherent() i.e. the
>> dmam_alloc_coherent() & accordingly cleanup the error handling
>> part.Also,remove the references to dma_free_coherent
>
> That last aspect looks a bit off to me - the heaps don't seem to be something that exist for the lifetime of the ION "device", given that these are specific runtime alloc and free calls, rather than the probe and remove routines. I don't know if CMA heaps are among those which ION creates and destroys frequently (enough that it apparently kicks off a whole background thread to manage the freeing), but this looks like a recipe for leaks. If the free call doesn't actually free the buffer, it's going to remain hanging around consuming precious CMA area until the ION device itself is torn down, which is likely never.
>
> I wouldn't say it's necessarily inappropriate to use managed DMA resources here to cover unexpected failure cases for the ION device itself (I see the comment in ion_device_remove()), but that means still using dmam_free_coherent() when naturally releasing allocations for other reasons (i.e. both cases here). Think Java finalisers, rather than C++ destructors.
>
> Robin.
>
Yes, Robin is correct. These allocations are not tied to the lifetime of the
device so it is incorrect to move to the manged APIs. The dma_alloc_coherent
allocations are done on request.
Ion isn't a good candidate to look at to switch APIs over to the devm
interface since it does many things in a non-standard way. You should
probably focus devm efforts outside of Ion (although if you find a
potential patch I'll certainly review it)
Thanks,
Laura
>> Signed-off-by: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
>> ---
>> v2:kbuild test robot reported warnings on ununsed
>> variables.Those warnings are fixed.
>> ---
>> drivers/staging/android/ion/ion_cma_heap.c | 11 ++---------
>> 1 file changed, 2 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
>> index a3446da..8cd720b 100644
>> --- a/drivers/staging/android/ion/ion_cma_heap.c
>> +++ b/drivers/staging/android/ion/ion_cma_heap.c
>> @@ -61,7 +61,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>> if (!info)
>> return ION_CMA_ALLOCATE_FAILED;
>>
>> - info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
>> + info->cpu_addr = dmam_alloc_coherent(dev, len, &(info->handle),
>> GFP_HIGHUSER | __GFP_ZERO);
>>
>> if (!info->cpu_addr) {
>> @@ -71,7 +71,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>>
>> info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
>> if (!info->table)
>> - goto free_mem;
>> + goto err;
>>
>> if (dma_get_sgtable(dev, info->table, info->cpu_addr, info->handle,
>> len))
>> @@ -83,8 +83,6 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
>>
>> free_table:
>> kfree(info->table);
>> -free_mem:
>> - dma_free_coherent(dev, len, info->cpu_addr, info->handle);
>> err:
>> kfree(info);
>> return ION_CMA_ALLOCATE_FAILED;
>> @@ -92,13 +90,8 @@ err:
>>
>> static void ion_cma_free(struct ion_buffer *buffer)
>> {
>> - struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
>> - struct device *dev = cma_heap->dev;
>> struct ion_cma_buffer_info *info = buffer->priv_virt;
>>
>> - dev_dbg(dev, "Release buffer %p\n", buffer);
>> - /* release memory */
>> - dma_free_coherent(dev, buffer->size, info->cpu_addr, info->handle);
>> /* release sg table */
>> sg_free_table(info->table);
>> kfree(info->table);
>>
>
[toc] | [prev] | [next] | [standalone]
| From | "Gujulan Elango, Hari Prasath (H.)" <hgujulan@visteon.com> |
|---|---|
| Date | 2016-02-04 06:20 +0100 |
| Subject | Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation |
| Message-ID | <qYkuJ-4bg-9@gated-at.bofh.it> |
| In reply to | #1325793 |
On Wed, Feb 03, 2016 at 10:11:04AM -0800, Laura Abbott wrote:
> On 02/03/2016 04:03 AM, Robin Murphy wrote:
> >On 03/02/16 06:49, Gujulan Elango, Hari Prasath (H.) wrote:
> >>From: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
> >>
> >>Use the managed version of the dma_alloc_coherent() i.e. the
> >>dmam_alloc_coherent() & accordingly cleanup the error handling
> >>part.Also,remove the references to dma_free_coherent
> >
> >That last aspect looks a bit off to me - the heaps don't seem to be something that exist for the lifetime of the ION "device", given that these are specific runtime alloc and free calls, rather than the probe and remove routines. I don't know if CMA heaps are among those which ION creates and destroys frequently (enough that it apparently kicks off a whole background thread to manage the freeing), but this looks like a recipe for leaks. If the free call doesn't actually free the buffer, it's going to remain hanging around consuming precious CMA area until the ION device itself is torn down, which is likely never.
> >
> >I wouldn't say it's necessarily inappropriate to use managed DMA resources here to cover unexpected failure cases for the ION device itself (I see the comment in ion_device_remove()), but that means still using dmam_free_coherent() when naturally releasing allocations for other reasons (i.e. both cases here). Think Java finalisers, rather than C++ destructors.
> >
> >Robin.
> >
>
> Yes, Robin is correct. These allocations are not tied to the lifetime of the
> device so it is incorrect to move to the manged APIs. The dma_alloc_coherent
> allocations are done on request.
>
> Ion isn't a good candidate to look at to switch APIs over to the devm
> interface since it does many things in a non-standard way. You should
> probably focus devm efforts outside of Ion (although if you find a
> potential patch I'll certainly review it)
>
> Thanks,
> Laura
>
> >>Signed-off-by: Hari Prasath Gujulan Elango <hgujulan@visteon.com>
> >>---
> >> v2:kbuild test robot reported warnings on ununsed
> >> variables.Those warnings are fixed.
> >>---
> >> drivers/staging/android/ion/ion_cma_heap.c | 11 ++---------
> >> 1 file changed, 2 insertions(+), 9 deletions(-)
> >>
> >>diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
> >>index a3446da..8cd720b 100644
> >>--- a/drivers/staging/android/ion/ion_cma_heap.c
> >>+++ b/drivers/staging/android/ion/ion_cma_heap.c
> >>@@ -61,7 +61,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
> >> if (!info)
> >> return ION_CMA_ALLOCATE_FAILED;
> >>
> >>- info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
> >>+ info->cpu_addr = dmam_alloc_coherent(dev, len, &(info->handle),
> >> GFP_HIGHUSER | __GFP_ZERO);
> >>
> >> if (!info->cpu_addr) {
> >>@@ -71,7 +71,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
> >>
> >> info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
> >> if (!info->table)
> >>- goto free_mem;
> >>+ goto err;
> >>
> >> if (dma_get_sgtable(dev, info->table, info->cpu_addr, info->handle,
> >> len))
> >>@@ -83,8 +83,6 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
> >>
> >> free_table:
> >> kfree(info->table);
> >>-free_mem:
> >>- dma_free_coherent(dev, len, info->cpu_addr, info->handle);
> >> err:
> >> kfree(info);
> >> return ION_CMA_ALLOCATE_FAILED;
> >>@@ -92,13 +90,8 @@ err:
> >>
> >> static void ion_cma_free(struct ion_buffer *buffer)
> >> {
> >>- struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
> >>- struct device *dev = cma_heap->dev;
> >> struct ion_cma_buffer_info *info = buffer->priv_virt;
> >>
> >>- dev_dbg(dev, "Release buffer %p\n", buffer);
> >>- /* release memory */
> >>- dma_free_coherent(dev, buffer->size, info->cpu_addr, info->handle);
> >> /* release sg table */
> >> sg_free_table(info->table);
> >> kfree(info->table);
> >>
> >
>
Robin & Laura,
Thanks for your review comments & I agreee both of you on this. Let's
drop this patch.
Regards
Hari Prasath
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web