diff mbox series

[i-g-t] i915/gem_ctx_persistence: Check precision of hostile cancellation

Message ID 20200224215650.39624-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [i-g-t] i915/gem_ctx_persistence: Check precision of hostile cancellation | expand

Commit Message

Chris Wilson Feb. 24, 2020, 9:56 p.m. UTC
Check that if we have to remove a hostile request from a non-persistent
context, we do so without harming any other concurrent users.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/gem_ctx_persistence.c | 63 ++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

Comments

Tvrtko Ursulin Feb. 25, 2020, 6:08 p.m. UTC | #1
On 24/02/2020 21:56, Chris Wilson wrote:
> Check that if we have to remove a hostile request from a non-persistent
> context, we do so without harming any other concurrent users.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>   tests/i915/gem_ctx_persistence.c | 63 ++++++++++++++++++++++++++++++++
>   1 file changed, 63 insertions(+)
> 
> diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c
> index 20007f5c4..cd174d263 100644
> --- a/tests/i915/gem_ctx_persistence.c
> +++ b/tests/i915/gem_ctx_persistence.c
> @@ -613,6 +613,62 @@ static void test_process_mixed(int pfd, unsigned int engine)
>   	gem_quiescent_gpu(pfd);
>   }
>   
> +static void
> +test_saturated_hostile(int i915, const struct intel_execution_engine2 *engine)
> +{
> +	const struct intel_execution_engine2 *other;
> +	igt_spin_t *spin;
> +	uint32_t ctx;
> +	int fence = -1;
> +
> +	/*
> +	 * Check that if we have to remove a hostile request from a
> +	 * non-persistent context, we do so without harming any other
> +	 * concurrent users.
> +	 */
> +
> +	__for_each_physical_engine(i915, other) {
> +		if (other->flags == engine->flags)
> +			continue;
> +
> +		spin = igt_spin_new(i915,
> +				   .engine = other->flags,
> +				   .flags = (IGT_SPIN_NO_PREEMPTION |
> +					     IGT_SPIN_FENCE_OUT));
> +
> +		if (fence < 0) {
> +			fence = spin->out_fence;
> +		} else {
> +			int tmp;
> +
> +			tmp = sync_fence_merge(fence, spin->out_fence);
> +			close(fence);
> +			close(spin->out_fence);
> +
> +			fence = tmp;
> +		}
> +		spin->out_fence = -1;
> +	}
> +
> +	ctx = gem_context_clone_with_engines(i915, 0);
> +	gem_context_set_persistence(i915, ctx, false);
> +	spin = igt_spin_new(i915, ctx,
> +			    .engine = engine->flags,
> +			    .flags = (IGT_SPIN_NO_PREEMPTION |
> +				      IGT_SPIN_POLL_RUN |
> +				      IGT_SPIN_FENCE_OUT));
> +	igt_spin_busywait_until_started(spin);
> +	gem_context_destroy(i915, ctx);
> +
> +	igt_assert_eq(sync_fence_wait(spin->out_fence, reset_timeout_ms), 0);
> +	igt_assert_eq(sync_fence_status(spin->out_fence), -EIO);
> +
> +	/* All other spinners should be left unharmed */
> +	gem_quiescent_gpu(i915);
> +	igt_assert_eq(sync_fence_wait(fence, reset_timeout_ms), 0);
> +	igt_assert_eq(sync_fence_status(fence), 1);

I don't quite get this test. Why would other spinners be unharmed? They 
are non-preemptible as well. And non-persistent spinner is alone on the 
engine. So what aspect you wanted to test?

Regards,

Tvrtko

> +}
> +
>   static void test_processes(int i915)
>   {
>   	struct {
> @@ -1041,6 +1097,13 @@ igt_main
>   			}
>   		}
>   
> +		igt_subtest_with_dynamic_f("saturated-hostile") {
> +			__for_each_physical_engine(i915, e) {
> +				igt_dynamic_f("%s", e->name)
> +					test_saturated_hostile(i915, e);
> +			}
> +		}
> +
>   		igt_subtest("smoketest")
>   			smoketest(i915);
>   	}
>
Chris Wilson Feb. 25, 2020, 6:11 p.m. UTC | #2
Quoting Tvrtko Ursulin (2020-02-25 18:08:14)
> 
> On 24/02/2020 21:56, Chris Wilson wrote:
> > Check that if we have to remove a hostile request from a non-persistent
> > context, we do so without harming any other concurrent users.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> > +     /* All other spinners should be left unharmed */
> > +     gem_quiescent_gpu(i915);
> > +     igt_assert_eq(sync_fence_wait(fence, reset_timeout_ms), 0);
> > +     igt_assert_eq(sync_fence_status(fence), 1);
> 
> I don't quite get this test. Why would other spinners be unharmed? They 
> are non-preemptible as well. And non-persistent spinner is alone on the 
> engine. So what aspect you wanted to test?

Per-engine reset. Termination of the non-persistent context should be
clean and precise, we don't allow creation of non-persistent contexts
unless we have that level of surgical precision. Otherwise it becomes a
new attack vector.
-Chris
Tvrtko Ursulin Feb. 25, 2020, 6:18 p.m. UTC | #3
On 25/02/2020 18:11, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2020-02-25 18:08:14)
>>
>> On 24/02/2020 21:56, Chris Wilson wrote:
>>> Check that if we have to remove a hostile request from a non-persistent
>>> context, we do so without harming any other concurrent users.
>>>
>>> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
>>> ---
>>> +     /* All other spinners should be left unharmed */
>>> +     gem_quiescent_gpu(i915);
>>> +     igt_assert_eq(sync_fence_wait(fence, reset_timeout_ms), 0);
>>> +     igt_assert_eq(sync_fence_status(fence), 1);
>>
>> I don't quite get this test. Why would other spinners be unharmed? They
>> are non-preemptible as well. And non-persistent spinner is alone on the
>> engine. So what aspect you wanted to test?
> 
> Per-engine reset. Termination of the non-persistent context should be
> clean and precise, we don't allow creation of non-persistent contexts
> unless we have that level of surgical precision. Otherwise it becomes a
> new attack vector.

If it is just engine reset then it does what it says on the tin.

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

Regards,

Tvrtko
Chris Wilson Feb. 25, 2020, 6:22 p.m. UTC | #4
Quoting Tvrtko Ursulin (2020-02-25 18:18:12)
> 
> On 25/02/2020 18:11, Chris Wilson wrote:
> > Quoting Tvrtko Ursulin (2020-02-25 18:08:14)
> >>
> >> On 24/02/2020 21:56, Chris Wilson wrote:
> >>> Check that if we have to remove a hostile request from a non-persistent
> >>> context, we do so without harming any other concurrent users.
> >>>
> >>> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> >>> ---
> >>> +     /* All other spinners should be left unharmed */
> >>> +     gem_quiescent_gpu(i915);
> >>> +     igt_assert_eq(sync_fence_wait(fence, reset_timeout_ms), 0);
> >>> +     igt_assert_eq(sync_fence_status(fence), 1);
> >>
> >> I don't quite get this test. Why would other spinners be unharmed? They
> >> are non-preemptible as well. And non-persistent spinner is alone on the
> >> engine. So what aspect you wanted to test?
> > 
> > Per-engine reset. Termination of the non-persistent context should be
> > clean and precise, we don't allow creation of non-persistent contexts
> > unless we have that level of surgical precision. Otherwise it becomes a
> > new attack vector.
> 
> If it is just engine reset then it does what it says on the tin.

I shall update the description to clarify that then :)
-Chris
diff mbox series

Patch

diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c
index 20007f5c4..cd174d263 100644
--- a/tests/i915/gem_ctx_persistence.c
+++ b/tests/i915/gem_ctx_persistence.c
@@ -613,6 +613,62 @@  static void test_process_mixed(int pfd, unsigned int engine)
 	gem_quiescent_gpu(pfd);
 }
 
+static void
+test_saturated_hostile(int i915, const struct intel_execution_engine2 *engine)
+{
+	const struct intel_execution_engine2 *other;
+	igt_spin_t *spin;
+	uint32_t ctx;
+	int fence = -1;
+
+	/*
+	 * Check that if we have to remove a hostile request from a
+	 * non-persistent context, we do so without harming any other
+	 * concurrent users.
+	 */
+
+	__for_each_physical_engine(i915, other) {
+		if (other->flags == engine->flags)
+			continue;
+
+		spin = igt_spin_new(i915,
+				   .engine = other->flags,
+				   .flags = (IGT_SPIN_NO_PREEMPTION |
+					     IGT_SPIN_FENCE_OUT));
+
+		if (fence < 0) {
+			fence = spin->out_fence;
+		} else {
+			int tmp;
+
+			tmp = sync_fence_merge(fence, spin->out_fence);
+			close(fence);
+			close(spin->out_fence);
+
+			fence = tmp;
+		}
+		spin->out_fence = -1;
+	}
+
+	ctx = gem_context_clone_with_engines(i915, 0);
+	gem_context_set_persistence(i915, ctx, false);
+	spin = igt_spin_new(i915, ctx,
+			    .engine = engine->flags,
+			    .flags = (IGT_SPIN_NO_PREEMPTION |
+				      IGT_SPIN_POLL_RUN |
+				      IGT_SPIN_FENCE_OUT));
+	igt_spin_busywait_until_started(spin);
+	gem_context_destroy(i915, ctx);
+
+	igt_assert_eq(sync_fence_wait(spin->out_fence, reset_timeout_ms), 0);
+	igt_assert_eq(sync_fence_status(spin->out_fence), -EIO);
+
+	/* All other spinners should be left unharmed */
+	gem_quiescent_gpu(i915);
+	igt_assert_eq(sync_fence_wait(fence, reset_timeout_ms), 0);
+	igt_assert_eq(sync_fence_status(fence), 1);
+}
+
 static void test_processes(int i915)
 {
 	struct {
@@ -1041,6 +1097,13 @@  igt_main
 			}
 		}
 
+		igt_subtest_with_dynamic_f("saturated-hostile") {
+			__for_each_physical_engine(i915, e) {
+				igt_dynamic_f("%s", e->name)
+					test_saturated_hostile(i915, e);
+			}
+		}
+
 		igt_subtest("smoketest")
 			smoketest(i915);
 	}