* [PATCH] arm64: dma-mapping: always clear allocated buffers
@ 2015-04-23 11:46 Marek Szyprowski
2015-04-23 14:28 ` Will Deacon
0 siblings, 1 reply; 2+ messages in thread
From: Marek Szyprowski @ 2015-04-23 11:46 UTC (permalink / raw)
To: linux-arm-kernel
Buffers allocated by dma_alloc_coherent() are always zeroed on Alpha,
ARM (32bit), MIPS, PowerPC, x86/x86_64 and probably other architectures.
It turned out that some drivers rely on this 'feature'. Allocated buffer
might be also exposed to userspace with dma_mmap() call, so clearing it
is desired from security point of view to avoid exposing random memory
to userspace. This patch unifies dma_alloc_coherent() behavior on ARM64
architecture with other implementations by unconditionally zeroing
allocated buffer.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
Hello,
This issue was really nasty to debug. The problem has been observed with
dw_mmc driver on Exynos 5433. I've also check if there are any calls to
dma_alloc_coherent() with __GFP_ZERO flag and found only two drivers in
the whole kernel tree: drivers/staging/android/ion/ion_cma_heap.c and
drivers/thunderbolt/nhi.c. The best will be to review all drivers and
add missing __GFP_ZERO flag or replace it with dma_zalloc_coherent() and
only then convert all implementation for all architectures to honor this
flag. However I expect that this is a huge task and for now ARM64 should
just match the behavior of other architectures.
Best regards
Marek Szyprowski
Samsung Poland R&D Center
---
arch/arm64/mm/dma-mapping.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index ef7d112..e0f14ee 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -67,8 +67,7 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags)
*ret_page = phys_to_page(phys);
ptr = (void *)val;
- if (flags & __GFP_ZERO)
- memset(ptr, 0, size);
+ memset(ptr, 0, size);
}
return ptr;
@@ -113,8 +112,7 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size,
*dma_handle = phys_to_dma(dev, page_to_phys(page));
addr = page_address(page);
- if (flags & __GFP_ZERO)
- memset(addr, 0, size);
+ memset(addr, 0, size);
return addr;
} else {
return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
--
1.9.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] arm64: dma-mapping: always clear allocated buffers
2015-04-23 11:46 [PATCH] arm64: dma-mapping: always clear allocated buffers Marek Szyprowski
@ 2015-04-23 14:28 ` Will Deacon
0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2015-04-23 14:28 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Apr 23, 2015 at 12:46:16PM +0100, Marek Szyprowski wrote:
> Buffers allocated by dma_alloc_coherent() are always zeroed on Alpha,
> ARM (32bit), MIPS, PowerPC, x86/x86_64 and probably other architectures.
That's pretty compelling, even if it sucks. Maybe we could add a debug
option to poison DMA buffers if __GFP_ZERO isn't passed? It might help
others avoid the painful debugging experience you had...
Will
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-23 14:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-23 11:46 [PATCH] arm64: dma-mapping: always clear allocated buffers Marek Szyprowski
2015-04-23 14:28 ` Will Deacon
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).