Nouveau Archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: daniel@ffwll.ch, airlied@gmail.com, mripard@kernel.org,
	maarten.lankhorst@linux.intel.com, christian.koenig@amd.com,
	sumit.semwal@linaro.org, dmitry.osipenko@collabora.com,
	robdclark@gmail.com, quic_abhinavk@quicinc.com,
	dmitry.baryshkov@linaro.org, sean@poorly.run,
	marijn.suijten@somainline.org, suijingfeng@loongson.cn,
	kherbst@redhat.com, lyude@redhat.com, dakr@redhat.com,
	airlied@redhat.com, kraxel@redhat.com, alexander.deucher@amd.com,
	Xinhui.Pan@amd.com, zack.rusin@broadcom.com,
	bcm-kernel-feedback-list@broadcom.com
Cc: dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
	freedreno@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	virtualization@lists.linux.dev,
	spice-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 01/13] drm/gem-shmem: Acquire reservation lock in GEM pin/unpin callbacks
Date: Tue, 27 Feb 2024 11:14:48 +0100	[thread overview]
Message-ID: <20240227113853.8464-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20240227113853.8464-1-tzimmermann@suse.de>

Export drm_gem_shmem_pin_locked() and acquire the reservation lock
directly in GEM pin callback. Same for unpin. Prepares for further
changes.

Dma-buf locking semantics require callers to hold the buffer's
reservation lock when invoking the pin and unpin callbacks. Prepare
gem-shmem accordingly by pushing locking out of the implementation.
A follow-up patch will fix locking for all GEM code at once.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_gem_shmem_helper.c |  6 ++++--
 include/drm/drm_gem_shmem_helper.h     | 16 ++++++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index e435f986cd135..0ac3dddb917f3 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -228,7 +228,7 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem)
 }
 EXPORT_SYMBOL(drm_gem_shmem_put_pages);
 
-static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem)
+int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem)
 {
 	int ret;
 
@@ -238,13 +238,15 @@ static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem)
 
 	return ret;
 }
+EXPORT_SYMBOL(drm_gem_shmem_pin_locked);
 
-static void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem)
+void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem)
 {
 	dma_resv_assert_held(shmem->base.resv);
 
 	drm_gem_shmem_put_pages(shmem);
 }
+EXPORT_SYMBOL(drm_gem_shmem_unpin_locked);
 
 /**
  * drm_gem_shmem_pin - Pin backing pages for a shmem GEM object
diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h
index bf0c31aa8fbe4..eb12aa9a8c556 100644
--- a/include/drm/drm_gem_shmem_helper.h
+++ b/include/drm/drm_gem_shmem_helper.h
@@ -108,6 +108,9 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
 			  struct iosys_map *map);
 int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct *vma);
 
+int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem);
+void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem);
+
 int drm_gem_shmem_madvise(struct drm_gem_shmem_object *shmem, int madv);
 
 static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem)
@@ -172,8 +175,15 @@ static inline void drm_gem_shmem_object_print_info(struct drm_printer *p, unsign
 static inline int drm_gem_shmem_object_pin(struct drm_gem_object *obj)
 {
 	struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
+	int ret;
+
+	ret = dma_resv_lock_interruptible(shmem->base.resv, NULL);
+	if (ret)
+		return ret;
+	ret = drm_gem_shmem_pin_locked(shmem);
+	dma_resv_unlock(shmem->base.resv);
 
-	return drm_gem_shmem_pin(shmem);
+	return ret;
 }
 
 /**
@@ -187,7 +197,9 @@ static inline void drm_gem_shmem_object_unpin(struct drm_gem_object *obj)
 {
 	struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
 
-	drm_gem_shmem_unpin(shmem);
+	dma_resv_lock(shmem->base.resv, NULL);
+	drm_gem_shmem_unpin_locked(shmem);
+	dma_resv_unlock(shmem->base.resv);
 }
 
 /**
-- 
2.43.2


  reply	other threads:[~2024-02-27 11:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 10:14 [PATCH 00/13] drm: Fix reservation locking for pin/unpin and console Thomas Zimmermann
2024-02-27 10:14 ` Thomas Zimmermann [this message]
2024-02-27 10:14 ` [PATCH 02/13] drm/gem-vram: Acquire reservation lock in GEM pin/unpin callbacks Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 03/13] drm/msm: Provide msm_gem_get_pages_locked() Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 04/13] drm/msm: Acquire reservation lock in GEM pin/unpin callback Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 05/13] drm/nouveau: Provide nouveau_bo_{pin,unpin}_locked() Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 06/13] drm/nouveau: Acquire reservation lock in GEM pin/unpin callbacks Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 07/13] drm/qxl: Provide qxl_bo_{pin,unpin}_locked() Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 08/13] drm/qxl: Acquire reservation lock in GEM pin/unpin callbacks Thomas Zimmermann
2024-02-28  3:47   ` Zack Rusin
2024-02-27 10:14 ` [PATCH 09/13] drm/gem: Acquire reservation lock in drm_gem_{pin/unpin}() Thomas Zimmermann
2024-02-28  3:52   ` Zack Rusin
2024-03-11 21:51   ` [09/13] " Sui Jingfeng
2024-02-27 10:14 ` [PATCH 10/13] drm/fbdev-generic: Fix locking with drm_client_buffer_vmap_local() Thomas Zimmermann
2024-03-11 22:36   ` [10/13] " Sui Jingfeng
2024-02-27 10:14 ` [PATCH 11/13] drm/client: Pin vmap'ed GEM buffers Thomas Zimmermann
2024-02-27 10:14 ` [PATCH 12/13] drm/gem-vram: Do not pin buffer objects for vmap Thomas Zimmermann
2024-02-27 10:15 ` [PATCH 13/13] drm/qxl: " Thomas Zimmermann
2024-02-27 14:03 ` [PATCH 00/13] drm: Fix reservation locking for pin/unpin and console Christian König
2024-02-27 15:42   ` Thomas Zimmermann
2024-02-27 18:14 ` Dmitry Osipenko
2024-02-27 18:33   ` Christian König
2024-02-28  8:19   ` Thomas Zimmermann
2024-03-01 16:44     ` Dmitry Osipenko
2024-02-28  3:54 ` Zack Rusin
2024-03-05 21:58 ` Dmitry Osipenko
2024-03-06 14:44   ` Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240227113853.8464-2-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=airlied@redhat.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=christian.koenig@amd.com \
    --cc=dakr@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=kherbst@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marijn.suijten@somainline.org \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=quic_abhinavk@quicinc.com \
    --cc=robdclark@gmail.com \
    --cc=sean@poorly.run \
    --cc=spice-devel@lists.freedesktop.org \
    --cc=suijingfeng@loongson.cn \
    --cc=sumit.semwal@linaro.org \
    --cc=virtualization@lists.linux.dev \
    --cc=zack.rusin@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).