All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules
Date: Wed,  6 Aug 2014 15:04:44 +0200	[thread overview]
Message-ID: <1407330298-27065-1-git-send-email-daniel.vetter@ffwll.ch> (raw)

From: Michel Thierry <michel.thierry@intel.com>

VMAs should take a reference of the address space they use.

Now, when the fd is closed, it will release the ref that the context was
holding, but it will still be referenced by any vmas that are still
active.

ppgtt_release() should then only be called when the last thing referencing
it releases the ref, and it can just call the base cleanup and free the
ppgtt.

Note that with this we will extend the lifetime of ppgtts which
contain shared objects. But all the non-shared objects will get
removed as soon as they drop of the active list and for the shared
ones the shrinker can eventually reap them. Since we currently can't
evict ppgtt pagetables either I don't think that temporary leak is
important.

Signed-off-by: Michel Thierry <michel.thierry@intel.com>
[danvet: Add note about potential ppgtt leak with this approach.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.h         |  2 ++
 drivers/gpu/drm/i915/i915_gem.c         |  8 ++++++++
 drivers/gpu/drm/i915/i915_gem_context.c | 23 +++--------------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     |  5 +++++
 4 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 7c25345ce3e5..5a18680011da 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2510,7 +2510,9 @@ void i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj);
 
 /* i915_gem_context.c */
 #define ctx_to_ppgtt(ctx) container_of((ctx)->vm, struct i915_hw_ppgtt, base)
+#define vm_to_ppgtt(vm) container_of(vm, struct i915_hw_ppgtt, base)
 int __must_check i915_gem_context_init(struct drm_device *dev);
+void ppgtt_release(struct kref *kref);
 void i915_gem_context_fini(struct drm_device *dev);
 void i915_gem_context_reset(struct drm_device *dev);
 int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index dcd8d7b42552..25a32b9c9b4b 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4499,12 +4499,20 @@ struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
 
 void i915_gem_vma_destroy(struct i915_vma *vma)
 {
+	struct i915_address_space *vm = NULL;
+	struct i915_hw_ppgtt *ppgtt = NULL;
 	WARN_ON(vma->node.allocated);
 
 	/* Keep the vma as a placeholder in the execbuffer reservation lists */
 	if (!list_empty(&vma->exec_list))
 		return;
 
+	vm = vma->vm;
+	ppgtt = vm_to_ppgtt(vm);
+
+	if (ppgtt)
+		kref_put(&ppgtt->ref, ppgtt_release);
+
 	list_del(&vma->vma_link);
 
 	kfree(vma);
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 3b99390e467a..ae706cba05ae 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -108,30 +108,13 @@ static void do_ppgtt_cleanup(struct i915_hw_ppgtt *ppgtt)
 		return;
 	}
 
-	/*
-	 * Make sure vmas are unbound before we take down the drm_mm
-	 *
-	 * FIXME: Proper refcounting should take care of this, this shouldn't be
-	 * needed at all.
-	 */
-	if (!list_empty(&vm->active_list)) {
-		struct i915_vma *vma;
-
-		list_for_each_entry(vma, &vm->active_list, mm_list)
-			if (WARN_ON(list_empty(&vma->vma_link) ||
-				    list_is_singular(&vma->vma_link)))
-				break;
-
-		i915_gem_evict_vm(&ppgtt->base, true);
-	} else {
-		i915_gem_retire_requests(dev);
-		i915_gem_evict_vm(&ppgtt->base, false);
-	}
+	/* vmas should already be unbound */
+	WARN_ON(!list_empty(&vm->active_list));
 
 	ppgtt->base.cleanup(&ppgtt->base);
 }
 
-static void ppgtt_release(struct kref *kref)
+void ppgtt_release(struct kref *kref)
 {
 	struct i915_hw_ppgtt *ppgtt =
 		container_of(kref, struct i915_hw_ppgtt, ref);
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 1411613f2174..90c3d0fae3f1 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -2159,10 +2159,15 @@ i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
 				  struct i915_address_space *vm)
 {
 	struct i915_vma *vma;
+	struct i915_hw_ppgtt *ppgtt = NULL;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
 	if (!vma)
 		vma = __i915_gem_vma_create(obj, vm);
 
+	ppgtt = vm_to_ppgtt(vm);
+	if (ppgtt)
+		kref_get(&ppgtt->ref);
+
 	return vma;
 }
-- 
1.9.3

             reply	other threads:[~2014-08-06 14:30 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-06 13:04 Daniel Vetter [this message]
2014-08-06 13:04 ` [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime handling Daniel Vetter
2014-08-08 13:00   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 03/15] drm/i915: Move i915_gem_chipset_flush to where it belongs Daniel Vetter
2014-08-12  8:45   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 04/15] drm/i915: Track file_priv, not ctx in the ppgtt structure Daniel Vetter
2014-08-06 13:04 ` [PATCH 05/15] drm/i915: Only refcount ppgtt if it actually is one Daniel Vetter
2014-08-08 13:02   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 06/15] drm/i915: Add proper prefix to obj_to_ggtt Daniel Vetter
2014-08-06 13:04 ` [PATCH 07/15] drm/i915: Allow i915_gem_setup_global_gtt to fail Daniel Vetter
2014-08-12  8:48   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 08/15] drm/i915: Fix up checks for aliasing ppgtt Daniel Vetter
2014-08-08 13:03   ` Thierry, Michel
2014-08-08 13:49     ` Daniel Vetter
2014-08-08 14:00       ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 09/15] drm/i915: Initialize the aliasing ppgtt as part of global gtt Daniel Vetter
2014-08-06 18:19   ` [PATCH 1/2] drm/i915: Rework ppgtt init to no require an aliasing ppgtt Daniel Vetter
2014-08-06 18:19     ` [PATCH 2/2] drm/i915: Initialize the aliasing ppgtt as part of global gtt Daniel Vetter
2014-08-08 13:04       ` Thierry, Michel
2014-08-06 19:55     ` [PATCH 1/2] drm/i915: Rework ppgtt init to no require an aliasing ppgtt Daniel Vetter
2014-08-12  8:58     ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 10/15] drm/i915: Only track real ppgtt for a context Daniel Vetter
2014-08-06 13:04 ` [PATCH 11/15] drm/i915: Drop create_vm argument to i915_gem_create_context Daniel Vetter
2014-08-08 13:06   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 12/15] drm/i915: Extract common cleanup into i915_ppgtt_release Daniel Vetter
2014-08-08 13:07   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 13/15] drm/i915: Extract commmon global gtt cleanup code Daniel Vetter
2014-08-08 13:08   ` Thierry, Michel
2014-08-06 13:04 ` [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt alongside the global gtt Daniel Vetter
2014-08-08 13:09   ` Thierry, Michel
2014-08-12 14:05     ` Daniel Vetter
2014-08-06 13:04 ` [PATCH 15/15] drm/i915: don't touch console_lock for I915_FBDEV=n Daniel Vetter

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=1407330298-27065-1-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.