public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH v2 0/7] Move dma-buf mmap() reservation locking down to exporters
@ 2023-04-06 16:06 Dmitry Osipenko
  2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 1/7] media: videobuf2: Don't assert held reservation lock for dma-buf mmapping Dmitry Osipenko
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2023-04-06 16:06 UTC (permalink / raw)
  To: Sumit Semwal, Christian König, Benjamin Gaignard, Liam Mark,
	Brian Starkey, John Stultz, Gerd Hoffmann, Daniel Vetter,
	Jani Nikula, Arnd Bergmann, Greg Kroah-Hartman, Thomas Zimmermann,
	Tomi Valkeinen, Thierry Reding, Tomasz Figa, Marek Szyprowski,
	Mauro Carvalho Chehab, Srinivas Kandagatla, Amol Maheshwari,
	Emil Velikov
  Cc: linux-arm-msm, intel-gfx, linux-kernel, dri-devel, linux-tegra,
	kernel, linux-media

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@sync@rcs0.html
[2] https://elixir.bootlin.com/linux/v6.3-rc4/source/drivers/gpu/drm/drm_prime.c#L924

Changelog:

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 (7):
  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
  fastrpc: 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        | 208 ++++++++----------
 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 -
 drivers/misc/fastrpc.c                        |   3 -
 include/drm/drm_gem_shmem_helper.h            |  14 +-
 18 files changed, 117 insertions(+), 190 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-05-19 13:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06 16:06 [Intel-gfx] [PATCH v2 0/7] Move dma-buf mmap() reservation locking down to exporters Dmitry Osipenko
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 1/7] media: videobuf2: Don't assert held reservation lock for dma-buf mmapping Dmitry Osipenko
2023-04-12 14:39   ` Hans Verkuil
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 2/7] dma-buf/heaps: " Dmitry Osipenko
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 3/7] udmabuf: " Dmitry Osipenko
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 4/7] fastrpc: " Dmitry Osipenko
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 5/7] drm: " Dmitry Osipenko
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 6/7] dma-buf: Change locking policy for mmap() Dmitry Osipenko
2023-05-01 15:42   ` Dmitry Osipenko
2023-04-06 16:06 ` [Intel-gfx] [PATCH v2 7/7] drm/shmem-helper: Switch to reservation lock Dmitry Osipenko
2023-04-06 18:11 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for Move dma-buf mmap() reservation locking down to exporters (rev2) Patchwork
2023-04-06 18:28 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2023-05-12 14:54 ` [Intel-gfx] (subset) [PATCH v2 0/7] Move dma-buf mmap() reservation locking down to exporters Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox