Skip to content

Commit 6ef0e3e

Browse files
NitinGoteAndi Shyti
authored andcommitted
drm/i915/gt: Retry RING_HEAD reset until it get sticks
we see an issue where resets fails because the engine resumes from an incorrect RING_HEAD. Since the RING_HEAD doesn't point to the remaining requests to re-run, but may instead point into the uninitialised portion of the ring, the GPU may be then fed invalid instructions from a privileged context, oft pushing the GPU into an unrecoverable hang. If at first the write doesn't succeed, try, try again. v2: Avoid unnecessary timeout macro (Andi) v3: Correct comment format (Andi) v4: Make it generic for all platform as it won't impact (Chris) Link: https://gitlab.freedesktop.org/drm/intel/-/issues/5432 Testcase: igt/i915_selftest/hangcheck Signed-off-by: Chris Wilson <[email protected]> Signed-off-by: Nitin Gote <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Andi Shyti <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e217f22 commit 6ef0e3e

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

drivers/gpu/drm/i915/gt/intel_ring_submission.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static bool stop_ring(struct intel_engine_cs *engine)
192192
static int xcs_resume(struct intel_engine_cs *engine)
193193
{
194194
struct intel_ring *ring = engine->legacy.ring;
195+
ktime_t kt;
195196

196197
ENGINE_TRACE(engine, "ring:{HEAD:%04x, TAIL:%04x}\n",
197198
ring->head, ring->tail);
@@ -230,9 +231,27 @@ static int xcs_resume(struct intel_engine_cs *engine)
230231
set_pp_dir(engine);
231232

232233
/* First wake the ring up to an empty/idle ring */
233-
ENGINE_WRITE_FW(engine, RING_HEAD, ring->head);
234+
for ((kt) = ktime_get() + (2 * NSEC_PER_MSEC);
235+
ktime_before(ktime_get(), (kt)); cpu_relax()) {
236+
/*
237+
* In case of resets fails because engine resumes from
238+
* incorrect RING_HEAD and then GPU may be then fed
239+
* to invalid instrcutions, which may lead to unrecoverable
240+
* hang. So at first write doesn't succeed then try again.
241+
*/
242+
ENGINE_WRITE_FW(engine, RING_HEAD, ring->head);
243+
if (ENGINE_READ_FW(engine, RING_HEAD) == ring->head)
244+
break;
245+
}
246+
234247
ENGINE_WRITE_FW(engine, RING_TAIL, ring->head);
235-
ENGINE_POSTING_READ(engine, RING_TAIL);
248+
if (ENGINE_READ_FW(engine, RING_HEAD) != ENGINE_READ_FW(engine, RING_TAIL)) {
249+
ENGINE_TRACE(engine, "failed to reset empty ring: [%x, %x]: %x\n",
250+
ENGINE_READ_FW(engine, RING_HEAD),
251+
ENGINE_READ_FW(engine, RING_TAIL),
252+
ring->head);
253+
goto err;
254+
}
236255

237256
ENGINE_WRITE_FW(engine, RING_CTL,
238257
RING_CTL_SIZE(ring->size) | RING_VALID);
@@ -241,12 +260,16 @@ static int xcs_resume(struct intel_engine_cs *engine)
241260
if (__intel_wait_for_register_fw(engine->uncore,
242261
RING_CTL(engine->mmio_base),
243262
RING_VALID, RING_VALID,
244-
5000, 0, NULL))
263+
5000, 0, NULL)) {
264+
ENGINE_TRACE(engine, "failed to restart\n");
245265
goto err;
266+
}
246267

247-
if (GRAPHICS_VER(engine->i915) > 2)
268+
if (GRAPHICS_VER(engine->i915) > 2) {
248269
ENGINE_WRITE_FW(engine,
249270
RING_MI_MODE, _MASKED_BIT_DISABLE(STOP_RING));
271+
ENGINE_POSTING_READ(engine, RING_MI_MODE);
272+
}
250273

251274
/* Now awake, let it get started */
252275
if (ring->tail != ring->head) {

0 commit comments

Comments
 (0)