[Intel-gfx] [PATCH v4 06/21] drm/i915: Prepare to dynamic dma-buf locking specification

Ruhl, Michael J michael.j.ruhl at intel.com
Thu Sep 1 14:02:59 UTC 2022


>-----Original Message-----
>From: Dmitry Osipenko <dmitry.osipenko at collabora.com>
>Sent: Wednesday, August 31, 2022 11:38 AM
>To: David Airlie <airlied at linux.ie>; Gerd Hoffmann <kraxel at redhat.com>;
>Gurchetan Singh <gurchetansingh at chromium.org>; Chia-I Wu
><olvaffe at gmail.com>; Daniel Vetter <daniel at ffwll.ch>; Daniel Almeida
><daniel.almeida at collabora.com>; Gert Wollny <gert.wollny at collabora.com>;
>Gustavo Padovan <gustavo.padovan at collabora.com>; Daniel Stone
><daniel at fooishbar.org>; Tomeu Vizoso <tomeu.vizoso at collabora.com>;
>Maarten Lankhorst <maarten.lankhorst at linux.intel.com>; Maxime Ripard
><mripard at kernel.org>; Thomas Zimmermann <tzimmermann at suse.de>;
>Rob Clark <robdclark at gmail.com>; Sumit Semwal
><sumit.semwal at linaro.org>; Christian König <christian.koenig at amd.com>;
>Pan, Xinhui <Xinhui.Pan at amd.com>; Thierry Reding
><thierry.reding at gmail.com>; Tomasz Figa <tfiga at chromium.org>; Marek
>Szyprowski <m.szyprowski at samsung.com>; Mauro Carvalho Chehab
><mchehab at kernel.org>; Alex Deucher <alexander.deucher at amd.com>; Jani
>Nikula <jani.nikula at linux.intel.com>; Joonas Lahtinen
><joonas.lahtinen at linux.intel.com>; Vivi, Rodrigo <rodrigo.vivi at intel.com>;
>Tvrtko Ursulin <tvrtko.ursulin at linux.intel.com>; Thomas Hellström
><thomas_os at shipmail.org>; Qiang Yu <yuq825 at gmail.com>; Srinivas
>Kandagatla <srinivas.kandagatla at linaro.org>; Amol Maheshwari
><amahesh at qti.qualcomm.com>; Jason Gunthorpe <jgg at ziepe.ca>; Leon
>Romanovsky <leon at kernel.org>; Gross, Jurgen <jgross at suse.com>; Stefano
>Stabellini <sstabellini at kernel.org>; Oleksandr Tyshchenko
><oleksandr_tyshchenko at epam.com>; Tomi Valkeinen <tomba at kernel.org>;
>Russell King <linux at armlinux.org.uk>; Lucas Stach <l.stach at pengutronix.de>;
>Christian Gmeiner <christian.gmeiner at gmail.com>
>Cc: dri-devel at lists.freedesktop.org; linux-kernel at vger.kernel.org; Dmitry
>Osipenko <digetx at gmail.com>; linux-media at vger.kernel.org; linaro-mm-
>sig at lists.linaro.org; amd-gfx at lists.freedesktop.org; intel-
>gfx at lists.freedesktop.org; kernel at collabora.com; virtualization at lists.linux-
>foundation.org; linux-rdma at vger.kernel.org; linux-arm-
>msm at vger.kernel.org
>Subject: [PATCH v4 06/21] drm/i915: Prepare to dynamic dma-buf locking
>specification
>
>Prepare i915 driver to the common dynamic dma-buf locking convention
>by starting to use the unlocked versions of dma-buf API functions
>and handling cases where importer now holds the reservation lock.
>
>Signed-off-by: Dmitry Osipenko <dmitry.osipenko at collabora.com>
>---
> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c       |  2 +-
> drivers/gpu/drm/i915/gem/i915_gem_object.c       | 12 ++++++++++++
> .../gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c | 16 ++++++++--------
> 3 files changed, 21 insertions(+), 9 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
>b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
>index f5062d0c6333..07eee1c09aaf 100644
>--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
>+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
>@@ -72,7 +72,7 @@ static int i915_gem_dmabuf_vmap(struct dma_buf
>*dma_buf,
> 	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
> 	void *vaddr;
>
>-	vaddr = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
>+	vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
> 	if (IS_ERR(vaddr))
> 		return PTR_ERR(vaddr);
>
>diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c
>b/drivers/gpu/drm/i915/gem/i915_gem_object.c
>index 389e9f157ca5..7e2a9b02526c 100644
>--- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
>+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
>@@ -331,7 +331,19 @@ static void __i915_gem_free_objects(struct
>drm_i915_private *i915,
> 			continue;
> 		}
>
>+		/*
>+		 * dma_buf_unmap_attachment() requires reservation to be
>+		 * locked. The imported GEM shouldn't share reservation lock,
>+		 * so it's safe to take the lock.
>+		 */
>+		if (obj->base.import_attach)
>+			i915_gem_object_lock(obj, NULL);

There is a lot of stuff going here.  Taking the lock may be premature...

> 		__i915_gem_object_pages_fini(obj);

The i915_gem_dmabuf.c:i915_gem_object_put_pages_dmabuf is where
unmap_attachment is actually called, would it make more sense to make
do the locking there?

Mike


>+
>+		if (obj->base.import_attach)
>+			i915_gem_object_unlock(obj);
>+
> 		__i915_gem_free_object(obj);
>
> 		/* But keep the pointer alive for RCU-protected lookups */
>diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
>b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
>index 62c61af77a42..9e3ed634aa0e 100644
>--- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
>+++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
>@@ -213,7 +213,7 @@ static int igt_dmabuf_import_same_driver(struct
>drm_i915_private *i915,
> 		goto out_import;
> 	}
>
>-	st = dma_buf_map_attachment(import_attach,
>DMA_BIDIRECTIONAL);
>+	st = dma_buf_map_attachment_unlocked(import_attach,
>DMA_BIDIRECTIONAL);
> 	if (IS_ERR(st)) {
> 		err = PTR_ERR(st);
> 		goto out_detach;
>@@ -226,7 +226,7 @@ static int igt_dmabuf_import_same_driver(struct
>drm_i915_private *i915,
> 		timeout = -ETIME;
> 	}
> 	err = timeout > 0 ? 0 : timeout;
>-	dma_buf_unmap_attachment(import_attach, st,
>DMA_BIDIRECTIONAL);
>+	dma_buf_unmap_attachment_unlocked(import_attach, st,
>DMA_BIDIRECTIONAL);
> out_detach:
> 	dma_buf_detach(dmabuf, import_attach);
> out_import:
>@@ -296,7 +296,7 @@ static int igt_dmabuf_import(void *arg)
> 		goto out_obj;
> 	}
>
>-	err = dma_buf_vmap(dmabuf, &map);
>+	err = dma_buf_vmap_unlocked(dmabuf, &map);
> 	dma_map = err ? NULL : map.vaddr;
> 	if (!dma_map) {
> 		pr_err("dma_buf_vmap failed\n");
>@@ -337,7 +337,7 @@ static int igt_dmabuf_import(void *arg)
>
> 	err = 0;
> out_dma_map:
>-	dma_buf_vunmap(dmabuf, &map);
>+	dma_buf_vunmap_unlocked(dmabuf, &map);
> out_obj:
> 	i915_gem_object_put(obj);
> out_dmabuf:
>@@ -358,7 +358,7 @@ static int igt_dmabuf_import_ownership(void *arg)
> 	if (IS_ERR(dmabuf))
> 		return PTR_ERR(dmabuf);
>
>-	err = dma_buf_vmap(dmabuf, &map);
>+	err = dma_buf_vmap_unlocked(dmabuf, &map);
> 	ptr = err ? NULL : map.vaddr;
> 	if (!ptr) {
> 		pr_err("dma_buf_vmap failed\n");
>@@ -367,7 +367,7 @@ static int igt_dmabuf_import_ownership(void *arg)
> 	}
>
> 	memset(ptr, 0xc5, PAGE_SIZE);
>-	dma_buf_vunmap(dmabuf, &map);
>+	dma_buf_vunmap_unlocked(dmabuf, &map);
>
> 	obj = to_intel_bo(i915_gem_prime_import(&i915->drm, dmabuf));
> 	if (IS_ERR(obj)) {
>@@ -418,7 +418,7 @@ static int igt_dmabuf_export_vmap(void *arg)
> 	}
> 	i915_gem_object_put(obj);
>
>-	err = dma_buf_vmap(dmabuf, &map);
>+	err = dma_buf_vmap_unlocked(dmabuf, &map);
> 	ptr = err ? NULL : map.vaddr;
> 	if (!ptr) {
> 		pr_err("dma_buf_vmap failed\n");
>@@ -435,7 +435,7 @@ static int igt_dmabuf_export_vmap(void *arg)
> 	memset(ptr, 0xc5, dmabuf->size);
>
> 	err = 0;
>-	dma_buf_vunmap(dmabuf, &map);
>+	dma_buf_vunmap_unlocked(dmabuf, &map);
> out:
> 	dma_buf_put(dmabuf);
> 	return err;
>--
>2.37.2



More information about the Intel-gfx mailing list