Skip to contentSkip to conversation

drm/i915: Track file_priv, not ctx in the ppgtt structure

PATCH In review Daniel Vetter 6 participants 31 messages Jul 30, 2014 – Aug 6, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/7 drm/i915: Track file_priv, not ctx in the ppgtt structure

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.

---
 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(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 9e737b771c40..3bf1d20c598b 100644
@@ -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 */
drivers/gpu/drm/i915/i915_gem_context.c +1 -21
index 899c6a7a5920..3b8367aa8404 100644
@@ -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",
drivers/gpu/drm/i915/i915_gem_gtt.c +21 -0
index baa94199239b..83ee41e5c1c7 100644
@@ -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 =
drivers/gpu/drm/i915/i915_gem_gtt.h +5 -1
index 380e034c66f8..0b04ef6167f8 100644
@@ -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)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 2/7 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.

---
 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(-)
drivers/gpu/drm/i915/i915_drv.h +9 -1
index c783cfe5515d..fd3a99c5a1bd 100644
@@ -2460,6 +2460,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));
@@ -2495,7 +2504,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);
drivers/gpu/drm/i915/i915_gem.c +2 -1
index b33a677b4b1e..c43ccfdf45a5 100644
@@ -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);
 
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -1
index 83ee41e5c1c7..3753bf184865 100644
@@ -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;
 }
Signature · 1 line
1.9.3
#2 lore raw

Re: [PATCH 2/7] drm/i915: Only refcount ppgtt if it actually is one

Quoted 5 lines · 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.

Wrong direction. If you make ggtt/ppgtt more similar we can loose having to write fragile code.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH 2/7] drm/i915: Only refcount ppgtt if it actually is one

Quoted 9 lines · Chris Wilson
Quoted 5 lines · 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.

Wrong direction. If you make ggtt/ppgtt more similar we can loose having to write fragile code.

So moving the kref into the address space? I guess that would work too, but I'm off for my extended w/e now ;-)
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#4 lore raw

Re: [PATCH 2/7] drm/i915: Only refcount ppgtt if it actually is one

Quoted 5 lines · Daniel Vetter
Quoted 4 lines · Chris Wilson
Quoted 3 lines · Daniel Vetter

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

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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

Wrong direction. If you make ggtt/ppgtt more similar we can loose having to write fragile code.

So moving the kref into the address space? I guess that would work too, but I'm off for my extended w/e now ;-)

Ok got bored and tried to implement this, but it doesn't work out too well. It needs a fair bit of reorg so that we can handle the global gtt and the ppgtt with the same refcounting scheme and clean them up properly. I think as a stop-gap this one here is better and the refcounting unification needs to be done on top.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#5 lore raw

PATCH 3/7 drm/i915: Add proper prefix to obj_to_ggtt

In reply to Daniel Vetter

Stuff in headers really aught to have this.

---
 drivers/gpu/drm/i915/i915_drv.h | 11 ++++++-----
 drivers/gpu/drm/i915/i915_gem.c |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +6 -5
index fd3a99c5a1bd..0762e19f9bc6 100644
@@ -2451,7 +2451,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)
 {
@@ -2471,19 +2471,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
@@ -2491,7 +2491,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
drivers/gpu/drm/i915/i915_gem.c +1 -1
index c43ccfdf45a5..f4e57fe05c6a 100644
@@ -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;
Signature · 1 line
1.9.3
Reviewed-by on v1 3/7
#6 lore raw

Re: [PATCH 3/7] drm/i915: Add proper prefix to obj_to_ggtt

Quoted 9 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Wednesday, July 30, 2014 8:42 PM
To: Intel Graphics Development
Cc: Daniel Vetter
Subject: [Intel-gfx] [PATCH 3/7] drm/i915: Add proper prefix to

obj_to_ggtt

Quoted 9 lines

Stuff in headers really aught to have this.

---
 drivers/gpu/drm/i915/i915_drv.h | 11 ++++++-----
 drivers/gpu/drm/i915/i915_gem.c |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

PATCH 4/7 drm/i915: Allow i915_gem_setup_global_gtt to fail

In reply to 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.

---
 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(-)
drivers/gpu/drm/i915/i915_gem.c +6 -1
index f4e57fe05c6a..d8399ee622b9 100644
@@ -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);
drivers/gpu/drm/i915/i915_gem_gtt.c +10 -6
index 3753bf184865..4fa7807ed4d5 100644
@@ -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)
drivers/gpu/drm/i915/i915_gem_gtt.h +2 -2
index 0b04ef6167f8..bea3541d5525 100644
@@ -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);
 
Signature · 1 line
1.9.3
#8 lore raw

Re: [PATCH 4/7] drm/i915: Allow i915_gem_setup_global_gtt to fail

Quoted 17 lines · 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.

---
 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(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index f4e57fe05c6a..d8399ee622b9 100644

drivers/gpu/drm/i915/i915_gem.c int i915_gem_init(struct drm_device *dev) · line 4766

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +2 -1
@@ -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) {

Just throw an error and keep on initialising. Optional features like this and stolen, we can keep going - so we should drop the error code return entirely for a better error message when we disable the feature. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#9 lore raw

PATCH 5/7 drm/i915: Initialize the aliasing ppgtt as part of global gtt

In reply to 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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +25 -6
index 4fa7807ed4d5..cb9bb13ff20a 100644
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	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;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,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 +1744,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 +1771,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)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
Signature · 1 line
1.9.3
#10 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

<[email protected]>

Quoted 126 lines · 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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +25 -6
index 4fa7807ed4d5..cb9bb13ff20a 100644
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	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;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,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 +1744,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 +1771,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)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#11 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 1 line · Ben Widawsky

<[email protected]>

and

<[email protected]>

Quoted 135 lines · Daniel Vetter
Quoted 126 lines

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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +25 -6
index 4fa7807ed4d5..cb9bb13ff20a 100644
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	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;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,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 +1744,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 +1771,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)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#12 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 6 lines · Ben Widawsky
Quoted 1 line · Ben Widawsky

<[email protected]>

and

<[email protected]>

Oops, was looking at the wrong this actually. Ignore please.

Quoted 143 lines
Quoted 136 lines · Daniel Vetter
Quoted 126 lines

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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +25 -6
index 4fa7807ed4d5..cb9bb13ff20a 100644
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	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;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,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 +1744,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 +1771,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)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#13 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

In reply to Ben Widawsky
Quoted 6 lines · Ben Widawsky
Quoted 1 line · Ben Widawsky

<[email protected]>

and

<[email protected]>

Both of these are merged, so I really don't follow what you're trying to tell here. So this can't be the usual "I've written this long ago, why was I ignored" complaint. Slightly more context instead of a bunch of old msg-ids highly appreciated.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#14 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

In reply to Daniel Vetter
Quoted 9 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Wednesday, July 30, 2014 8:42 PM
To: Intel Graphics Development
Cc: Daniel Vetter
Subject: [Intel-gfx] [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt

as part

Quoted 20 lines

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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31
+++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -0
@@ -1766,6 +1771,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);

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device · line 1783

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +9 -0
 
+	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)

__hw_ppgtt_init will return '0' if successful.

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -1
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
--

1.9.3

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#15 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

In reply to Daniel Vetter
Quoted 99 lines · 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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +11 -6
index 4fa7807ed4d5..cb9bb13ff20a 100644
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	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;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,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 +1744,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);
 

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device *dev, · line 1774

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
@@ -1766,6 +1771,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)) {

Should that be !USES_FULL_PPGTT ?

Quoted 23 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +13 -0
+		struct i915_hw_ppgtt *ppgtt;
+
+		ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+		if (!ppgtt)
+			return -ENOMEM;
+
+		ret = __hw_ppgtt_init(dev, ppgtt);
+		if (!ret)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 2 lines
Ville Syrjälä
Intel OTC
#16 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 9 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Ville Syrjälä
Sent: Thursday, July 31, 2014 5:16 PM
To: Daniel Vetter
Cc: Intel Graphics Development
Subject: Re: [Intel-gfx] [PATCH 5/7] drm/i915: Initialize the aliasing

ppgtt as

Quoted 51 lines

part of global gtt

Quoted 11 lines · 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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31

+++++++++++++++++++++++++------

Review

Quoted 3 lines
 2 files changed, 26 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_gem_context.c

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device

Quoted 4 lines

index 3b8367aa8404..7a455fcee3a7 100644

drivers/gpu/drm/i915/i915_gem_context.c +0 -0
@@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device

*dev,

Quoted 18 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -11
 			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. */

drivers/gpu/drm/i915/i915_gem_context.c int i915_gem_context_init(struct drm_device *dev) · line 353

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
@@ -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));

drivers/gpu/drm/i915/i915_gem_context.c int i915_gem_context_init(struct drm_device *dev) · line 355

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
 	if (IS_ERR(ctx)) {
 		DRM_ERROR("Failed to create default global context (error

%ld)\n",

Quoted 12 lines

Review

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
 			  PTR_ERR(ctx));
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_gem_gtt.c

drivers/gpu/drm/i915/i915_gem_gtt.c static int gen6_ppgtt_init(struct i915_hw_ppgtt

Quoted 4 lines

index 4fa7807ed4d5..cb9bb13ff20a 100644

drivers/gpu/drm/i915/i915_gem_gtt.c +0 -0
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt

*ppgtt)

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -1
 	return 0;
 }
 
-int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt

*ppgtt)

Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_gtt.c static int gen6_ppgtt_init(struct i915_hw_ppgtt · line 1194

Quoted 1 line
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
+int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt

*ppgtt)

Quoted 7 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -1
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	int ret = 0;
 
 	ppgtt->base.dev = dev;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
 
Quoted 10 lines

drivers/gpu/drm/i915/i915_gem_gtt.c static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +4 -2
 	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)

Quoted 21 lines

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +4 -1
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret = 0;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,7 @@ int i915_gem_setup_global_gtt(struct

drm_device *dev,

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
 	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 +1744,7 @@ int i915_gem_setup_global_gtt(struct

drm_device *dev,

Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device *dev,

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -0
 	/* 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);

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device *dev,

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -1
-		int ret;
+
 		DRM_DEBUG_KMS("reserving preallocated space: %lx +

%zx\n",

Quoted 1 line
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -0
 			      i915_gem_obj_ggtt_offset(obj),

obj->base.size);

Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -0
@@ -1766,6 +1771,20 @@ int i915_gem_setup_global_gtt(struct

drm_device *dev,

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device *dev, · line 1774

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
 	/* 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)) {

Should that be !USES_FULL_PPGTT ?

I think we need this for aliasing & full ppgtt (the global default ctx)... so it should be USES_PPGTT.

Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +13 -1
+		struct i915_hw_ppgtt *ppgtt;
+
+		ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+		if (!ppgtt)
+			return -ENOMEM;
+
+		ret = __hw_ppgtt_init(dev, ppgtt);
+		if (!ret)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
--

1.9.3

Quoted 12 lines
Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#17 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 10 lines · Michel
Quoted 8 lines

Review int i915_gem_setup_global_gtt(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -1766,6 +1771,20 @@ int i915_gem_setup_global_gtt(struct

drm_device *dev,

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device *dev, · line 1774

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
 	/* 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)) {

Should that be !USES_FULL_PPGTT ?

I think we need this for aliasing & full ppgtt (the global default ctx)... so it should be USES_PPGTT.

We want to setup the aliasing ppgtt _only_ when required, so we don't actually need it for USES_FULL_PPGTT. So Ville's right here. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#18 lore raw

Re: [PATCH 5/7] drm/i915: Initialize the aliasing ppgtt as part of global gtt

In reply to Ville Syrjälä
Quoted 99 lines · Ville Syrjälä
Quoted 98 lines · 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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +------------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +11 -6
index 4fa7807ed4d5..cb9bb13ff20a 100644
@@ -1191,23 +1191,27 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	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;
 
+	ret = __hw_ppgtt_init(dev, ppgtt);
 	if (!ret) {
-		struct drm_i915_private *dev_priv = dev->dev_private;
 		kref_init(&ppgtt->ref);
 		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
 			    ppgtt->base.total);
@@ -1728,6 +1732,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 +1744,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);
 
Quoted 7 lines

drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_setup_global_gtt(struct drm_device *dev, · line 1774

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
@@ -1766,6 +1771,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)) {

Should that be !USES_FULL_PPGTT ?

Yup. And since I've also fumbled the check for __hw_ppgtt_init I really wonder what exactly I've tested on my gen6 here ...

Time to hide and lick wounds I think ;-)
-Daniel

Quoted 28 lines
Quoted 24 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +13 -0
+		struct i915_hw_ppgtt *ppgtt;
+
+		ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+		if (!ppgtt)
+			return -ENOMEM;
+
+		ret = __hw_ppgtt_init(dev, ppgtt);
+		if (!ret)
+			return ret;
+
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#19 lore raw

PATCH 1/1 drm/i915: Initialize the aliasing ppgtt as part of global gtt

In reply to 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" <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 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(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -12
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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));
drivers/gpu/drm/i915/i915_gem_gtt.c +30 -12

84 lines not on this page · raw message

Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#20 lore raw

Re: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 40 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Monday, August 04, 2014 3:19 PM
To: Intel Graphics Development
Cc: Daniel Vetter; Thierry, Michel; Ville Syrjälä
Subject: [PATCH] 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.

Cc "Thierry, Michel" <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 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(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -1
index 3b8367aa8404..7a455fcee3a7 100644
@@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device *dev,
 			goto err_unpin;
 		} else
 			ctx->vm = &ppgtt->base;
-

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device *dev, · line 289

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -10
-		/* 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;
-		}

I expect some problems with full ppgtt & this (in some places, the driver is still making some decisions based on dev_priv->mm.aliasing_ppgtt, which now will be null). Should I address these problems in a subsequent patch?

Quoted 16 lines
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
 	} 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));
}

Quoted 2 lines

--
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#21 lore raw

Re: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 47 lines · Michel
Quoted 47 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Monday, August 04, 2014 3:19 PM
To: Intel Graphics Development
Cc: Daniel Vetter; Thierry, Michel; Ville Syrjälä
Subject: [PATCH] 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.

Cc "Thierry, Michel" <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 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(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -8
index 3b8367aa8404..7a455fcee3a7 100644
@@ -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;
-			}
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device *dev, · line 289

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -3
-
-			dev_priv->mm.aliasing_ppgtt = ppgtt;
-		}

I expect some problems with full ppgtt & this (in some places, the driver is still making some decisions based on dev_priv->mm.aliasing_ppgtt, which now will be null). Should I address these problems in a subsequent patch?

Oh, good catch. I've done a bit a review and found two cases:
- Driver unload code. Already fairly broken, made much worse by my series here. I've fixed that up yesterday and will resend the series with those additional patches and revised patches.
- cmd parser. I guess that should be a fixup patch on top. I'll also do that.

Have you spotted any other places?

Thanks, Daniel

Quoted 20 lines
Quoted 19 lines
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
 	} 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));
}

--
1.9.3

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#22 lore raw

Re: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 9 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Wednesday, August 06, 2014 9:31 AM
To: Thierry, Michel
Cc: Daniel Vetter; Intel Graphics Development
Subject: Re: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of

global gtt

Quoted 10 lines · Michel
Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Monday, August 04, 2014 3:19 PM
To: Intel Graphics Development
Cc: Daniel Vetter; Thierry, Michel; Ville Syrjälä
Subject: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of

global gtt

Quoted 50 lines
Quoted 13 lines
Quoted 13 lines

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.

Quoted 6 lines
Quoted 6 lines
Cc "Thierry, Michel" <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +---------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 42

+++++++++++++++++++++++-

Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device

Quoted 9 lines

---------

 2 files changed, 31 insertions(+), 24 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
index 3b8367aa8404..7a455fcee3a7 100644
@@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device

*dev,

Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -8
 			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;
-			}
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device *dev, · line 289

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -3
-
-			dev_priv->mm.aliasing_ppgtt = ppgtt;
-		}

I expect some problems with full ppgtt & this (in some places, the driver is still making some decisions based on dev_priv->mm.aliasing_ppgtt, which now will be null). Should I address these problems in a subsequent patch?

Quoted 8 lines

Oh, good catch. I've done a bit a review and found two cases:
- Driver unload code. Already fairly broken, made much worse by my series here. I've fixed that up yesterday and will resend the series with those additional patches and revised patches.
- cmd parser. I guess that should be a fixup patch on top. I'll also do that.

Have you spotted any other places?

The other place is gen8_ring_dispatch_execbuffer, it won't set the ppgtt flag in MI_BATCH_BUFFER_START.

Quoted 27 lines

Thanks, Daniel

Quoted 5 lines

drivers/gpu/drm/i915/i915_gem_context.c int i915_gem_context_init(struct drm_device

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
 	} 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)

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
 		}
 	}
 
-	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));
}

Quoted 3 lines
Quoted 2 lines

--
1.9.3

Quoted 4 lines

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

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#23 lore raw

Re: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of global gtt

Quoted 78 lines · Michel
Quoted 9 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Wednesday, August 06, 2014 9:31 AM
To: Thierry, Michel
Cc: Daniel Vetter; Intel Graphics Development
Subject: Re: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of

global gtt

Quoted 10 lines · Michel
Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Monday, August 04, 2014 3:19 PM
To: Intel Graphics Development
Cc: Daniel Vetter; Thierry, Michel; Ville Syrjälä
Subject: [PATCH] drm/i915: Initialize the aliasing ppgtt as part of

global gtt

Quoted 57 lines
Quoted 13 lines
Quoted 13 lines

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.

Quoted 6 lines
Quoted 6 lines
Cc "Thierry, Michel" <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 13 +---------
 drivers/gpu/drm/i915/i915_gem_gtt.c     | 42

+++++++++++++++++++++++-

Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device

Quoted 9 lines

---------

 2 files changed, 31 insertions(+), 24 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
index 3b8367aa8404..7a455fcee3a7 100644
@@ -276,17 +276,6 @@ i915_gem_create_context(struct drm_device

*dev,

Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -8
 			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;
-			}
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_context.c i915_gem_create_context(struct drm_device *dev, · line 289

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -3
-
-			dev_priv->mm.aliasing_ppgtt = ppgtt;
-		}

I expect some problems with full ppgtt & this (in some places, the driver is still making some decisions based on dev_priv->mm.aliasing_ppgtt, which now will be null). Should I address these problems in a subsequent patch?

Oh, good catch. I've done a bit a review and found two cases:
- Driver unload code. Already fairly broken, made much worse by my series here. I've fixed that up yesterday and will resend the series with those additional patches and revised patches.
- cmd parser. I guess that should be a fixup patch on top. I'll also do that.

Quoted 3 lines
Quoted 1 line

Have you spotted any other places?

The other place is gen8_ring_dispatch_execbuffer, it won't set the ppgtt flag in MI_BATCH_BUFFER_START.

Indeed. I've also found a few other really fishy places. Will follow up with revised patches.
-Daniel

Quoted 32 lines
Quoted 32 lines

Thanks, Daniel

Quoted 5 lines

drivers/gpu/drm/i915/i915_gem_context.c int i915_gem_context_init(struct drm_device

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
 	} 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)

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
 		}
 	}
 
-	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));
}

Quoted 3 lines
Quoted 2 lines

--
1.9.3

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#24 lore raw

PATCH 6/7 drm/i915: Only track real ppgtt for a context

In reply to 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.

---
 drivers/gpu/drm/i915/i915_debugfs.c        |  2 +-
 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, 19 insertions(+), 29 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 3bf1d20c598b..aaf07e230cb0 100644
@@ -1774,7 +1774,7 @@ 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 (i915_gem_context_is_default(ctx))
 		seq_puts(m, "  default context:\n");
drivers/gpu/drm/i915/i915_drv.h +1 -2
index 0762e19f9bc6..3230b08aff13 100644
@@ -616,7 +616,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;
@@ -2504,7 +2504,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);
drivers/gpu/drm/i915/i915_gem_context.c +7 -21
index 7a455fcee3a7..c00e5d027774 100644
@@ -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;
 	}
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -2
index 60998fc4e5b2..54b3d8c8b228 100644
@@ -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);
drivers/gpu/drm/i915/i915_gpu_error.c +7 -3
index 0b3f69439451..06072120b15d 100644
@@ -958,6 +958,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.
@@ -965,9 +971,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)
Signature · 1 line
1.9.3
#25 lore raw

Re: [PATCH 6/7] drm/i915: Only track real ppgtt for a context

Quoted 10 lines · 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.

Quoted 4 lines

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

Jesse looked up the Jira for this one for me, so

OTC-Jira: VIZ-3724

Cheers, Daniel

Quoted 157 lines
---
 drivers/gpu/drm/i915/i915_debugfs.c        |  2 +-
 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, 19 insertions(+), 29 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 3bf1d20c598b..aaf07e230cb0 100644
@@ -1774,7 +1774,7 @@ 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 (i915_gem_context_is_default(ctx))
 		seq_puts(m, "  default context:\n");
drivers/gpu/drm/i915/i915_drv.h +1 -2
index 0762e19f9bc6..3230b08aff13 100644
@@ -616,7 +616,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;
@@ -2504,7 +2504,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);
drivers/gpu/drm/i915/i915_gem_context.c +7 -21
index 7a455fcee3a7..c00e5d027774 100644
@@ -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;
 	}
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -2
index 60998fc4e5b2..54b3d8c8b228 100644
@@ -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);
drivers/gpu/drm/i915/i915_gpu_error.c +7 -3
index 0b3f69439451..06072120b15d 100644
@@ -958,6 +958,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.
@@ -965,9 +971,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)
Signature · 1 line
1.9.3
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#26 lore raw

PATCH 1/1 drm/i915: Only track real ppgtt for a context

In reply to 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.

Cc: "Thierry, Michel" <[email protected]>
Cc: Ville Syrjälä <[email protected]>
OTC-Jira: VIZ-3724

---
 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(-)
drivers/gpu/drm/i915/i915_debugfs.c +8 -3
index 3bf1d20c598b..2bd4beada1bd 100644
@@ -1774,7 +1774,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_puts(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");
@@ -1834,8 +1840,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;
drivers/gpu/drm/i915/i915_drv.h +1 -2
index 0762e19f9bc6..3230b08aff13 100644
@@ -616,7 +616,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;
@@ -2504,7 +2504,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);
drivers/gpu/drm/i915/i915_gem_context.c +7 -21
index 7a455fcee3a7..c00e5d027774 100644
@@ -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;
 	}
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -2
index 60998fc4e5b2..54b3d8c8b228 100644
@@ -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);
drivers/gpu/drm/i915/i915_gpu_error.c +7 -3
index 0b3f69439451..06072120b15d 100644
@@ -958,6 +958,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.
@@ -965,9 +971,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)
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#27 lore raw

Re: [PATCH] drm/i915: Only track real ppgtt for a context

Quoted 44 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Monday, August 04, 2014 3:21 PM
To: Intel Graphics Development
Cc: Daniel Vetter; Thierry, Michel; Ville Syrjälä
Subject: [PATCH] drm/i915: Only track real ppgtt for a context

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.

Cc: "Thierry, Michel" <[email protected]>
Cc: Ville Syrjälä <[email protected]>
OTC-Jira: VIZ-3724

---
 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(-)
drivers/gpu/drm/i915/i915_debugfs.c +0 -0
index 3bf1d20c598b..2bd4beada1bd 100644

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_ctx(int id, void *ptr, void *data) · line 1781

Quoted 9 lines
drivers/gpu/drm/i915/i915_debugfs.c +5 -1
@@ -1774,7 +1774,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_puts(m, "  no ppgtt for context %d\n",
+			 ctx->user_handle);

Should be seq_printf().

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +2 -1
+		return 0;
+	}
 
 	if (i915_gem_context_is_default(ctx))
 		seq_puts(m, "  default context:\n");
@@ -1834,8 +1840,7 @@ static void gen6_ppgtt_info(struct seq_file *m,
--

1.9.3

Apart from that,

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#28 lore raw

PATCH 1/1 drm/i915: Only track real ppgtt for a context

In reply to 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.

Cc "Thierry, Michel" <[email protected]>
Cc Ville Syrjälä <[email protected]>

OTC-Jira: VIZ-3724

---
 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(-)
drivers/gpu/drm/i915/i915_debugfs.c +8 -3
index 3bf1d20c598b..7e8d94b53333 100644
@@ -1774,7 +1774,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");
@@ -1834,8 +1840,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;
drivers/gpu/drm/i915/i915_drv.h +1 -2
index 0762e19f9bc6..3230b08aff13 100644
@@ -616,7 +616,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;
@@ -2504,7 +2504,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);
drivers/gpu/drm/i915/i915_gem_context.c +7 -21
index 7a455fcee3a7..c00e5d027774 100644
@@ -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;
 	}
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -2
index 60998fc4e5b2..54b3d8c8b228 100644
@@ -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);
drivers/gpu/drm/i915/i915_gpu_error.c +7 -3
index 0b3f69439451..06072120b15d 100644
@@ -958,6 +958,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.
@@ -965,9 +971,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)
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#29 lore raw

PATCH 7/7 drm/i915: Drop create_vm argument to i915_gem_create_context

In reply to 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.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +5 -6
index c00e5d027774..655ed6228aab 100644
@@ -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);
Signature · 1 line
1.9.3
Reviewed-by on v1 1/7
#30 lore raw
In reply to Daniel Vetter
Quoted 8 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Wednesday, July 30, 2014 8:42 PM
To: Intel Graphics Development
Cc: Daniel Vetter
Subject: [Intel-gfx] [PATCH 1/7] drm/i915: Track file_priv, not ctx in the

ppgtt

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void

Quoted 22 lines

structure

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.

---
 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(-)
drivers/gpu/drm/i915/i915_debugfs.c +0 -0
index 9e737b771c40..3bf1d20c598b 100644
@@ -333,7 +333,7 @@ static int per_file_stats(int id, void *ptr, void

*data)

Quoted 112 lines
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
 			}
 
 			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;
drivers/gpu/drm/i915/i915_debugfs.c +0 -0
 			if (obj->ring) /* XXX per-vma statistic */
drivers/gpu/drm/i915/i915_gem_context.c +0 -20
index 899c6a7a5920..3b8367aa8404 100644
@@ -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,
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
 		    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)) {
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
 			DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",
drivers/gpu/drm/i915/i915_gem_gtt.c +21 -0
index baa94199239b..83ee41e5c1c7 100644
@@ -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)

{

drivers/gpu/drm/i915/i915_gem_gtt.c +0 -0
 	struct i915_hw_ppgtt *ppgtt =
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -1
index 380e034c66f8..0b04ef6167f8 100644
@@ -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,

drivers/gpu/drm/i915/i915_gem_gtt.h bool intel_enable_ppgtt(struct drm_device *dev, · line 283

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +2 -0
@@ -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);

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +0 -0
 static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
 {

if (ppgtt)
--
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx