if (intel_context_is_closed(rq->context)) returntrue;
rcu_read_lock();
ctx = rcu_dereference(rq->context->gem_context); if (ctx && !kref_get_unless_zero(&ctx->ref))
ctx = NULL;
rcu_read_unlock(); if (!ctx) return intel_context_is_banned(rq->context);
atomic_inc(&ctx->guilty_count);
/* Cool contexts are too cool to be banned! (Used for reset testing.) */ if (!i915_gem_context_is_bannable(ctx)) {
banned = false; goto out;
}
drm_notice(&ctx->i915->drm, "%s context reset due to GPU hang\n",
ctx->name);
/* Record the timestamp for the last N hangs */
prev_hang = ctx->hang_timestamp[0]; for (i = 0; i < ARRAY_SIZE(ctx->hang_timestamp) - 1; i++)
ctx->hang_timestamp[i] = ctx->hang_timestamp[i + 1];
ctx->hang_timestamp[i] = jiffies;
/* If we have hung N+1 times in rapid succession, we ban the context! */
banned = !i915_gem_context_is_recoverable(ctx); if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
banned = true; if (banned)
drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
ctx->name, atomic_read(&ctx->guilty_count));
/* Assert reset for at least 50 usec, and wait for acknowledgement. */
pci_write_config_byte(pdev, I915_GDRST, GRDOM_RESET_ENABLE);
udelay(50);
err = _wait_for_atomic(i915_in_reset(pdev), 50000, 0);
/* Clear the reset request. */
pci_write_config_byte(pdev, I915_GDRST, 0);
udelay(50); if (!err)
err = _wait_for_atomic(!i915_in_reset(pdev), 50000, 0);
/* Reset the hardware domains (GENX_GRDOM_*) specified by mask */ staticint gen6_hw_domain_reset(struct intel_gt *gt, u32 hw_domain_mask)
{ struct intel_uncore *uncore = gt->uncore; int loops; int err;
/* * On some platforms, e.g. Jasperlake, we see that the engine register * state is not cleared until shortly after GDRST reports completion, * causing a failure as we try to immediately resume while the internal * state is still in flux. If we immediately repeat the reset, the * second reset appears to serialise with the first, and since it is a * no-op, the registers should retain their reset value. However, there * is still a concern that upon leaving the second reset, the internal * engine state is still in flux and not ready for resuming. * * Starting on MTL, there are some prep steps that we need to do when * resetting some engines that need to be applied every time we write to * GEN6_GDRST. As those are time consuming (tens of ms), we don't want * to perform that twice, so, since the Jasperlake issue hasn't been * observed on MTL, we avoid repeating the reset on newer platforms.
*/
loops = GRAPHICS_VER_FULL(gt->i915) < IP_VER(12, 70) ? 2 : 1;
/* * GEN6_GDRST is not in the gt power well, no need to check * for fifo space for the write or forcewake the chip for * the read
*/ do {
intel_uncore_write_fw(uncore, GEN6_GDRST, hw_domain_mask);
/* Wait for the device to ack the reset requests. */
err = __intel_wait_for_register_fw(uncore, GEN6_GDRST,
hw_domain_mask, 0,
2000, 0,
NULL);
} while (err == 0 && --loops); if (err)
GT_TRACE(gt, "Wait for 0x%08x engines reset failed\n",
hw_domain_mask);
/* * As we have observed that the engine state is still volatile * after GDRST is acked, impose a small delay to let everything settle.
*/
udelay(50);
switch (engine->class) { case VIDEO_DECODE_CLASS: if ((BIT(engine->instance) & vdbox_sfc_access) == 0) return 0;
fallthrough; case VIDEO_ENHANCEMENT_CLASS:
get_sfc_forced_lock_data(engine, &sfc_lock);
break; default: return 0;
}
if (!(intel_uncore_read_fw(uncore, sfc_lock.usage_reg) & sfc_lock.usage_bit)) { struct intel_engine_cs *paired_vecs;
if (engine->class != VIDEO_DECODE_CLASS ||
GRAPHICS_VER(engine->i915) != 12) return 0;
/* * Wa_14010733141 * * If the VCS-MFX isn't using the SFC, we also need to check * whether VCS-HCP is using it. If so, we need to issue a *VE* * forced lock on the VE engine that shares the same SFC.
*/ if (!(intel_uncore_read_fw(uncore,
GEN12_HCP_SFC_LOCK_STATUS(engine->mmio_base)) &
GEN12_HCP_SFC_USAGE_BIT)) return 0;
/* * If the engine is using an SFC, tell the engine that a software reset * is going to happen. The engine will then try to force lock the SFC. * If SFC ends up being locked to the engine we want to reset, we have * to reset it as well (we will unlock it once the reset sequence is * completed).
*/
intel_uncore_rmw_fw(uncore, sfc_lock.lock_reg, 0, sfc_lock.lock_bit);
ret = __intel_wait_for_register_fw(uncore,
sfc_lock.ack_reg,
sfc_lock.ack_bit,
sfc_lock.ack_bit,
1000, 0, NULL);
/* * Was the SFC released while we were trying to lock it? * * We should reset both the engine and the SFC if: * - We were locking the SFC to this engine and the lock succeeded * OR * - We were locking the SFC to a different engine (Wa_14010733141) * but the SFC was released before the lock was obtained. * * Otherwise we need only reset the engine by itself and we can * leave the SFC alone.
*/
lock_obtained = (intel_uncore_read_fw(uncore, sfc_lock.usage_reg) &
sfc_lock.usage_bit) != 0; if (lock_obtained == lock_to_other) return 0;
if (ret) {
ENGINE_TRACE(engine, "Wait for SFC forced lock ack failed\n"); return ret;
}
sfc_unlock: /* * We unlock the SFC based on the lock status and not the result of * gen11_lock_sfc to make sure that we clean properly if something * wrong happened during the lock (e.g. lock acquired after timeout * expiration). * * Due to Wa_14010733141, we may have locked an SFC to an engine that * wasn't being reset. So instead of calling gen11_unlock_sfc() * on engine_mask, we instead call it on the mask of engines that our * gen11_lock_sfc() calls told us actually had locks attempted.
*/
for_each_engine_masked(engine, gt, unlock_mask, tmp)
gen11_unlock_sfc(engine);
for_each_engine_masked(engine, gt, engine_mask, tmp) {
ret = gen8_engine_reset_prepare(engine); if (ret && !reset_non_ready) goto skip_reset;
/* * If this is not the first failed attempt to prepare, * we decide to proceed anyway. * * By doing so we risk context corruption and with * some gens (kbl), possible system hang if reset * happens during active bb execution. * * We rather take context corruption instead of * failed reset with a wedged driver/gpu. And * active bb execution case should be covered by * stop_engines() we have before the reset.
*/
}
/* * Wa_22011100796:dg2, whenever Full soft reset is required, * reset all individual engines firstly, and then do a full soft reset. * * This is best effort, so ignore any error from the initial reset.
*/ if (IS_DG2(gt->i915) && engine_mask == ALL_ENGINES)
__gen11_reset_engines(gt, gt->info.engine_mask, 0);
if (GRAPHICS_VER(gt->i915) >= 11)
ret = __gen11_reset_engines(gt, engine_mask, retry); else
ret = __gen6_reset_engines(gt, engine_mask, retry);
/* * wa_14015076503: if the GSC FW is loaded, we need to alert it that * we're going to do a GSC engine reset and then wait for 200ms for the * FW to get ready for it. However, if this is the first ALL_ENGINES * reset attempt and the GSC is not busy, we can try to instead reset * the GuC and all the other engines individually to avoid the 200ms * wait. * Skipping the GSC engine is safe because, differently from other * engines, the GSCCS only role is to forward the commands to the GSC * FW, so it doesn't have any HW outside of the CS itself and therefore * it has no state that we don't explicitly re-init on resume or on * context switch LRC or power context). The HW for the GSC uC is * managed by the GSC FW so we don't need to care about that.
*/ if (engine_mask == ALL_ENGINES && first && intel_engine_is_idle(gt->engine[GSC0])) {
__reset_guc(gt);
engine_mask = gt->info.engine_mask & ~BIT(GSC0);
} else {
intel_uncore_rmw(gt->uncore,
HECI_H_GS1(MTL_GSC_HECI2_BASE),
0, HECI_H_GS1_ER_PREP);
/* make sure the reset bit is clear when writing the CSR reg */
intel_uncore_rmw(gt->uncore,
HECI_H_CSR(MTL_GSC_HECI2_BASE),
HECI_H_CSR_RST, HECI_H_CSR_IG);
msleep(200);
}
staticint __intel_gt_reset(struct intel_gt *gt, intel_engine_mask_t engine_mask)
{ constint retries = engine_mask == ALL_ENGINES ? RESET_MAX_RETRIES : 1;
reset_func reset; int ret = -ETIMEDOUT; int retry;
reset = intel_get_gpu_reset(gt); if (!reset) return -ENODEV;
/* * If the power well sleeps during the reset, the reset * request may be dropped and never completes (causing -EIO).
*/
intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); for (retry = 0; ret == -ETIMEDOUT && retry < retries; retry++) {
intel_engine_mask_t reset_mask;
bool intel_has_gpu_reset(conststruct intel_gt *gt)
{ if (!gt->i915->params.reset) return NULL;
return intel_get_gpu_reset(gt);
}
bool intel_has_reset_engine(conststruct intel_gt *gt)
{ if (gt->i915->params.reset < 2) returnfalse;
return INTEL_INFO(gt->i915)->has_reset_engine;
}
int intel_reset_guc(struct intel_gt *gt)
{ int ret;
GEM_BUG_ON(!HAS_GT_UC(gt->i915));
intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL);
ret = __reset_guc(gt);
intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL);
return ret;
}
/* * Ensure irq handler finishes, and not run again. * Also return the active request so that we only search for it once.
*/ staticvoid reset_prepare_engine(struct intel_engine_cs *engine)
{ /* * During the reset sequence, we must prevent the engine from * entering RC6. As the context state is undefined until we restart * the engine, if it does enter RC6 during the reset, the state * written to the powercontext is undefined and so we may lose * GPU state upon resume, i.e. fail to restart after a reset.
*/
intel_uncore_forcewake_get(engine->uncore, FORCEWAKE_ALL); if (engine->reset.prepare)
engine->reset.prepare(engine);
}
staticvoid revoke_mmaps(struct intel_gt *gt)
{ int i;
for (i = 0; i < gt->ggtt->num_fences; i++) { struct drm_vma_offset_node *node; struct i915_vma *vma;
u64 vma_offset;
vma = READ_ONCE(gt->ggtt->fence_regs[i].vma); if (!vma) continue;
/** * For GuC mode with submission enabled, ensure submission * is disabled before stopping ring. * * For GuC mode with submission disabled, ensure that GuC is not * sanitized, do that after engine reset. reset_prepare() * is followed by engine reset which in this mode requires GuC to * process any CSB FIFO entries generated by the resets.
*/ if (intel_uc_uses_guc_submission(>->uc))
intel_uc_reset_prepare(>->uc);
if (test_bit(I915_WEDGED, >->reset.flags)) return;
GT_TRACE(gt, "start\n");
/* * First, stop submission to hw, but do not yet complete requests by * rolling the global seqno forward (since this would complete requests * for which we haven't set the fence error to EIO yet).
*/
awake = reset_prepare(gt);
/* Even if the GPU reset fails, it should still stop the engines */ if (!intel_gt_gpu_reset_clobbers_display(gt))
intel_gt_reset_all_engines(gt);
/* * Make sure no request can slip through without getting completed by * either this call here to intel_engine_write_global_seqno, or the one * in nop_submit_request.
*/
synchronize_rcu_expedited();
set_bit(I915_WEDGED, >->reset.flags);
/* Mark all executing requests as skipped */
local_bh_disable();
for_each_engine(engine, gt, id) if (engine->reset.cancel)
engine->reset.cancel(engine);
intel_uc_cancel_requests(>->uc);
local_bh_enable();
if (!test_bit(I915_WEDGED, >->reset.flags)) returntrue;
/* Never fully initialised, recovery impossible */ if (intel_gt_has_unrecoverable_error(gt)) returnfalse;
GT_TRACE(gt, "start\n");
/* * Before unwedging, make sure that all pending operations * are flushed and errored out - we may have requests waiting upon * third party fences. We marked all inflight requests as EIO, and * every execbuf since returned EIO, for consistency we want all * the currently pending requests to also be marked as EIO, which * is done inside our nop_submit_request - and so we must wait. * * No more can be submitted until we reset the wedged bit.
*/
spin_lock(&timelines->lock);
list_for_each_entry(tl, &timelines->active_list, link) { struct dma_fence *fence;
fence = i915_active_fence_get(&tl->last_request); if (!fence) continue;
spin_unlock(&timelines->lock);
/* * All internal dependencies (i915_requests) will have * been flushed by the set-wedge, but we may be stuck waiting * for external fences. These should all be capped to 10s * (I915_FENCE_TIMEOUT) so this wait should not be unbounded * in the worst case.
*/
dma_fence_default_wait(fence, false, MAX_SCHEDULE_TIMEOUT);
dma_fence_put(fence);
/* We must reset pending GPU events before restoring our submission */
ok = !HAS_EXECLISTS(gt->i915); /* XXX better agnosticism desired */ if (!intel_gt_gpu_reset_clobbers_display(gt))
ok = intel_gt_reset_all_engines(gt) == 0; if (!ok) { /* * Warn CI about the unrecoverable wedged condition. * Time for a reboot.
*/
add_taint_for_CI(gt->i915, TAINT_WARN); returnfalse;
}
/* * Undo nop_submit_request. We prevent all new i915 requests from * being queued (by disallowing execbuf whilst wedged) so having * waited for all active requests above, we know the system is idle * and do not have to worry about a thread being inside * engine->submit_request() as we swap over. So unlike installing * the nop_submit_request on reset, we can do this from normal * context and do not require stop_machine().
*/
intel_engines_reset_default_submission(gt);
GT_TRACE(gt, "end\n");
smp_mb__before_atomic(); /* complete takeover before enabling execbuf */
clear_bit(I915_WEDGED, >->reset.flags);
/** * intel_gt_reset - reset chip after a hang * @gt: #intel_gt to reset * @stalled_mask: mask of the stalled engines with the guilty requests * @reason: user error message for why we are resetting * * Reset the chip. Useful if a hang is detected. Marks the device as wedged * on failure. * * Procedure is fairly simple: * - reset the chip using the reset reg * - re-init context state * - re-init hardware status page * - re-init ring buffer * - re-init interrupt state * - re-init display
*/ void intel_gt_reset(struct intel_gt *gt,
intel_engine_mask_t stalled_mask, constchar *reason)
{ struct intel_display *display = gt->i915->display;
intel_engine_mask_t awake; int ret;
/* * FIXME: Revoking cpu mmap ptes cannot be done from a dma_fence * critical section like gpu reset.
*/
gt_revoke(gt);
mutex_lock(>->reset.mutex);
/* Clear any previous failed attempts at recovery. Time to try again. */ if (!__intel_gt_unset_wedged(gt)) goto unlock;
if (reason)
gt_notice(gt, "Resetting chip for %s\n", reason);
atomic_inc(>->i915->gpu_error.reset_count);
awake = reset_prepare(gt);
if (!intel_has_gpu_reset(gt)) { if (gt->i915->params.reset)
gt_err(gt, "GPU reset not supported\n"); else
gt_dbg(gt, "GPU reset disabled\n"); goto error;
}
if (intel_gt_gpu_reset_clobbers_display(gt))
intel_irq_suspend(gt->i915);
if (do_reset(gt, stalled_mask)) {
gt_err(gt, "Failed to reset chip\n"); goto taint;
}
if (intel_gt_gpu_reset_clobbers_display(gt))
intel_irq_resume(gt->i915);
intel_overlay_reset(display);
/* sanitize uC after engine reset */ if (!intel_uc_uses_guc_submission(>->uc))
intel_uc_reset_prepare(>->uc); /* * Next we need to restore the context, but we don't use those * yet either... * * Ring buffer needs to be re-initialized in the KMS case, or if X * was running at the time of the reset (i.e. we weren't VT * switched away).
*/
ret = intel_gt_init_hw(gt); if (ret) {
gt_err(gt, "Failed to initialise HW following reset (%d)\n", ret); goto taint;
}
taint: /* * History tells us that if we cannot reset the GPU now, we * never will. This then impacts everything that is run * subsequently. On failing the reset, we mark the driver * as wedged, preventing further execution on the GPU. * We also want to go one step further and add a taint to the * kernel so that any subsequent faults can be traced back to * this failure. This is important for CI, where if the * GPU/driver fails we would like to reboot and restart testing * rather than continue on into oblivion. For everyone else, * the system should still plod along, but they have been warned!
*/
add_taint_for_CI(gt->i915, TAINT_WARN);
error:
__intel_gt_set_wedged(gt); goto finish;
}
/** * intel_gt_reset_all_engines() - Reset all engines in the given gt. * @gt: the GT to reset all engines for. * * This function resets all engines within the given gt. * * Returns: * Zero on success, negative error code on failure.
*/ int intel_gt_reset_all_engines(struct intel_gt *gt)
{ return __intel_gt_reset(gt, ALL_ENGINES);
}
/** * intel_gt_reset_engine() - Reset a specific engine within a gt. * @engine: engine to be reset. * * This function resets the specified engine within a gt. * * Returns: * Zero on success, negative error code on failure.
*/ int intel_gt_reset_engine(struct intel_engine_cs *engine)
{ return __intel_gt_reset(engine->gt, engine->mask);
}
int __intel_engine_reset_bh(struct intel_engine_cs *engine, constchar *msg)
{ struct intel_gt *gt = engine->gt; int ret;
if (intel_engine_uses_guc(engine)) return -ENODEV;
if (!intel_engine_pm_get_if_awake(engine)) return 0;
reset_prepare_engine(engine);
if (msg)
drm_notice(&engine->i915->drm, "Resetting %s for %s\n", engine->name, msg);
i915_increase_reset_engine_count(&engine->i915->gpu_error, engine);
ret = intel_gt_reset_engine(engine); if (ret) { /* If we fail here, we expect to fallback to a global reset */
ENGINE_TRACE(engine, "Failed to reset %s, err: %d\n", engine->name, ret); goto out;
}
/* * The request that caused the hang is stuck on elsp, we know the * active request and can drop it, adjust head to skip the offending * request to resume executing remaining requests in the queue.
*/
__intel_engine_reset(engine, true);
/* * The engine and its registers (and workarounds in case of render) * have been reset to their default values. Follow the init_ring * process to program RING_MODE, HWSP and re-enable submission.
*/
ret = intel_engine_resume(engine);
/** * intel_engine_reset - reset GPU engine to recover from a hang * @engine: engine to reset * @msg: reason for GPU reset; or NULL for no drm_notice() * * Reset a specific GPU engine. Useful if a hang is detected. * Returns zero on successful reset or otherwise an error code. * * Procedure is: * - identifies the request that caused the hang and it is dropped * - reset engine (which will force the engine to idle) * - re-init/configure engine
*/ int intel_engine_reset(struct intel_engine_cs *engine, constchar *msg)
{ int err;
/** * intel_gt_handle_error - handle a gpu error * @gt: the intel_gt * @engine_mask: mask representing engines that are hung * @flags: control flags * @fmt: Error message format string * * Do some basic checking of register state at error time and * dump it to the syslog. Also call i915_capture_error_state() to make * sure we get a record and make it available in debugfs. Fire a uevent * so userspace knows something bad happened (should trigger collection * of a ring dump etc.).
*/ void intel_gt_handle_error(struct intel_gt *gt,
intel_engine_mask_t engine_mask, unsignedlong flags, constchar *fmt, ...)
{ struct intel_engine_cs *engine;
intel_wakeref_t wakeref;
intel_engine_mask_t tmp; char error_msg[80]; char *msg = NULL;
/* * In most cases it's guaranteed that we get here with an RPM * reference held, for example because there is a pending GPU * request that won't finish until the reset is done. This * isn't the case at least when we get here by doing a * simulated reset via debugfs, so get an RPM reference.
*/
wakeref = intel_runtime_pm_get(gt->uncore->rpm);
/* * Try engine reset when available. We fall back to full reset if * single reset fails.
*/ if (!intel_uc_uses_guc_submission(>->uc) &&
intel_has_reset_engine(gt) && !intel_gt_is_wedged(gt)) {
local_bh_disable();
for_each_engine_masked(engine, gt, engine_mask, tmp) {
BUILD_BUG_ON(I915_RESET_BACKOFF >= I915_RESET_ENGINE); if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
>->reset.flags)) continue;
if (__intel_engine_reset_bh(engine, msg) == 0)
engine_mask &= ~engine->mask;
/* Full reset needs the mutex, stop any other user trying to do so. */ if (test_and_set_bit(I915_RESET_BACKOFF, >->reset.flags)) {
wait_event(gt->reset.queue,
!test_bit(I915_RESET_BACKOFF, >->reset.flags)); goto out; /* piggy-back on the other reset */
}
/* Make sure i915_reset_trylock() sees the I915_RESET_BACKOFF */
synchronize_rcu_expedited();
/* * Prevent any other reset-engine attempt. We don't do this for GuC * submission the GuC owns the per-engine reset, not the i915.
*/ if (!intel_uc_uses_guc_submission(>->uc)) {
for_each_engine(engine, gt, tmp) { while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
>->reset.flags))
wait_on_bit(>->reset.flags,
I915_RESET_ENGINE + engine->id,
TASK_UNINTERRUPTIBLE);
}
}
/* Flush everyone using a resource about to be clobbered */
synchronize_srcu_expedited(>->reset.backoff_srcu);
int intel_gt_terminally_wedged(struct intel_gt *gt)
{
might_sleep();
if (!intel_gt_is_wedged(gt)) return 0;
if (intel_gt_has_unrecoverable_error(gt)) return -EIO;
/* Reset still in progress? Maybe we will recover? */ if (wait_event_interruptible(gt->reset.queue,
!test_bit(I915_RESET_BACKOFF,
>->reset.flags))) return -EINTR;
/* * While undesirable to wait inside the shrinker, complain anyway. * * If we have to wait during shrinking, we guarantee forward progress * by forcing the reset. Therefore during the reset we must not * re-enter the shrinker. By declaring that we take the reset mutex * within the shrinker, we forbid ourselves from performing any * fs-reclaim or taking related locks during reset.
*/
i915_gem_shrinker_taints_mutex(gt->i915, >->reset.mutex);
/* no GPU until we are ready! */
__set_bit(I915_WEDGED, >->reset.flags);
}
/* * Wa_22011802037 requires that we (or the GuC) ensure that no command * streamers are executing MI_FORCE_WAKE while an engine reset is initiated.
*/ bool intel_engine_reset_needs_wa_22011802037(struct intel_gt *gt)
{ if (GRAPHICS_VER(gt->i915) < 11) returnfalse;
if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0)) returntrue;
if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70)) returnfalse;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.