drm/i915/guc: Fix requests of a banned context never completing
Subsystems (2)
v4 cover drm/i915/guc: Fix requests of a banned context never completing
From: Javier MV <[email protected]>
On ADL-P with GuC submission, a GuC context reset during a request watchdog cancellation can leave the context's requests incomplete forever: the client hangs on its fences and, once killed, its buffers stay pinned until reboot (7.5 GB here). Reported in
https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15301.
Sequence (llama.cpp Vulkan compute, request_timeout_ms=2000, preempt_timeout_ms=7500):
1. The watchdog blocks the context to cancel a request.
2. GuC can't preempt the compute work and resets the context. i915 bans it and unwinds its requests.
3. The late schedule disable done clears SCHED_STATE_BANNED, and unblock re-enables the banned context.
4. GuC resets it again at the first preemption. That reset is ignored, and after a full GT reset the dequeue completes only the last of its merged requests.
Patch 1 completes all of them once the context is off the HW. Patch 2 stops unblock from re-enabling a non-schedulable context.
Tested on i5-1235U (8086:46a8), GuC 70.36.0, Ubuntu 7.0.0-42 and -43 (the touched code is identical in mainline). Without the series: 5 hangs in 17 runs, one leaked. With v2: 30 runs, 4 hangs, all contained (VK_ERROR_DEVICE_LOST, nothing pinned). With v4: 30 runs, no regressions, but no hang reproduced.
I can reproduce this (a hang every 10 to 30 runs) and test other approaches. Logs and error states are in the issue.
I have an extra patch that cancels the requests when a banned context gets another reset notification. It never ran in my tests, so I left it out.
Written with Claude Code (Opus 5.5). I ran the tests and reviewed the patches.
v4: patch 1 uses the off-HW test of guc_context_revoke() and leaves the
other cases to the schedule disable done handler (Sashiko).
v3: shorter commit messages and comments (Rodrigo), rebased on v7.4-rc3.
v2: fix a use-after-free in patch 1; patch 2 also covers exiting contexts
(Sashiko).
v3: https://lore.kernel.org/intel-gfx/[email protected]/
v2: https://lore.kernel.org/intel-gfx/[email protected]/
v1: https://lore.kernel.org/intel-gfx/[email protected]/
Patchwork CI didn't run on v1 to v3 (my address isn't on the CI allowlist). If someone can trigger it for this version, I'd appreciate it.
Javier MV (2):
drm/i915/guc: Complete all requests of a non-schedulable context drm/i915/guc: Don't unblock a non-schedulable context
.../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.51.1
PATCH v4 1/2 drm/i915/guc: Complete all requests of a non-schedulable context
From: Javier MV <[email protected]>
guc_dequeue_one_context() merges the queued requests of a context and passes only the last one to __guc_add_request(), which marks only that one complete when the context is banned or exiting. The earlier ones are on ce->guc_state.requests and need the context to run to signal their breadcrumbs. After a full GT reset the context is unregistered and never runs again, so they never complete and their objects stay pinned. Seen on ADL-P after a GuC context reset of a Vulkan compute job: the client waited on its fences forever, and 7.5 GB stayed pinned after it was killed.
Complete every request on the list once the context is off the HW, with the same test as guc_context_revoke(). Otherwise leave them to the schedule disable done handler, which cancels the whole list in order.
Found with the help of Claude Code.
---
v4:
- Same off-HW test as guc_context_revoke(), and no else branch:
completing rq alone was out of order, and a pending enable left by a reset kept the earlier requests from completing (Sashiko).
v3:
- Shorter commit message and comment (Rodrigo).
v2:
- Complete rq on its own only when the loop doesn't run, under the lock. v1 completed it again after the unlock, when the loop had already completed it and it could have been retired and freed (Sashiko).
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +13 -1
@@ -709,7 +709,19 @@ static int __guc_add_request(struct intel_guc *guc, struct i915_request *rq)* request resubmitted after the context was banned. */ if (unlikely (!intel_context_is_schedulable (ce))) { -i915_request_put (i915_request_mark_eio (rq)); +struct i915_request *pos; + +/* +* rq and the requests merged before it are on +* ce->guc_state.requests. If the context is off the HW, complete +* them all here; otherwise the schedule disable done handler will. +*/ +spin_lock (&ce->guc_state.lock); +if (!context_enabled (ce) && !context_pending_disable (ce)) +list_for_each_entry (pos, &ce->guc_state.requests, sched.link) +i915_request_put (i915_request_mark_eio (pos)); +spin_unlock (&ce->guc_state.lock); +intel_engine_signal_breadcrumbs (ce->engine);return 0 ; }
Signature · 1 line
2.51.1
PATCH v4 2/2 drm/i915/guc: Don't unblock a non-schedulable context
In reply to Javier MVFrom: Javier MV <[email protected]>
If a context is banned or revoked while guc_context_cancel_request() has it blocked, guc_context_revoke() finds the block's schedule disable pending and leaves the cancellation to its done handler, which clears SCHED_STATE_BANNED. guc_context_unblock() then enables scheduling again. GuC resets the context at the first preemption (1 ms timeout), the second reset is ignored, and on ADL-P this ended in a full GT reset.
Also check intel_context_is_schedulable(), which stays false.
Found with the help of Claude Code.
---
v4:
- No changes.
v3:
- Shorter commit message and comment (Rodrigo).
v2:
- Check !intel_context_is_schedulable() instead of intel_context_is_banned(): revoke takes the same path for exiting contexts (Sashiko).
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2 -0
@@ -3180,7 +3180,9 @@ static bool context_cant_unblock(struct intel_context *ce) {lockdep_assert_held (&ce->guc_state.lock); +/* The sched disable done handler clears SCHED_STATE_BANNED */ return (ce->guc_state.sched_state &SCHED_STATE_NO_UNBLOCK ) || + !intel_context_is_schedulable (ce) ||context_guc_id_invalid (ce) || !ctx_id_mapped (ce_to_guc (ce), ce->guc_id.id) || !intel_context_is_pinned (ce);
Signature · 1 line
2.51.1
Patchwork
CI✗ LGCI.VerificationFailed: failure for drm/i915/guc: Fix requests of a banned context never completing (rev4)
In reply to Javier MV== Series Details ==
== Series Details ==
Series: drm/i915/guc: Fix requests of a banned context never completing (rev4)
URL : https://patchwork.freedesktop.org/series/178201/
State : failure
== Summary ==
Series author address '[email protected]' is not on the allowlist, which prevents CI from being automatically triggered. If you want CI to run for this series, ask Patchwork project owners to click 'retest' on the series in Patchwork. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/193495/ (on built-in)