When a buffer is shared through dma-buf, clients are expected to bracket their CPU accesses with DMA_BUF_IOCTL_SYNC, but there's no way to ensure they do. With WC mappings, there are no CPU cache lines to maintain, so waiting on fences is enough. With WB mappings, a missed sync can leave dirty cache lines behind, which may later be written back over data the GPU produced for another client.
To avoid this, don't allow WB_MMAP BOs to be shared. PanVK already keeps WB_MMAP BOs private, so this makes the kernel enforce the same policy. Suggested-by: Faith Ekstrand <[email protected]> Suggested-by: Boris Brezillon <[email protected]> Signed-off-by: Maíra Canal <[email protected]> --- drivers/gpu/drm/panthor/panthor_gem.c | 4 ++++ include/uapi/drm/panthor_drm.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c index 22b57ab6f929..730567d97f46 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -577,6 +577,10 @@ panthor_gem_prime_export(struct drm_gem_object *obj, int flags) if (to_panthor_bo(obj)->exclusive_vm_root_gem) return ERR_PTR(-EINVAL); + /* WB_MMAP BOs can't be shared. */ + if (to_panthor_bo(obj)->flags & DRM_PANTHOR_BO_WB_MMAP) + return ERR_PTR(-EINVAL); + return drm_gem_dmabuf_export(dev, &exp_info); } diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h index a2ff0f4ec691..8f3a3e680264 100644 --- a/include/uapi/drm/panthor_drm.h +++ b/include/uapi/drm/panthor_drm.h @@ -771,6 +771,8 @@ enum drm_panthor_bo_flags { * CPU map the buffer object in userspace by forcing the "Write-Back * Cacheable" cacheability attribute. The mapping otherwise uses the * "Non-Cacheable" attribute if the GPU is not IO coherent. + * + * Buffer objects created with this flag can't be exported. */ DRM_PANTHOR_BO_WB_MMAP = (1 << 1), }; -- 2.56.0
