diff mbox series

[11/23] drm/i915/selftests: Make evict tolerant of foreign objects

Message ID 20190117143519.16086-12-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [01/23] drm/i915: Make all GPU resets atomic | expand

Commit Message

Chris Wilson Jan. 17, 2019, 2:34 p.m. UTC
The evict selftests presumed that all objects in use had been allocated
by itself. This is a dubious claim and so instead of asserting complete
control over the object lists, take (temporary) ownership of them
instead.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 64 +++++++++++++++----
 1 file changed, 53 insertions(+), 11 deletions(-)

Comments

Tvrtko Ursulin Jan. 17, 2019, 5:29 p.m. UTC | #1
On 17/01/2019 14:34, Chris Wilson wrote:
> The evict selftests presumed that all objects in use had been allocated
> by itself. This is a dubious claim and so instead of asserting complete
> control over the object lists, take (temporary) ownership of them
> instead.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>   .../gpu/drm/i915/selftests/i915_gem_evict.c   | 64 +++++++++++++++----
>   1 file changed, 53 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> index fb7df895afeb..c8deb961a020 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> @@ -31,30 +31,63 @@
>   
>   static int populate_ggtt(struct drm_i915_private *i915)
>   {
> -	struct drm_i915_gem_object *obj;
> +	struct drm_i915_gem_object *obj, *on;
> +	unsigned long expected_unbound, expected_bound;
> +	unsigned long unbound, bound, count;

Minor/optional comment - longs seem like overkill for either filling 
ggtt with page size objects or for initial state. :)

>   	u64 size;
> +	int err;
> +
> +	expected_unbound = 0;
> +	list_for_each_entry(obj, &i915->mm.unbound_list, mm.link) {
> +		i915_gem_object_get(obj);
> +		expected_unbound++;
> +	}
> +
> +	expected_bound = 0;
> +	list_for_each_entry(obj, &i915->mm.bound_list, mm.link) {
> +		i915_gem_object_get(obj);
> +		expected_bound++;
> +	}
>   
> +	count = 0;
>   	for (size = 0;
>   	     size + I915_GTT_PAGE_SIZE <= i915->ggtt.vm.total;
>   	     size += I915_GTT_PAGE_SIZE) {
>   		struct i915_vma *vma;
>   
>   		obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE);
> -		if (IS_ERR(obj))
> -			return PTR_ERR(obj);
> +		if (IS_ERR(obj)) {
> +			err = PTR_ERR(obj);
> +			goto cleanup;
> +		}
>   
>   		vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
> -		if (IS_ERR(vma))
> -			return PTR_ERR(vma);
> +		if (IS_ERR(vma)) {
> +			err = PTR_ERR(vma);
> +			goto cleanup;
> +		}
> +
> +		count++;
>   	}
>   
> -	if (!list_empty(&i915->mm.unbound_list)) {
> -		size = 0;
> -		list_for_each_entry(obj, &i915->mm.unbound_list, mm.link)
> -			size++;
> +	unbound = 0;
> +	list_for_each_entry(obj, &i915->mm.unbound_list, mm.link)
> +		unbound++;
> +	if (unbound != expected_unbound) {
> +		pr_err("%s: Found %lu objects unbound, expected %lu!\n",
> +		       __func__, unbound, expected_unbound);
> +		err = -EINVAL;
> +		goto cleanup;
> +	}
>   
> -		pr_err("Found %lld objects unbound!\n", size);
> -		return -EINVAL;
> +	bound = 0;
> +	list_for_each_entry(obj, &i915->mm.bound_list, mm.link)
> +		bound++;
> +	if (bound != expected_bound + count) {
> +		pr_err("%s: Found %lu objects bound, expected %lu!\n",
> +		       __func__, bound, expected_bound + count);
> +		err = -EINVAL;
> +		goto cleanup;
>   	}
>   
>   	if (list_empty(&i915->ggtt.vm.bound_list)) {
> @@ -63,6 +96,15 @@ static int populate_ggtt(struct drm_i915_private *i915)
>   	}
>   
>   	return 0;
> +
> +cleanup:
> +	list_for_each_entry_safe(obj, on, &i915->mm.unbound_list, mm.link)
> +		i915_gem_object_put(obj);
> +
> +	list_for_each_entry_safe(obj, on, &i915->mm.bound_list, mm.link)
> +		i915_gem_object_put(obj);
> +
> +	return err;
>   }
>   
>   static void unpin_ggtt(struct drm_i915_private *i915)
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
Chris Wilson Jan. 18, 2019, 11:23 a.m. UTC | #2
Quoting Tvrtko Ursulin (2019-01-17 17:29:34)
> 
> On 17/01/2019 14:34, Chris Wilson wrote:
> > The evict selftests presumed that all objects in use had been allocated
> > by itself. This is a dubious claim and so instead of asserting complete
> > control over the object lists, take (temporary) ownership of them
> > instead.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> >   .../gpu/drm/i915/selftests/i915_gem_evict.c   | 64 +++++++++++++++----
> >   1 file changed, 53 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> > index fb7df895afeb..c8deb961a020 100644
> > --- a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> > +++ b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
> > @@ -31,30 +31,63 @@
> >   
> >   static int populate_ggtt(struct drm_i915_private *i915)
> >   {
> > -     struct drm_i915_gem_object *obj;
> > +     struct drm_i915_gem_object *obj, *on;
> > +     unsigned long expected_unbound, expected_bound;
> > +     unsigned long unbound, bound, count;
> 
> Minor/optional comment - longs seem like overkill for either filling 
> ggtt with page size objects or for initial state. :)

Force of habit, or just hope for the glorious future.
-Chris
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
index fb7df895afeb..c8deb961a020 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
@@ -31,30 +31,63 @@ 
 
 static int populate_ggtt(struct drm_i915_private *i915)
 {
-	struct drm_i915_gem_object *obj;
+	struct drm_i915_gem_object *obj, *on;
+	unsigned long expected_unbound, expected_bound;
+	unsigned long unbound, bound, count;
 	u64 size;
+	int err;
+
+	expected_unbound = 0;
+	list_for_each_entry(obj, &i915->mm.unbound_list, mm.link) {
+		i915_gem_object_get(obj);
+		expected_unbound++;
+	}
+
+	expected_bound = 0;
+	list_for_each_entry(obj, &i915->mm.bound_list, mm.link) {
+		i915_gem_object_get(obj);
+		expected_bound++;
+	}
 
+	count = 0;
 	for (size = 0;
 	     size + I915_GTT_PAGE_SIZE <= i915->ggtt.vm.total;
 	     size += I915_GTT_PAGE_SIZE) {
 		struct i915_vma *vma;
 
 		obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE);
-		if (IS_ERR(obj))
-			return PTR_ERR(obj);
+		if (IS_ERR(obj)) {
+			err = PTR_ERR(obj);
+			goto cleanup;
+		}
 
 		vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
-		if (IS_ERR(vma))
-			return PTR_ERR(vma);
+		if (IS_ERR(vma)) {
+			err = PTR_ERR(vma);
+			goto cleanup;
+		}
+
+		count++;
 	}
 
-	if (!list_empty(&i915->mm.unbound_list)) {
-		size = 0;
-		list_for_each_entry(obj, &i915->mm.unbound_list, mm.link)
-			size++;
+	unbound = 0;
+	list_for_each_entry(obj, &i915->mm.unbound_list, mm.link)
+		unbound++;
+	if (unbound != expected_unbound) {
+		pr_err("%s: Found %lu objects unbound, expected %lu!\n",
+		       __func__, unbound, expected_unbound);
+		err = -EINVAL;
+		goto cleanup;
+	}
 
-		pr_err("Found %lld objects unbound!\n", size);
-		return -EINVAL;
+	bound = 0;
+	list_for_each_entry(obj, &i915->mm.bound_list, mm.link)
+		bound++;
+	if (bound != expected_bound + count) {
+		pr_err("%s: Found %lu objects bound, expected %lu!\n",
+		       __func__, bound, expected_bound + count);
+		err = -EINVAL;
+		goto cleanup;
 	}
 
 	if (list_empty(&i915->ggtt.vm.bound_list)) {
@@ -63,6 +96,15 @@  static int populate_ggtt(struct drm_i915_private *i915)
 	}
 
 	return 0;
+
+cleanup:
+	list_for_each_entry_safe(obj, on, &i915->mm.unbound_list, mm.link)
+		i915_gem_object_put(obj);
+
+	list_for_each_entry_safe(obj, on, &i915->mm.bound_list, mm.link)
+		i915_gem_object_put(obj);
+
+	return err;
 }
 
 static void unpin_ggtt(struct drm_i915_private *i915)