drm/i915/guc: Fix requests of a banned context never completing
Subsystems (2)
v3 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 (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). v3 changes only text.
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.
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).
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 or v2 (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 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.51.1
PATCH v3 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, as guc_cancel_context_requests() does.
Found with the help of Claude Code.
---
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).
.../gpu/drm/i915/gt/uc/intel_guc_submission.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16 -1
@@ -709,7 +709,22 @@ 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; + +/* +* Only the last merged request is passed in. Once the context +* is off the HW, complete all of them (rq included). +*/ +spin_lock (&ce->guc_state.lock); +if (!context_enabled (ce) && !context_pending_enable (ce) && + !context_pending_disable (ce)) { +list_for_each_entry (pos, &ce->guc_state.requests, sched.link) +i915_request_put (i915_request_mark_eio (pos)); + }else { +i915_request_put (i915_request_mark_eio (rq)); + } +spin_unlock (&ce->guc_state.lock); +intel_engine_signal_breadcrumbs (ce->engine);return 0 ; }
Signature · 1 line
2.51.1
PATCH v3 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.
---
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
@@ -3183,7 +3183,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
[email protected]
AI reviewRe: [PATCH v3 1/2] drm/i915/guc: Complete all requests of a non-schedulable context
In reply to Javier MVThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/i915/guc: out-of-order completion and missed cancel in __guc_add_request() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/i915/guc: out-of-order completion and missed cancel in __guc_add_request()
--
commit 8c211d88b3b41f45abe7f135b95dfbf93ce1feef
Author: Javier MV <[email protected]>
drm/i915/guc: Complete all requests of a non-schedulable context
This commit completes all queued requests on ce->guc_state.requests in __guc_add_request() when a non-schedulable context is off the hardware.
Quoted 18 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9
-1@@ -709,7 +709,22 @@ 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; + +/* +* Only the last merged request is passed in. Once the context +* is off the HW, complete all of them (rq included). +*/ +spin_lock (&ce->guc_state.lock); +if (!context_enabled (ce) && !context_pending_enable (ce) && + !context_pending_disable (ce)) {
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static int __guc_add_request(struct intel_guc *guc, struct i915_request *rq) · line 730
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+list_for_each_entry (pos, &ce->guc_state.requests, sched.link) +i915_request_put (i915_request_mark_eio (pos)); + }else { +i915_request_put (i915_request_mark_eio (rq)); + } +spin_unlock (&ce->guc_state.lock); +intel_engine_signal_breadcrumbs (ce->engine);return 0 ; }
[Severity: High]
Does the else branch complete rq out of order while earlier merged or in-flight requests on the same context are still incomplete?
Both guc_dequeue_one_context() and guc_bypass_tasklet_submit() call __i915_request_submit() -> add_to_context() on every merged request before calling guc_add_request(), placing them in sequence order on ce->guc_state.requests and ce->timeline->requests. When the context is still enabled or pending disable, those earlier requests remain incomplete until the schedule-disable G2H calls guc_cancel_context_requests(). Marking only the tail request rq complete here violates timeline ordering:i915_request_retire_upto() hits GEM_BUG_ON(!i915_request_completed(tmp)) on the older requests, and __i915_active_fence_set() retires vma->active and ce->active callbacks attached to rq while earlier requests are still running on the GPU.
Checking !context_pending_enable(ce) can also leave the earlier merged requests uncompleted forever. If __guc_reset_context() clears SCHED_STATE_ENABLED while SCHED_STATE_PENDING_ENABLE is still set, guc_context_revoke() sees !context_enabled(ce) && !context_pending_disable(ce) and does not send a schedule-disable H2G, while intel_guc_sched_done_process_msg() only clears SCHED_STATE_PENDING_ENABLE when the pending-enable G2H arrives without calling guc_cancel_context_requests().
Matching guc_context_revoke() by checking !context_enabled(ce) && !context_pending_disable(ce) and dropping the else branch would avoid both issues, since rq is already on ce->guc_state.requests and will be completed in order by guc_cancel_context_requests() once the schedule-disable completes.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Patchwork
CI✗ LGCI.VerificationFailed: failure for drm/i915/guc: Fix requests of a banned context never completing (rev3)
In reply to Javier MV== Series Details ==
== Series Details ==
Series: drm/i915/guc: Fix requests of a banned context never completing (rev3)
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/193335/ (on built-in)