* [PATCH v5 0/4] FD close cleanup for XE
@ 2026-11-19 0:04 Daniel Charles
2026-11-19 0:04 ` [PATCH v5 1/4] drm/xe: Read scheduler message opcode under lock Daniel Charles
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Daniel Charles @ 2026-11-19 0:04 UTC (permalink / raw)
To: intel-xe; +Cc: x.wang, jia.yao, matthew.brost, jonathan.cavitt, Daniel Charles
On FD close, serialized TDR cleanup can lag behind VM teardown. GuC
may continue scheduling contexts while their page tables are being
torn down, leading to CAT errors and repeated engine resets.
This series keeps the early scheduling disable outside the serialized
TDR path and makes FD close wait before releasing queue references.
FD close first kills all queues, then waits for each queue before
dropping its reference.
Changes since v4:
- Patch 1 is unchanged.
- Patch 2 adds per-queue scheduling-state waitqueues as a standalone
prerequisite. SCHED_DONE wakes waiters on the affected queue after
updating its state, without waking unrelated CT waiters.
- Patch 3 restricts early group DISABLE to the primary's own KILL.
It also allows pending disable on a killed queue in run_job and
avoids issuing a second DISABLE from TDR if KILL already disabled
scheduling.
- Patch 4 requires a KILL acknowledgement before accepting a disabled
scheduling state, so FD close cannot finish the wait before KILL
runs. Multi-queue members wait for their primary's acknowledgement
and scheduling state on its per-queue waitqueue, replacing the
shared kill_wq from v4.
v4: https://patchwork.freedesktop.org/series/175996/#rev4
Daniel Charles (2):
drm/xe: Notify scheduling-state waiters per exec queue
drm/xe: Synchronously wait for queue kill on FD close
Matthew Brost (2):
drm/xe: Read scheduler message opcode under lock
drm/xe: Disable scheduling early on FD close to avoid CAT error
cascade
drivers/gpu/drm/xe/xe_device.c | 5 +
drivers/gpu/drm/xe/xe_exec_queue.c | 13 ++
drivers/gpu/drm/xe/xe_exec_queue.h | 1 +
drivers/gpu/drm/xe/xe_exec_queue_types.h | 2 +
drivers/gpu/drm/xe/xe_gpu_scheduler.c | 13 +-
drivers/gpu/drm/xe/xe_gpu_scheduler_types.h | 2 +-
drivers/gpu/drm/xe/xe_gt_sriov_vf.c | 1 +
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 10 +-
drivers/gpu/drm/xe/xe_guc_submit.c | 180 +++++++++++++++++--
drivers/gpu/drm/xe/xe_guc_submit.h | 1 +
10 files changed, 206 insertions(+), 22 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v5 1/4] drm/xe: Read scheduler message opcode under lock
2026-11-19 0:04 [PATCH v5 0/4] FD close cleanup for XE Daniel Charles
@ 2026-11-19 0:04 ` Daniel Charles
2026-11-19 0:04 ` [PATCH v5 2/4] drm/xe: Notify scheduling-state waiters per exec queue Daniel Charles
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Charles @ 2026-11-19 0:04 UTC (permalink / raw)
To: intel-xe; +Cc: x.wang, jia.yao, matthew.brost, jonathan.cavitt, stable
From: Matthew Brost <matthew.brost@intel.com>
For static scheduler messages, the opcode is only guaranteed to remain
stable while the message is on the pending message list. Read the opcode
under the message lock before removing the message from the pending list,
and pass it through the processing pipeline.
Fixes: ff796870f5dd ("drm/xe/guc: rework exec queue teardown PM/unplug handling")
Cc: stable@kernel.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_gpu_scheduler.c | 13 +++++++++----
drivers/gpu/drm/xe/xe_gpu_scheduler_types.h | 2 +-
drivers/gpu/drm/xe/xe_guc_submit.c | 7 ++++---
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_gpu_scheduler.c b/drivers/gpu/drm/xe/xe_gpu_scheduler.c
index 9c8004d5dd915..d656db758cb3c 100644
--- a/drivers/gpu/drm/xe/xe_gpu_scheduler.c
+++ b/drivers/gpu/drm/xe/xe_gpu_scheduler.c
@@ -23,15 +23,19 @@ static void xe_sched_process_msg_queue_if_ready(struct xe_gpu_scheduler *sched)
}
static struct xe_sched_msg *
-xe_sched_get_msg(struct xe_gpu_scheduler *sched)
+xe_sched_get_msg(struct xe_gpu_scheduler *sched, unsigned int *opcode)
{
struct xe_sched_msg *msg;
xe_sched_msg_lock(sched);
msg = list_first_entry_or_null(&sched->msgs,
struct xe_sched_msg, link);
- if (msg)
+ if (msg) {
+ /* The opcode is only stable under lock for static messages */
+ *opcode = msg->opcode;
+
list_del_init(&msg->link);
+ }
xe_sched_msg_unlock(sched);
return msg;
@@ -42,13 +46,14 @@ static void xe_sched_process_msg_work(struct work_struct *w)
struct xe_gpu_scheduler *sched =
container_of(w, struct xe_gpu_scheduler, work_process_msg);
struct xe_sched_msg *msg;
+ unsigned int opcode;
if (drm_sched_is_stopped(&sched->base))
return;
- msg = xe_sched_get_msg(sched);
+ msg = xe_sched_get_msg(sched, &opcode);
if (msg) {
- sched->ops->process_msg(msg);
+ sched->ops->process_msg(msg, opcode);
xe_sched_process_msg_queue_if_ready(sched);
}
diff --git a/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h b/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h
index 78ef2e8ded4f3..163a0d85e3cb9 100644
--- a/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h
+++ b/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h
@@ -34,7 +34,7 @@ struct xe_sched_backend_ops {
* @process_msg: Process a message. Allowed to block, it is this
* function's responsibility to free message if dynamically allocated.
*/
- void (*process_msg)(struct xe_sched_msg *msg);
+ void (*process_msg)(struct xe_sched_msg *msg, unsigned int opcode);
};
/**
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
index 7ce73489c35fc..c4ef3e9bf7a18 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -2056,16 +2056,17 @@ static void __guc_exec_queue_process_msg_cgp_sync(struct xe_sched_msg *msg,
#define MSG_HEAD BIT(9)
#define MSG_PM_REF BIT(10)
-static void guc_exec_queue_process_msg(struct xe_sched_msg *msg)
+static void guc_exec_queue_process_msg(struct xe_sched_msg *msg,
+ unsigned int opcode)
{
struct xe_device *xe = guc_to_xe(exec_queue_to_guc(msg->private_data));
int idx;
- bool pm_ref = !!(msg->opcode & MSG_PM_REF);
+ bool pm_ref = !!(opcode & MSG_PM_REF);
bool bound = drm_dev_enter(&xe->drm, &idx);
trace_xe_sched_msg_recv(msg);
- switch (msg->opcode & OPCODE_MASK) {
+ switch (opcode & OPCODE_MASK) {
case CLEANUP:
__guc_exec_queue_process_msg_cleanup(msg, bound);
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 2/4] drm/xe: Notify scheduling-state waiters per exec queue
2026-11-19 0:04 [PATCH v5 0/4] FD close cleanup for XE Daniel Charles
2026-11-19 0:04 ` [PATCH v5 1/4] drm/xe: Read scheduler message opcode under lock Daniel Charles
@ 2026-11-19 0:04 ` Daniel Charles
2026-11-19 0:04 ` [PATCH v5 3/4] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade Daniel Charles
2026-11-19 0:04 ` [PATCH v5 4/4] drm/xe: Synchronously wait for queue kill on FD close Daniel Charles
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Charles @ 2026-11-19 0:04 UTC (permalink / raw)
To: intel-xe; +Cc: x.wang, jia.yao, matthew.brost, jonathan.cavitt, Daniel Charles
Wait for GuC scheduling state changes on the exec queue whose state is
being inspected. Wake its waiters after processing SCHED_DONE instead
of relying on a CT interrupt that can wake them before state changes.
Keep the existing CT notifications for their remaining users.
On submission stop, wedge and VF recovery, notify published queues.
Hold the lookup XArray lock with interrupts saved to prevent queue
removal during the walk, and skip parallel queue aliases.
v5: New prerequisite for early KILL and FD-close waits.
Signed-off-by: Daniel Charles <daniel.charles@intel.com>
---
drivers/gpu/drm/xe/xe_gt_sriov_vf.c | 1 +
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 2 +
drivers/gpu/drm/xe/xe_guc_submit.c | 39 +++++++++++++++++---
drivers/gpu/drm/xe/xe_guc_submit.h | 1 +
4 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_vf.c b/drivers/gpu/drm/xe/xe_gt_sriov_vf.c
index 37899fcf5b227..fc853c195fdb8 100644
--- a/drivers/gpu/drm/xe/xe_gt_sriov_vf.c
+++ b/drivers/gpu/drm/xe/xe_gt_sriov_vf.c
@@ -910,6 +910,7 @@ static void vf_start_migration_recovery(struct xe_gt *gt)
smp_wmb(); /* Ensure above writes visible before wake */
xe_guc_ct_wake_waiters(>->uc.guc.ct);
+ xe_guc_submit_wake_state_waiters(>->uc.guc);
started = queue_work(gt->ordered_wq, >->sriov.vf.migration.worker);
xe_gt_sriov_info(gt, "VF migration recovery %s\n", started ?
diff --git a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
index 74b711abe2572..2b1a40e288f17 100644
--- a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
+++ b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
@@ -52,6 +52,8 @@ struct xe_guc_exec_queue {
u16 id;
/** @suspend_wait: wait queue used to wait on pending suspends */
wait_queue_head_t suspend_wait;
+ /** @state_wq: wait queue for scheduling enable/disable state changes */
+ wait_queue_head_t state_wq;
/**
* @suspend_pending: a suspend of the exec_queue is pending.
* Protected by @sched.msg_lock.
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
index c4ef3e9bf7a18..a3c2abb9254ff 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -551,6 +551,30 @@ static bool vf_recovery(struct xe_guc *guc)
return xe_gt_recovery_pending(guc_to_gt(guc));
}
+/**
+ * xe_guc_submit_wake_state_waiters() - Wake all scheduling-state waiters
+ * @guc: the &xe_guc
+ *
+ * Notify per-queue waiters when a GuC-wide stop or recovery changes their
+ * wait conditions. May be called from interrupt context.
+ */
+void xe_guc_submit_wake_state_waiters(struct xe_guc *guc)
+{
+ struct xarray *lookup = &guc->submission_state.exec_queue_lookup;
+ struct xe_exec_queue *q;
+ unsigned long index, flags;
+
+ if (!guc->submission_state.initialized)
+ return;
+
+ /* Prevent removal and freeing of queues while waking their waiters. */
+ xa_lock_irqsave(lookup, flags);
+ xa_for_each(lookup, index, q)
+ if (q->guc->id == index)
+ wake_up_all(&q->guc->state_wq);
+ xa_unlock_irqrestore(lookup, flags);
+}
+
static void xe_guc_exec_queue_trigger_cleanup(struct xe_exec_queue *q)
{
struct xe_guc *guc = exec_queue_to_guc(q);
@@ -1372,7 +1396,7 @@ static void disable_scheduling_deregister(struct xe_guc *guc,
set_min_preemption_timeout(guc, q);
smp_rmb();
- ret = wait_event_timeout(guc->ct.wq,
+ ret = wait_event_timeout(q->guc->state_wq,
(!exec_queue_pending_enable(q) &&
!exec_queue_pending_disable(q)) ||
xe_guc_read_stopped(guc) ||
@@ -1433,6 +1457,7 @@ void xe_guc_submit_wedge(struct xe_guc *guc)
if (xe_exec_queue_get_unless_zero(q))
set_exec_queue_wedged(q);
mutex_unlock(&guc->submission_state.lock);
+ xe_guc_submit_wake_state_waiters(guc);
} else {
/* Forcefully kill any remaining exec queues, signal fences */
guc_submit_reset_prepare(guc);
@@ -1537,7 +1562,7 @@ static void enable_scheduling(struct xe_exec_queue *q)
xe_guc_ct_send(&guc->ct, action, ARRAY_SIZE(action),
G2H_LEN_DW_SCHED_CONTEXT_MODE_SET, 1);
- ret = wait_event_timeout(guc->ct.wq,
+ ret = wait_event_timeout(q->guc->state_wq,
!exec_queue_pending_enable(q) ||
xe_guc_read_stopped(guc) ||
vf_recovery(guc), HZ * 5);
@@ -1683,7 +1708,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
* Wait for any pending G2H to flush out before
* modifying state
*/
- ret = wait_event_timeout(guc->ct.wq,
+ ret = wait_event_timeout(primary->guc->state_wq,
(!exec_queue_pending_enable(primary) &&
!exec_queue_pending_disable(primary)) ||
xe_guc_read_stopped(guc) ||
@@ -1705,7 +1730,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
* lost. If this occurs, trigger a GT reset to recover.
*/
smp_rmb();
- ret = wait_event_timeout(guc->ct.wq,
+ ret = wait_event_timeout(primary->guc->state_wq,
!xe_uc_fw_is_running(&guc->fw) ||
!exec_queue_pending_disable(primary) ||
xe_guc_read_stopped(guc) ||
@@ -1980,7 +2005,7 @@ static void __guc_exec_queue_process_msg_suspend(struct xe_sched_msg *msg,
if (guc_exec_queue_allowed_to_change_state(q) && !exec_queue_suspended(q) &&
exec_queue_enabled(q) && bound) {
- wait_event(guc->ct.wq, vf_recovery(guc) ||
+ wait_event(q->guc->state_wq, vf_recovery(guc) ||
((q->guc->resume_time != RESUME_PENDING ||
xe_guc_read_stopped(guc)) && !exec_queue_pending_disable(q)));
@@ -2129,6 +2154,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
ge->q = q;
init_rcu_head(&ge->rcu);
init_waitqueue_head(&ge->suspend_wait);
+ init_waitqueue_head(&ge->state_wq);
for (i = 0; i < MAX_STATIC_MSG_TYPE; ++i)
INIT_LIST_HEAD(&ge->static_msgs[i].link);
@@ -2787,6 +2813,7 @@ static int guc_submit_reset_prepare(struct xe_guc *guc)
ret = atomic_fetch_or(1, &guc->submission_state.stopped);
smp_wmb();
wake_up_all(&guc->ct.wq);
+ xe_guc_submit_wake_state_waiters(guc);
return ret;
}
@@ -3350,6 +3377,7 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q,
clear_exec_queue_pending_enable(q);
smp_wmb();
wake_up_all(&guc->ct.wq);
+ wake_up_all(&q->guc->state_wq);
} else {
bool was_pending;
@@ -3385,6 +3413,7 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q,
clear_exec_queue_pending_disable(q);
}
}
+ wake_up_all(&q->guc->state_wq);
}
}
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.h b/drivers/gpu/drm/xe/xe_guc_submit.h
index 29abf07d8f041..0749f7c400b63 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.h
+++ b/drivers/gpu/drm/xe/xe_guc_submit.h
@@ -28,6 +28,7 @@ void xe_guc_submit_unpause(struct xe_guc *guc);
void xe_guc_submit_unpause_vf(struct xe_guc *guc);
void xe_guc_submit_unpause_prepare_vf(struct xe_guc *guc);
void xe_guc_submit_wedge(struct xe_guc *guc);
+void xe_guc_submit_wake_state_waiters(struct xe_guc *guc);
int xe_guc_read_stopped(struct xe_guc *guc);
int xe_guc_sched_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 3/4] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade
2026-11-19 0:04 [PATCH v5 0/4] FD close cleanup for XE Daniel Charles
2026-11-19 0:04 ` [PATCH v5 1/4] drm/xe: Read scheduler message opcode under lock Daniel Charles
2026-11-19 0:04 ` [PATCH v5 2/4] drm/xe: Notify scheduling-state waiters per exec queue Daniel Charles
@ 2026-11-19 0:04 ` Daniel Charles
2026-11-19 0:04 ` [PATCH v5 4/4] drm/xe: Synchronously wait for queue kill on FD close Daniel Charles
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Charles @ 2026-11-19 0:04 UTC (permalink / raw)
To: intel-xe; +Cc: x.wang, jia.yao, matthew.brost, jonathan.cavitt, Daniel Charles
From: Matthew Brost <matthew.brost@intel.com>
When an FD is closed with many exec queues, teardown relies on the TDR
path to clean up scheduling. However, the TDR handling is serialized
(i.e., only one exec queue is processed at a time), which can make it
too slow compared to GuC scheduling activity.
In this window, GuC may continue to schedule contexts backed by invalid
page tables, leading to a cascade of CAT errors and repeated engine
resets. This significantly increases recovery time and can degrade
system stability.
To mitigate this, eagerly disable scheduling by sending a self-message
outside of the TDR path. This prevents further scheduling of invalid
contexts and avoids the CAT error/reset cascade.
Wait for pending enable/disable operations to complete before sending
the early disable. If the queue has no references when the KILL message
is processed, let the following CLEANUP message handle teardown. Assert
that the queue is referenced when kill is entered.
Early KILL waits on the per-queue scheduling-state waitqueue. Only the
primary can issue the early DISABLE for a multi-queue group. Allow
pending disable on killed queues in run_job and have TDR recheck whether
scheduling is still enabled after waiting for a pending transition.
v5: Updated the description for the waitqueue, primary-only group KILL,
and the run_job and TDR fixes.
Cc: Wang Xin <x.wang@intel.com>
Cc: Jia Yao <jia.yao@intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Daniel Charles <daniel.charles@intel.com>
---
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 2 +-
drivers/gpu/drm/xe/xe_guc_submit.c | 87 ++++++++++++++++++--
2 files changed, 80 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
index 2b1a40e288f17..3f5b1950a248a 100644
--- a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
+++ b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
@@ -36,7 +36,7 @@ struct xe_guc_exec_queue {
* a message needs to sent through the GPU scheduler but memory
* allocations are not allowed.
*/
-#define MAX_STATIC_MSG_TYPE 4
+#define MAX_STATIC_MSG_TYPE 5
struct xe_sched_msg static_msgs[MAX_STATIC_MSG_TYPE];
/** @destroy_async: do final destroy async from this worker */
struct work_struct destroy_async;
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
index a3c2abb9254ff..3010e8ca36b4a 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -1319,12 +1319,16 @@ guc_exec_queue_run_job(struct drm_sched_job *drm_job)
struct xe_sched_job *job = to_xe_sched_job(drm_job);
struct xe_exec_queue *q = job->q;
struct xe_guc *guc = exec_queue_to_guc(q);
+ unsigned int state = atomic_read(&q->guc->state);
bool killed_or_banned_or_wedged_or_error =
- exec_queue_killed_or_banned_or_wedged(q) ||
+ (state & (EXEC_QUEUE_STATE_KILLED | EXEC_QUEUE_STATE_BANNED |
+ EXEC_QUEUE_STATE_WEDGED)) ||
xe_sched_job_is_error(job);
- xe_gt_assert(guc_to_gt(guc), !(exec_queue_destroyed(q) || exec_queue_pending_disable(q)) ||
- exec_queue_banned(q) || exec_queue_suspended(q));
+ xe_gt_assert(guc_to_gt(guc),
+ !(state & (EXEC_QUEUE_STATE_DESTROYED | EXEC_QUEUE_STATE_PENDING_DISABLE)) ||
+ (state & (EXEC_QUEUE_STATE_BANNED | EXEC_QUEUE_STATE_SUSPENDED)) ||
+ ((state & EXEC_QUEUE_STATE_KILLED) && !(state & EXEC_QUEUE_STATE_DESTROYED)));
trace_xe_sched_job_run(job);
@@ -1718,7 +1722,9 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
if (!ret || xe_guc_read_stopped(guc))
goto trigger_reset;
- disable_scheduling(primary, skip_timeout_check);
+ /* KILL may have already disabled scheduling. */
+ if (exec_queue_enabled(primary))
+ disable_scheduling(primary, skip_timeout_check);
}
/*
@@ -2070,12 +2076,44 @@ static void __guc_exec_queue_process_msg_cgp_sync(struct xe_sched_msg *msg,
guc_exec_queue_send_cgp_sync(q, 0);
}
+static void __guc_exec_queue_process_msg_kill(struct xe_sched_msg *msg,
+ bool bound)
+{
+ struct xe_exec_queue *q = msg->private_data;
+ struct xe_guc *guc = exec_queue_to_guc(q);
+ int ret;
+
+ /* At zero references, the queued CLEANUP message handles disabling. */
+ if (!kref_read(&q->refcount) || !bound || exec_queue_wedged(q))
+ return;
+
+ ret = wait_event_timeout(q->guc->state_wq,
+ (!exec_queue_pending_enable(q) &&
+ !exec_queue_pending_disable(q)) ||
+ xe_guc_read_stopped(guc) ||
+ vf_recovery(guc), HZ * 5);
+ if (!ret && !vf_recovery(guc)) {
+ xe_gt_warn(q->gt, "Pending enable/disable failed to respond on kill, guc_id=%d\n",
+ q->guc->id);
+ xe_gt_reset_async(q->gt);
+ xe_sched_tdr_queue_imm(&q->guc->sched);
+ return;
+ }
+
+ if (xe_guc_read_stopped(guc) || vf_recovery(guc))
+ return;
+
+ if (exec_queue_enabled(q))
+ disable_scheduling(q, true);
+}
+
#define CLEANUP 1 /* Non-zero values to catch uninitialized msg */
#define SET_SCHED_PROPS 2
#define SUSPEND 3
#define RESUME 4
#define SET_MULTI_QUEUE_PRIORITY 5
#define CGP_SYNC_MSG 6
+#define KILL 7
#define OPCODE_MASK 0xf
#define MSG_LOCKED BIT(8)
#define MSG_HEAD BIT(9)
@@ -2110,6 +2148,9 @@ static void guc_exec_queue_process_msg(struct xe_sched_msg *msg,
case CGP_SYNC_MSG:
__guc_exec_queue_process_msg_cgp_sync(msg, bound);
break;
+ case KILL:
+ __guc_exec_queue_process_msg_kill(msg, bound);
+ break;
default:
XE_WARN_ON("Unknown message type");
}
@@ -2237,8 +2278,21 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
return err;
}
+static bool guc_exec_queue_try_add_msg(struct xe_exec_queue *q,
+ struct xe_sched_msg *msg,
+ u32 opcode);
+
+#define STATIC_MSG_CLEANUP 0
+#define STATIC_MSG_SUSPEND 1
+#define STATIC_MSG_RESUME 2
+#define STATIC_MSG_CGP_SYNC 3
+#define STATIC_MSG_KILL 4
static void guc_exec_queue_kill(struct xe_exec_queue *q)
{
+ struct xe_sched_msg *msg = q->guc->static_msgs + STATIC_MSG_KILL;
+
+ xe_gt_assert(q->gt, kref_read(&q->refcount));
+
trace_xe_exec_queue_kill(q);
set_exec_queue_killed(q);
/*
@@ -2248,6 +2302,27 @@ static void guc_exec_queue_kill(struct xe_exec_queue *q)
* stays set until the queue is torn down.
*/
suspend_wait_wake(q);
+
+ /*
+ * We eagerly send a message to ourselves to disable scheduling, as the
+ * TDR is serialized (i.e., only one exec queue is processed at a time).
+ * If an FD is closed with many exec queues, the TDR can be slower than
+ * the GuC scheduling contexts with invalid page tables, creating a
+ * cascade of CAT errors and engine resets, which is quite slow. Avoid
+ * this by immediately disabling scheduling outside of the TDR.
+ *
+ * Only the primary's own KILL may do this for a multi-queue group.
+ * Group jobs share its ordered submit workqueue and the killed primary
+ * prevents later member jobs from submitting to GuC.
+ */
+ if (!xe_exec_queue_is_multi_queue_secondary(q) && !exec_queue_wedged(q)) {
+ struct xe_gpu_scheduler *sched = &q->guc->sched;
+
+ xe_sched_msg_lock(sched);
+ guc_exec_queue_try_add_msg(q, msg, KILL);
+ xe_sched_msg_unlock(sched);
+ }
+
xe_guc_exec_queue_trigger_cleanup(q);
}
@@ -2300,10 +2375,6 @@ static bool guc_exec_queue_try_add_msg(struct xe_exec_queue *q,
return true;
}
-#define STATIC_MSG_CLEANUP 0
-#define STATIC_MSG_SUSPEND 1
-#define STATIC_MSG_RESUME 2
-#define STATIC_MSG_CGP_SYNC 3
static void guc_exec_queue_destroy(struct xe_exec_queue *q)
{
struct xe_sched_msg *msg = q->guc->static_msgs + STATIC_MSG_CLEANUP;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 4/4] drm/xe: Synchronously wait for queue kill on FD close
2026-11-19 0:04 [PATCH v5 0/4] FD close cleanup for XE Daniel Charles
` (2 preceding siblings ...)
2026-11-19 0:04 ` [PATCH v5 3/4] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade Daniel Charles
@ 2026-11-19 0:04 ` Daniel Charles
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Charles @ 2026-11-19 0:04 UTC (permalink / raw)
To: intel-xe; +Cc: x.wang, jia.yao, matthew.brost, jonathan.cavitt, Daniel Charles
GuC may still schedule contexts while FD close tears down their page
tables, producing CAT errors and engine resets. Split FD close into
two passes: kill every queue, then wait for each queue before dropping
its reference.
Require the KILL handler to acknowledge processing before accepting a
single scheduling-state snapshot. For multi-queue groups, all members
wait for the primary KILL acknowledgement and scheduling state on the
primary state waitqueue.
The wait also exits on GuC submission stop, VF recovery, or wedge. On
timeout, request a GT reset asynchronously; the wait does not establish
hardware quiescence on those paths.
v2:
- Bound the wait with a timeout, GT reset on timeout (Sashiko, Matt B)
- Drop the flush_work() loop (Matt B)
- Use xe_assert() for the killed-queue check (Matt B)
- Merge the put loop into the kill_sync loop (Matt B)
v3:
- Wait on a dedicated kill_wq instead of waking ct.wq on every
scheduling-disable SCHED_DONE (CI)
v5: Rewrote the description for the primary KILL acknowledgement and
per-queue state waitqueue.
Assisted-by: LLM
Signed-off-by: Daniel Charles <daniel.charles@intel.com>
---
drivers/gpu/drm/xe/xe_device.c | 5 +++
drivers/gpu/drm/xe/xe_exec_queue.c | 13 ++++++
drivers/gpu/drm/xe/xe_exec_queue.h | 1 +
drivers/gpu/drm/xe/xe_exec_queue_types.h | 2 +
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 6 +++
drivers/gpu/drm/xe/xe_guc_submit.c | 47 ++++++++++++++++++++
6 files changed, 74 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 8392c9fad3c48..cf75fa3b8fa4b 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -190,8 +190,13 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
if (q->vm && q->hwe->hw_engine_group)
xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
xe_exec_queue_kill(q);
+ }
+
+ xa_for_each(&xef->exec_queue.xa, idx, q) {
+ xe_exec_queue_kill_sync(q);
xe_exec_queue_put(q);
}
+
xa_for_each(&xef->vm.xa, idx, vm)
xe_vm_close_and_put(vm);
diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c
index 9a8efa2bf2bfb..8ba2cf45694dd 100644
--- a/drivers/gpu/drm/xe/xe_exec_queue.c
+++ b/drivers/gpu/drm/xe/xe_exec_queue.c
@@ -1622,6 +1622,19 @@ void xe_exec_queue_kill(struct xe_exec_queue *q)
xe_vm_remove_compute_exec_queue(q->vm, q);
}
+/**
+ * xe_exec_queue_kill_sync() - Wait for queue scheduling to stop
+ * @q: The exec queue
+ *
+ * This function waits for the backend to finish stopping the queue after
+ * xe_exec_queue_kill(). It is safe to call multiple times.
+ */
+void xe_exec_queue_kill_sync(struct xe_exec_queue *q)
+{
+ if (q->ops->kill_sync)
+ q->ops->kill_sync(q);
+}
+
/**
* xe_exec_queue_destroy_ioctl() - Destroy an exec queue via IOCTL
* @dev: DRM device
diff --git a/drivers/gpu/drm/xe/xe_exec_queue.h b/drivers/gpu/drm/xe/xe_exec_queue.h
index e8963f85cabd9..4be023b9a4c6c 100644
--- a/drivers/gpu/drm/xe/xe_exec_queue.h
+++ b/drivers/gpu/drm/xe/xe_exec_queue.h
@@ -119,6 +119,7 @@ bool xe_exec_queue_is_lr(struct xe_exec_queue *q);
bool xe_exec_queue_is_idle(struct xe_exec_queue *q, int extra_jobs);
void xe_exec_queue_kill(struct xe_exec_queue *q);
+void xe_exec_queue_kill_sync(struct xe_exec_queue *q);
int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file);
diff --git a/drivers/gpu/drm/xe/xe_exec_queue_types.h b/drivers/gpu/drm/xe/xe_exec_queue_types.h
index 48c05398b0168..4882eeccb9bd5 100644
--- a/drivers/gpu/drm/xe/xe_exec_queue_types.h
+++ b/drivers/gpu/drm/xe/xe_exec_queue_types.h
@@ -294,6 +294,8 @@ struct xe_exec_queue_ops {
int (*init)(struct xe_exec_queue *q);
/** @kill: Kill inflight submissions for backend */
void (*kill)(struct xe_exec_queue *q);
+ /** @kill_sync: Wait for the backend to stop queue scheduling */
+ void (*kill_sync)(struct xe_exec_queue *q);
/** @fini: Undoes the init() for submission backend */
void (*fini)(struct xe_exec_queue *q);
/**
diff --git a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
index 3f5b1950a248a..cb0e460f4762f 100644
--- a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
+++ b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
@@ -54,6 +54,12 @@ struct xe_guc_exec_queue {
wait_queue_head_t suspend_wait;
/** @state_wq: wait queue for scheduling enable/disable state changes */
wait_queue_head_t state_wq;
+ /**
+ * @kill_processed: KILL handler has drained earlier submission work and
+ * issued any required disable. Published with release semantics and
+ * never cleared by repeated kill requests.
+ */
+ bool kill_processed;
/**
* @suspend_pending: a suspend of the exec_queue is pending.
* Protected by @sched.msg_lock.
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
index 3010e8ca36b4a..4e5cca77403ce 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -2087,6 +2087,9 @@ static void __guc_exec_queue_process_msg_kill(struct xe_sched_msg *msg,
if (!kref_read(&q->refcount) || !bound || exec_queue_wedged(q))
return;
+ if (READ_ONCE(q->guc->kill_processed))
+ return;
+
ret = wait_event_timeout(q->guc->state_wq,
(!exec_queue_pending_enable(q) &&
!exec_queue_pending_disable(q)) ||
@@ -2105,6 +2108,10 @@ static void __guc_exec_queue_process_msg_kill(struct xe_sched_msg *msg,
if (exec_queue_enabled(q))
disable_scheduling(q, true);
+
+ /* Publish only after disable_scheduling() has established pending state. */
+ smp_store_release(&q->guc->kill_processed, true);
+ wake_up_all(&q->guc->state_wq);
}
#define CLEANUP 1 /* Non-zero values to catch uninitialized msg */
@@ -2326,6 +2333,45 @@ static void guc_exec_queue_kill(struct xe_exec_queue *q)
xe_guc_exec_queue_trigger_cleanup(q);
}
+static bool guc_exec_queue_kill_complete(struct xe_exec_queue *primary)
+{
+ unsigned int state;
+
+ /*
+ * Pair with the primary KILL handler's release so earlier submission
+ * work has finished and any required DISABLE has been issued.
+ */
+ if (!smp_load_acquire(&primary->guc->kill_processed))
+ return false;
+
+ state = atomic_read(&primary->guc->state);
+
+ return !(state & (EXEC_QUEUE_STATE_ENABLED |
+ EXEC_QUEUE_STATE_PENDING_DISABLE |
+ EXEC_QUEUE_STATE_PENDING_ENABLE));
+}
+
+static void guc_exec_queue_kill_sync(struct xe_exec_queue *q)
+{
+ struct xe_exec_queue *primary = xe_exec_queue_multi_queue_primary(q);
+ struct xe_guc *guc = exec_queue_to_guc(primary);
+ long ret;
+
+ xe_assert(guc_to_xe(guc), exec_queue_killed(q));
+
+ /* FD close has already killed every primary before waiting on any member. */
+ ret = wait_event_timeout(primary->guc->state_wq,
+ guc_exec_queue_kill_complete(primary) ||
+ xe_guc_read_stopped(guc) ||
+ vf_recovery(guc) ||
+ exec_queue_wedged(primary), HZ * 5);
+ if (!ret) {
+ xe_gt_warn(q->gt, "Queue kill failed to respond, guc_id=%d\n",
+ primary->guc->id);
+ xe_gt_reset_async(q->gt);
+ }
+}
+
static void guc_exec_queue_add_msg(struct xe_exec_queue *q, struct xe_sched_msg *msg,
u32 opcode)
{
@@ -2803,6 +2849,7 @@ static u64 guc_exec_queue_reset_status(struct xe_exec_queue *q)
static const struct xe_exec_queue_ops guc_exec_queue_ops = {
.init = guc_exec_queue_init,
.kill = guc_exec_queue_kill,
+ .kill_sync = guc_exec_queue_kill_sync,
.fini = guc_exec_queue_fini,
.destroy = guc_exec_queue_destroy,
.set_priority = guc_exec_queue_set_priority,
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-19 0:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 0:04 [PATCH v5 0/4] FD close cleanup for XE Daniel Charles
2026-11-19 0:04 ` [PATCH v5 1/4] drm/xe: Read scheduler message opcode under lock Daniel Charles
2026-11-19 0:04 ` [PATCH v5 2/4] drm/xe: Notify scheduling-state waiters per exec queue Daniel Charles
2026-11-19 0:04 ` [PATCH v5 3/4] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade Daniel Charles
2026-11-19 0:04 ` [PATCH v5 4/4] drm/xe: Synchronously wait for queue kill on FD close Daniel Charles
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox