Skip to content

Move dma-buf mmap() reservation locking down to exporters

Dmitry Osipenko dri-devel intel-gfx linux-media linux-tegra lkml 4 versions – Applied

Status from this message: Applied to misc-next

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest6 patches 11 repliesApplied
  2. v36 patches 3 repliesSuperseded
  3. v27 patches 3 repliesApplied
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v17 patches4 repliesSuperseded

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/6media: videobuf2: Don't assert held reservation lock for dma-buf mmappingdrivers/media/common/videobuf2/videobuf2-dma-contig.c drivers/media/common/videobuf2/videobuf2-dma-sg.c drivers/media/common/videobuf2/videobuf2-vmalloc.c+0 -90 replies
2/6dma-buf/heaps: Don't assert held reservation lock for dma-buf mmappingdrivers/dma-buf/heaps/cma_heap.c drivers/dma-buf/heaps/system_heap.c+0 -63 replies
3/6udmabuf: Don't assert held reservation lock for dma-buf mmappingdrivers/dma-buf/udmabuf.c+0 -20 replies
4/6drm: Don't assert held reservation lock for dma-buf mmappingdrivers/gpu/drm/drm_prime.c drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c +1 more+0 -80 replies
5/6dma-buf: Change locking policy for mmap()drivers/dma-buf/dma-buf.c+3 -143 replies
6/6drm/shmem-helper: Switch to reservation lockdrivers/gpu/drm/drm_gem_shmem_helper.c drivers/gpu/drm/lima/lima_gem.c drivers/gpu/drm/panfrost/panfrost_drv.c +3 more+116 -1484 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchEmil VelikovHans VerkuilChristian KönigThomas Zimmermann
1/6R-b R-b
2/6R-b
3/6R-b
4/6R-b A-b
5/6R-b
6/6R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/6] Move dma-buf mmap() reservation locking down to exporters

This patchset makes dma-buf exporters responisble for taking care of the reservation lock. I also included patch that moves drm-shmem to use reservation lock, to let CI test the whole set. I'm going to take all the patches via the drm-misc tree, please give an ack.

Previous policy stated that dma-buf core takes the lock around mmap() callback. Which meant that both importers and exporters shouldn't touch the reservation lock in the mmap() code path. This worked well until Intel-CI found a deadlock problem in a case of self-imported dma-buf [1].

The problem happens when userpace mmaps a self-imported dma-buf, i.e. mmaps the dma-buf FD. DRM core treats self-imported dma-bufs as own GEMs [2]. There is no way to differentiate a prime GEM from a normal GEM for drm-shmem in drm_gem_shmem_mmap(), which resulted in a deadlock problem for drm-shmem mmap() code path once it's switched to use reservation lock.

It was difficult to fix the drm-shmem problem without adjusting dma-buf locking policy. In parctice not much changed from importers perspective because previosly dma-buf was taking the lock in between of importers and exporters. Now this lock is shifted down to exporters.

[1] https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114671v2/shard-snb5/igt@prime_vgem@[email protected]
[2] https://elixir.bootlin.com/linux/v6.3-rc4/source/drivers/gpu/drm/drm_prime.c#L924

Changelog:

v4: - Added dma_resv_assert_held() to drm_gem_shmem_get_pages(), making
assert consistent with the put() variant. Suggested by Emil Velikov.

v3: - Added r-b from Hans Verkuil to the videobuf2 patch.

- The v2 fastrpc patch was already applied, not including it anymore. Though, the cover-letter says that I'd want to apply all the patches via the drm-misc tree to keep the proper ordering of the changes.

- Previously Intel's CI gave a flake failure to v2, want to re-test it again.

v2: - Added ack from Christian König to the DRM patch.

- Dropped "fixes" tag from the patches, like was requested by Christian König. The patches don't actually need a backport and merely improve the locking policy.

- Dropped "reverts" from the patch titles to prevent them from auto-backporting by the stable bot based on the title.

- Added r-b from Emil Velikov and placed the drm_WARN in the drm-shmem patch like he suggested in a comment to v1.

- Corrected drm-shmem patch dma_resv_lock(obj->resv) inconsistently used with dma_resv_unlock(shmem->base.resv). Now shmem->base.resv variant is used for all locks/unlocks.

Dmitry Osipenko (6):
media: videobuf2: Don't assert held reservation lock for dma-buf
mmapping
dma-buf/heaps: Don't assert held reservation lock for dma-buf mmapping
udmabuf: Don't assert held reservation lock for dma-buf mmapping
drm: Don't assert held reservation lock for dma-buf mmapping
dma-buf: Change locking policy for mmap() drm/shmem-helper: Switch to reservation lock

 drivers/dma-buf/dma-buf.c                     |  17 +-
 drivers/dma-buf/heaps/cma_heap.c              |   3 -
 drivers/dma-buf/heaps/system_heap.c           |   3 -
 drivers/dma-buf/udmabuf.c                     |   2 -
 drivers/gpu/drm/drm_gem_shmem_helper.c        | 210 ++++++++----------
 drivers/gpu/drm/drm_prime.c                   |   2 -
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c    |   2 -
 drivers/gpu/drm/lima/lima_gem.c               |   8 +-
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c     |   2 -
 drivers/gpu/drm/panfrost/panfrost_drv.c       |   7 +-
 .../gpu/drm/panfrost/panfrost_gem_shrinker.c  |   6 +-
 drivers/gpu/drm/panfrost/panfrost_mmu.c       |  19 +-
 drivers/gpu/drm/tegra/gem.c                   |   2 -
 .../common/videobuf2/videobuf2-dma-contig.c   |   3 -
 .../media/common/videobuf2/videobuf2-dma-sg.c |   3 -
 .../common/videobuf2/videobuf2-vmalloc.c      |   3 -
 include/drm/drm_gem_shmem_helper.h            |  14 +-
 17 files changed, 119 insertions(+), 187 deletions(-)
Signature · 1 line
2.40.1