Re: [PATCH] ARM: dma-mapping: always clear allocated buffers in __alloc_from_pool

2019-03-13 Thread Christoph Hellwig
On Tue, Mar 12, 2019 at 05:16:37PM +0800, Yue Haibing wrote:
> From: YueHaibing 
> 
> Like commit 518a2f1925c3 ("dma-mapping: zero memory returned
> from dma_alloc_*"), if we want to map memory from the DMA
> allocator to userspace it must be zeroed at allocation time 
> to prevent stale data leaks. On arm platform, if the allocator
> is pool_allocator in __dma_alloc, then the mem is alloced by
> __alloc_from_pool, which also need be zeroed.

The observations looks correct, and because this memory is already
remapped I don't think we need __dma_clear_buffer here.

But I'd love to see a review from Russell as well.


[PATCH] ARM: dma-mapping: always clear allocated buffers in __alloc_from_pool

2019-03-12 Thread Yue Haibing
From: YueHaibing 

Like commit 518a2f1925c3 ("dma-mapping: zero memory returned
from dma_alloc_*"), if we want to map memory from the DMA
allocator to userspace it must be zeroed at allocation time 
to prevent stale data leaks. On arm platform, if the allocator
is pool_allocator in __dma_alloc, then the mem is alloced by
__alloc_from_pool, which also need be zeroed.

Signed-off-by: YueHaibing 
---
 arch/arm/mm/dma-mapping.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 8a90f29..28ad6d5 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -558,6 +558,7 @@ static void *__alloc_from_pool(size_t size, struct page 
**ret_page)
 
*ret_page = phys_to_page(phys);
ptr = (void *)val;
+   memset(ptr, 0, size);
}
 
return ptr;
-- 
2.7.0




Re: [PATCH] ARM: dma-mapping: always clear allocated buffers

2018-07-24 Thread YueHaibing
On 2018/7/25 2:09, Christoph Hellwig wrote:
> On Tue, Jul 24, 2018 at 10:04:35PM +0800, YueHaibing wrote:
>> Sean Wang report dma_zalloc_coherent doesn't work as expect on his
>> armv7,the allocated mem is not zeroed.The reason is __alloc_from_pool
>> doesn't honor __GFP_ZERO.
> 
> Please explain the "why" a little more.  All the explanations are in
> the referenced arm64 commit and should be mentioned here as well.

ok, will send v2.

> 
> .
> 



Re: [PATCH] ARM: dma-mapping: always clear allocated buffers

2018-07-24 Thread YueHaibing
On 2018/7/25 2:09, Christoph Hellwig wrote:
> On Tue, Jul 24, 2018 at 10:04:35PM +0800, YueHaibing wrote:
>> Sean Wang report dma_zalloc_coherent doesn't work as expect on his
>> armv7,the allocated mem is not zeroed.The reason is __alloc_from_pool
>> doesn't honor __GFP_ZERO.
> 
> Please explain the "why" a little more.  All the explanations are in
> the referenced arm64 commit and should be mentioned here as well.

ok, will send v2.

> 
> .
> 



Re: [PATCH] ARM: dma-mapping: always clear allocated buffers

2018-07-24 Thread Christoph Hellwig
On Tue, Jul 24, 2018 at 10:04:35PM +0800, YueHaibing wrote:
> Sean Wang report dma_zalloc_coherent doesn't work as expect on his
> armv7,the allocated mem is not zeroed.The reason is __alloc_from_pool
> doesn't honor __GFP_ZERO.

Please explain the "why" a little more.  All the explanations are in
the referenced arm64 commit and should be mentioned here as well.


Re: [PATCH] ARM: dma-mapping: always clear allocated buffers

2018-07-24 Thread Christoph Hellwig
On Tue, Jul 24, 2018 at 10:04:35PM +0800, YueHaibing wrote:
> Sean Wang report dma_zalloc_coherent doesn't work as expect on his
> armv7,the allocated mem is not zeroed.The reason is __alloc_from_pool
> doesn't honor __GFP_ZERO.

Please explain the "why" a little more.  All the explanations are in
the referenced arm64 commit and should be mentioned here as well.


[PATCH] ARM: dma-mapping: always clear allocated buffers

2018-07-24 Thread YueHaibing
Sean Wang report dma_zalloc_coherent doesn't work as expect on his
armv7,the allocated mem is not zeroed.The reason is __alloc_from_pool
doesn't honor __GFP_ZERO.

Like commit 6829e274a623 ("arm64: dma-mapping: always clear allocated buffers")
does,always clear allocated buffers to fix this.

Reported-by: Sean Wang 
Signed-off-by: YueHaibing 
Reviewed-by: zhong jiang 
---
 arch/arm/mm/dma-mapping.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 6656647..cf5882f 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -564,6 +564,7 @@ static void *__alloc_from_pool(size_t size, struct page 
**ret_page)
 
*ret_page = phys_to_page(phys);
ptr = (void *)val;
+   memset(ptr, 0, size);
}
 
return ptr;
-- 
2.7.0




[PATCH] ARM: dma-mapping: always clear allocated buffers

2018-07-24 Thread YueHaibing
Sean Wang report dma_zalloc_coherent doesn't work as expect on his
armv7,the allocated mem is not zeroed.The reason is __alloc_from_pool
doesn't honor __GFP_ZERO.

Like commit 6829e274a623 ("arm64: dma-mapping: always clear allocated buffers")
does,always clear allocated buffers to fix this.

Reported-by: Sean Wang 
Signed-off-by: YueHaibing 
Reviewed-by: zhong jiang 
---
 arch/arm/mm/dma-mapping.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 6656647..cf5882f 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -564,6 +564,7 @@ static void *__alloc_from_pool(size_t size, struct page 
**ret_page)
 
*ret_page = phys_to_page(phys);
ptr = (void *)val;
+   memset(ptr, 0, size);
}
 
return ptr;
-- 
2.7.0