Skip to content

Commit dd65a94

Browse files
mszyprowctmarinas
authored andcommitted
arm64: dma-mapping: clear buffers allocated with FORCE_CONTIGUOUS flag
dma_alloc_*() buffers might be exposed to userspace via mmap() call, so they should be cleared on allocation. In case of IOMMU-based dma-mapping implementation such buffer clearing was missing in the code path for DMA_ATTR_FORCE_CONTIGUOUS flag handling, because dma_alloc_from_contiguous() doesn't honor __GFP_ZERO flag. This patch fixes this issue. For more information on clearing buffers allocated by dma_alloc_* functions, see commit 6829e27 ("arm64: dma-mapping: always clear allocated buffers"). Fixes: 44176bb ("arm64: Add support for DMA_ATTR_FORCE_CONTIGUOUS to IOMMU") Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent ce397d2 commit dd65a94

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/arm64/mm/dma-mapping.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,14 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
583583
size >> PAGE_SHIFT);
584584
return NULL;
585585
}
586-
if (!coherent)
587-
__dma_flush_area(page_to_virt(page), iosize);
588-
589586
addr = dma_common_contiguous_remap(page, size, VM_USERMAP,
590587
prot,
591588
__builtin_return_address(0));
592-
if (!addr) {
589+
if (addr) {
590+
memset(addr, 0, size);
591+
if (!coherent)
592+
__dma_flush_area(page_to_virt(page), iosize);
593+
} else {
593594
iommu_dma_unmap_page(dev, *handle, iosize, 0, attrs);
594595
dma_release_from_contiguous(dev, page,
595596
size >> PAGE_SHIFT);

0 commit comments

Comments
 (0)