[Intel-gfx] [PATCH 20/20] drm/i915/selftests: Check that resets are safe from inside the shrinker

Chris Wilson chris at chris-wilson.co.uk
Fri Jul 21 12:32:38 UTC 2017


We need to be able to reclaim from any process context, including the
shrinker. We can simulate being inside the shrinker using lockdep and
adjusting the task's reclaim state.

References: https://bugs.freedesktop.org/show_bug.cgi?id=101857
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/selftests/intel_hangcheck.c | 39 ++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/gpu/drm/i915/selftests/intel_hangcheck.c b/drivers/gpu/drm/i915/selftests/intel_hangcheck.c
index 4129d01b67a1..f800bf7a822d 100644
--- a/drivers/gpu/drm/i915/selftests/intel_hangcheck.c
+++ b/drivers/gpu/drm/i915/selftests/intel_hangcheck.c
@@ -359,6 +359,44 @@ static int igt_global_reset(void *arg)
 	return err;
 }
 
+static int igt_reclaim_reset(void *arg)
+{
+	struct drm_i915_private *i915 = arg;
+	unsigned int reset_count;
+	int err = 0;
+
+	/* Check that we can perform a reset from inside the shrinker/kswapd */
+
+	global_reset_lock(i915);
+	set_bit(I915_RESET_HANDOFF, &i915->gpu_error.flags);
+
+	mutex_lock(&i915->drm.struct_mutex);
+	reset_count = i915_reset_count(&i915->gpu_error);
+
+	/* We need to support resets from any process context, including
+	 * from inside the shrinker.
+	 */
+	lockdep_set_current_reclaim_state(GFP_KERNEL);
+
+	i915_reset(i915, I915_RESET_QUIET);
+
+	lockdep_clear_current_reclaim_state();
+
+	if (i915_reset_count(&i915->gpu_error) == reset_count) {
+		pr_err("No GPU reset recorded!\n");
+		err = -EINVAL;
+	}
+	mutex_unlock(&i915->drm.struct_mutex);
+
+	GEM_BUG_ON(test_bit(I915_RESET_HANDOFF, &i915->gpu_error.flags));
+	global_reset_unlock(i915);
+
+	if (i915_terminally_wedged(&i915->gpu_error))
+		err = -EIO;
+
+	return err;
+}
+
 static int igt_reset_engine(void *arg)
 {
 	struct drm_i915_private *i915 = arg;
@@ -840,6 +878,7 @@ int intel_hangcheck_live_selftests(struct drm_i915_private *i915)
 	static const struct i915_subtest tests[] = {
 		SUBTEST(igt_hang_sanitycheck),
 		SUBTEST(igt_global_reset),
+		SUBTEST(igt_reclaim_reset),
 		SUBTEST(igt_reset_engine),
 		SUBTEST(igt_reset_active_engines),
 		SUBTEST(igt_wait_reset),
-- 
2.13.3



More information about the Intel-gfx mailing list