From: Arun Iyengar <[email protected]>

On a coherent GPU a heap BO is not write-combined, so PANFROST_SYNC_BO
on it reaches drm_gem_shmem_get_pages_sgt() with bo->base.pages being
the fault handler's sparse page array, and drm_prime_pages_to_sg()
dereferences the NULL entries of the chunks not faulted in yet. With no
chunk faulted in, it pins the whole heap and sets bo->base.pages without
bo->sgts, which the next GPU fault on the heap dereferences.

Heap BOs are not CPU-mappable (panfrost_ioctl_mmap_bo() refuses them,
panfrost_gem_create() refuses PANFROST_BO_WB_MMAP for them), so there is
nothing to sync: return -EINVAL, as for imported BOs.

Found by code review (Sashiko). Not tested on a coherent GPU: on the
Mali-G31 here a heap BO is write-combined and the sync returned early.

Fixes: 7be45f548976 ("drm/panfrost: Add a PANFROST_SYNC_BO ioctl")
Cc: [email protected]
Reported-by: Sashiko <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Arun Iyengar <[email protected]>
---
 drivers/gpu/drm/panfrost/panfrost_gem.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c 
b/drivers/gpu/drm/panfrost/panfrost_gem.c
index 518f24549..f72edb65b 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gem.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
@@ -569,6 +569,10 @@ panfrost_gem_sync(struct drm_gem_object *obj, u32 type, 
u32 offset, u32 size)
        if (drm_gem_is_imported(&shmem->base))
                return -EINVAL;
 
+       /* A heap BO's pages and sg tables belong to the GPU fault handler. */
+       if (bo->is_heap)
+               return -EINVAL;
+
        switch (type) {
        case PANFROST_BO_SYNC_CPU_CACHE_FLUSH:
        case PANFROST_BO_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE:

-- 
2.55.0


Reply via email to