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 follow 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/panfrost/panfrost_gem.c | 4 ++++ include/uapi/drm/panfrost_drm.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index 8c0facd498d7..e5546b5755f8 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -391,6 +391,10 @@ panfrost_gem_prime_export(struct drm_gem_object *obj, int flags) .resv = obj->resv, }; + /* WB_MMAP BOs can't be shared. */ + if (to_panfrost_bo(obj)->wb_mmap) + return ERR_PTR(-EINVAL); + return drm_gem_dmabuf_export(dev, &exp_info); } diff --git a/include/uapi/drm/panfrost_drm.h b/include/uapi/drm/panfrost_drm.h index 7831c48c59c0..2cc44591e82b 100644 --- a/include/uapi/drm/panfrost_drm.h +++ b/include/uapi/drm/panfrost_drm.h @@ -126,6 +126,7 @@ struct drm_panfrost_wait_bo { /* Valid flags to pass to drm_panfrost_create_bo. * PANFROST_BO_WB_MMAP can't be set if PANFROST_BO_HEAP is. + * Also, PANFROST_BO_WB_MMAP BOs can't be exported. */ #define PANFROST_BO_NOEXEC 1 #define PANFROST_BO_HEAP 2 -- 2.56.0
