[1/2] drm/i915: do not clear mappings beyond VMA size

Submitted by Joonas Lahtinen on April 17, 2015, 1:59 p.m.

Details

Message ID 1429279186.5819.0.camel@jlahtine-mobl1
State New
Headers show

Not browsing as part of any series.

Commit Message

Joonas Lahtinen April 17, 2015, 1:59 p.m.
Do not to clear mappings outside the allocated VMA under any
circumstances. Only clear the smaller of VMA or object page count.

This is required to allow creating partial object VMAs which in
turn are needed for partial GGTT views.

Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 9041f3d..18c695b 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1730,9 +1730,14 @@  ppgtt_bind_vma(struct i915_vma *vma,
 
 static void ppgtt_unbind_vma(struct i915_vma *vma)
 {
+	struct drm_i915_gem_object *obj = vma->obj;
+	const uint64_t size = min_t(uint64_t,
+				    obj->base.size,
+				    vma->node.size);
+
 	vma->vm->clear_range(vma->vm,
 			     vma->node.start,
-			     vma->obj->base.size,
+			     size,
 			     true);
 }
 
@@ -2078,8 +2083,11 @@  static void i915_ggtt_clear_range(struct i915_address_space *vm,
 
 static void i915_ggtt_unbind_vma(struct i915_vma *vma)
 {
+	struct drm_i915_gem_object *obj = vma->obj;
 	const unsigned int first = vma->node.start >> PAGE_SHIFT;
-	const unsigned int size = vma->obj->base.size >> PAGE_SHIFT;
+	const unsigned int size = min_t(uint64_t,
+					obj->base.size,
+					vma->node.size) >> PAGE_SHIFT;
 
 	BUG_ON(!i915_is_ggtt(vma->vm));
 	vma->bound = 0;
@@ -2139,21 +2147,27 @@  static void ggtt_unbind_vma(struct i915_vma *vma)
 	struct drm_device *dev = vma->vm->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_object *obj = vma->obj;
+	const uint64_t size = min_t(uint64_t,
+				    obj->base.size,
+				    vma->node.size);
 
 	if (vma->bound & GLOBAL_BIND) {
 		vma->vm->clear_range(vma->vm,
 				     vma->node.start,
-				     obj->base.size,
+				     size,
 				     true);
+
 		vma->bound &= ~GLOBAL_BIND;
 	}
 
 	if (vma->bound & LOCAL_BIND) {
 		struct i915_hw_ppgtt *appgtt = dev_priv->mm.aliasing_ppgtt;
+
 		appgtt->base.clear_range(&appgtt->base,
 					 vma->node.start,
-					 obj->base.size,
+					 size,
 					 true);
+
 		vma->bound &= ~LOCAL_BIND;
 	}
 }

Comments

On Fri, Apr 17, 2015 at 04:59:46PM +0300, Joonas Lahtinen wrote:
> Do not to clear mappings outside the allocated VMA under any
> circumstances. Only clear the smaller of VMA or object page count.
> 
> This is required to allow creating partial object VMAs which in
> turn are needed for partial GGTT views.

This doesn't fix a current bug so it doesn't need to be sent ahead of
the partial views.
-Chris