From 03cfd33c5f341370509952e7d8f06bd60fdc92b5 Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 20 Mar 2020 15:42:01 +0000 Subject: MGS-5565 staging: android: ion: Flush cache after zero CMA allocated memory ION CMA memory default is cacheable, need flush cache after memset(), else cache and physical memory not sync may cause problem. Issue case: VPU Video playback or GPU render have dirty line issue. Root cause: ION CMA allocate cacheable buffer and do memset(), some data still in cache not in physical memory, VPU or GPU write the buffer with physical address, or user call ion_mmap() to map the buffer through pgprot_writecombine() as no-cache and write the buffer, later some CPU cache access trigger cache flush, previous memset() data go to physical memory as dirty data. Change-Id: I82b4cb61bbe6cffc687d452f9f81c1e35914d2f1 Signed-off-by: Richard Liu (cherry picked from commit 5d360f25f3523311b5f478b7b1c7bc9020cfda58) --- drivers/staging/android/ion/ion_cma_heap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index fa3e4b7e0c9f..80df813372e4 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "ion.h" @@ -60,12 +61,22 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, void *vaddr = kmap_atomic(page); memset(vaddr, 0, PAGE_SIZE); +#ifdef CONFIG_ARM64 + __flush_dcache_area(vaddr,PAGE_SIZE); +#else + __cpuc_flush_dcache_area(vaddr,PAGE_SIZE); +#endif kunmap_atomic(vaddr); page++; nr_clear_pages--; } } else { memset(page_address(pages), 0, size); +#ifdef CONFIG_ARM64 + __flush_dcache_area(page_address(pages),size); +#else + __cpuc_flush_dcache_area(page_address(pages),size); +#endif } table = kmalloc(sizeof(*table), GFP_KERNEL); -- cgit v1.2.3