Skip to content

Commit 576c930

Browse files
bbrezillonstevenprice-arm
authored andcommitted
drm/panthor: Flush shmem writes before mapping buffers CPU-uncached
The shmem layer zeroes out the new pages using cached mappings, and if we don't CPU-flush we might leave dirty cachelines behind, leading to potential data leaks and/or asynchronous buffer corruption when dirty cachelines are evicted. Fixes: 8a1cc07 ("drm/panthor: Add GEM logical block") Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Steven Price <steven.price@arm.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Signed-off-by: Steven Price <steven.price@arm.com> Link: https://patch.msgid.link/20251107171214.1186299-1-boris.brezillon@collabora.com
1 parent eef295a commit 576c930

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

drivers/gpu/drm/panthor/panthor_gem.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,23 @@ panthor_gem_create_with_handle(struct drm_file *file,
288288

289289
panthor_gem_debugfs_set_usage_flags(bo, 0);
290290

291+
/* If this is a write-combine mapping, we query the sgt to force a CPU
292+
* cache flush (dma_map_sgtable() is called when the sgt is created).
293+
* This ensures the zero-ing is visible to any uncached mapping created
294+
* by vmap/mmap.
295+
* FIXME: Ideally this should be done when pages are allocated, not at
296+
* BO creation time.
297+
*/
298+
if (shmem->map_wc) {
299+
struct sg_table *sgt;
300+
301+
sgt = drm_gem_shmem_get_pages_sgt(shmem);
302+
if (IS_ERR(sgt)) {
303+
ret = PTR_ERR(sgt);
304+
goto out_put_gem;
305+
}
306+
}
307+
291308
/*
292309
* Allocate an id of idr table where the obj is registered
293310
* and handle has the id what user can see.
@@ -296,6 +313,7 @@ panthor_gem_create_with_handle(struct drm_file *file,
296313
if (!ret)
297314
*size = bo->base.base.size;
298315

316+
out_put_gem:
299317
/* drop reference from allocate - handle holds it now. */
300318
drm_gem_object_put(&shmem->base);
301319

0 commit comments

Comments
 (0)