If we do a device level reset, we lose vital registers that may be in concurrent use by userspace (i.e. the GGTT and its fencing). To be paranoid and prevent that memory access from being corrupted, we want to pause all other processes/threads, so that the device reset is the only thing running on the system.
Signed-off-by: Chris Wilson <ch...@chris-wilson.co.uk> --- drivers/gpu/drm/i915/i915_reset.c | 85 +++++++++---------- .../gpu/drm/i915/selftests/intel_hangcheck.c | 18 ++++ 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_reset.c b/drivers/gpu/drm/i915/i915_reset.c index da1c8db1f93c..77e666a27c69 100644 --- a/drivers/gpu/drm/i915/i915_reset.c +++ b/drivers/gpu/drm/i915/i915_reset.c @@ -5,6 +5,7 @@ */ #include <linux/sched/mm.h> +#include <linux/stop_machine.h> #include "i915_drv.h" #include "i915_gpu_error.h" @@ -428,22 +429,6 @@ int intel_gpu_reset(struct drm_i915_private *i915, unsigned int engine_mask) int retry; int ret; - /* - * We want to perform per-engine reset from atomic context (e.g. - * softirq), which imposes the constraint that we cannot sleep. - * However, experience suggests that spending a bit of time waiting - * for a reset helps in various cases, so for a full-device reset - * we apply the opposite rule and wait if we want to. As we should - * always follow up a failed per-engine reset with a full device reset, - * being a little faster, stricter and more error prone for the - * atomic case seems an acceptable compromise. - * - * Unfortunately this leads to a bimodal routine, when the goal was - * to have a single reset function that worked for resetting any - * number of engines simultaneously. - */ - might_sleep_if(engine_mask == ALL_ENGINES); - /* * If the power well sleeps during the reset, the reset * request may be dropped and never completes (causing -EIO). @@ -475,8 +460,6 @@ int intel_gpu_reset(struct drm_i915_private *i915, unsigned int engine_mask) } if (ret != -ETIMEDOUT || engine_mask != ALL_ENGINES) break; - - cond_resched(); } intel_uncore_forcewake_put(i915, FORCEWAKE_ALL); @@ -645,12 +628,19 @@ static void reset_engine(struct intel_engine_cs *engine, engine->reset.reset(engine, rq); } -static void gt_reset(struct drm_i915_private *i915, unsigned int stalled_mask) +static int gt_reset(struct drm_i915_private *i915, unsigned int stalled_mask) { struct intel_engine_cs *engine; enum intel_engine_id id; + int err; - lockdep_assert_held(&i915->drm.struct_mutex); + /* + * Everything depends on having the GTT running, so we need to start + * there. + */ + err = i915_ggtt_enable_hw(i915); + if (err) + return err; i915_retire_requests(i915); @@ -684,6 +674,7 @@ static void gt_reset(struct drm_i915_private *i915, unsigned int stalled_mask) } i915_gem_restore_fences(i915); + return 0; } static void reset_finish_engine(struct intel_engine_cs *engine) @@ -894,6 +885,36 @@ bool i915_gem_unset_wedged(struct drm_i915_private *i915) return ret; } +struct __i915_reset { + struct drm_i915_private *i915; + unsigned int stalled_mask; +}; + +static int __i915_reset__BKL(void *data) +{ + struct __i915_reset *arg = data; + int err; + + err = intel_gpu_reset(arg->i915, ALL_ENGINES); + if (err) + return err; + + return gt_reset(arg->i915, arg->stalled_mask); +} + +static int do_reset(struct drm_i915_private *i915, unsigned int stalled_mask) +{ + struct __i915_reset arg = { i915, stalled_mask }; + int err, i; + + err = stop_machine(__i915_reset__BKL, &arg, NULL); + for (i = 0; err && i < 3; i++) { + msleep(100); + err = stop_machine(__i915_reset__BKL, &arg, NULL); + } + + return err; +} /** * i915_reset - reset chip after a hang * @i915: #drm_i915_private to reset @@ -919,7 +940,6 @@ void i915_reset(struct drm_i915_private *i915, { struct i915_gpu_error *error = &i915->gpu_error; int ret; - int i; GEM_TRACE("flags=%lx\n", error->flags); @@ -952,32 +972,11 @@ void i915_reset(struct drm_i915_private *i915, goto error; } - for (i = 0; i < 3; i++) { - ret = intel_gpu_reset(i915, ALL_ENGINES); - if (ret == 0) - break; - - msleep(100); - } - if (ret) { + if (do_reset(i915, stalled_mask)) { dev_err(i915->drm.dev, "Failed to reset chip\n"); goto taint; } - /* Ok, now get things going again... */ - - /* - * Everything depends on having the GTT running, so we need to start - * there. - */ - ret = i915_ggtt_enable_hw(i915); - if (ret) { - DRM_ERROR("Failed to re-enable GGTT following reset (%d)\n", - ret); - goto error; - } - - gt_reset(i915, stalled_mask); intel_overlay_reset(i915); /* diff --git a/drivers/gpu/drm/i915/selftests/intel_hangcheck.c b/drivers/gpu/drm/i915/selftests/intel_hangcheck.c index e30910009fe3..c0b57a679f34 100644 --- a/drivers/gpu/drm/i915/selftests/intel_hangcheck.c +++ b/drivers/gpu/drm/i915/selftests/intel_hangcheck.c @@ -1532,6 +1532,24 @@ static int igt_atomic_reset(void *arg) if (i915_terminally_wedged(&i915->gpu_error)) goto out; + if (intel_has_gpu_reset(i915)) { + const typeof(*phases) *p; + + for (p = phases; p->name; p++) { + GEM_TRACE("intel_gpu_reset under %s\n", p->name); + + p->critical_section_begin(); + err = intel_gpu_reset(i915, ALL_ENGINES); + p->critical_section_end(); + + if (err) { + pr_err("intel_gpu_reset failed under %s\n", + p->name); + goto out; + } + } + } + if (intel_has_reset_engine(i915)) { struct intel_engine_cs *engine; enum intel_engine_id id; -- 2.19.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx