diff mbox

[2/2] drm/i915: move vma sanity checking into i915_vma_bind

Message ID 20161213160059.6646-2-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Matthew Auld Dec. 13, 2016, 4 p.m. UTC
If we move the sanity checking from gen8_alloc_va_range_3lvl and
gen6_alloc_va_range into i915_vma_bind, we will increase our coverage to
now both callbacks. We also convert each WARN_ON over to a GEM_WARN_ON.

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 12 ------------
 drivers/gpu/drm/i915/i915_vma.c     |  6 ++++++
 2 files changed, 6 insertions(+), 12 deletions(-)

Comments

Chris Wilson Dec. 13, 2016, 4:41 p.m. UTC | #1
On Tue, Dec 13, 2016 at 04:00:59PM +0000, Matthew Auld wrote:
> If we move the sanity checking from gen8_alloc_va_range_3lvl and
> gen6_alloc_va_range into i915_vma_bind, we will increase our coverage to
> now both callbacks. We also convert each WARN_ON over to a GEM_WARN_ON.
> 
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 12 ------------
>  drivers/gpu/drm/i915/i915_vma.c     |  6 ++++++
>  2 files changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index ef00d36680c9..4f405b445b6c 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1303,15 +1303,6 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
>  	uint32_t pdpes = I915_PDPES_PER_PDP(dev_priv);
>  	int ret;
>  
> -	/* Wrap is never okay since we can only represent 48b, and we don't
> -	 * actually use the other side of the canonical address space.
> -	 */
> -	if (WARN_ON(start + length < start))
> -		return -ENODEV;
> -
> -	if (WARN_ON(start + length > vm->total))
> -		return -ENODEV;
> -
>  	ret = alloc_gen8_temp_bitmaps(&new_page_dirs, &new_page_tables, pdpes);
>  	if (ret)
>  		return ret;
> @@ -1929,9 +1920,6 @@ static int gen6_alloc_va_range(struct i915_address_space *vm,
>  	uint32_t pde;
>  	int ret;
>  
> -	if (WARN_ON(start_in + length_in > ppgtt->base.total))
> -		return -ENODEV;
> -
>  	start = start_save = start_in;
>  	length = length_save = length_in;
>  
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index 37c3eebe8316..9e121222c5eb 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -176,6 +176,12 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
>  	if (bind_flags == 0)
>  		return 0;

#define range_overfows(start, size, max) ({
	typeof(start) start__ = (start);
	typeof(size) size__ = (size);
	typeof(max) max__ = (max);
	(void)(&start__ == &size__);
	(void)(&start__ == &max__);
	start > max || size > max - start;
})

if (GEM_WARN_ON(range_overflows(vma->node.start,
				vma->node.size,
				vma->vm->total))
    return -ENODEV;

Then look at pread/pwrite for where we can reuse range_overflows(), e.g.
if (range_overflows(args->offset, args->size, obj->base.size)) {

Might need a range_overflows_t();
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index ef00d36680c9..4f405b445b6c 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1303,15 +1303,6 @@  static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
 	uint32_t pdpes = I915_PDPES_PER_PDP(dev_priv);
 	int ret;
 
-	/* Wrap is never okay since we can only represent 48b, and we don't
-	 * actually use the other side of the canonical address space.
-	 */
-	if (WARN_ON(start + length < start))
-		return -ENODEV;
-
-	if (WARN_ON(start + length > vm->total))
-		return -ENODEV;
-
 	ret = alloc_gen8_temp_bitmaps(&new_page_dirs, &new_page_tables, pdpes);
 	if (ret)
 		return ret;
@@ -1929,9 +1920,6 @@  static int gen6_alloc_va_range(struct i915_address_space *vm,
 	uint32_t pde;
 	int ret;
 
-	if (WARN_ON(start_in + length_in > ppgtt->base.total))
-		return -ENODEV;
-
 	start = start_save = start_in;
 	length = length_save = length_in;
 
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 37c3eebe8316..9e121222c5eb 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -176,6 +176,12 @@  int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
 	if (bind_flags == 0)
 		return 0;
 
+	if (GEM_WARN_ON(vma->node.start + vma->node.size < vma->node.start))
+		return -ENODEV;
+
+	if (GEM_WARN_ON(vma->node.start + vma->node.size > vma->vm->total))
+		return -ENODEV;
+
 	if (vma_flags == 0 && vma->vm->allocate_va_range) {
 		trace_i915_va_alloc(vma);
 		ret = vma->vm->allocate_va_range(vma->vm,