This series follows up on the discussion in the V3D cached maps series
[1], about how to handle CPU-cached BOs that are shared through dma-buf.

As pointed by Faith and Boris, when a buffer is shared through dma-buf,
there's no way to ensure that a client will properly bracket their CPU
accesses with DMA_BUF_IOCTL_SYNC. With WC mappings, waiting on fences is
enough to guarantee consistency. However, with WB mappings, a missed sync
can leave dirty cache lines behind, which another client can end up
writing over.

PanVK already keeps WB_MMAP BOs private, so this series only makes the
kernel enforce the same policy on Panfrost and Panthor. As discussed in
v1, the custom dma_buf_ops are kept, as they're still needed for
IO-coherent GPUs.

- Patch 1 adds the drm_gem_shmem_sync() helper, taken from [2], with
  locking around the sgt walk and handling of unbacked/purged BOs.
- Patch 2 converts Panfrost to drm_gem_shmem_sync(). V3D will also use it
  to implement its cached maps, which I'll send in a separate series.
- Patches 3 and 4 refuse to export WB_MMAP BOs in Panfrost and Panthor.

The Panthor changes were tested locally on hardware and the series was
also tested in Mesa CI (Panfrost and Panthor) without regressions.

[1] 
https://lore.kernel.org/dri-devel/[email protected]/T/
[2] 
https://lore.kernel.org/dri-devel/[email protected]/

Best regards,
- Maíra

---
Changes in v2:

- Dropped the patches "[PATCH 3/6] drm/panfrost: Drop custom dma_buf_ops"
  and "[PATCH 6/6] drm/panthor: Drop custom dma_buf_ops" (Boris Brezillon)
- [1/4] Dropped Steven Price's R-b, as the locking changed.
- [1/4] Added a resv lock across the sgt walk, similarly to what's done in
  panthor_gem_sync() (Sashiko)
- [1/4] Stop populating pages on purged or unbacked BOs (Sashiko)
- [2/4] Move right after the drm_gem_shmem_sync() patch, add Fixes: tag
  and reword the commit message.
- Link to v1: 
https://lore.kernel.org/r/[email protected]

---
Faith Ekstrand (1):
      drm/shmem: Add a drm_gem_shmem_sync() helper

Maíra Canal (3):
      drm/panfrost: Use drm_gem_shmem_sync()
      drm/panfrost: Refuse to export WB_MMAP BOs
      drm/panthor: Refuse to export WB_MMAP BOs

 drivers/gpu/drm/drm_gem_shmem_helper.c  | 108 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/panfrost/panfrost_gem.c |  78 +++--------------------
 drivers/gpu/drm/panthor/panthor_gem.c   |   4 ++
 include/drm/drm_gem_shmem_helper.h      |  17 +++++
 include/uapi/drm/panfrost_drm.h         |   1 +
 include/uapi/drm/panthor_drm.h          |   2 +
 6 files changed, 141 insertions(+), 69 deletions(-)
---
base-commit: ce335050d9a670491139f5e4337934c3e963e7f4
change-id: 20261119-pan-drop-dma-buf-hooks-98f7f19f3b51

Reply via email to