]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/panthor: Flush shmem writes before mapping buffers CPU-uncached
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 7 Nov 2025 17:12:14 +0000 (18:12 +0100)
committerSteven Price <steven.price@arm.com>
Mon, 10 Nov 2025 14:56:06 +0000 (14:56 +0000)
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: 8a1cc07578bf ("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
drivers/gpu/drm/panthor/panthor_gem.c

index 156c7a0b62a231219645095d6012a5b108130bbc..3f43686f0195886ff3fe231fd38636e0d0af098a 100644 (file)
@@ -288,6 +288,23 @@ panthor_gem_create_with_handle(struct drm_file *file,
 
        panthor_gem_debugfs_set_usage_flags(bo, 0);
 
+       /* If this is a write-combine mapping, we query the sgt to force a CPU
+        * cache flush (dma_map_sgtable() is called when the sgt is created).
+        * This ensures the zero-ing is visible to any uncached mapping created
+        * by vmap/mmap.
+        * FIXME: Ideally this should be done when pages are allocated, not at
+        * BO creation time.
+        */
+       if (shmem->map_wc) {
+               struct sg_table *sgt;
+
+               sgt = drm_gem_shmem_get_pages_sgt(shmem);
+               if (IS_ERR(sgt)) {
+                       ret = PTR_ERR(sgt);
+                       goto out_put_gem;
+               }
+       }
+
        /*
         * Allocate an id of idr table where the obj is registered
         * and handle has the id what user can see.
@@ -296,6 +313,7 @@ panthor_gem_create_with_handle(struct drm_file *file,
        if (!ret)
                *size = bo->base.base.size;
 
+out_put_gem:
        /* drop reference from allocate - handle holds it now. */
        drm_gem_object_put(&shmem->base);