Skip to content

Commit d233d7e

Browse files
bbrezillonHeyMeco
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 <[email protected]>
1 parent 12446bd commit d233d7e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

drivers/gpu/drm/panthor/panthor_gem.c

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

292292
panthor_gem_debugfs_set_usage_flags(bo, 0);
293293

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

319+
out_put_gem:
302320
/* drop reference from allocate - handle holds it now. */
303321
drm_gem_object_put(&shmem->base);
304322

0 commit comments

Comments
 (0)