Skip to content

Commit 651dabe

Browse files
icklerodrigovivi
authored andcommitted
drm/i915/gem: Always test execution status on closing the context
Verify that if a context is active at the time it is closed, that it is either persistent and preemptible (with hangcheck running) or it shall be removed from execution. Fixes: 9a40bdd ("drm/i915/gt: Expose heartbeat interval via sysfs") Testcase: igt/gem_ctx_persistence/heartbeat-close Signed-off-by: Chris Wilson <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: <[email protected]> # v5.7+ Reviewed-by: Tvrtko Ursulin <[email protected]> Acked-by: Joonas Lahtinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit d3bb2f9) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent ca65fc0 commit 651dabe

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -390,24 +390,6 @@ __context_engines_static(const struct i915_gem_context *ctx)
390390
return rcu_dereference_protected(ctx->engines, true);
391391
}
392392

393-
static bool __reset_engine(struct intel_engine_cs *engine)
394-
{
395-
struct intel_gt *gt = engine->gt;
396-
bool success = false;
397-
398-
if (!intel_has_reset_engine(gt))
399-
return false;
400-
401-
if (!test_and_set_bit(I915_RESET_ENGINE + engine->id,
402-
&gt->reset.flags)) {
403-
success = intel_engine_reset(engine, NULL) == 0;
404-
clear_and_wake_up_bit(I915_RESET_ENGINE + engine->id,
405-
&gt->reset.flags);
406-
}
407-
408-
return success;
409-
}
410-
411393
static void __reset_context(struct i915_gem_context *ctx,
412394
struct intel_engine_cs *engine)
413395
{
@@ -431,12 +413,7 @@ static bool __cancel_engine(struct intel_engine_cs *engine)
431413
* kill the banned context, we fallback to doing a local reset
432414
* instead.
433415
*/
434-
if (IS_ACTIVE(CONFIG_DRM_I915_PREEMPT_TIMEOUT) &&
435-
!intel_engine_pulse(engine))
436-
return true;
437-
438-
/* If we are unable to send a pulse, try resetting this engine. */
439-
return __reset_engine(engine);
416+
return intel_engine_pulse(engine) == 0;
440417
}
441418

442419
static bool
@@ -506,7 +483,7 @@ static struct intel_engine_cs *active_engine(struct intel_context *ce)
506483
return engine;
507484
}
508485

509-
static void kill_engines(struct i915_gem_engines *engines)
486+
static void kill_engines(struct i915_gem_engines *engines, bool ban)
510487
{
511488
struct i915_gem_engines_iter it;
512489
struct intel_context *ce;
@@ -521,7 +498,7 @@ static void kill_engines(struct i915_gem_engines *engines)
521498
for_each_gem_engine(ce, engines, it) {
522499
struct intel_engine_cs *engine;
523500

524-
if (intel_context_set_banned(ce))
501+
if (ban && intel_context_set_banned(ce))
525502
continue;
526503

527504
/*
@@ -534,7 +511,7 @@ static void kill_engines(struct i915_gem_engines *engines)
534511
engine = active_engine(ce);
535512

536513
/* First attempt to gracefully cancel the context */
537-
if (engine && !__cancel_engine(engine))
514+
if (engine && !__cancel_engine(engine) && ban)
538515
/*
539516
* If we are unable to send a preemptive pulse to bump
540517
* the context from the GPU, we have to resort to a full
@@ -544,8 +521,10 @@ static void kill_engines(struct i915_gem_engines *engines)
544521
}
545522
}
546523

547-
static void kill_stale_engines(struct i915_gem_context *ctx)
524+
static void kill_context(struct i915_gem_context *ctx)
548525
{
526+
bool ban = (!i915_gem_context_is_persistent(ctx) ||
527+
!ctx->i915->params.enable_hangcheck);
549528
struct i915_gem_engines *pos, *next;
550529

551530
spin_lock_irq(&ctx->stale.lock);
@@ -558,7 +537,7 @@ static void kill_stale_engines(struct i915_gem_context *ctx)
558537

559538
spin_unlock_irq(&ctx->stale.lock);
560539

561-
kill_engines(pos);
540+
kill_engines(pos, ban);
562541

563542
spin_lock_irq(&ctx->stale.lock);
564543
GEM_BUG_ON(i915_sw_fence_signaled(&pos->fence));
@@ -570,11 +549,6 @@ static void kill_stale_engines(struct i915_gem_context *ctx)
570549
spin_unlock_irq(&ctx->stale.lock);
571550
}
572551

573-
static void kill_context(struct i915_gem_context *ctx)
574-
{
575-
kill_stale_engines(ctx);
576-
}
577-
578552
static void engines_idle_release(struct i915_gem_context *ctx,
579553
struct i915_gem_engines *engines)
580554
{
@@ -609,7 +583,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,
609583

610584
kill:
611585
if (list_empty(&engines->link)) /* raced, already closed */
612-
kill_engines(engines);
586+
kill_engines(engines, true);
613587

614588
i915_sw_fence_commit(&engines->fence);
615589
}
@@ -667,9 +641,7 @@ static void context_close(struct i915_gem_context *ctx)
667641
* case we opt to forcibly kill off all remaining requests on
668642
* context close.
669643
*/
670-
if (!i915_gem_context_is_persistent(ctx) ||
671-
!ctx->i915->params.enable_hangcheck)
672-
kill_context(ctx);
644+
kill_context(ctx);
673645

674646
i915_gem_context_put(ctx);
675647
}

0 commit comments

Comments
 (0)