All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules
@ 2014-08-06 13:04 Daniel Vetter
  2014-08-06 13:04 ` [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime handling Daniel Vetter
                   ` (13 more replies)
  0 siblings, 14 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

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

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime handling
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
@ 2014-08-06 13:04 ` 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
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

So when reviewing Michel's patch I've noticed a few things and cleaned
them up:
- The early checks in ppgtt_release are now redundant: The inactive
  list should always be empty now, so we can ditch these checks. Even
  for the aliasing ppgtt (though that's a different confusion) since
  we tear that down after all the objects are gone.
- The ppgtt handling functions are splattered all over. Consolidate
  them in i915_gem_gtt.c, give them OCD prefixes and add wrappers for
  get/put.
- There was a bit a confusion in ppgtt_release about whether it cares
  about the active or inactive list. It should care about them both,
  so augment the WARNINGs to check for both.

There's still create_vm_for_ctx left to do, put that is blocked on the
removal of ppgtt->ctx. Once that's done we can rename it to
i915_ppgtt_create and move it to its siblings for handling ppgtts.

v2: Move the ppgtt checks into the inline get/put functions as
suggested by Chris.

v3: Inline the now redundant ppgtt local variable.

Cc: Michel Thierry <michel.thierry@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.h         |  1 -
 drivers/gpu/drm/i915/i915_gem.c         |  5 +----
 drivers/gpu/drm/i915/i915_gem_context.c | 36 ++++-----------------------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 20 +++++++++++++-----
 drivers/gpu/drm/i915/i915_gem_gtt.h     | 14 ++++++++++++-
 5 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 5a18680011da..d349dd75ed69 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2512,7 +2512,6 @@ void i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj);
 #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 25a32b9c9b4b..b33a677b4b1e 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4500,7 +4500,6 @@ 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 */
@@ -4508,10 +4507,8 @@ void i915_gem_vma_destroy(struct i915_vma *vma)
 		return;
 
 	vm = vma->vm;
-	ppgtt = vm_to_ppgtt(vm);
 
-	if (ppgtt)
-		kref_put(&ppgtt->ref, ppgtt_release);
+	i915_ppgtt_put(vm_to_ppgtt(vm));
 
 	list_del(&vma->vma_link);
 
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index ae706cba05ae..899c6a7a5920 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -96,33 +96,6 @@
 #define GEN6_CONTEXT_ALIGN (64<<10)
 #define GEN7_CONTEXT_ALIGN 4096
 
-static void do_ppgtt_cleanup(struct i915_hw_ppgtt *ppgtt)
-{
-	struct drm_device *dev = ppgtt->base.dev;
-	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct i915_address_space *vm = &ppgtt->base;
-
-	if (ppgtt == dev_priv->mm.aliasing_ppgtt ||
-	    (list_empty(&vm->active_list) && list_empty(&vm->inactive_list))) {
-		ppgtt->base.cleanup(&ppgtt->base);
-		return;
-	}
-
-	/* vmas should already be unbound */
-	WARN_ON(!list_empty(&vm->active_list));
-
-	ppgtt->base.cleanup(&ppgtt->base);
-}
-
-void ppgtt_release(struct kref *kref)
-{
-	struct i915_hw_ppgtt *ppgtt =
-		container_of(kref, struct i915_hw_ppgtt, ref);
-
-	do_ppgtt_cleanup(ppgtt);
-	kfree(ppgtt);
-}
-
 static size_t get_context_alignment(struct drm_device *dev)
 {
 	if (IS_GEN6(dev))
@@ -171,8 +144,7 @@ void i915_gem_context_free(struct kref *ctx_ref)
 			ppgtt = ctx_to_ppgtt(ctx);
 	}
 
-	if (ppgtt)
-		kref_put(&ppgtt->ref, ppgtt_release);
+	i915_ppgtt_put(ppgtt);
 	if (ctx->legacy_hw_ctx.rcs_state)
 		drm_gem_object_unreference(&ctx->legacy_hw_ctx.rcs_state->base);
 	list_del(&ctx->link);
@@ -219,7 +191,7 @@ create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)
 	if (!ppgtt)
 		return ERR_PTR(-ENOMEM);
 
-	ret = i915_gem_init_ppgtt(dev, ppgtt);
+	ret = i915_ppgtt_init(dev, ppgtt);
 	if (ret) {
 		kfree(ppgtt);
 		return ERR_PTR(ret);
@@ -231,7 +203,7 @@ create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)
 
 static struct intel_context *
 __create_hw_context(struct drm_device *dev,
-		  struct drm_i915_file_private *file_priv)
+		    struct drm_i915_file_private *file_priv)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_context *ctx;
@@ -339,7 +311,7 @@ i915_gem_create_context(struct drm_device *dev,
 		/* For platforms which only have aliasing PPGTT, we fake the
 		 * address space and refcounting. */
 		ctx->vm = &dev_priv->mm.aliasing_ppgtt->base;
-		kref_get(&dev_priv->mm.aliasing_ppgtt->ref);
+		i915_ppgtt_get(dev_priv->mm.aliasing_ppgtt);
 	} else
 		ctx->vm = &dev_priv->gtt.base;
 
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 90c3d0fae3f1..1a20e1b4f052 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1191,7 +1191,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	return 0;
 }
 
-int i915_gem_init_ppgtt(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret = 0;
@@ -1222,6 +1222,19 @@ int i915_gem_init_ppgtt(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
 	return ret;
 }
 
+void  i915_ppgtt_release(struct kref *kref)
+{
+	struct i915_hw_ppgtt *ppgtt =
+		container_of(kref, struct i915_hw_ppgtt, ref);
+
+	/* vmas should already be unbound */
+	WARN_ON(!list_empty(&ppgtt->base.active_list));
+	WARN_ON(!list_empty(&ppgtt->base.inactive_list));
+
+	ppgtt->base.cleanup(&ppgtt->base);
+	kfree(ppgtt);
+}
+
 static void
 ppgtt_bind_vma(struct i915_vma *vma,
 	       enum i915_cache_level cache_level,
@@ -2159,15 +2172,12 @@ 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);
+	i915_ppgtt_get(vm_to_ppgtt(vm));
 
 	return vma;
 }
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 8d6f7c18c404..57d401343e8d 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -273,7 +273,19 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
 			       unsigned long mappable_end, unsigned long end);
 
 bool intel_enable_ppgtt(struct drm_device *dev, bool full);
-int i915_gem_init_ppgtt(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
+
+int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
+void i915_ppgtt_release(struct kref *kref);
+static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
+{
+	if (ppgtt)
+		kref_get(&ppgtt->ref);
+}
+static inline void i915_ppgtt_put(struct i915_hw_ppgtt *ppgtt)
+{
+	if (ppgtt)
+		kref_put(&ppgtt->ref, i915_ppgtt_release);
+}
 
 void i915_check_and_clear_faults(struct drm_device *dev);
 void i915_gem_suspend_gtt_mappings(struct drm_device *dev);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 03/15] drm/i915: Move i915_gem_chipset_flush to where it belongs
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
  2014-08-06 13:04 ` [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime handling Daniel Vetter
@ 2014-08-06 13:04 ` 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
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Include depency hell ftw! So need to move this into a real function.

Also fix up the header include order in i915_drv.h: The rule is to
always include core headers first, then local stuff.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.h     | 7 -------
 drivers/gpu/drm/i915/i915_gem_gtt.c | 6 ++++++
 drivers/gpu/drm/i915/i915_gem_gtt.h | 2 ++
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index d349dd75ed69..194367f0ba1a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2556,13 +2556,6 @@ int __must_check i915_gem_evict_something(struct drm_device *dev,
 int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
 int i915_gem_evict_everything(struct drm_device *dev);
 
-/* belongs in i915_gem_gtt.h */
-static inline void i915_gem_chipset_flush(struct drm_device *dev)
-{
-	if (INTEL_INFO(dev)->gen < 6)
-		intel_gtt_chipset_flush();
-}
-
 /* i915_gem_stolen.c */
 int i915_gem_init_stolen(struct drm_device *dev);
 int i915_gem_stolen_setup_compression(struct drm_device *dev, int size, int fb_cpp);
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 1a20e1b4f052..baa94199239b 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -2031,6 +2031,12 @@ static void gen6_gmch_remove(struct i915_address_space *vm)
 	teardown_scratch_page(vm->dev);
 }
 
+void i915_gem_chipset_flush(struct drm_device *dev)
+{
+	if (INTEL_INFO(dev)->gen < 6)
+		intel_gtt_chipset_flush();
+}
+
 static int i915_gmch_probe(struct drm_device *dev,
 			   size_t *gtt_total,
 			   size_t *stolen,
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 57d401343e8d..380e034c66f8 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -294,4 +294,6 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev);
 int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj);
 void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj);
 
+void i915_gem_chipset_flush(struct drm_device *dev);
+
 #endif
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 04/15] drm/i915: Track file_priv, not ctx in the ppgtt structure
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
  2014-08-06 13:04 ` [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime handling Daniel Vetter
  2014-08-06 13:04 ` [PATCH 03/15] drm/i915: Move i915_gem_chipset_flush to where it belongs Daniel Vetter
@ 2014-08-06 13:04 ` Daniel Vetter
  2014-08-06 13:04 ` [PATCH 05/15] drm/i915: Only refcount ppgtt if it actually is one Daniel Vetter
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Hardware contexts reference a ppgtt, not the other way round. And the
only user of this (in debugfs) actually only cares about which file
the ppgtt is associated with. So give it what it wants.

While at it give the ppgtt create function a proper name&place.

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_debugfs.c     |  2 +-
 drivers/gpu/drm/i915/i915_gem_context.c | 22 +---------------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 21 +++++++++++++++++++++
 drivers/gpu/drm/i915/i915_gem_gtt.h     |  6 +++++-
 4 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 330caa1ab9f9..5c40d49042b8 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -333,7 +333,7 @@ static int per_file_stats(int id, void *ptr, void *data)
 			}
 
 			ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
-			if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv)
+			if (ppgtt->file_priv != stats->file_priv)
 				continue;
 
 			if (obj->ring) /* XXX per-vma statistic */
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 899c6a7a5920..3b8367aa8404 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -181,26 +181,6 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size)
 	return obj;
 }
 
-static struct i915_hw_ppgtt *
-create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)
-{
-	struct i915_hw_ppgtt *ppgtt;
-	int ret;
-
-	ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
-	if (!ppgtt)
-		return ERR_PTR(-ENOMEM);
-
-	ret = i915_ppgtt_init(dev, ppgtt);
-	if (ret) {
-		kfree(ppgtt);
-		return ERR_PTR(ret);
-	}
-
-	ppgtt->ctx = ctx;
-	return ppgtt;
-}
-
 static struct intel_context *
 __create_hw_context(struct drm_device *dev,
 		    struct drm_i915_file_private *file_priv)
@@ -287,7 +267,7 @@ i915_gem_create_context(struct drm_device *dev,
 	}
 
 	if (create_vm) {
-		struct i915_hw_ppgtt *ppgtt = create_vm_for_ctx(dev, ctx);
+		struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev, file_priv);
 
 		if (IS_ERR_OR_NULL(ppgtt)) {
 			DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index baa94199239b..83ee41e5c1c7 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1222,6 +1222,27 @@ int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
 	return ret;
 }
 
+struct i915_hw_ppgtt *
+i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private *fpriv)
+{
+	struct i915_hw_ppgtt *ppgtt;
+	int ret;
+
+	ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+	if (!ppgtt)
+		return ERR_PTR(-ENOMEM);
+
+	ret = i915_ppgtt_init(dev, ppgtt);
+	if (ret) {
+		kfree(ppgtt);
+		return ERR_PTR(ret);
+	}
+
+	ppgtt->file_priv = fpriv;
+
+	return ppgtt;
+}
+
 void  i915_ppgtt_release(struct kref *kref)
 {
 	struct i915_hw_ppgtt *ppgtt =
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 380e034c66f8..0b04ef6167f8 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -34,6 +34,8 @@
 #ifndef __I915_GEM_GTT_H__
 #define __I915_GEM_GTT_H__
 
+struct drm_i915_file_private;
+
 typedef uint32_t gen6_gtt_pte_t;
 typedef uint64_t gen8_gtt_pte_t;
 typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;
@@ -258,7 +260,7 @@ struct i915_hw_ppgtt {
 		dma_addr_t *gen8_pt_dma_addr[4];
 	};
 
-	struct intel_context *ctx;
+	struct drm_i915_file_private *file_priv;
 
 	int (*enable)(struct i915_hw_ppgtt *ppgtt);
 	int (*switch_mm)(struct i915_hw_ppgtt *ppgtt,
@@ -276,6 +278,8 @@ bool intel_enable_ppgtt(struct drm_device *dev, bool full);
 
 int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
 void i915_ppgtt_release(struct kref *kref);
+struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_device *dev,
+					struct drm_i915_file_private *fpriv);
 static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
 {
 	if (ppgtt)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 05/15] drm/i915: Only refcount ppgtt if it actually is one
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (2 preceding siblings ...)
  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 ` 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
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

This essentially unbreaks non-ppgtt operation where we'd scribble over
random memory.

While at it give the vm_to_ppgtt function a proper prefix and make it
a bit more paranoid.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.h     | 10 +++++++++-
 drivers/gpu/drm/i915/i915_gem.c     |  3 ++-
 drivers/gpu/drm/i915/i915_gem_gtt.c |  3 ++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 194367f0ba1a..31422bc07445 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2475,6 +2475,15 @@ static inline bool i915_is_ggtt(struct i915_address_space *vm)
 	return vm == ggtt;
 }
 
+static inline struct i915_hw_ppgtt *
+i915_vm_to_ppgtt(struct i915_address_space *vm)
+{
+	WARN_ON(i915_is_ggtt(vm));
+
+	return container_of(vm, struct i915_hw_ppgtt, base);
+}
+
+
 static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
 {
 	return i915_gem_obj_bound(obj, obj_to_ggtt(obj));
@@ -2510,7 +2519,6 @@ 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 i915_gem_context_fini(struct drm_device *dev);
 void i915_gem_context_reset(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index b33a677b4b1e..c43ccfdf45a5 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4508,7 +4508,8 @@ void i915_gem_vma_destroy(struct i915_vma *vma)
 
 	vm = vma->vm;
 
-	i915_ppgtt_put(vm_to_ppgtt(vm));
+	if (!i915_is_ggtt(vm))
+		i915_ppgtt_put(i915_vm_to_ppgtt(vm));
 
 	list_del(&vma->vma_link);
 
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 83ee41e5c1c7..3753bf184865 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -2204,7 +2204,8 @@ i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
 	if (!vma)
 		vma = __i915_gem_vma_create(obj, vm);
 
-	i915_ppgtt_get(vm_to_ppgtt(vm));
+	if (!i915_is_ggtt(vm))
+		i915_ppgtt_get(i915_vm_to_ppgtt(vm));
 
 	return vma;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 06/15] drm/i915: Add proper prefix to obj_to_ggtt
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (3 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 05/15] drm/i915: Only refcount ppgtt if it actually is one Daniel Vetter
@ 2014-08-06 13:04 ` Daniel Vetter
  2014-08-06 13:04 ` [PATCH 07/15] drm/i915: Allow i915_gem_setup_global_gtt to fail Daniel Vetter
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Stuff in headers really aught to have this.

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.h | 11 ++++++-----
 drivers/gpu/drm/i915/i915_gem.c |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 31422bc07445..0c10c9ab1b96 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2466,7 +2466,7 @@ static inline bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj) {
 }
 
 /* Some GGTT VM helpers */
-#define obj_to_ggtt(obj) \
+#define i915_obj_to_ggtt(obj) \
 	(&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base)
 static inline bool i915_is_ggtt(struct i915_address_space *vm)
 {
@@ -2486,19 +2486,19 @@ i915_vm_to_ppgtt(struct i915_address_space *vm)
 
 static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
 {
-	return i915_gem_obj_bound(obj, obj_to_ggtt(obj));
+	return i915_gem_obj_bound(obj, i915_obj_to_ggtt(obj));
 }
 
 static inline unsigned long
 i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *obj)
 {
-	return i915_gem_obj_offset(obj, obj_to_ggtt(obj));
+	return i915_gem_obj_offset(obj, i915_obj_to_ggtt(obj));
 }
 
 static inline unsigned long
 i915_gem_obj_ggtt_size(struct drm_i915_gem_object *obj)
 {
-	return i915_gem_obj_size(obj, obj_to_ggtt(obj));
+	return i915_gem_obj_size(obj, i915_obj_to_ggtt(obj));
 }
 
 static inline int __must_check
@@ -2506,7 +2506,8 @@ i915_gem_obj_ggtt_pin(struct drm_i915_gem_object *obj,
 		      uint32_t alignment,
 		      unsigned flags)
 {
-	return i915_gem_object_pin(obj, obj_to_ggtt(obj), alignment, flags | PIN_GLOBAL);
+	return i915_gem_object_pin(obj, i915_obj_to_ggtt(obj),
+				   alignment, flags | PIN_GLOBAL);
 }
 
 static inline int
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index c43ccfdf45a5..f4e57fe05c6a 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -5266,7 +5266,7 @@ struct i915_vma *i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj)
 		return NULL;
 
 	vma = list_first_entry(&obj->vma_list, typeof(*vma), vma_link);
-	if (vma->vm != obj_to_ggtt(obj))
+	if (vma->vm != i915_obj_to_ggtt(obj))
 		return NULL;
 
 	return vma;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 07/15] drm/i915: Allow i915_gem_setup_global_gtt to fail
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (4 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 06/15] drm/i915: Add proper prefix to obj_to_ggtt Daniel Vetter
@ 2014-08-06 13:04 ` 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
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

We already needs this just as a safety check in case the preallocation
reservation dance fails. But we definitely need this to be able to
move tha aliasing ppgtt setup back out of the context code to this
place, where it belongs.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem.c     |  7 ++++++-
 drivers/gpu/drm/i915/i915_gem_gtt.c | 16 ++++++++++------
 drivers/gpu/drm/i915/i915_gem_gtt.h |  4 ++--
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index f4e57fe05c6a..d8399ee622b9 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4762,7 +4762,12 @@ int i915_gem_init(struct drm_device *dev)
 			DRM_DEBUG_DRIVER("allow wake ack timed out\n");
 	}
 
-	i915_gem_init_userptr(dev);
+	ret = i915_gem_init_userptr(dev);
+	if (ret) {
+		mutex_unlock(&dev->struct_mutex);
+		return ret;
+	}
+
 	i915_gem_init_global_gtt(dev);
 
 	ret = i915_gem_context_init(dev);
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 3753bf184865..4fa7807ed4d5 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1709,10 +1709,10 @@ static void i915_gtt_color_adjust(struct drm_mm_node *node,
 	}
 }
 
-void i915_gem_setup_global_gtt(struct drm_device *dev,
-			       unsigned long start,
-			       unsigned long mappable_end,
-			       unsigned long end)
+int i915_gem_setup_global_gtt(struct drm_device *dev,
+			      unsigned long start,
+			      unsigned long mappable_end,
+			      unsigned long end)
 {
 	/* Let GEM Manage all of the aperture.
 	 *
@@ -1745,8 +1745,10 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,
 
 		WARN_ON(i915_gem_obj_ggtt_bound(obj));
 		ret = drm_mm_reserve_node(&ggtt_vm->mm, &vma->node);
-		if (ret)
-			DRM_DEBUG_KMS("Reservation failed\n");
+		if (ret) {
+			DRM_DEBUG_KMS("Reservation failed: %i\n", ret);
+			return ret;
+		}
 		obj->has_global_gtt_mapping = 1;
 	}
 
@@ -1763,6 +1765,8 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,
 
 	/* And finally clear the reserved guard page */
 	ggtt_vm->clear_range(ggtt_vm, end - PAGE_SIZE, PAGE_SIZE, true);
+
+	return 0;
 }
 
 void i915_gem_init_global_gtt(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 0b04ef6167f8..bea3541d5525 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -271,8 +271,8 @@ struct i915_hw_ppgtt {
 
 int i915_gem_gtt_init(struct drm_device *dev);
 void i915_gem_init_global_gtt(struct drm_device *dev);
-void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
-			       unsigned long mappable_end, unsigned long end);
+int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
+			      unsigned long mappable_end, unsigned long end);
 
 bool intel_enable_ppgtt(struct drm_device *dev, bool full);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 08/15] drm/i915: Fix up checks for aliasing ppgtt
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (5 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 07/15] drm/i915: Allow i915_gem_setup_global_gtt to fail Daniel Vetter
@ 2014-08-06 13:04 ` Daniel Vetter
  2014-08-08 13:03   ` Thierry, Michel
  2014-08-06 13:04 ` [PATCH 09/15] drm/i915: Initialize the aliasing ppgtt as part of global gtt Daniel Vetter
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

A subsequent patch will no longer initialize the aliasing ppgtt if we
have full ppgtt enabled, since we simply don't need that any more.

Unfortunately a few places check for the aliasing ppgtt instead of
checking for ppgtt in general. Fix them up.

One special case are the gtt offset and size macros, which have some
code to remap the aliasing ppgtt to the global gtt. The aliasing ppgtt
is _not_ a logical address space, so passing that in as the vm is
plain and simple a bug. So just WARN about it and carry on - we have a
gracefully fall-through anyway if we can't find the vma.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_cmd_parser.c  | 4 +---
 drivers/gpu/drm/i915/i915_dma.c         | 2 +-
 drivers/gpu/drm/i915/i915_gem.c         | 8 ++------
 drivers/gpu/drm/i915/intel_ringbuffer.c | 4 +---
 4 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
index dea99d92fb4a..c45856bcc8b9 100644
--- a/drivers/gpu/drm/i915/i915_cmd_parser.c
+++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
@@ -842,8 +842,6 @@ finish:
  */
 bool i915_needs_cmd_parser(struct intel_engine_cs *ring)
 {
-	struct drm_i915_private *dev_priv = ring->dev->dev_private;
-
 	if (!ring->needs_cmd_parser)
 		return false;
 
@@ -852,7 +850,7 @@ bool i915_needs_cmd_parser(struct intel_engine_cs *ring)
 	 * disabled. That will cause all of the parser's PPGTT checks to
 	 * fail. For now, disable parsing when PPGTT is off.
 	 */
-	if (!dev_priv->mm.aliasing_ppgtt)
+	if (USES_PPGTT(ring->dev))
 		return false;
 
 	return (i915.enable_cmd_parser == 1);
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 2e7f03ad5ee2..e5ac1a6e9d26 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -999,7 +999,7 @@ static int i915_getparam(struct drm_device *dev, void *data,
 		value = HAS_WT(dev);
 		break;
 	case I915_PARAM_HAS_ALIASING_PPGTT:
-		value = dev_priv->mm.aliasing_ppgtt || USES_FULL_PPGTT(dev);
+		value = USES_PPGTT(dev);
 		break;
 	case I915_PARAM_HAS_WAIT_TIMEOUT:
 		value = 1;
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index d8399ee622b9..a79deb189146 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -5114,9 +5114,7 @@ unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,
 	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
 	struct i915_vma *vma;
 
-	if (!dev_priv->mm.aliasing_ppgtt ||
-	    vm == &dev_priv->mm.aliasing_ppgtt->base)
-		vm = &dev_priv->gtt.base;
+	WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
 
 	list_for_each_entry(vma, &o->vma_list, vma_link) {
 		if (vma->vm == vm)
@@ -5157,9 +5155,7 @@ unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
 	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
 	struct i915_vma *vma;
 
-	if (!dev_priv->mm.aliasing_ppgtt ||
-	    vm == &dev_priv->mm.aliasing_ppgtt->base)
-		vm = &dev_priv->gtt.base;
+	WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
 
 	BUG_ON(list_empty(&o->vma_list));
 
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 05969f03c0c1..390e38325b37 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1977,9 +1977,7 @@ gen8_ring_dispatch_execbuffer(struct intel_engine_cs *ring,
 			      u64 offset, u32 len,
 			      unsigned flags)
 {
-	struct drm_i915_private *dev_priv = ring->dev->dev_private;
-	bool ppgtt = dev_priv->mm.aliasing_ppgtt != NULL &&
-		!(flags & I915_DISPATCH_SECURE);
+	bool ppgtt = USES_PPGTT(ring->dev) && !(flags & I915_DISPATCH_SECURE);
 	int ret;
 
 	ret = intel_ring_begin(ring, 4);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 09/15] drm/i915: Initialize the aliasing ppgtt as part of global gtt
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (6 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 08/15] drm/i915: Fix up checks for aliasing ppgtt Daniel Vetter
@ 2014-08-06 13:04 ` 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 13:04 ` [PATCH 10/15] drm/i915: Only track real ppgtt for a context Daniel Vetter
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Stuffing this into the context setup code doesn't make a lot of sense.
Also reusing the real ppgtt setup code makes even less sense since the
aliasing ppgtt isn't a real address space. Leaving all that stuff
unitialized will make sure that we catch any abusers promptly.

This is also a prep work to clean up the context->ppgtt link.

v2: Fix up the logic fail, I've fumbled it so badly to completely
disable ppgtt on gen6. Spotted by Ville and Michel. Also move around
the pde write into the gen6 init function, since otherwise it won't
work at all.

Cc: "Thierry, Michel" <michel.thierry@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +---------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 42 +++++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 3b8367aa8404..7a455fcee3a7 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device *dev,
 			goto err_unpin;
 		} else
 			ctx->vm = &ppgtt->base;
-
-		/* This case is reserved for the global default context and
-		 * should only happen once. */
-		if (is_global_default_ctx) {
-			if (WARN_ON(dev_priv->mm.aliasing_ppgtt)) {
-				ret = -EEXIST;
-				goto err_unpin;
-			}
-
-			dev_priv->mm.aliasing_ppgtt = ppgtt;
-		}
 	} else if (USES_PPGTT(dev)) {
 		/* For platforms which only have aliasing PPGTT, we fake the
 		 * address space and refcounting. */
@@ -361,7 +350,7 @@ int i915_gem_context_init(struct drm_device *dev)
 		}
 	}
 
-	ctx = i915_gem_create_context(dev, NULL, USES_PPGTT(dev));
+	ctx = i915_gem_create_context(dev, NULL, USES_FULL_PPGTT(dev));
 	if (IS_ERR(ctx)) {
 		DRM_ERROR("Failed to create default global context (error %ld)\n",
 			  PTR_ERR(ctx));
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 4fa7807ed4d5..a4c1740d79be 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1188,35 +1188,38 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 			 ppgtt->node.size >> 20,
 			 ppgtt->node.start / PAGE_SIZE);
 
+	gen6_write_pdes(ppgtt);
+	DRM_DEBUG("Adding PPGTT at offset %x\n",
+		  ppgtt->pd_offset << 10);
+
 	return 0;
 }
 
-int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	int ret = 0;
 
 	ppgtt->base.dev = dev;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
 
 	if (INTEL_INFO(dev)->gen < 8)
-		ret = gen6_ppgtt_init(ppgtt);
+		return gen6_ppgtt_init(ppgtt);
 	else if (IS_GEN8(dev))
-		ret = gen8_ppgtt_init(ppgtt, dev_priv->gtt.base.total);
+		return gen8_ppgtt_init(ppgtt, dev_priv->gtt.base.total);
 	else
 		BUG();
+}
+int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret = 0;
 
-	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
+	ret = __hw_ppgtt_init(dev, ppgtt);
+	if (ret == 0) {
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
 		i915_init_vm(dev_priv, &ppgtt->base);
-		if (INTEL_INFO(dev)->gen < 8) {
-			gen6_write_pdes(ppgtt);
-			DRM_DEBUG("Adding PPGTT at offset %x\n",
-				  ppgtt->pd_offset << 10);
-		}
 	}
 
 	return ret;
@@ -1728,6 +1731,7 @@ int i915_gem_setup_global_gtt(struct drm_device *dev,
 	struct drm_mm_node *entry;
 	struct drm_i915_gem_object *obj;
 	unsigned long hole_start, hole_end;
+	int ret;
 
 	BUG_ON(mappable_end > end);
 
@@ -1739,7 +1743,7 @@ int i915_gem_setup_global_gtt(struct drm_device *dev,
 	/* Mark any preallocated objects as occupied */
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
 		struct i915_vma *vma = i915_gem_obj_to_vma(obj, ggtt_vm);
-		int ret;
+
 		DRM_DEBUG_KMS("reserving preallocated space: %lx + %zx\n",
 			      i915_gem_obj_ggtt_offset(obj), obj->base.size);
 
@@ -1766,6 +1770,20 @@ int i915_gem_setup_global_gtt(struct drm_device *dev,
 	/* And finally clear the reserved guard page */
 	ggtt_vm->clear_range(ggtt_vm, end - PAGE_SIZE, PAGE_SIZE, true);
 
+	if (HAS_ALIASING_PPGTT(dev) && !USES_FULL_PPGTT(dev)) {
+		struct i915_hw_ppgtt *ppgtt;
+
+		ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+		if (!ppgtt)
+			return -ENOMEM;
+
+		ret = __hw_ppgtt_init(dev, ppgtt);
+		if (ret != 0)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
-- 
1.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 10/15] drm/i915: Only track real ppgtt for a context
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (7 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 09/15] drm/i915: Initialize the aliasing ppgtt as part of global gtt Daniel Vetter
@ 2014-08-06 13:04 ` Daniel Vetter
  2014-08-06 13:04 ` [PATCH 11/15] drm/i915: Drop create_vm argument to i915_gem_create_context Daniel Vetter
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

There's a bit a confusion since we track the global gtt,
the aliasing and real ppgtt in the ctx->vm pointer. And not
all callers really bother to check for the different cases and just
presume that it points to a real ppgtt.

Now looking closely we don't actually need ->vm to always point at an
address space - the only place that cares actually has fixup code
already to decide whether to look at the per-proces or the global
address space.

So switch to just tracking the ppgtt directly and ditch all the
extraneous code.

v2: Fixup the ppgtt debugfs file to not oops on a NULL ctx->ppgtt.
Also drop the early exit - without aliasing ppgtt we want to dump all
the ppgtts of the contexts if we have full ppgtt.

v3: Actually git add the compile fix.

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
Cc: "Thierry, Michel" <michel.thierry@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
OTC-Jira: VIZ-3724
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_debugfs.c        | 11 ++++++++---
 drivers/gpu/drm/i915/i915_drv.h            |  3 +--
 drivers/gpu/drm/i915/i915_gem_context.c    | 28 +++++++---------------------
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  5 +++--
 drivers/gpu/drm/i915/i915_gpu_error.c      | 10 +++++++---
 5 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 5c40d49042b8..115cf2cec475 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -1815,7 +1815,13 @@ static int per_file_ctx(int id, void *ptr, void *data)
 {
 	struct intel_context *ctx = ptr;
 	struct seq_file *m = data;
-	struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(ctx);
+	struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
+
+	if (!ppgtt) {
+		seq_printf(m, "  no ppgtt for context %d\n",
+			   ctx->user_handle);
+		return 0;
+	}
 
 	if (i915_gem_context_is_default(ctx))
 		seq_puts(m, "  default context:\n");
@@ -1875,8 +1881,7 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
 		seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
 
 		ppgtt->debug_dump(ppgtt, m);
-	} else
-		return;
+	}
 
 	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
 		struct drm_i915_file_private *file_priv = file->driver_priv;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 0c10c9ab1b96..f1cfc0999e6b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -622,7 +622,7 @@ struct intel_context {
 	uint8_t remap_slice;
 	struct drm_i915_file_private *file_priv;
 	struct i915_ctx_hang_stats hang_stats;
-	struct i915_address_space *vm;
+	struct i915_hw_ppgtt *ppgtt;
 
 	struct {
 		struct drm_i915_gem_object *rcs_state;
@@ -2519,7 +2519,6 @@ i915_gem_object_ggtt_unbind(struct drm_i915_gem_object *obj)
 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)
 int __must_check i915_gem_context_init(struct drm_device *dev);
 void i915_gem_context_fini(struct drm_device *dev);
 void i915_gem_context_reset(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 7a455fcee3a7..c00e5d027774 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -136,15 +136,8 @@ void i915_gem_context_free(struct kref *ctx_ref)
 {
 	struct intel_context *ctx = container_of(ctx_ref,
 						   typeof(*ctx), ref);
-	struct i915_hw_ppgtt *ppgtt = NULL;
 
-	if (ctx->legacy_hw_ctx.rcs_state) {
-		/* We refcount even the aliasing PPGTT to keep the code symmetric */
-		if (USES_PPGTT(ctx->legacy_hw_ctx.rcs_state->base.dev))
-			ppgtt = ctx_to_ppgtt(ctx);
-	}
-
-	i915_ppgtt_put(ppgtt);
+	i915_ppgtt_put(ctx->ppgtt);
 	if (ctx->legacy_hw_ctx.rcs_state)
 		drm_gem_object_unreference(&ctx->legacy_hw_ctx.rcs_state->base);
 	list_del(&ctx->link);
@@ -240,7 +233,6 @@ i915_gem_create_context(struct drm_device *dev,
 			bool create_vm)
 {
 	const bool is_global_default_ctx = file_priv == NULL;
-	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_context *ctx;
 	int ret = 0;
 
@@ -274,15 +266,10 @@ i915_gem_create_context(struct drm_device *dev,
 					 PTR_ERR(ppgtt));
 			ret = PTR_ERR(ppgtt);
 			goto err_unpin;
-		} else
-			ctx->vm = &ppgtt->base;
-	} else if (USES_PPGTT(dev)) {
-		/* For platforms which only have aliasing PPGTT, we fake the
-		 * address space and refcounting. */
-		ctx->vm = &dev_priv->mm.aliasing_ppgtt->base;
-		i915_ppgtt_get(dev_priv->mm.aliasing_ppgtt);
-	} else
-		ctx->vm = &dev_priv->gtt.base;
+		}
+
+		ctx->ppgtt = ppgtt;
+	}
 
 	return ctx;
 
@@ -538,7 +525,6 @@ static int do_switch(struct intel_engine_cs *ring,
 {
 	struct drm_i915_private *dev_priv = ring->dev->dev_private;
 	struct intel_context *from = ring->last_context;
-	struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(to);
 	u32 hw_flags = 0;
 	bool uninitialized = false;
 	int ret, i;
@@ -566,8 +552,8 @@ static int do_switch(struct intel_engine_cs *ring,
 	 */
 	from = ring->last_context;
 
-	if (USES_FULL_PPGTT(ring->dev)) {
-		ret = ppgtt->switch_mm(ppgtt, ring, false);
+	if (to->ppgtt) {
+		ret = to->ppgtt->switch_mm(to->ppgtt, ring, false);
 		if (ret)
 			goto unpin_out;
 	}
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 60998fc4e5b2..54b3d8c8b228 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -1318,8 +1318,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 
 	i915_gem_context_reference(ctx);
 
-	vm = ctx->vm;
-	if (!USES_FULL_PPGTT(dev))
+	if (ctx->ppgtt)
+		vm = &ctx->ppgtt->base;
+	else
 		vm = &dev_priv->gtt.base;
 
 	eb = eb_create(args);
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index 7c478e6cedae..00d2324466fd 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -963,6 +963,12 @@ static void i915_gem_record_rings(struct drm_device *dev,
 
 		request = i915_gem_find_active_request(ring);
 		if (request) {
+			struct i915_address_space *vm;
+
+			vm = request->ctx && request->ctx->ppgtt ?
+				&request->ctx->ppgtt->base :
+				&dev_priv->gtt.base;
+
 			/* We need to copy these to an anonymous buffer
 			 * as the simplest method to avoid being overwritten
 			 * by userspace.
@@ -970,9 +976,7 @@ static void i915_gem_record_rings(struct drm_device *dev,
 			error->ring[i].batchbuffer =
 				i915_error_object_create(dev_priv,
 							 request->batch_obj,
-							 request->ctx ?
-							 request->ctx->vm :
-							 &dev_priv->gtt.base);
+							 vm);
 
 			if (HAS_BROKEN_CS_TLB(dev_priv->dev) &&
 			    ring->scratch.obj)
-- 
1.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 11/15] drm/i915: Drop create_vm argument to i915_gem_create_context
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (8 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 10/15] drm/i915: Only track real ppgtt for a context Daniel Vetter
@ 2014-08-06 13:04 ` 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
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Now that all the flow is streamlined the rule is simple: We create
a new ppgtt for a new context when we have full ppgtt enabled.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index c00e5d027774..655ed6228aab 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -229,8 +229,7 @@ err_out:
  */
 static struct intel_context *
 i915_gem_create_context(struct drm_device *dev,
-			struct drm_i915_file_private *file_priv,
-			bool create_vm)
+			struct drm_i915_file_private *file_priv)
 {
 	const bool is_global_default_ctx = file_priv == NULL;
 	struct intel_context *ctx;
@@ -258,7 +257,7 @@ i915_gem_create_context(struct drm_device *dev,
 		}
 	}
 
-	if (create_vm) {
+	if (USES_FULL_PPGTT(dev)) {
 		struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev, file_priv);
 
 		if (IS_ERR_OR_NULL(ppgtt)) {
@@ -337,7 +336,7 @@ int i915_gem_context_init(struct drm_device *dev)
 		}
 	}
 
-	ctx = i915_gem_create_context(dev, NULL, USES_FULL_PPGTT(dev));
+	ctx = i915_gem_create_context(dev, NULL);
 	if (IS_ERR(ctx)) {
 		DRM_ERROR("Failed to create default global context (error %ld)\n",
 			  PTR_ERR(ctx));
@@ -438,7 +437,7 @@ int i915_gem_context_open(struct drm_device *dev, struct drm_file *file)
 	idr_init(&file_priv->context_idr);
 
 	mutex_lock(&dev->struct_mutex);
-	ctx = i915_gem_create_context(dev, file_priv, USES_FULL_PPGTT(dev));
+	ctx = i915_gem_create_context(dev, file_priv);
 	mutex_unlock(&dev->struct_mutex);
 
 	if (IS_ERR(ctx)) {
@@ -696,7 +695,7 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
 	if (ret)
 		return ret;
 
-	ctx = i915_gem_create_context(dev, file_priv, USES_FULL_PPGTT(dev));
+	ctx = i915_gem_create_context(dev, file_priv);
 	mutex_unlock(&dev->struct_mutex);
 	if (IS_ERR(ctx))
 		return PTR_ERR(ctx);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 12/15] drm/i915: Extract common cleanup into i915_ppgtt_release
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (9 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 11/15] drm/i915: Drop create_vm argument to i915_gem_create_context Daniel Vetter
@ 2014-08-06 13:04 ` 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
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Address space cleanup isn't really a job for the low-level cleanup
callbacks. Without this change we can't reuse the low-level cleanup
callback for the aliasing ppgtt cleanup.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index a4c1740d79be..bbf113ed7339 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -403,9 +403,6 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)
 	struct i915_hw_ppgtt *ppgtt =
 		container_of(vm, struct i915_hw_ppgtt, base);
 
-	list_del(&vm->global_link);
-	drm_mm_takedown(&vm->mm);
-
 	gen8_ppgtt_unmap_pages(ppgtt);
 	gen8_ppgtt_free(ppgtt);
 }
@@ -1029,8 +1026,6 @@ static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
 	struct i915_hw_ppgtt *ppgtt =
 		container_of(vm, struct i915_hw_ppgtt, base);
 
-	list_del(&vm->global_link);
-	drm_mm_takedown(&ppgtt->base.mm);
 	drm_mm_remove_node(&ppgtt->node);
 
 	gen6_ppgtt_unmap_pages(ppgtt);
@@ -1255,6 +1250,9 @@ void  i915_ppgtt_release(struct kref *kref)
 	WARN_ON(!list_empty(&ppgtt->base.active_list));
 	WARN_ON(!list_empty(&ppgtt->base.inactive_list));
 
+	list_del(&ppgtt->base.global_link);
+	drm_mm_takedown(&ppgtt->base.mm);
+
 	ppgtt->base.cleanup(&ppgtt->base);
 	kfree(ppgtt);
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 13/15] drm/i915: Extract commmon global gtt cleanup code
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (10 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 12/15] drm/i915: Extract common cleanup into i915_ppgtt_release Daniel Vetter
@ 2014-08-06 13:04 ` 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-06 13:04 ` [PATCH 15/15] drm/i915: don't touch console_lock for I915_FBDEV=n Daniel Vetter
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

We want to move the aliasing ppgtt cleanup back into the global
gtt cleanup code for symmetric, but first we need to create such
a place.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_dma.c     |  4 ++--
 drivers/gpu/drm/i915/i915_gem_gtt.c | 20 ++++++++++++--------
 drivers/gpu/drm/i915/i915_gem_gtt.h |  1 +
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index e5ac1a6e9d26..c176a6c97c80 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1817,7 +1817,7 @@ out_mtrrfree:
 	arch_phys_wc_del(dev_priv->gtt.mtrr);
 	io_mapping_free(dev_priv->gtt.mappable);
 out_gtt:
-	dev_priv->gtt.base.cleanup(&dev_priv->gtt.base);
+	i915_global_gtt_cleanup(dev);
 out_regs:
 	intel_uncore_fini(dev);
 	pci_iounmap(dev->pdev, dev_priv->regs);
@@ -1916,7 +1916,7 @@ int i915_driver_unload(struct drm_device *dev)
 	destroy_workqueue(dev_priv->wq);
 	pm_qos_remove_request(&dev_priv->pm_qos);
 
-	dev_priv->gtt.base.cleanup(&dev_priv->gtt.base);
+	i915_global_gtt_cleanup(dev);
 
 	intel_uncore_fini(dev);
 	if (dev_priv->regs != NULL)
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index bbf113ed7339..2eab0b6a32e8 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1796,6 +1796,18 @@ void i915_gem_init_global_gtt(struct drm_device *dev)
 	i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
 }
 
+void i915_global_gtt_cleanup(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct i915_address_space *vm = &dev_priv->gtt.base;
+
+	if (drm_mm_initialized(&vm->mm)) {
+		drm_mm_takedown(&vm->mm);
+		list_del(&vm->global_link);
+	}
+
+	vm->cleanup(vm);
+}
 static int setup_scratch_page(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
@@ -2064,10 +2076,6 @@ static void gen6_gmch_remove(struct i915_address_space *vm)
 
 	struct i915_gtt *gtt = container_of(vm, struct i915_gtt, base);
 
-	if (drm_mm_initialized(&vm->mm)) {
-		drm_mm_takedown(&vm->mm);
-		list_del(&vm->global_link);
-	}
 	iounmap(gtt->gsm);
 	teardown_scratch_page(vm->dev);
 }
@@ -2106,10 +2114,6 @@ static int i915_gmch_probe(struct drm_device *dev,
 
 static void i915_gmch_remove(struct i915_address_space *vm)
 {
-	if (drm_mm_initialized(&vm->mm)) {
-		drm_mm_takedown(&vm->mm);
-		list_del(&vm->global_link);
-	}
 	intel_gmch_remove();
 }
 
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index bea3541d5525..6b30ebad0a0a 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -273,6 +273,7 @@ int i915_gem_gtt_init(struct drm_device *dev);
 void i915_gem_init_global_gtt(struct drm_device *dev);
 int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
 			      unsigned long mappable_end, unsigned long end);
+void i915_global_gtt_cleanup(struct drm_device *dev);
 
 bool intel_enable_ppgtt(struct drm_device *dev, bool full);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt alongside the global gtt
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (11 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 13/15] drm/i915: Extract commmon global gtt cleanup code Daniel Vetter
@ 2014-08-06 13:04 ` Daniel Vetter
  2014-08-08 13:09   ` Thierry, Michel
  2014-08-06 13:04 ` [PATCH 15/15] drm/i915: don't touch console_lock for I915_FBDEV=n Daniel Vetter
  13 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Also remove related WARN_ONs which seem to have been hit since a rather
long time. But apperently no one noticed since our module reload is
already WARNING-infested :(

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_dma.c     | 4 ----
 drivers/gpu/drm/i915/i915_gem_gtt.c | 7 +++++++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index c176a6c97c80..94afe7c4458b 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1388,7 +1388,6 @@ cleanup_gem:
 	i915_gem_cleanup_ringbuffer(dev);
 	i915_gem_context_fini(dev);
 	mutex_unlock(&dev->struct_mutex);
-	WARN_ON(dev_priv->mm.aliasing_ppgtt);
 cleanup_irq:
 	drm_irq_uninstall(dev);
 cleanup_gem_stolen:
@@ -1897,7 +1896,6 @@ int i915_driver_unload(struct drm_device *dev)
 		mutex_lock(&dev->struct_mutex);
 		i915_gem_cleanup_ringbuffer(dev);
 		i915_gem_context_fini(dev);
-		WARN_ON(dev_priv->mm.aliasing_ppgtt);
 		mutex_unlock(&dev->struct_mutex);
 		i915_gem_cleanup_stolen(dev);
 
@@ -1905,8 +1903,6 @@ int i915_driver_unload(struct drm_device *dev)
 			i915_free_hws(dev);
 	}
 
-	WARN_ON(!list_empty(&dev_priv->vm_list));
-
 	drm_vblank_cleanup(dev);
 
 	intel_teardown_gmbus(dev);
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 2eab0b6a32e8..ff031bb1f296 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1801,6 +1801,12 @@ void i915_global_gtt_cleanup(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 
+	if (dev_priv->mm.aliasing_ppgtt) {
+		struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
+
+		ppgtt->base.cleanup(&ppgtt->base);
+	}
+
 	if (drm_mm_initialized(&vm->mm)) {
 		drm_mm_takedown(&vm->mm);
 		list_del(&vm->global_link);
@@ -1808,6 +1814,7 @@ void i915_global_gtt_cleanup(struct drm_device *dev)
 
 	vm->cleanup(vm);
 }
+
 static int setup_scratch_page(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 15/15] drm/i915: don't touch console_lock for I915_FBDEV=n
  2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
                   ` (12 preceding siblings ...)
  2014-08-06 13:04 ` [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt alongside the global gtt Daniel Vetter
@ 2014-08-06 13:04 ` Daniel Vetter
  13 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 13:04 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

We still have locking hilarity between the console_lock and the world,
so really don't bother with it if at all possible. This shuts up a
locdep splat I'm seeing after a system s/r cycle followed by reloading
i915.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 6c4b25ce8bb0..f522a6371bc0 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -554,9 +554,11 @@ static int i915_drm_freeze(struct drm_device *dev)
 	intel_uncore_forcewake_reset(dev, false);
 	intel_opregion_fini(dev);
 
+#ifdef CONFIG_DRM_I915_FBDEV
 	console_lock();
 	intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED);
 	console_unlock();
+#endif
 
 	dev_priv->suspend_count++;
 
@@ -677,6 +679,7 @@ static int __i915_drm_thaw(struct drm_device *dev, bool restore_gtt_mappings)
 
 	intel_opregion_init(dev);
 
+#ifdef CONFIG_DRM_I915_FBDEV
 	/*
 	 * The console lock can be pretty contented on resume due
 	 * to all the printk activity.  Try to keep it out of the hot
@@ -688,6 +691,7 @@ static int __i915_drm_thaw(struct drm_device *dev, bool restore_gtt_mappings)
 	} else {
 		schedule_work(&dev_priv->console_resume_work);
 	}
+#endif
 
 	mutex_lock(&dev_priv->modeset_restore_lock);
 	dev_priv->modeset_restore = MODESET_DONE;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 1/2] drm/i915: Rework ppgtt init to no require an aliasing ppgtt
  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   ` Daniel Vetter
  2014-08-06 18:19     ` [PATCH 2/2] drm/i915: Initialize the aliasing ppgtt as part of global gtt Daniel Vetter
                       ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 18:19 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Currently we abuse the aliasing ppgtt to set up the ppgtt support in
general. Which is a bit backwards since with full ppgtt we don't ever
need the aliasing ppgtt.

So untangling this and separate the ppgtt init from the aliasing
ppgtt. While at it drag it out of the context enabling (which just
does a switch to the default context).

Note that we still have the differentiation between synchronous and
asynchronous ppgtt setup, but that will soon vanish. So also correctly
wire up the return value handling to be prepared for when ->switch_mm
drops the synchronous parameter and could start to fail.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem.c         |  8 ++++
 drivers/gpu/drm/i915/i915_gem_context.c |  7 ---
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 84 +++++++++++++--------------------
 drivers/gpu/drm/i915/i915_gem_gtt.h     |  1 +
 4 files changed, 42 insertions(+), 58 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index a79deb189146..caf92bac2152 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4742,6 +4742,14 @@ i915_gem_init_hw(struct drm_device *dev)
 	if (ret && ret != -EIO) {
 		DRM_ERROR("Context enable failed %d\n", ret);
 		i915_gem_cleanup_ringbuffer(dev);
+
+		return ret;
+	}
+
+	ret = i915_ppgtt_init_hw(dev);
+	if (ret && ret != -EIO) {
+		DRM_ERROR("PPGTT enable failed %d\n", ret);
+		i915_gem_cleanup_ringbuffer(dev);
 	}
 
 	return ret;
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 3b8367aa8404..4af5f05b24e8 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -424,13 +424,6 @@ int i915_gem_context_enable(struct drm_i915_private *dev_priv)
 	struct intel_engine_cs *ring;
 	int ret, i;
 
-	/* This is the only place the aliasing PPGTT gets enabled, which means
-	 * it has to happen before we bail on reset */
-	if (dev_priv->mm.aliasing_ppgtt) {
-		struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
-		ppgtt->enable(ppgtt);
-	}
-
 	/* FIXME: We should make this work, even in reset */
 	if (i915_reset_in_progress(&dev_priv->gpu_error))
 		return 0;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 4fa7807ed4d5..bf70ab44b968 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -78,7 +78,6 @@ static void ppgtt_bind_vma(struct i915_vma *vma,
 			   enum i915_cache_level cache_level,
 			   u32 flags);
 static void ppgtt_unbind_vma(struct i915_vma *vma);
-static int gen8_ppgtt_enable(struct i915_hw_ppgtt *ppgtt);
 
 static inline gen8_gtt_pte_t gen8_pte_encode(dma_addr_t addr,
 					     enum i915_cache_level level,
@@ -615,7 +614,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)
 		kunmap_atomic(pd_vaddr);
 	}
 
-	ppgtt->enable = gen8_ppgtt_enable;
 	ppgtt->switch_mm = gen8_mm_switch;
 	ppgtt->base.clear_range = gen8_ppgtt_clear_range;
 	ppgtt->base.insert_entries = gen8_ppgtt_insert_entries;
@@ -836,39 +834,20 @@ static int gen6_mm_switch(struct i915_hw_ppgtt *ppgtt,
 	return 0;
 }
 
-static int gen8_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
+static void gen8_ppgtt_enable(struct drm_device *dev)
 {
-	struct drm_device *dev = ppgtt->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_engine_cs *ring;
-	int j, ret;
+	int j;
 
 	for_each_ring(ring, dev_priv, j) {
 		I915_WRITE(RING_MODE_GEN7(ring),
 			   _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
-
-		/* We promise to do a switch later with FULL PPGTT. If this is
-		 * aliasing, this is the one and only switch we'll do */
-		if (USES_FULL_PPGTT(dev))
-			continue;
-
-		ret = ppgtt->switch_mm(ppgtt, ring, true);
-		if (ret)
-			goto err_out;
 	}
-
-	return 0;
-
-err_out:
-	for_each_ring(ring, dev_priv, j)
-		I915_WRITE(RING_MODE_GEN7(ring),
-			   _MASKED_BIT_DISABLE(GFX_PPGTT_ENABLE));
-	return ret;
 }
 
-static int gen7_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
+static void gen7_ppgtt_enable(struct drm_device *dev)
 {
-	struct drm_device *dev = ppgtt->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_engine_cs *ring;
 	uint32_t ecochk, ecobits;
@@ -887,31 +866,16 @@ static int gen7_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
 	I915_WRITE(GAM_ECOCHK, ecochk);
 
 	for_each_ring(ring, dev_priv, i) {
-		int ret;
 		/* GFX_MODE is per-ring on gen7+ */
 		I915_WRITE(RING_MODE_GEN7(ring),
 			   _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
-
-		/* We promise to do a switch later with FULL PPGTT. If this is
-		 * aliasing, this is the one and only switch we'll do */
-		if (USES_FULL_PPGTT(dev))
-			continue;
-
-		ret = ppgtt->switch_mm(ppgtt, ring, true);
-		if (ret)
-			return ret;
 	}
-
-	return 0;
 }
 
-static int gen6_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
+static void gen6_ppgtt_enable(struct drm_device *dev)
 {
-	struct drm_device *dev = ppgtt->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct intel_engine_cs *ring;
 	uint32_t ecochk, gab_ctl, ecobits;
-	int i;
 
 	ecobits = I915_READ(GAC_ECO_BITS);
 	I915_WRITE(GAC_ECO_BITS, ecobits | ECOBITS_SNB_BIT |
@@ -924,14 +888,6 @@ static int gen6_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
 	I915_WRITE(GAM_ECOCHK, ecochk | ECOCHK_SNB_BIT | ECOCHK_PPGTT_CACHE64B);
 
 	I915_WRITE(GFX_MODE, _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
-
-	for_each_ring(ring, dev_priv, i) {
-		int ret = ppgtt->switch_mm(ppgtt, ring, true);
-		if (ret)
-			return ret;
-	}
-
-	return 0;
 }
 
 /* PPGTT support for Sandybdrige/Gen6 and later */
@@ -1151,13 +1107,10 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 
 	ppgtt->base.pte_encode = dev_priv->gtt.base.pte_encode;
 	if (IS_GEN6(dev)) {
-		ppgtt->enable = gen6_ppgtt_enable;
 		ppgtt->switch_mm = gen6_mm_switch;
 	} else if (IS_HASWELL(dev)) {
-		ppgtt->enable = gen7_ppgtt_enable;
 		ppgtt->switch_mm = hsw_mm_switch;
 	} else if (IS_GEN7(dev)) {
-		ppgtt->enable = gen7_ppgtt_enable;
 		ppgtt->switch_mm = gen7_mm_switch;
 	} else
 		BUG();
@@ -1222,6 +1175,35 @@ int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
 	return ret;
 }
 
+int i915_ppgtt_init_hw(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_engine_cs *ring;
+	struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
+	int i, ret = 0;
+
+	if (!USES_PPGTT(dev))
+		return 0;
+
+	if (IS_GEN6(dev))
+		gen6_ppgtt_enable(dev);
+	else if (IS_GEN7(dev))
+		gen7_ppgtt_enable(dev);
+	else if (INTEL_INFO(dev)->gen >= 8)
+		gen8_ppgtt_enable(dev);
+	else
+		WARN_ON(1);
+
+	if (ppgtt) {
+		for_each_ring(ring, dev_priv, i) {
+			ret = ppgtt->switch_mm(ppgtt, ring, true);
+			if (ret != 0)
+				return ret;
+		}
+	}
+
+	return ret;
+}
 struct i915_hw_ppgtt *
 i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private *fpriv)
 {
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index bea3541d5525..45aa15fa4af2 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -277,6 +277,7 @@ int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
 bool intel_enable_ppgtt(struct drm_device *dev, bool full);
 
 int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
+int i915_ppgtt_init_hw(struct drm_device *dev);
 void i915_ppgtt_release(struct kref *kref);
 struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_device *dev,
 					struct drm_i915_file_private *fpriv);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 2/2] drm/i915: Initialize the aliasing ppgtt as part of global gtt
  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     ` 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
  2 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 18:19 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

Stuffing this into the context setup code doesn't make a lot of sense.
Also reusing the real ppgtt setup code makes even less sense since the
aliasing ppgtt isn't a real address space. Leaving all that stuff
unitialized will make sure that we catch any abusers promptly.

This is also a prep work to clean up the context->ppgtt link.

v2: Fix up the logic fail, I've fumbled it so badly to completely
disable ppgtt on gen6. Spotted by Ville and Michel. Also move around
the pde write into the gen6 init function, since otherwise it won't
work at all.

v3: Only initialize the aliasing ppgtt when we actually enable it.

Cc: "Thierry, Michel" <michel.thierry@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +---------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 42 +++++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 4af5f05b24e8..07f4d060575b 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device *dev,
 			goto err_unpin;
 		} else
 			ctx->vm = &ppgtt->base;
-
-		/* This case is reserved for the global default context and
-		 * should only happen once. */
-		if (is_global_default_ctx) {
-			if (WARN_ON(dev_priv->mm.aliasing_ppgtt)) {
-				ret = -EEXIST;
-				goto err_unpin;
-			}
-
-			dev_priv->mm.aliasing_ppgtt = ppgtt;
-		}
 	} else if (USES_PPGTT(dev)) {
 		/* For platforms which only have aliasing PPGTT, we fake the
 		 * address space and refcounting. */
@@ -361,7 +350,7 @@ int i915_gem_context_init(struct drm_device *dev)
 		}
 	}
 
-	ctx = i915_gem_create_context(dev, NULL, USES_PPGTT(dev));
+	ctx = i915_gem_create_context(dev, NULL, USES_FULL_PPGTT(dev));
 	if (IS_ERR(ctx)) {
 		DRM_ERROR("Failed to create default global context (error %ld)\n",
 			  PTR_ERR(ctx));
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index bf70ab44b968..653a1166a3fa 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1141,35 +1141,38 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 			 ppgtt->node.size >> 20,
 			 ppgtt->node.start / PAGE_SIZE);
 
+	gen6_write_pdes(ppgtt);
+	DRM_DEBUG("Adding PPGTT at offset %x\n",
+		  ppgtt->pd_offset << 10);
+
 	return 0;
 }
 
-int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	int ret = 0;
 
 	ppgtt->base.dev = dev;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
 
 	if (INTEL_INFO(dev)->gen < 8)
-		ret = gen6_ppgtt_init(ppgtt);
+		return gen6_ppgtt_init(ppgtt);
 	else if (IS_GEN8(dev))
-		ret = gen8_ppgtt_init(ppgtt, dev_priv->gtt.base.total);
+		return gen8_ppgtt_init(ppgtt, dev_priv->gtt.base.total);
 	else
 		BUG();
+}
+int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret = 0;
 
-	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
+	ret = __hw_ppgtt_init(dev, ppgtt);
+	if (ret == 0) {
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
 		i915_init_vm(dev_priv, &ppgtt->base);
-		if (INTEL_INFO(dev)->gen < 8) {
-			gen6_write_pdes(ppgtt);
-			DRM_DEBUG("Adding PPGTT at offset %x\n",
-				  ppgtt->pd_offset << 10);
-		}
 	}
 
 	return ret;
@@ -1710,6 +1713,7 @@ int i915_gem_setup_global_gtt(struct drm_device *dev,
 	struct drm_mm_node *entry;
 	struct drm_i915_gem_object *obj;
 	unsigned long hole_start, hole_end;
+	int ret;
 
 	BUG_ON(mappable_end > end);
 
@@ -1721,7 +1725,7 @@ int i915_gem_setup_global_gtt(struct drm_device *dev,
 	/* Mark any preallocated objects as occupied */
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
 		struct i915_vma *vma = i915_gem_obj_to_vma(obj, ggtt_vm);
-		int ret;
+
 		DRM_DEBUG_KMS("reserving preallocated space: %lx + %zx\n",
 			      i915_gem_obj_ggtt_offset(obj), obj->base.size);
 
@@ -1748,6 +1752,20 @@ int i915_gem_setup_global_gtt(struct drm_device *dev,
 	/* And finally clear the reserved guard page */
 	ggtt_vm->clear_range(ggtt_vm, end - PAGE_SIZE, PAGE_SIZE, true);
 
+	if (USES_PPGTT(dev) && !USES_FULL_PPGTT(dev)) {
+		struct i915_hw_ppgtt *ppgtt;
+
+		ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+		if (!ppgtt)
+			return -ENOMEM;
+
+		ret = __hw_ppgtt_init(dev, ppgtt);
+		if (ret != 0)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
-- 
1.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH 1/2] drm/i915: Rework ppgtt init to no require an aliasing ppgtt
  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-06 19:55     ` Daniel Vetter
  2014-08-12  8:58     ` Thierry, Michel
  2 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-06 19:55 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter

On Wed, Aug 06, 2014 at 08:19:53PM +0200, Daniel Vetter wrote:
> Currently we abuse the aliasing ppgtt to set up the ppgtt support in
> general. Which is a bit backwards since with full ppgtt we don't ever
> need the aliasing ppgtt.
> 
> So untangling this and separate the ppgtt init from the aliasing
> ppgtt. While at it drag it out of the context enabling (which just
> does a switch to the default context).
> 
> Note that we still have the differentiation between synchronous and
> asynchronous ppgtt setup, but that will soon vanish. So also correctly
> wire up the return value handling to be prepared for when ->switch_mm
> drops the synchronous parameter and could start to fail.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Aside: This will conflict quite a bit with Alistars gpu reset rework to
ditch the synchronous parameter from ppgtt->switch_mm. If Alistars patch
is ready first I'll rebase and resend, otherwise I'll fix it up while
applying. It shouldn't be too hairy really.
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_gem.c         |  8 ++++
>  drivers/gpu/drm/i915/i915_gem_context.c |  7 ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c     | 84 +++++++++++++--------------------
>  drivers/gpu/drm/i915/i915_gem_gtt.h     |  1 +
>  4 files changed, 42 insertions(+), 58 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index a79deb189146..caf92bac2152 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -4742,6 +4742,14 @@ i915_gem_init_hw(struct drm_device *dev)
>  	if (ret && ret != -EIO) {
>  		DRM_ERROR("Context enable failed %d\n", ret);
>  		i915_gem_cleanup_ringbuffer(dev);
> +
> +		return ret;
> +	}
> +
> +	ret = i915_ppgtt_init_hw(dev);
> +	if (ret && ret != -EIO) {
> +		DRM_ERROR("PPGTT enable failed %d\n", ret);
> +		i915_gem_cleanup_ringbuffer(dev);
>  	}
>  
>  	return ret;
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> index 3b8367aa8404..4af5f05b24e8 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -424,13 +424,6 @@ int i915_gem_context_enable(struct drm_i915_private *dev_priv)
>  	struct intel_engine_cs *ring;
>  	int ret, i;
>  
> -	/* This is the only place the aliasing PPGTT gets enabled, which means
> -	 * it has to happen before we bail on reset */
> -	if (dev_priv->mm.aliasing_ppgtt) {
> -		struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
> -		ppgtt->enable(ppgtt);
> -	}
> -
>  	/* FIXME: We should make this work, even in reset */
>  	if (i915_reset_in_progress(&dev_priv->gpu_error))
>  		return 0;
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 4fa7807ed4d5..bf70ab44b968 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -78,7 +78,6 @@ static void ppgtt_bind_vma(struct i915_vma *vma,
>  			   enum i915_cache_level cache_level,
>  			   u32 flags);
>  static void ppgtt_unbind_vma(struct i915_vma *vma);
> -static int gen8_ppgtt_enable(struct i915_hw_ppgtt *ppgtt);
>  
>  static inline gen8_gtt_pte_t gen8_pte_encode(dma_addr_t addr,
>  					     enum i915_cache_level level,
> @@ -615,7 +614,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)
>  		kunmap_atomic(pd_vaddr);
>  	}
>  
> -	ppgtt->enable = gen8_ppgtt_enable;
>  	ppgtt->switch_mm = gen8_mm_switch;
>  	ppgtt->base.clear_range = gen8_ppgtt_clear_range;
>  	ppgtt->base.insert_entries = gen8_ppgtt_insert_entries;
> @@ -836,39 +834,20 @@ static int gen6_mm_switch(struct i915_hw_ppgtt *ppgtt,
>  	return 0;
>  }
>  
> -static int gen8_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
> +static void gen8_ppgtt_enable(struct drm_device *dev)
>  {
> -	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct intel_engine_cs *ring;
> -	int j, ret;
> +	int j;
>  
>  	for_each_ring(ring, dev_priv, j) {
>  		I915_WRITE(RING_MODE_GEN7(ring),
>  			   _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
> -
> -		/* We promise to do a switch later with FULL PPGTT. If this is
> -		 * aliasing, this is the one and only switch we'll do */
> -		if (USES_FULL_PPGTT(dev))
> -			continue;
> -
> -		ret = ppgtt->switch_mm(ppgtt, ring, true);
> -		if (ret)
> -			goto err_out;
>  	}
> -
> -	return 0;
> -
> -err_out:
> -	for_each_ring(ring, dev_priv, j)
> -		I915_WRITE(RING_MODE_GEN7(ring),
> -			   _MASKED_BIT_DISABLE(GFX_PPGTT_ENABLE));
> -	return ret;
>  }
>  
> -static int gen7_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
> +static void gen7_ppgtt_enable(struct drm_device *dev)
>  {
> -	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct intel_engine_cs *ring;
>  	uint32_t ecochk, ecobits;
> @@ -887,31 +866,16 @@ static int gen7_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
>  	I915_WRITE(GAM_ECOCHK, ecochk);
>  
>  	for_each_ring(ring, dev_priv, i) {
> -		int ret;
>  		/* GFX_MODE is per-ring on gen7+ */
>  		I915_WRITE(RING_MODE_GEN7(ring),
>  			   _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
> -
> -		/* We promise to do a switch later with FULL PPGTT. If this is
> -		 * aliasing, this is the one and only switch we'll do */
> -		if (USES_FULL_PPGTT(dev))
> -			continue;
> -
> -		ret = ppgtt->switch_mm(ppgtt, ring, true);
> -		if (ret)
> -			return ret;
>  	}
> -
> -	return 0;
>  }
>  
> -static int gen6_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
> +static void gen6_ppgtt_enable(struct drm_device *dev)
>  {
> -	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> -	struct intel_engine_cs *ring;
>  	uint32_t ecochk, gab_ctl, ecobits;
> -	int i;
>  
>  	ecobits = I915_READ(GAC_ECO_BITS);
>  	I915_WRITE(GAC_ECO_BITS, ecobits | ECOBITS_SNB_BIT |
> @@ -924,14 +888,6 @@ static int gen6_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
>  	I915_WRITE(GAM_ECOCHK, ecochk | ECOCHK_SNB_BIT | ECOCHK_PPGTT_CACHE64B);
>  
>  	I915_WRITE(GFX_MODE, _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
> -
> -	for_each_ring(ring, dev_priv, i) {
> -		int ret = ppgtt->switch_mm(ppgtt, ring, true);
> -		if (ret)
> -			return ret;
> -	}
> -
> -	return 0;
>  }
>  
>  /* PPGTT support for Sandybdrige/Gen6 and later */
> @@ -1151,13 +1107,10 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
>  
>  	ppgtt->base.pte_encode = dev_priv->gtt.base.pte_encode;
>  	if (IS_GEN6(dev)) {
> -		ppgtt->enable = gen6_ppgtt_enable;
>  		ppgtt->switch_mm = gen6_mm_switch;
>  	} else if (IS_HASWELL(dev)) {
> -		ppgtt->enable = gen7_ppgtt_enable;
>  		ppgtt->switch_mm = hsw_mm_switch;
>  	} else if (IS_GEN7(dev)) {
> -		ppgtt->enable = gen7_ppgtt_enable;
>  		ppgtt->switch_mm = gen7_mm_switch;
>  	} else
>  		BUG();
> @@ -1222,6 +1175,35 @@ int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>  	return ret;
>  }
>  
> +int i915_ppgtt_init_hw(struct drm_device *dev)
> +{
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct intel_engine_cs *ring;
> +	struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
> +	int i, ret = 0;
> +
> +	if (!USES_PPGTT(dev))
> +		return 0;
> +
> +	if (IS_GEN6(dev))
> +		gen6_ppgtt_enable(dev);
> +	else if (IS_GEN7(dev))
> +		gen7_ppgtt_enable(dev);
> +	else if (INTEL_INFO(dev)->gen >= 8)
> +		gen8_ppgtt_enable(dev);
> +	else
> +		WARN_ON(1);
> +
> +	if (ppgtt) {
> +		for_each_ring(ring, dev_priv, i) {
> +			ret = ppgtt->switch_mm(ppgtt, ring, true);
> +			if (ret != 0)
> +				return ret;
> +		}
> +	}
> +
> +	return ret;
> +}
>  struct i915_hw_ppgtt *
>  i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private *fpriv)
>  {
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index bea3541d5525..45aa15fa4af2 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -277,6 +277,7 @@ int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
>  bool intel_enable_ppgtt(struct drm_device *dev, bool full);
>  
>  int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
> +int i915_ppgtt_init_hw(struct drm_device *dev);
>  void i915_ppgtt_release(struct kref *kref);
>  struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_device *dev,
>  					struct drm_i915_file_private *fpriv);
> -- 
> 1.9.3
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime handling
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:00 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 8698 bytes --]



> -----Original Message-----
> From: Daniel Vetter [mailto:daniel.vetter@ffwll.ch]
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter; Thierry, Michel; Chris Wilson
> Subject: [PATCH 02/15] drm/i915: Some cleanups for the ppgtt lifetime
> handling
> 
> So when reviewing Michel's patch I've noticed a few things and cleaned
> them up:
> - The early checks in ppgtt_release are now redundant: The inactive
>   list should always be empty now, so we can ditch these checks. Even
>   for the aliasing ppgtt (though that's a different confusion) since
>   we tear that down after all the objects are gone.
> - The ppgtt handling functions are splattered all over. Consolidate
>   them in i915_gem_gtt.c, give them OCD prefixes and add wrappers for
>   get/put.
> - There was a bit a confusion in ppgtt_release about whether it cares
>   about the active or inactive list. It should care about them both,
>   so augment the WARNINGs to check for both.
> 
> There's still create_vm_for_ctx left to do, put that is blocked on the
> removal of ppgtt->ctx. Once that's done we can rename it to
> i915_ppgtt_create and move it to its siblings for handling ppgtts.
> 
> v2: Move the ppgtt checks into the inline get/put functions as
> suggested by Chris.
> 
> v3: Inline the now redundant ppgtt local variable.
> 
> Cc: Michel Thierry <michel.thierry@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_drv.h         |  1 -
>  drivers/gpu/drm/i915/i915_gem.c         |  5 +----
>  drivers/gpu/drm/i915/i915_gem_context.c | 36
++++----------------------------
> -
>  drivers/gpu/drm/i915/i915_gem_gtt.c     | 20 +++++++++++++-----
>  drivers/gpu/drm/i915/i915_gem_gtt.h     | 14 ++++++++++++-
>  5 files changed, 33 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h
> b/drivers/gpu/drm/i915/i915_drv.h
> index 5a18680011da..d349dd75ed69 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2512,7 +2512,6 @@ void i915_gem_object_ggtt_unpin(struct
> drm_i915_gem_object *obj);
>  #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 25a32b9c9b4b..b33a677b4b1e 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -4500,7 +4500,6 @@ 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
> */
> @@ -4508,10 +4507,8 @@ void i915_gem_vma_destroy(struct i915_vma
> *vma)
>  		return;
> 
>  	vm = vma->vm;
> -	ppgtt = vm_to_ppgtt(vm);
> 
> -	if (ppgtt)
> -		kref_put(&ppgtt->ref, ppgtt_release);
> +	i915_ppgtt_put(vm_to_ppgtt(vm));
> 
>  	list_del(&vma->vma_link);
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c
> b/drivers/gpu/drm/i915/i915_gem_context.c
> index ae706cba05ae..899c6a7a5920 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -96,33 +96,6 @@
>  #define GEN6_CONTEXT_ALIGN (64<<10)
>  #define GEN7_CONTEXT_ALIGN 4096
> 
> -static void do_ppgtt_cleanup(struct i915_hw_ppgtt *ppgtt)
> -{
> -	struct drm_device *dev = ppgtt->base.dev;
> -	struct drm_i915_private *dev_priv = dev->dev_private;
> -	struct i915_address_space *vm = &ppgtt->base;
> -
> -	if (ppgtt == dev_priv->mm.aliasing_ppgtt ||
> -	    (list_empty(&vm->active_list) &&
list_empty(&vm->inactive_list)))
> {
> -		ppgtt->base.cleanup(&ppgtt->base);
> -		return;
> -	}
> -
> -	/* vmas should already be unbound */
> -	WARN_ON(!list_empty(&vm->active_list));
> -
> -	ppgtt->base.cleanup(&ppgtt->base);
> -}
> -
> -void ppgtt_release(struct kref *kref)
> -{
> -	struct i915_hw_ppgtt *ppgtt =
> -		container_of(kref, struct i915_hw_ppgtt, ref);
> -
> -	do_ppgtt_cleanup(ppgtt);
> -	kfree(ppgtt);
> -}
> -
>  static size_t get_context_alignment(struct drm_device *dev)
>  {
>  	if (IS_GEN6(dev))
> @@ -171,8 +144,7 @@ void i915_gem_context_free(struct kref *ctx_ref)
>  			ppgtt = ctx_to_ppgtt(ctx);
>  	}
> 
> -	if (ppgtt)
> -		kref_put(&ppgtt->ref, ppgtt_release);
> +	i915_ppgtt_put(ppgtt);
>  	if (ctx->legacy_hw_ctx.rcs_state)
>  		drm_gem_object_unreference(&ctx-
> >legacy_hw_ctx.rcs_state->base);
>  	list_del(&ctx->link);
> @@ -219,7 +191,7 @@ create_vm_for_ctx(struct drm_device *dev, struct
> intel_context *ctx)
>  	if (!ppgtt)
>  		return ERR_PTR(-ENOMEM);
> 
> -	ret = i915_gem_init_ppgtt(dev, ppgtt);
> +	ret = i915_ppgtt_init(dev, ppgtt);
>  	if (ret) {
>  		kfree(ppgtt);
>  		return ERR_PTR(ret);
> @@ -231,7 +203,7 @@ create_vm_for_ctx(struct drm_device *dev, struct
> intel_context *ctx)
> 
>  static struct intel_context *
>  __create_hw_context(struct drm_device *dev,
> -		  struct drm_i915_file_private *file_priv)
> +		    struct drm_i915_file_private *file_priv)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct intel_context *ctx;
> @@ -339,7 +311,7 @@ i915_gem_create_context(struct drm_device *dev,
>  		/* For platforms which only have aliasing PPGTT, we fake the
>  		 * address space and refcounting. */
>  		ctx->vm = &dev_priv->mm.aliasing_ppgtt->base;
> -		kref_get(&dev_priv->mm.aliasing_ppgtt->ref);
> +		i915_ppgtt_get(dev_priv->mm.aliasing_ppgtt);
>  	} else
>  		ctx->vm = &dev_priv->gtt.base;
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 90c3d0fae3f1..1a20e1b4f052 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1191,7 +1191,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt
> *ppgtt)
>  	return 0;
>  }
> 
> -int i915_gem_init_ppgtt(struct drm_device *dev, struct i915_hw_ppgtt
> *ppgtt)
> +int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	int ret = 0;
> @@ -1222,6 +1222,19 @@ int i915_gem_init_ppgtt(struct drm_device *dev,
> struct i915_hw_ppgtt *ppgtt)
>  	return ret;
>  }
> 
> +void  i915_ppgtt_release(struct kref *kref)
> +{
> +	struct i915_hw_ppgtt *ppgtt =
> +		container_of(kref, struct i915_hw_ppgtt, ref);
> +
> +	/* vmas should already be unbound */
> +	WARN_ON(!list_empty(&ppgtt->base.active_list));
> +	WARN_ON(!list_empty(&ppgtt->base.inactive_list));
> +
> +	ppgtt->base.cleanup(&ppgtt->base);
> +	kfree(ppgtt);
> +}
> +
>  static void
>  ppgtt_bind_vma(struct i915_vma *vma,
>  	       enum i915_cache_level cache_level,
> @@ -2159,15 +2172,12 @@ 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);
> +	i915_ppgtt_get(vm_to_ppgtt(vm));
> 
>  	return vma;
>  }
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h
> b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index 8d6f7c18c404..57d401343e8d 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -273,7 +273,19 @@ void i915_gem_setup_global_gtt(struct drm_device
> *dev, unsigned long start,
>  			       unsigned long mappable_end, unsigned long
> end);
> 
>  bool intel_enable_ppgtt(struct drm_device *dev, bool full);
> -int i915_gem_init_ppgtt(struct drm_device *dev, struct i915_hw_ppgtt
> *ppgtt);
> +
> +int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
> +void i915_ppgtt_release(struct kref *kref);
> +static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
> +{
> +	if (ppgtt)
> +		kref_get(&ppgtt->ref);
> +}
> +static inline void i915_ppgtt_put(struct i915_hw_ppgtt *ppgtt)
> +{
> +	if (ppgtt)
> +		kref_put(&ppgtt->ref, i915_ppgtt_release);
> +}
> 
>  void i915_check_and_clear_faults(struct drm_device *dev);
>  void i915_gem_suspend_gtt_mappings(struct drm_device *dev);
> --
> 1.9.3
Reviewed-by: Michel Thierry <michel.thierry@intel.com>


[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 05/15] drm/i915: Only refcount ppgtt if it actually is one
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:02 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 3090 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 05/15] drm/i915: Only refcount ppgtt if it
actually
> is one
> 
> This essentially unbreaks non-ppgtt operation where we'd scribble over
> random memory.
> 
> While at it give the vm_to_ppgtt function a proper prefix and make it
> a bit more paranoid.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_drv.h     | 10 +++++++++-
>  drivers/gpu/drm/i915/i915_gem.c     |  3 ++-
>  drivers/gpu/drm/i915/i915_gem_gtt.c |  3 ++-
>  3 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h
> b/drivers/gpu/drm/i915/i915_drv.h
> index 194367f0ba1a..31422bc07445 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2475,6 +2475,15 @@ static inline bool i915_is_ggtt(struct
> i915_address_space *vm)
>  	return vm == ggtt;
>  }
> 
> +static inline struct i915_hw_ppgtt *
> +i915_vm_to_ppgtt(struct i915_address_space *vm)
> +{
> +	WARN_ON(i915_is_ggtt(vm));
> +
> +	return container_of(vm, struct i915_hw_ppgtt, base);
> +}
> +
> +
>  static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object
> *obj)
>  {
>  	return i915_gem_obj_bound(obj, obj_to_ggtt(obj));
> @@ -2510,7 +2519,6 @@ 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 i915_gem_context_fini(struct drm_device *dev);
>  void i915_gem_context_reset(struct drm_device *dev);
> diff --git a/drivers/gpu/drm/i915/i915_gem.c
> b/drivers/gpu/drm/i915/i915_gem.c
> index b33a677b4b1e..c43ccfdf45a5 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -4508,7 +4508,8 @@ void i915_gem_vma_destroy(struct i915_vma
> *vma)
> 
>  	vm = vma->vm;
> 
> -	i915_ppgtt_put(vm_to_ppgtt(vm));
> +	if (!i915_is_ggtt(vm))
> +		i915_ppgtt_put(i915_vm_to_ppgtt(vm));
> 
>  	list_del(&vma->vma_link);
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 83ee41e5c1c7..3753bf184865 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -2204,7 +2204,8 @@ i915_gem_obj_lookup_or_create_vma(struct
> drm_i915_gem_object *obj,
>  	if (!vma)
>  		vma = __i915_gem_vma_create(obj, vm);
> 
> -	i915_ppgtt_get(vm_to_ppgtt(vm));
> +	if (!i915_is_ggtt(vm))
> +		i915_ppgtt_get(i915_vm_to_ppgtt(vm));
> 
>  	return vma;
>  }
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 08/15] drm/i915: Fix up checks for aliasing ppgtt
  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
  0 siblings, 1 reply; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:03 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 4711 bytes --]


> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 08/15] drm/i915: Fix up checks for aliasing
ppgtt
>
> A subsequent patch will no longer initialize the aliasing ppgtt if we
> have full ppgtt enabled, since we simply don't need that any more.
>
> Unfortunately a few places check for the aliasing ppgtt instead of
> checking for ppgtt in general. Fix them up.
>
> One special case are the gtt offset and size macros, which have some
> code to remap the aliasing ppgtt to the global gtt. The aliasing ppgtt
> is _not_ a logical address space, so passing that in as the vm is
> plain and simple a bug. So just WARN about it and carry on - we have a
> gracefully fall-through anyway if we can't find the vma.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_cmd_parser.c  | 4 +---
>  drivers/gpu/drm/i915/i915_dma.c         | 2 +-
>  drivers/gpu/drm/i915/i915_gem.c         | 8 ++------
>  drivers/gpu/drm/i915/intel_ringbuffer.c | 4 +---
>  4 files changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c
> b/drivers/gpu/drm/i915/i915_cmd_parser.c
> index dea99d92fb4a..c45856bcc8b9 100644
> --- a/drivers/gpu/drm/i915/i915_cmd_parser.c
> +++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
> @@ -842,8 +842,6 @@ finish:
>   */
>  bool i915_needs_cmd_parser(struct intel_engine_cs *ring)
>  {
> -	struct drm_i915_private *dev_priv = ring->dev->dev_private;
> -
>  	if (!ring->needs_cmd_parser)
>  		return false;
>
> @@ -852,7 +850,7 @@ bool i915_needs_cmd_parser(struct intel_engine_cs
> *ring)
>  	 * disabled. That will cause all of the parser's PPGTT checks to
>  	 * fail. For now, disable parsing when PPGTT is off.
>  	 */
> -	if (!dev_priv->mm.aliasing_ppgtt)
> +	if (USES_PPGTT(ring->dev))
>  		return false;
>
>  	return (i915.enable_cmd_parser == 1);
> diff --git a/drivers/gpu/drm/i915/i915_dma.c
> b/drivers/gpu/drm/i915/i915_dma.c
> index 2e7f03ad5ee2..e5ac1a6e9d26 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -999,7 +999,7 @@ static int i915_getparam(struct drm_device *dev, void
> *data,
>  		value = HAS_WT(dev);
>  		break;
>  	case I915_PARAM_HAS_ALIASING_PPGTT:
> -		value = dev_priv->mm.aliasing_ppgtt ||
> USES_FULL_PPGTT(dev);
> +		value = USES_PPGTT(dev);
>  		break;
>  	case I915_PARAM_HAS_WAIT_TIMEOUT:
>  		value = 1;
> diff --git a/drivers/gpu/drm/i915/i915_gem.c
> b/drivers/gpu/drm/i915/i915_gem.c
> index d8399ee622b9..a79deb189146 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -5114,9 +5114,7 @@ unsigned long i915_gem_obj_offset(struct
> drm_i915_gem_object *o,
>  	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
>  	struct i915_vma *vma;
>
> -	if (!dev_priv->mm.aliasing_ppgtt ||
> -	    vm == &dev_priv->mm.aliasing_ppgtt->base)
> -		vm = &dev_priv->gtt.base;
> +	WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
>
>  	list_for_each_entry(vma, &o->vma_list, vma_link) {
>  		if (vma->vm == vm)
> @@ -5157,9 +5155,7 @@ unsigned long i915_gem_obj_size(struct
> drm_i915_gem_object *o,
>  	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
>  	struct i915_vma *vma;
>
> -	if (!dev_priv->mm.aliasing_ppgtt ||
> -	    vm == &dev_priv->mm.aliasing_ppgtt->base)
> -		vm = &dev_priv->gtt.base;
> +	WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
>
>  	BUG_ON(list_empty(&o->vma_list));
>
> diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c
> b/drivers/gpu/drm/i915/intel_ringbuffer.c
> index 05969f03c0c1..390e38325b37 100644
> --- a/drivers/gpu/drm/i915/intel_ringbuffer.c
> +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
> @@ -1977,9 +1977,7 @@ gen8_ring_dispatch_execbuffer(struct
> intel_engine_cs *ring,
>  			      u64 offset, u32 len,
>  			      unsigned flags)
>  {
> -	struct drm_i915_private *dev_priv = ring->dev->dev_private;
> -	bool ppgtt = dev_priv->mm.aliasing_ppgtt != NULL &&
> -		!(flags & I915_DISPATCH_SECURE);
> +	bool ppgtt = USES_PPGTT(ring->dev) && !(flags &
> I915_DISPATCH_SECURE);
>  	int ret;
>
>  	ret = intel_ring_begin(ring, 4);
> --
> 1.9.3
>
Sorry, I spotted another instance in gen8_ppgtt_info (debugfs). It is more 
gen8_ppgtt_info's fault, so I'm sending a follow up patch for it.
Unless you want to combine them...
Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 2/2] drm/i915: Initialize the aliasing ppgtt as part of global gtt
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:04 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 5641 bytes --]



> -----Original Message-----
> From: Daniel Vetter [mailto:daniel.vetter@ffwll.ch]
> Sent: Wednesday, August 06, 2014 7:20 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter; Thierry, Michel; Ville Syrjälä
> Subject: [PATCH 2/2] drm/i915: Initialize the aliasing ppgtt as part of global gtt
> 
> Stuffing this into the context setup code doesn't make a lot of sense.
> Also reusing the real ppgtt setup code makes even less sense since the
> aliasing ppgtt isn't a real address space. Leaving all that stuff
> unitialized will make sure that we catch any abusers promptly.
> 
> This is also a prep work to clean up the context->ppgtt link.
> 
> v2: Fix up the logic fail, I've fumbled it so badly to completely
> disable ppgtt on gen6. Spotted by Ville and Michel. Also move around
> the pde write into the gen6 init function, since otherwise it won't
> work at all.
> 
> v3: Only initialize the aliasing ppgtt when we actually enable it.
> 
> Cc: "Thierry, Michel" <michel.thierry@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_gem_context.c | 13 +---------
>  drivers/gpu/drm/i915/i915_gem_gtt.c     | 42 +++++++++++++++++++++++-
> ---------
>  2 files changed, 31 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c
> b/drivers/gpu/drm/i915/i915_gem_context.c
> index 4af5f05b24e8..07f4d060575b 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device *dev,
>  			goto err_unpin;
>  		} else
>  			ctx->vm = &ppgtt->base;
> -
> -		/* This case is reserved for the global default context and
> -		 * should only happen once. */
> -		if (is_global_default_ctx) {
> -			if (WARN_ON(dev_priv->mm.aliasing_ppgtt)) {
> -				ret = -EEXIST;
> -				goto err_unpin;
> -			}
> -
> -			dev_priv->mm.aliasing_ppgtt = ppgtt;
> -		}
>  	} else if (USES_PPGTT(dev)) {
>  		/* For platforms which only have aliasing PPGTT, we fake the
>  		 * address space and refcounting. */
> @@ -361,7 +350,7 @@ int i915_gem_context_init(struct drm_device *dev)
>  		}
>  	}
> 
> -	ctx = i915_gem_create_context(dev, NULL, USES_PPGTT(dev));
> +	ctx = i915_gem_create_context(dev, NULL,
> USES_FULL_PPGTT(dev));
>  	if (IS_ERR(ctx)) {
>  		DRM_ERROR("Failed to create default global context (error
> %ld)\n",
>  			  PTR_ERR(ctx));
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index bf70ab44b968..653a1166a3fa 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1141,35 +1141,38 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt
> *ppgtt)
>  			 ppgtt->node.size >> 20,
>  			 ppgtt->node.start / PAGE_SIZE);
> 
> +	gen6_write_pdes(ppgtt);
> +	DRM_DEBUG("Adding PPGTT at offset %x\n",
> +		  ppgtt->pd_offset << 10);
> +
>  	return 0;
>  }
> 
> -int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
> +int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> -	int ret = 0;
> 
>  	ppgtt->base.dev = dev;
>  	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
> 
>  	if (INTEL_INFO(dev)->gen < 8)
> -		ret = gen6_ppgtt_init(ppgtt);
> +		return gen6_ppgtt_init(ppgtt);
>  	else if (IS_GEN8(dev))
> -		ret = gen8_ppgtt_init(ppgtt, dev_priv->gtt.base.total);
> +		return gen8_ppgtt_init(ppgtt, dev_priv->gtt.base.total);
>  	else
>  		BUG();
> +}
> +int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
> +{
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	int ret = 0;
> 
> -	if (!ret) {
> -		struct drm_i915_private *dev_priv = dev->dev_private;
> +	ret = __hw_ppgtt_init(dev, ppgtt);
> +	if (ret == 0) {
>  		kref_init(&ppgtt->ref);
>  		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
>  			    ppgtt->base.total);
>  		i915_init_vm(dev_priv, &ppgtt->base);
> -		if (INTEL_INFO(dev)->gen < 8) {
> -			gen6_write_pdes(ppgtt);
> -			DRM_DEBUG("Adding PPGTT at offset %x\n",
> -				  ppgtt->pd_offset << 10);
> -		}
>  	}
> 
>  	return ret;
> @@ -1710,6 +1713,7 @@ int i915_gem_setup_global_gtt(struct drm_device
> *dev,
>  	struct drm_mm_node *entry;
>  	struct drm_i915_gem_object *obj;
>  	unsigned long hole_start, hole_end;
> +	int ret;
> 
>  	BUG_ON(mappable_end > end);
> 
> @@ -1721,7 +1725,7 @@ int i915_gem_setup_global_gtt(struct drm_device
> *dev,
>  	/* Mark any preallocated objects as occupied */
>  	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
>  		struct i915_vma *vma = i915_gem_obj_to_vma(obj,
> ggtt_vm);
> -		int ret;
> +
>  		DRM_DEBUG_KMS("reserving preallocated space: %lx +
> %zx\n",
>  			      i915_gem_obj_ggtt_offset(obj), obj->base.size);
> 
> @@ -1748,6 +1752,20 @@ int i915_gem_setup_global_gtt(struct drm_device
> *dev,
>  	/* And finally clear the reserved guard page */
>  	ggtt_vm->clear_range(ggtt_vm, end - PAGE_SIZE, PAGE_SIZE, true);
> 
> +	if (USES_PPGTT(dev) && !USES_FULL_PPGTT(dev)) {
> +		struct i915_hw_ppgtt *ppgtt;
> +
> +		ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
> +		if (!ppgtt)
> +			return -ENOMEM;
> +
> +		ret = __hw_ppgtt_init(dev, ppgtt);
> +		if (ret != 0)
> +			return ret;
> +
> +		dev_priv->mm.aliasing_ppgtt = ppgtt;
> +	}
> +
>  	return 0;
>  }
> 
Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> --
> 1.9.3


[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 11/15] drm/i915: Drop create_vm argument to i915_gem_create_context
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:06 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 2722 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 11/15] drm/i915: Drop create_vm argument to
> i915_gem_create_context
> 
> Now that all the flow is streamlined the rule is simple: We create
> a new ppgtt for a new context when we have full ppgtt enabled.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_gem_context.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c
> b/drivers/gpu/drm/i915/i915_gem_context.c
> index c00e5d027774..655ed6228aab 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -229,8 +229,7 @@ err_out:
>   */
>  static struct intel_context *
>  i915_gem_create_context(struct drm_device *dev,
> -			struct drm_i915_file_private *file_priv,
> -			bool create_vm)
> +			struct drm_i915_file_private *file_priv)
>  {
>  	const bool is_global_default_ctx = file_priv == NULL;
>  	struct intel_context *ctx;
> @@ -258,7 +257,7 @@ i915_gem_create_context(struct drm_device *dev,
>  		}
>  	}
> 
> -	if (create_vm) {
> +	if (USES_FULL_PPGTT(dev)) {
>  		struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev,
> file_priv);
> 
>  		if (IS_ERR_OR_NULL(ppgtt)) {
> @@ -337,7 +336,7 @@ int i915_gem_context_init(struct drm_device *dev)
>  		}
>  	}
> 
> -	ctx = i915_gem_create_context(dev, NULL,
> USES_FULL_PPGTT(dev));
> +	ctx = i915_gem_create_context(dev, NULL);
>  	if (IS_ERR(ctx)) {
>  		DRM_ERROR("Failed to create default global context (error
> %ld)\n",
>  			  PTR_ERR(ctx));
> @@ -438,7 +437,7 @@ int i915_gem_context_open(struct drm_device *dev,
> struct drm_file *file)
>  	idr_init(&file_priv->context_idr);
> 
>  	mutex_lock(&dev->struct_mutex);
> -	ctx = i915_gem_create_context(dev, file_priv,
> USES_FULL_PPGTT(dev));
> +	ctx = i915_gem_create_context(dev, file_priv);
>  	mutex_unlock(&dev->struct_mutex);
> 
>  	if (IS_ERR(ctx)) {
> @@ -696,7 +695,7 @@ int i915_gem_context_create_ioctl(struct drm_device
> *dev, void *data,
>  	if (ret)
>  		return ret;
> 
> -	ctx = i915_gem_create_context(dev, file_priv,
> USES_FULL_PPGTT(dev));
> +	ctx = i915_gem_create_context(dev, file_priv);
>  	mutex_unlock(&dev->struct_mutex);
>  	if (IS_ERR(ctx))
>  		return PTR_ERR(ctx);
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 12/15] drm/i915: Extract common cleanup into i915_ppgtt_release
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:07 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 2086 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 12/15] drm/i915: Extract common cleanup into
> i915_ppgtt_release
> 
> Address space cleanup isn't really a job for the low-level cleanup
> callbacks. Without this change we can't reuse the low-level cleanup
> callback for the aliasing ppgtt cleanup.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index a4c1740d79be..bbf113ed7339 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -403,9 +403,6 @@ static void gen8_ppgtt_cleanup(struct
> i915_address_space *vm)
>  	struct i915_hw_ppgtt *ppgtt =
>  		container_of(vm, struct i915_hw_ppgtt, base);
> 
> -	list_del(&vm->global_link);
> -	drm_mm_takedown(&vm->mm);
> -
>  	gen8_ppgtt_unmap_pages(ppgtt);
>  	gen8_ppgtt_free(ppgtt);
>  }
> @@ -1029,8 +1026,6 @@ static void gen6_ppgtt_cleanup(struct
> i915_address_space *vm)
>  	struct i915_hw_ppgtt *ppgtt =
>  		container_of(vm, struct i915_hw_ppgtt, base);
> 
> -	list_del(&vm->global_link);
> -	drm_mm_takedown(&ppgtt->base.mm);
>  	drm_mm_remove_node(&ppgtt->node);
> 
>  	gen6_ppgtt_unmap_pages(ppgtt);
> @@ -1255,6 +1250,9 @@ void  i915_ppgtt_release(struct kref *kref)
>  	WARN_ON(!list_empty(&ppgtt->base.active_list));
>  	WARN_ON(!list_empty(&ppgtt->base.inactive_list));
> 
> +	list_del(&ppgtt->base.global_link);
> +	drm_mm_takedown(&ppgtt->base.mm);
> +
>  	ppgtt->base.cleanup(&ppgtt->base);
>  	kfree(ppgtt);
>  }
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 13/15] drm/i915: Extract commmon global gtt cleanup code
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:08 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 3853 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 13/15] drm/i915: Extract commmon global gtt
> cleanup code
> 
> We want to move the aliasing ppgtt cleanup back into the global
> gtt cleanup code for symmetric, but first we need to create such
> a place.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_dma.c     |  4 ++--
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 20 ++++++++++++--------
>  drivers/gpu/drm/i915/i915_gem_gtt.h |  1 +
>  3 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_dma.c
> b/drivers/gpu/drm/i915/i915_dma.c
> index e5ac1a6e9d26..c176a6c97c80 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -1817,7 +1817,7 @@ out_mtrrfree:
>  	arch_phys_wc_del(dev_priv->gtt.mtrr);
>  	io_mapping_free(dev_priv->gtt.mappable);
>  out_gtt:
> -	dev_priv->gtt.base.cleanup(&dev_priv->gtt.base);
> +	i915_global_gtt_cleanup(dev);
>  out_regs:
>  	intel_uncore_fini(dev);
>  	pci_iounmap(dev->pdev, dev_priv->regs);
> @@ -1916,7 +1916,7 @@ int i915_driver_unload(struct drm_device *dev)
>  	destroy_workqueue(dev_priv->wq);
>  	pm_qos_remove_request(&dev_priv->pm_qos);
> 
> -	dev_priv->gtt.base.cleanup(&dev_priv->gtt.base);
> +	i915_global_gtt_cleanup(dev);
> 
>  	intel_uncore_fini(dev);
>  	if (dev_priv->regs != NULL)
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index bbf113ed7339..2eab0b6a32e8 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1796,6 +1796,18 @@ void i915_gem_init_global_gtt(struct drm_device
> *dev)
>  	i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
>  }
> 
> +void i915_global_gtt_cleanup(struct drm_device *dev)
> +{
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct i915_address_space *vm = &dev_priv->gtt.base;
> +
> +	if (drm_mm_initialized(&vm->mm)) {
> +		drm_mm_takedown(&vm->mm);
> +		list_del(&vm->global_link);
> +	}
> +
> +	vm->cleanup(vm);
> +}
>  static int setup_scratch_page(struct drm_device *dev)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> @@ -2064,10 +2076,6 @@ static void gen6_gmch_remove(struct
> i915_address_space *vm)
> 
>  	struct i915_gtt *gtt = container_of(vm, struct i915_gtt, base);
> 
> -	if (drm_mm_initialized(&vm->mm)) {
> -		drm_mm_takedown(&vm->mm);
> -		list_del(&vm->global_link);
> -	}
>  	iounmap(gtt->gsm);
>  	teardown_scratch_page(vm->dev);
>  }
> @@ -2106,10 +2114,6 @@ static int i915_gmch_probe(struct drm_device
> *dev,
> 
>  static void i915_gmch_remove(struct i915_address_space *vm)
>  {
> -	if (drm_mm_initialized(&vm->mm)) {
> -		drm_mm_takedown(&vm->mm);
> -		list_del(&vm->global_link);
> -	}
>  	intel_gmch_remove();
>  }
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h
> b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index bea3541d5525..6b30ebad0a0a 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -273,6 +273,7 @@ int i915_gem_gtt_init(struct drm_device *dev);
>  void i915_gem_init_global_gtt(struct drm_device *dev);
>  int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long
start,
>  			      unsigned long mappable_end, unsigned long
> end);
> +void i915_global_gtt_cleanup(struct drm_device *dev);
> 
>  bool intel_enable_ppgtt(struct drm_device *dev, bool full);
> 
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt alongside the global gtt
  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
  0 siblings, 1 reply; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 13:09 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 2845 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt
> alongside the global gtt
> 
> Also remove related WARN_ONs which seem to have been hit since a rather
> long time. But apperently no one noticed since our module reload is
> already WARNING-infested :(
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_dma.c     | 4 ----
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 7 +++++++
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_dma.c
> b/drivers/gpu/drm/i915/i915_dma.c
> index c176a6c97c80..94afe7c4458b 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -1388,7 +1388,6 @@ cleanup_gem:
>  	i915_gem_cleanup_ringbuffer(dev);
>  	i915_gem_context_fini(dev);
>  	mutex_unlock(&dev->struct_mutex);
> -	WARN_ON(dev_priv->mm.aliasing_ppgtt);
>  cleanup_irq:
>  	drm_irq_uninstall(dev);
>  cleanup_gem_stolen:
> @@ -1897,7 +1896,6 @@ int i915_driver_unload(struct drm_device *dev)
>  		mutex_lock(&dev->struct_mutex);
>  		i915_gem_cleanup_ringbuffer(dev);
>  		i915_gem_context_fini(dev);
> -		WARN_ON(dev_priv->mm.aliasing_ppgtt);
>  		mutex_unlock(&dev->struct_mutex);
>  		i915_gem_cleanup_stolen(dev);
> 
> @@ -1905,8 +1903,6 @@ int i915_driver_unload(struct drm_device *dev)
>  			i915_free_hws(dev);
>  	}
> 
> -	WARN_ON(!list_empty(&dev_priv->vm_list));
> -
>  	drm_vblank_cleanup(dev);
> 
>  	intel_teardown_gmbus(dev);
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 2eab0b6a32e8..ff031bb1f296 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1801,6 +1801,12 @@ void i915_global_gtt_cleanup(struct drm_device
> *dev)
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct i915_address_space *vm = &dev_priv->gtt.base;
> 
> +	if (dev_priv->mm.aliasing_ppgtt) {
> +		struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
> +
> +		ppgtt->base.cleanup(&ppgtt->base);
> +	}
> +
>  	if (drm_mm_initialized(&vm->mm)) {
>  		drm_mm_takedown(&vm->mm);
>  		list_del(&vm->global_link);
> @@ -1808,6 +1814,7 @@ void i915_global_gtt_cleanup(struct drm_device
> *dev)
> 
>  	vm->cleanup(vm);
>  }
> +
>  static int setup_scratch_page(struct drm_device *dev)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 08/15] drm/i915: Fix up checks for aliasing ppgtt
  2014-08-08 13:03   ` Thierry, Michel
@ 2014-08-08 13:49     ` Daniel Vetter
  2014-08-08 14:00       ` Thierry, Michel
  0 siblings, 1 reply; 32+ messages in thread
From: Daniel Vetter @ 2014-08-08 13:49 UTC (permalink / raw)
  To: Thierry, Michel; +Cc: Daniel Vetter, Intel Graphics Development

On Fri, Aug 08, 2014 at 01:03:53PM +0000, Thierry, Michel wrote:
> 
> > -----Original Message-----
> > From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> > Of Daniel Vetter
> > Sent: Wednesday, August 06, 2014 2:05 PM
> > To: Intel Graphics Development
> > Cc: Daniel Vetter
> > Subject: [Intel-gfx] [PATCH 08/15] drm/i915: Fix up checks for aliasing
> ppgtt
> >
> > A subsequent patch will no longer initialize the aliasing ppgtt if we
> > have full ppgtt enabled, since we simply don't need that any more.
> >
> > Unfortunately a few places check for the aliasing ppgtt instead of
> > checking for ppgtt in general. Fix them up.
> >
> > One special case are the gtt offset and size macros, which have some
> > code to remap the aliasing ppgtt to the global gtt. The aliasing ppgtt
> > is _not_ a logical address space, so passing that in as the vm is
> > plain and simple a bug. So just WARN about it and carry on - we have a
> > gracefully fall-through anyway if we can't find the vma.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> > ---
> >  drivers/gpu/drm/i915/i915_cmd_parser.c  | 4 +---
> >  drivers/gpu/drm/i915/i915_dma.c         | 2 +-
> >  drivers/gpu/drm/i915/i915_gem.c         | 8 ++------
> >  drivers/gpu/drm/i915/intel_ringbuffer.c | 4 +---
> >  4 files changed, 5 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c
> > b/drivers/gpu/drm/i915/i915_cmd_parser.c
> > index dea99d92fb4a..c45856bcc8b9 100644
> > --- a/drivers/gpu/drm/i915/i915_cmd_parser.c
> > +++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
> > @@ -842,8 +842,6 @@ finish:
> >   */
> >  bool i915_needs_cmd_parser(struct intel_engine_cs *ring)
> >  {
> > -	struct drm_i915_private *dev_priv = ring->dev->dev_private;
> > -
> >  	if (!ring->needs_cmd_parser)
> >  		return false;
> >
> > @@ -852,7 +850,7 @@ bool i915_needs_cmd_parser(struct intel_engine_cs
> > *ring)
> >  	 * disabled. That will cause all of the parser's PPGTT checks to
> >  	 * fail. For now, disable parsing when PPGTT is off.
> >  	 */
> > -	if (!dev_priv->mm.aliasing_ppgtt)
> > +	if (USES_PPGTT(ring->dev))
> >  		return false;
> >
> >  	return (i915.enable_cmd_parser == 1);
> > diff --git a/drivers/gpu/drm/i915/i915_dma.c
> > b/drivers/gpu/drm/i915/i915_dma.c
> > index 2e7f03ad5ee2..e5ac1a6e9d26 100644
> > --- a/drivers/gpu/drm/i915/i915_dma.c
> > +++ b/drivers/gpu/drm/i915/i915_dma.c
> > @@ -999,7 +999,7 @@ static int i915_getparam(struct drm_device *dev, void
> > *data,
> >  		value = HAS_WT(dev);
> >  		break;
> >  	case I915_PARAM_HAS_ALIASING_PPGTT:
> > -		value = dev_priv->mm.aliasing_ppgtt ||
> > USES_FULL_PPGTT(dev);
> > +		value = USES_PPGTT(dev);
> >  		break;
> >  	case I915_PARAM_HAS_WAIT_TIMEOUT:
> >  		value = 1;
> > diff --git a/drivers/gpu/drm/i915/i915_gem.c
> > b/drivers/gpu/drm/i915/i915_gem.c
> > index d8399ee622b9..a79deb189146 100644
> > --- a/drivers/gpu/drm/i915/i915_gem.c
> > +++ b/drivers/gpu/drm/i915/i915_gem.c
> > @@ -5114,9 +5114,7 @@ unsigned long i915_gem_obj_offset(struct
> > drm_i915_gem_object *o,
> >  	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
> >  	struct i915_vma *vma;
> >
> > -	if (!dev_priv->mm.aliasing_ppgtt ||
> > -	    vm == &dev_priv->mm.aliasing_ppgtt->base)
> > -		vm = &dev_priv->gtt.base;
> > +	WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
> >
> >  	list_for_each_entry(vma, &o->vma_list, vma_link) {
> >  		if (vma->vm == vm)
> > @@ -5157,9 +5155,7 @@ unsigned long i915_gem_obj_size(struct
> > drm_i915_gem_object *o,
> >  	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
> >  	struct i915_vma *vma;
> >
> > -	if (!dev_priv->mm.aliasing_ppgtt ||
> > -	    vm == &dev_priv->mm.aliasing_ppgtt->base)
> > -		vm = &dev_priv->gtt.base;
> > +	WARN_ON(vm == &dev_priv->mm.aliasing_ppgtt->base);
> >
> >  	BUG_ON(list_empty(&o->vma_list));
> >
> > diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c
> > b/drivers/gpu/drm/i915/intel_ringbuffer.c
> > index 05969f03c0c1..390e38325b37 100644
> > --- a/drivers/gpu/drm/i915/intel_ringbuffer.c
> > +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
> > @@ -1977,9 +1977,7 @@ gen8_ring_dispatch_execbuffer(struct
> > intel_engine_cs *ring,
> >  			      u64 offset, u32 len,
> >  			      unsigned flags)
> >  {
> > -	struct drm_i915_private *dev_priv = ring->dev->dev_private;
> > -	bool ppgtt = dev_priv->mm.aliasing_ppgtt != NULL &&
> > -		!(flags & I915_DISPATCH_SECURE);
> > +	bool ppgtt = USES_PPGTT(ring->dev) && !(flags &
> > I915_DISPATCH_SECURE);
> >  	int ret;
> >
> >  	ret = intel_ring_begin(ring, 4);
> > --
> > 1.9.3
> >
> Sorry, I spotted another instance in gen8_ppgtt_info (debugfs). It is more 
> gen8_ppgtt_info's fault, so I'm sending a follow up patch for it.
> Unless you want to combine them...
> Reviewed-by: Michel Thierry <michel.thierry@intel.com>

Actually I spotted that one and decided that I can't break things worse
than it is - the aliasing ppgtt for full ppgtt is completely unused
(except for these checks), so dumping it doesn't add value.

To check: Does your r-b apply here still even without any fixup for gen8
ppgtt_info?
-Daniel

> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 08/15] drm/i915: Fix up checks for aliasing ppgtt
  2014-08-08 13:49     ` Daniel Vetter
@ 2014-08-08 14:00       ` Thierry, Michel
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-08 14:00 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 2762 bytes --]



> -----Original Message-----
> From: Daniel Vetter [mailto:daniel.vetter@ffwll.ch] On Behalf Of Daniel
> Vetter
> Sent: Friday, August 08, 2014 2:49 PM
> To: Thierry, Michel
> Cc: Daniel Vetter; Intel Graphics Development
> Subject: Re: [Intel-gfx] [PATCH 08/15] drm/i915: Fix up checks for
aliasing
> ppgtt
> 
> On Fri, Aug 08, 2014 at 01:03:53PM +0000, Thierry, Michel wrote:
> >
> > > -----Original Message-----
> > > From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On
> Behalf
> > > Of Daniel Vetter
> > > Sent: Wednesday, August 06, 2014 2:05 PM
> > > To: Intel Graphics Development
> > > Cc: Daniel Vetter
> > > Subject: [Intel-gfx] [PATCH 08/15] drm/i915: Fix up checks for
aliasing
> > ppgtt
> > >
> > > A subsequent patch will no longer initialize the aliasing ppgtt if we
> > > have full ppgtt enabled, since we simply don't need that any more.
> > >
> > > Unfortunately a few places check for the aliasing ppgtt instead of
> > > checking for ppgtt in general. Fix them up.
> > >
> > > One special case are the gtt offset and size macros, which have some
> > > code to remap the aliasing ppgtt to the global gtt. The aliasing ppgtt
> > > is _not_ a logical address space, so passing that in as the vm is
> > > plain and simple a bug. So just WARN about it and carry on - we have a
> > > gracefully fall-through anyway if we can't find the vma.
> > >
> > > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> > > ---
> > >  drivers/gpu/drm/i915/i915_cmd_parser.c  | 4 +---
> > >  drivers/gpu/drm/i915/i915_dma.c         | 2 +-
> > >  drivers/gpu/drm/i915/i915_gem.c         | 8 ++------
> > >  drivers/gpu/drm/i915/intel_ringbuffer.c | 4 +---
> > >  4 files changed, 5 insertions(+), 13 deletions(-)
> > >
> > > --
> > > 1.9.3
> > >
> > Sorry, I spotted another instance in gen8_ppgtt_info (debugfs). It is
more
> > gen8_ppgtt_info's fault, so I'm sending a follow up patch for it.
> > Unless you want to combine them...
> > Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> Actually I spotted that one and decided that I can't break things worse
> than it is - the aliasing ppgtt for full ppgtt is completely unused
> (except for these checks), so dumping it doesn't add value.
> 
> To check: Does your r-b apply here still even without any fixup for gen8
> ppgtt_info?
> -Daniel
Yes, the r-b still applies. 
And you're also right about gen8_ppgtt_info, it wouldn't print anything
useful in its current state.
-Michel
> 
> > > _______________________________________________
> > > Intel-gfx mailing list
> > > Intel-gfx@lists.freedesktop.org
> > > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> 
> 
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> +41 (0) 79 365 57 48 - http://blog.ffwll.ch

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 03/15] drm/i915: Move i915_gem_chipset_flush to where it belongs
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-12  8:45 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 2936 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 03/15] drm/i915: Move i915_gem_chipset_flush
> to where it belongs
> 
> Include depency hell ftw! So need to move this into a real function.
> 
> Also fix up the header include order in i915_drv.h: The rule is to
> always include core headers first, then local stuff.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_drv.h     | 7 -------
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 6 ++++++
>  drivers/gpu/drm/i915/i915_gem_gtt.h | 2 ++
>  3 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h
> b/drivers/gpu/drm/i915/i915_drv.h
> index d349dd75ed69..194367f0ba1a 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2556,13 +2556,6 @@ int __must_check
> i915_gem_evict_something(struct drm_device *dev,
>  int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
>  int i915_gem_evict_everything(struct drm_device *dev);
> 
> -/* belongs in i915_gem_gtt.h */
> -static inline void i915_gem_chipset_flush(struct drm_device *dev)
> -{
> -	if (INTEL_INFO(dev)->gen < 6)
> -		intel_gtt_chipset_flush();
> -}
> -
>  /* i915_gem_stolen.c */
>  int i915_gem_init_stolen(struct drm_device *dev);
>  int i915_gem_stolen_setup_compression(struct drm_device *dev, int size,
> int fb_cpp);
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 1a20e1b4f052..baa94199239b 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -2031,6 +2031,12 @@ static void gen6_gmch_remove(struct
> i915_address_space *vm)
>  	teardown_scratch_page(vm->dev);
>  }
> 
> +void i915_gem_chipset_flush(struct drm_device *dev)
> +{
> +	if (INTEL_INFO(dev)->gen < 6)
> +		intel_gtt_chipset_flush();
> +}
> +
>  static int i915_gmch_probe(struct drm_device *dev,
>  			   size_t *gtt_total,
>  			   size_t *stolen,
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h
> b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index 57d401343e8d..380e034c66f8 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -294,4 +294,6 @@ void i915_gem_restore_gtt_mappings(struct
> drm_device *dev);
>  int __must_check i915_gem_gtt_prepare_object(struct
> drm_i915_gem_object *obj);
>  void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj);
> 
> +void i915_gem_chipset_flush(struct drm_device *dev);
> +
>  #endif
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 07/15] drm/i915: Allow i915_gem_setup_global_gtt to fail
  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
  0 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-12  8:48 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 3755 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 2:05 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 07/15] drm/i915: Allow
> i915_gem_setup_global_gtt to fail
> 
> We already needs this just as a safety check in case the preallocation
> reservation dance fails. But we definitely need this to be able to
> move tha aliasing ppgtt setup back out of the context code to this
> place, where it belongs.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_gem.c     |  7 ++++++-
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 16 ++++++++++------
>  drivers/gpu/drm/i915/i915_gem_gtt.h |  4 ++--
>  3 files changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c
> b/drivers/gpu/drm/i915/i915_gem.c
> index f4e57fe05c6a..d8399ee622b9 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -4762,7 +4762,12 @@ int i915_gem_init(struct drm_device *dev)
>  			DRM_DEBUG_DRIVER("allow wake ack timed
> out\n");
>  	}
> 
> -	i915_gem_init_userptr(dev);
> +	ret = i915_gem_init_userptr(dev);
> +	if (ret) {
> +		mutex_unlock(&dev->struct_mutex);
> +		return ret;
> +	}
> +
>  	i915_gem_init_global_gtt(dev);
> 
>  	ret = i915_gem_context_init(dev);
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 3753bf184865..4fa7807ed4d5 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1709,10 +1709,10 @@ static void i915_gtt_color_adjust(struct
> drm_mm_node *node,
>  	}
>  }
> 
> -void i915_gem_setup_global_gtt(struct drm_device *dev,
> -			       unsigned long start,
> -			       unsigned long mappable_end,
> -			       unsigned long end)
> +int i915_gem_setup_global_gtt(struct drm_device *dev,
> +			      unsigned long start,
> +			      unsigned long mappable_end,
> +			      unsigned long end)
>  {
>  	/* Let GEM Manage all of the aperture.
>  	 *
> @@ -1745,8 +1745,10 @@ void i915_gem_setup_global_gtt(struct
> drm_device *dev,
> 
>  		WARN_ON(i915_gem_obj_ggtt_bound(obj));
>  		ret = drm_mm_reserve_node(&ggtt_vm->mm, &vma-
> >node);
> -		if (ret)
> -			DRM_DEBUG_KMS("Reservation failed\n");
> +		if (ret) {
> +			DRM_DEBUG_KMS("Reservation failed: %i\n", ret);
> +			return ret;
> +		}
>  		obj->has_global_gtt_mapping = 1;
>  	}
> 
> @@ -1763,6 +1765,8 @@ void i915_gem_setup_global_gtt(struct
> drm_device *dev,
> 
>  	/* And finally clear the reserved guard page */
>  	ggtt_vm->clear_range(ggtt_vm, end - PAGE_SIZE, PAGE_SIZE, true);
> +
> +	return 0;
>  }
> 
>  void i915_gem_init_global_gtt(struct drm_device *dev)
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h
> b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index 0b04ef6167f8..bea3541d5525 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -271,8 +271,8 @@ struct i915_hw_ppgtt {
> 
>  int i915_gem_gtt_init(struct drm_device *dev);
>  void i915_gem_init_global_gtt(struct drm_device *dev);
> -void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long
> start,
> -			       unsigned long mappable_end, unsigned long
> end);
> +int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long
> start,
> +			      unsigned long mappable_end, unsigned long
> end);
> 
>  bool intel_enable_ppgtt(struct drm_device *dev, bool full);
> 

Reviewed-by: Michel Thierry <michel.thierry@intel.com>

> --
> 1.9.3
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 1/2] drm/i915: Rework ppgtt init to no require an aliasing ppgtt
  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-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
  2 siblings, 0 replies; 32+ messages in thread
From: Thierry, Michel @ 2014-08-12  8:58 UTC (permalink / raw)
  To: Daniel Vetter, Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 8630 bytes --]



> -----Original Message-----
> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Daniel Vetter
> Sent: Wednesday, August 06, 2014 7:20 PM
> To: Intel Graphics Development
> Cc: Daniel Vetter
> Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Rework ppgtt init to no require
an
> aliasing ppgtt
> 
> Currently we abuse the aliasing ppgtt to set up the ppgtt support in
> general. Which is a bit backwards since with full ppgtt we don't ever
> need the aliasing ppgtt.
> 
> So untangling this and separate the ppgtt init from the aliasing
> ppgtt. While at it drag it out of the context enabling (which just
> does a switch to the default context).
> 
> Note that we still have the differentiation between synchronous and
> asynchronous ppgtt setup, but that will soon vanish. So also correctly
> wire up the return value handling to be prepared for when ->switch_mm
> drops the synchronous parameter and could start to fail.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_gem.c         |  8 ++++
>  drivers/gpu/drm/i915/i915_gem_context.c |  7 ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c     | 84
+++++++++++++-----------------
> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.h     |  1 +
>  4 files changed, 42 insertions(+), 58 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c
> b/drivers/gpu/drm/i915/i915_gem.c
> index a79deb189146..caf92bac2152 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -4742,6 +4742,14 @@ i915_gem_init_hw(struct drm_device *dev)
>  	if (ret && ret != -EIO) {
>  		DRM_ERROR("Context enable failed %d\n", ret);
>  		i915_gem_cleanup_ringbuffer(dev);
> +
> +		return ret;
> +	}
> +
> +	ret = i915_ppgtt_init_hw(dev);
> +	if (ret && ret != -EIO) {
> +		DRM_ERROR("PPGTT enable failed %d\n", ret);
> +		i915_gem_cleanup_ringbuffer(dev);
>  	}
> 
>  	return ret;
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c
> b/drivers/gpu/drm/i915/i915_gem_context.c
> index 3b8367aa8404..4af5f05b24e8 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -424,13 +424,6 @@ int i915_gem_context_enable(struct
> drm_i915_private *dev_priv)
>  	struct intel_engine_cs *ring;
>  	int ret, i;
> 
> -	/* This is the only place the aliasing PPGTT gets enabled, which
> means
> -	 * it has to happen before we bail on reset */
> -	if (dev_priv->mm.aliasing_ppgtt) {
> -		struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
> -		ppgtt->enable(ppgtt);
> -	}
> -
>  	/* FIXME: We should make this work, even in reset */
>  	if (i915_reset_in_progress(&dev_priv->gpu_error))
>  		return 0;
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 4fa7807ed4d5..bf70ab44b968 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -78,7 +78,6 @@ static void ppgtt_bind_vma(struct i915_vma *vma,
>  			   enum i915_cache_level cache_level,
>  			   u32 flags);
>  static void ppgtt_unbind_vma(struct i915_vma *vma);
> -static int gen8_ppgtt_enable(struct i915_hw_ppgtt *ppgtt);
> 
>  static inline gen8_gtt_pte_t gen8_pte_encode(dma_addr_t addr,
>  					     enum i915_cache_level level,
> @@ -615,7 +614,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt
> *ppgtt, uint64_t size)
>  		kunmap_atomic(pd_vaddr);
>  	}
> 
> -	ppgtt->enable = gen8_ppgtt_enable;
>  	ppgtt->switch_mm = gen8_mm_switch;
>  	ppgtt->base.clear_range = gen8_ppgtt_clear_range;
>  	ppgtt->base.insert_entries = gen8_ppgtt_insert_entries;
> @@ -836,39 +834,20 @@ static int gen6_mm_switch(struct i915_hw_ppgtt
> *ppgtt,
>  	return 0;
>  }
> 
> -static int gen8_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
> +static void gen8_ppgtt_enable(struct drm_device *dev)
>  {
> -	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct intel_engine_cs *ring;
> -	int j, ret;
> +	int j;
> 
>  	for_each_ring(ring, dev_priv, j) {
>  		I915_WRITE(RING_MODE_GEN7(ring),
>  			   _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
> -
> -		/* We promise to do a switch later with FULL PPGTT. If this
is
> -		 * aliasing, this is the one and only switch we'll do */
> -		if (USES_FULL_PPGTT(dev))
> -			continue;
> -
> -		ret = ppgtt->switch_mm(ppgtt, ring, true);
> -		if (ret)
> -			goto err_out;
>  	}
> -
> -	return 0;
> -
> -err_out:
> -	for_each_ring(ring, dev_priv, j)
> -		I915_WRITE(RING_MODE_GEN7(ring),
> -			   _MASKED_BIT_DISABLE(GFX_PPGTT_ENABLE));
> -	return ret;
>  }
> 
> -static int gen7_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
> +static void gen7_ppgtt_enable(struct drm_device *dev)
>  {
> -	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct intel_engine_cs *ring;
>  	uint32_t ecochk, ecobits;
> @@ -887,31 +866,16 @@ static int gen7_ppgtt_enable(struct i915_hw_ppgtt
> *ppgtt)
>  	I915_WRITE(GAM_ECOCHK, ecochk);
> 
>  	for_each_ring(ring, dev_priv, i) {
> -		int ret;
>  		/* GFX_MODE is per-ring on gen7+ */
>  		I915_WRITE(RING_MODE_GEN7(ring),
>  			   _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
> -
> -		/* We promise to do a switch later with FULL PPGTT. If this
is
> -		 * aliasing, this is the one and only switch we'll do */
> -		if (USES_FULL_PPGTT(dev))
> -			continue;
> -
> -		ret = ppgtt->switch_mm(ppgtt, ring, true);
> -		if (ret)
> -			return ret;
>  	}
> -
> -	return 0;
>  }
> 
> -static int gen6_ppgtt_enable(struct i915_hw_ppgtt *ppgtt)
> +static void gen6_ppgtt_enable(struct drm_device *dev)
>  {
> -	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> -	struct intel_engine_cs *ring;
>  	uint32_t ecochk, gab_ctl, ecobits;
> -	int i;
> 
>  	ecobits = I915_READ(GAC_ECO_BITS);
>  	I915_WRITE(GAC_ECO_BITS, ecobits | ECOBITS_SNB_BIT |
> @@ -924,14 +888,6 @@ static int gen6_ppgtt_enable(struct i915_hw_ppgtt
> *ppgtt)
>  	I915_WRITE(GAM_ECOCHK, ecochk | ECOCHK_SNB_BIT |
> ECOCHK_PPGTT_CACHE64B);
> 
>  	I915_WRITE(GFX_MODE,
> _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
> -
> -	for_each_ring(ring, dev_priv, i) {
> -		int ret = ppgtt->switch_mm(ppgtt, ring, true);
> -		if (ret)
> -			return ret;
> -	}
> -
> -	return 0;
>  }
> 
>  /* PPGTT support for Sandybdrige/Gen6 and later */
> @@ -1151,13 +1107,10 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt
> *ppgtt)
> 
>  	ppgtt->base.pte_encode = dev_priv->gtt.base.pte_encode;
>  	if (IS_GEN6(dev)) {
> -		ppgtt->enable = gen6_ppgtt_enable;
>  		ppgtt->switch_mm = gen6_mm_switch;
>  	} else if (IS_HASWELL(dev)) {
> -		ppgtt->enable = gen7_ppgtt_enable;
>  		ppgtt->switch_mm = hsw_mm_switch;
>  	} else if (IS_GEN7(dev)) {
> -		ppgtt->enable = gen7_ppgtt_enable;
>  		ppgtt->switch_mm = gen7_mm_switch;
>  	} else
>  		BUG();
> @@ -1222,6 +1175,35 @@ int i915_ppgtt_init(struct drm_device *dev, struct
> i915_hw_ppgtt *ppgtt)
>  	return ret;
>  }
> 
> +int i915_ppgtt_init_hw(struct drm_device *dev)
> +{
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct intel_engine_cs *ring;
> +	struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
> +	int i, ret = 0;
> +
> +	if (!USES_PPGTT(dev))
> +		return 0;
> +
> +	if (IS_GEN6(dev))
> +		gen6_ppgtt_enable(dev);
> +	else if (IS_GEN7(dev))
> +		gen7_ppgtt_enable(dev);
> +	else if (INTEL_INFO(dev)->gen >= 8)
> +		gen8_ppgtt_enable(dev);
> +	else
> +		WARN_ON(1);
> +
> +	if (ppgtt) {
> +		for_each_ring(ring, dev_priv, i) {
> +			ret = ppgtt->switch_mm(ppgtt, ring, true);
> +			if (ret != 0)
> +				return ret;
> +		}
> +	}
> +
> +	return ret;
> +}
>  struct i915_hw_ppgtt *
>  i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private
> *fpriv)
>  {
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h
> b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index bea3541d5525..45aa15fa4af2 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -277,6 +277,7 @@ int i915_gem_setup_global_gtt(struct drm_device
> *dev, unsigned long start,
>  bool intel_enable_ppgtt(struct drm_device *dev, bool full);
> 
>  int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt);
> +int i915_ppgtt_init_hw(struct drm_device *dev);
>  void i915_ppgtt_release(struct kref *kref);
>  struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_device *dev,
>  					struct drm_i915_file_private
*fpriv);
> --
> 1.9.3

Reviewed-by: Michel Thierry <michel.thierry@intel.com>

> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6656 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt alongside the global gtt
  2014-08-08 13:09   ` Thierry, Michel
@ 2014-08-12 14:05     ` Daniel Vetter
  0 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2014-08-12 14:05 UTC (permalink / raw)
  To: Thierry, Michel; +Cc: Daniel Vetter, Intel Graphics Development

On Fri, Aug 08, 2014 at 01:09:25PM +0000, Thierry, Michel wrote:
> 
> 
> > -----Original Message-----
> > From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf
> > Of Daniel Vetter
> > Sent: Wednesday, August 06, 2014 2:05 PM
> > To: Intel Graphics Development
> > Cc: Daniel Vetter
> > Subject: [Intel-gfx] [PATCH 14/15] drm/i915: Cleanup aliasging ppgtt
> > alongside the global gtt
> > 
> > Also remove related WARN_ONs which seem to have been hit since a rather
> > long time. But apperently no one noticed since our module reload is
> > already WARNING-infested :(
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> > ---
> >  drivers/gpu/drm/i915/i915_dma.c     | 4 ----
> >  drivers/gpu/drm/i915/i915_gem_gtt.c | 7 +++++++
> >  2 files changed, 7 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/i915_dma.c
> > b/drivers/gpu/drm/i915/i915_dma.c
> > index c176a6c97c80..94afe7c4458b 100644
> > --- a/drivers/gpu/drm/i915/i915_dma.c
> > +++ b/drivers/gpu/drm/i915/i915_dma.c
> > @@ -1388,7 +1388,6 @@ cleanup_gem:
> >  	i915_gem_cleanup_ringbuffer(dev);
> >  	i915_gem_context_fini(dev);
> >  	mutex_unlock(&dev->struct_mutex);
> > -	WARN_ON(dev_priv->mm.aliasing_ppgtt);
> >  cleanup_irq:
> >  	drm_irq_uninstall(dev);
> >  cleanup_gem_stolen:
> > @@ -1897,7 +1896,6 @@ int i915_driver_unload(struct drm_device *dev)
> >  		mutex_lock(&dev->struct_mutex);
> >  		i915_gem_cleanup_ringbuffer(dev);
> >  		i915_gem_context_fini(dev);
> > -		WARN_ON(dev_priv->mm.aliasing_ppgtt);
> >  		mutex_unlock(&dev->struct_mutex);
> >  		i915_gem_cleanup_stolen(dev);
> > 
> > @@ -1905,8 +1903,6 @@ int i915_driver_unload(struct drm_device *dev)
> >  			i915_free_hws(dev);
> >  	}
> > 
> > -	WARN_ON(!list_empty(&dev_priv->vm_list));
> > -
> >  	drm_vblank_cleanup(dev);
> > 
> >  	intel_teardown_gmbus(dev);
> > diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c
> > b/drivers/gpu/drm/i915/i915_gem_gtt.c
> > index 2eab0b6a32e8..ff031bb1f296 100644
> > --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> > +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> > @@ -1801,6 +1801,12 @@ void i915_global_gtt_cleanup(struct drm_device
> > *dev)
> >  	struct drm_i915_private *dev_priv = dev->dev_private;
> >  	struct i915_address_space *vm = &dev_priv->gtt.base;
> > 
> > +	if (dev_priv->mm.aliasing_ppgtt) {
> > +		struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
> > +
> > +		ppgtt->base.cleanup(&ppgtt->base);
> > +	}
> > +
> >  	if (drm_mm_initialized(&vm->mm)) {
> >  		drm_mm_takedown(&vm->mm);
> >  		list_del(&vm->global_link);
> > @@ -1808,6 +1814,7 @@ void i915_global_gtt_cleanup(struct drm_device
> > *dev)
> > 
> >  	vm->cleanup(vm);
> >  }
> > +
> >  static int setup_scratch_page(struct drm_device *dev)
> >  {
> >  	struct drm_i915_private *dev_priv = dev->dev_private;
> > --
> > 1.9.3
> 
> Reviewed-by: Michel Thierry <michel.thierry@intel.com>

Thanks for the review, all patches merged. Aside I've spotted a bit of
spelling fail in my commit messages - review should also complain about
that.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2014-08-12 14:05 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-06 13:04 [PATCH 01/15] drm/i915: vma/ppgtt lifetime rules Daniel Vetter
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

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.