dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: "David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Christian König" <christian.koenig@amd.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Qiang Yu" <yuq825@gmail.com>,
	"Steven Price" <steven.price@arm.com>,
	"Boris Brezillon" <boris.brezillon@collabora.com>,
	"Frank Binns" <frank.binns@imgtec.com>,
	"Matt Coster" <matt.coster@imgtec.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com
Subject: [PATCH v20 09/10] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin
Date: Sun, 23 Mar 2025 00:26:07 +0300	[thread overview]
Message-ID: <20250322212608.40511-10-dmitry.osipenko@collabora.com> (raw)
In-Reply-To: <20250322212608.40511-1-dmitry.osipenko@collabora.com>

The vmapped pages shall be pinned in memory and previously get/put_pages()
were implicitly hard-pinning/unpinning the pages. This will no longer be
the case with addition of memory shrinker because pages_use_count > 0 won't
determine anymore whether pages are hard-pinned (they will be soft-pinned),
while the new pages_pin_count will do the hard-pinning. Switch the
vmap/vunmap() to use pin/unpin() functions in a preparation of addition
of the memory shrinker support to drm-shmem.

Acked-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 6 +++---
 include/drm/drm_gem_shmem_helper.h     | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 6fb96e790abd..84a196bbe44f 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -360,7 +360,7 @@ int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem,
 			return 0;
 		}
 
-		ret = drm_gem_shmem_get_pages_locked(shmem);
+		ret = drm_gem_shmem_pin_locked(shmem);
 		if (ret)
 			goto err_zero_use;
 
@@ -383,7 +383,7 @@ int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem,
 
 err_put_pages:
 	if (!drm_gem_is_imported(obj))
-		drm_gem_shmem_put_pages_locked(shmem);
+		drm_gem_shmem_unpin_locked(shmem);
 err_zero_use:
 	shmem->vmap_use_count = 0;
 
@@ -420,7 +420,7 @@ void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
 			return;
 
 		vunmap(shmem->vaddr);
-		drm_gem_shmem_put_pages_locked(shmem);
+		drm_gem_shmem_unpin_locked(shmem);
 	}
 
 	shmem->vaddr = NULL;
diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h
index 3a4be433d5f0..8b9bba87ae63 100644
--- a/include/drm/drm_gem_shmem_helper.h
+++ b/include/drm/drm_gem_shmem_helper.h
@@ -130,7 +130,7 @@ int drm_gem_shmem_madvise_locked(struct drm_gem_shmem_object *shmem, int madv);
 static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem)
 {
 	return (shmem->madv > 0) &&
-		!shmem->vmap_use_count && shmem->sgt &&
+		!refcount_read(&shmem->pages_pin_count) && shmem->sgt &&
 		!shmem->base.dma_buf && !drm_gem_is_imported(&shmem->base);
 }
 
-- 
2.49.0


  parent reply	other threads:[~2025-03-22 21:30 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-22 21:25 [PATCH v20 00/10] Add generic DRM-shmem memory shrinker (part 1) Dmitry Osipenko
2025-03-22 21:25 ` [PATCH v20 01/10] drm/gem: Change locked/unlocked postfix of drm_gem_v/unmap() function names Dmitry Osipenko
2025-03-24 13:05   ` Christian König
2025-03-25 13:15     ` Dmitry Osipenko
2025-03-22 21:26 ` [PATCH v20 02/10] drm/gem: Add _locked postfix to functions that have unlocked counterpart Dmitry Osipenko
2025-03-22 21:26 ` [PATCH v20 03/10] drm/gem: Document locking rule of vmap and evict callbacks Dmitry Osipenko
2025-03-22 21:26 ` [PATCH v20 04/10] drm/shmem-helper: Make all exported symbols GPL Dmitry Osipenko
2025-03-22 21:26 ` [PATCH v20 05/10] drm/shmem-helper: Refactor locked/unlocked functions Dmitry Osipenko
2025-03-27 11:25   ` Jani Nikula
2025-03-27 11:27     ` Jani Nikula
2025-03-27 11:29       ` Jani Nikula
2025-03-22 21:26 ` [PATCH v20 06/10] drm/shmem-helper: Remove obsoleted is_iomem test Dmitry Osipenko
2025-03-22 21:26 ` [PATCH v20 07/10] drm/shmem-helper: Add and use pages_pin_count Dmitry Osipenko
2025-03-22 21:26 ` [PATCH v20 08/10] drm/shmem-helper: Use refcount_t for pages_use_count Dmitry Osipenko
2025-03-22 21:26 ` Dmitry Osipenko [this message]
2025-04-02 12:47   ` [PATCH v20 09/10] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin Thomas Zimmermann
2025-04-02 12:58     ` Dmitry Osipenko
2025-04-02 13:21       ` Boris Brezillon
2025-04-03  7:20         ` Thomas Zimmermann
2025-04-03  8:50           ` Boris Brezillon
2025-04-04  8:01             ` Thomas Zimmermann
2025-04-04 14:52               ` Boris Brezillon
2025-04-04 14:58                 ` Thomas Zimmermann
2025-04-07  9:56                   ` Boris Brezillon
2025-03-22 21:26 ` [PATCH v20 10/10] drm/shmem-helper: Use refcount_t for vmap_use_count Dmitry Osipenko
2025-03-25 14:17 ` [PATCH v20 00/10] Add generic DRM-shmem memory shrinker (part 1) Thomas Zimmermann
2025-03-26 20:08   ` Dmitry Osipenko
2025-03-27 10:45     ` Boris Brezillon
2025-03-27 10:47       ` Dmitry Osipenko
2025-04-03  0:37 ` Lucas De Marchi
2025-04-03  7:03   ` Thomas Zimmermann
2025-04-03 14:10     ` Dmitry Osipenko

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=20250322212608.40511-10-dmitry.osipenko@collabora.com \
    --to=dmitry.osipenko@collabora.com \
    --cc=airlied@gmail.com \
    --cc=boris.brezillon@collabora.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=frank.binns@imgtec.com \
    --cc=kernel@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matt.coster@imgtec.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    --cc=yuq825@gmail.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 NNTP newsgroup(s).