dri-devel Archive on lore.kernel.org
 help / color / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@redhat.com, daniel@ffwll.ch,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	hdegoede@redhat.com, christian.koenig@amd.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH 7/8] drm/vram-helper: Remove vmap reference counting
Date: Mon, 30 Nov 2020 13:04:32 +0100
Message-ID: <20201130120433.7205-8-tzimmermann@suse.de> (raw)
In-Reply-To: <20201130120433.7205-1-tzimmermann@suse.de>

Overlapping or nested mappings of the same BO are not allowed by the
semantics of the GEM vmap/vunmap operations. Concurent access to the
GEM object is prevented by reservation locks.

So we don't need the reference counter in the GEM VRAM object. Remove
it.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 19 ++++---------------
 include/drm/drm_gem_vram_helper.h     | 17 +++--------------
 2 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index ac0fa9da1c83..a44718dd66cb 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -113,7 +113,6 @@ static void drm_gem_vram_cleanup(struct drm_gem_vram_object *gbo)
 	 * up; only release the GEM object.
 	 */
 
-	WARN_ON(gbo->vmap_use_count);
 	WARN_ON(dma_buf_map_is_set(&gbo->map));
 
 	drm_gem_object_release(&gbo->bo.base);
@@ -384,15 +383,10 @@ static int drm_gem_vram_kmap_locked(struct drm_gem_vram_object *gbo,
 {
 	int ret;
 
-	if (gbo->vmap_use_count > 0)
-		goto out;
-
 	ret = ttm_bo_vmap(&gbo->bo, &gbo->map);
 	if (ret)
 		return ret;
 
-out:
-	++gbo->vmap_use_count;
 	*map = gbo->map;
 
 	return 0;
@@ -403,15 +397,9 @@ static void drm_gem_vram_kunmap_locked(struct drm_gem_vram_object *gbo,
 {
 	struct drm_device *dev = gbo->bo.base.dev;
 
-	if (drm_WARN_ON_ONCE(dev, !gbo->vmap_use_count))
-		return;
-
 	if (drm_WARN_ON_ONCE(dev, !dma_buf_map_is_equal(&gbo->map, map)))
 		return; /* BUG: map not mapped from this BO */
 
-	if (--gbo->vmap_use_count > 0)
-		return;
-
 	/*
 	 * Permanently mapping and unmapping buffers adds overhead from
 	 * updating the page tables and creates debugging output. Therefore,
@@ -596,12 +584,13 @@ static void drm_gem_vram_bo_driver_move_notify(struct drm_gem_vram_object *gbo,
 					       struct ttm_resource *new_mem)
 {
 	struct ttm_buffer_object *bo = &gbo->bo;
-	struct drm_device *dev = bo->base.dev;
+	struct dma_buf_map *map = &gbo->map;
 
-	if (drm_WARN_ON_ONCE(dev, gbo->vmap_use_count))
+	if (dma_buf_map_is_null(map))
 		return;
 
-	ttm_bo_vunmap(bo, &gbo->map);
+	ttm_bo_vunmap(bo, map);
+	dma_buf_map_clear(map);
 }
 
 static int drm_gem_vram_bo_driver_move(struct drm_gem_vram_object *gbo,
diff --git a/include/drm/drm_gem_vram_helper.h b/include/drm/drm_gem_vram_helper.h
index 2d22888b5754..b679349bbfb2 100644
--- a/include/drm/drm_gem_vram_helper.h
+++ b/include/drm/drm_gem_vram_helper.h
@@ -42,25 +42,14 @@ struct ww_acquire_ctx;
  * dedicated memory. The buffer object can be evicted to system memory if
  * video memory becomes scarce.
  *
- * GEM VRAM objects perform reference counting for pin and mapping
- * operations. So a buffer object that has been pinned N times with
- * drm_gem_vram_pin() must be unpinned N times with
- * drm_gem_vram_unpin(). The same applies to pairs of
- * drm_gem_vram_kmap() and drm_gem_vram_kunmap(), as well as pairs of
- * drm_gem_vram_vmap() and drm_gem_vram_vunmap().
+ * GEM VRAM objects perform reference counting for pin operations. So a
+ * buffer object that has been pinned N times with drm_gem_vram_pin() must
+ * be unpinned N times with drm_gem_vram_unpin().
  */
 struct drm_gem_vram_object {
 	struct ttm_buffer_object bo;
 	struct dma_buf_map map;
 
-	/**
-	 * @vmap_use_count:
-	 *
-	 * Reference count on the virtual address.
-	 * The address are un-mapped when the count reaches zero.
-	 */
-	unsigned int vmap_use_count;
-
 	/* Supported placements are %TTM_PL_VRAM and %TTM_PL_SYSTEM */
 	struct ttm_placement placement;
 	struct ttm_place placements[2];
-- 
2.29.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply index

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 12:04 [PATCH 0/8] drm/vram-helper: Lock GEM BOs while they are mapped Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 1/8] drm/gem: Write down some rules for vmap usage Thomas Zimmermann
2020-11-30 15:30   ` Daniel Vetter
2020-11-30 15:33     ` Christian König
2020-12-01  8:32       ` Thomas Zimmermann
2020-12-01  9:10         ` Daniel Vetter
2020-12-01  9:40           ` Thomas Zimmermann
2020-12-01 10:00             ` Daniel Vetter
2020-12-01 10:27               ` Thomas Zimmermann
2020-12-01 10:34                 ` Christian König
2020-12-01 11:30                   ` Thomas Zimmermann
2020-12-01 12:14                     ` Christian König
2020-12-01 12:33                       ` Thomas Zimmermann
2020-12-01 12:38                         ` Christian König
2020-12-01 12:51                           ` Thomas Zimmermann
2020-12-01 12:53                             ` Thomas Zimmermann
2020-12-01 13:05                               ` Christian König
2020-12-01 16:54                 ` Daniel Vetter
2020-12-01 12:05               ` Thomas Zimmermann
2020-12-01  9:13         ` Christian König
2020-12-01  9:30           ` Thomas Zimmermann
2020-12-01  8:15     ` Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 2/8] drm/ast: Only map cursor BOs during updates Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 3/8] drm/vram-helper: Provide drm_gem_vram_vmap_unlocked() Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 4/8] drm/ast: Use drm_gem_vram_vmap_unlocked() in ast_cursor_show() Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 5/8] drm/vboxvideo: Use drm_gem_vram_vmap_unlocked() in cursor update Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 6/8] drm/vram-helper: Remove pinning and locking from drm_gem_vram_vmap() Thomas Zimmermann
2020-11-30 12:04 ` Thomas Zimmermann [this message]
2020-11-30 12:04 ` [PATCH 8/8] drm/vram-helper: Simplify vmap implementation Thomas Zimmermann
2020-11-30 12:27 ` [PATCH 0/8] drm/vram-helper: Lock GEM BOs while they are mapped Christian König
2020-11-30 12:45 ` 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=20201130120433.7205-8-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@redhat.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    /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

dri-devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dri-devel/0 dri-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dri-devel dri-devel/ https://lore.kernel.org/dri-devel \
		dri-devel@lists.freedesktop.org
	public-inbox-index dri-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.freedesktop.lists.dri-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git