The memory CAT error handler uses the same cleanup path as the
context-reset handler. This immediately triggers the TDR, which can
send a scheduling-disable request before the context-reset notification
arrives.

On a BMG dGPU, an early disable after a CCS memory CAT error is
associated with subsequent contexts being enabled but never starting
work. Recovery occurs later when a scheduling-disable timeout triggers
a GT reset.

Separate waking user-fence waiters from triggering the TDR. On a memory
CAT notification, mark the queue reset and wake waiters without starting
the TDR. Keep the existing cleanup triggered by the context-reset
notification.

Leave the uncorrectable-error and CGP context-error paths unchanged.

Tested on a BMG dGPU using a standalone SYCL reproducer with two
separate processes.

The first process submits a kernel that reads an unmapped GPU address,
causing a page fault followed by a memory CAT error. It then calls
abort() without waiting for the kernel to finish.

After that process exits, a second process, called "victim", starts.
It submits a simple kernel that writes 7 to a device allocation,
copies the value back to the CPU and checks the result.

Without the patch, the victim can hang and reach its 60-second
userspace timeout. With the patch, the victim completed and returned
the expected value in all tested rounds where the first process triggered
the fault.

Recovery without a context-reset notification still needs confirmation,
particularly for LR queues, which have no normal finite job timeout.
Independent queue-kill and cleanup paths are unchanged.

Cc: Matthew Brost <[email protected]>
Cc: Thomas Hellström <[email protected]>
Cc: Himal Prasad Ghimiray <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Cc: Tejas Upadhyay <[email protected]>
Assisted-by: LLM
Signed-off-by: Arvind Yadav <[email protected]>
---
 drivers/gpu/drm/xe/xe_guc_submit.c | 50 ++++++++++++++++++++++--------
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c 
b/drivers/gpu/drm/xe/xe_guc_submit.c
index d76f125f9c3a..aa382634a235 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -557,17 +557,39 @@ static bool vf_recovery(struct xe_guc *guc)
        return xe_gt_recovery_pending(guc_to_gt(guc));
 }
 
-static void xe_guc_exec_queue_trigger_cleanup(struct xe_exec_queue *q)
+static void xe_guc_exec_queue_wake_ufence(struct xe_exec_queue *q)
 {
        struct xe_guc *guc = exec_queue_to_guc(q);
        struct xe_device *xe = guc_to_xe(guc);
 
        /** to wakeup xe_wait_user_fence ioctl if exec queue is reset */
        wake_up_all(&xe->ufence_wq);
+}
+
+static void xe_guc_exec_queue_trigger_cleanup(struct xe_exec_queue *q)
+{
+       xe_guc_exec_queue_wake_ufence(q);
 
        xe_sched_tdr_queue_imm(&q->guc->sched);
 }
 
+/*
+ * Allow callers to wake user-fence waiters without triggering the TDR.
+ * The memory CAT handler uses this to avoid starting cleanup before
+ * the context-reset notification arrives.
+ */
+static void xe_queue_trigger_cleanup_for_reset(struct xe_exec_queue *q,
+                                              bool trigger_tdr)
+{
+       if (exec_queue_banned(q))
+               return;
+
+       if (trigger_tdr)
+               xe_guc_exec_queue_trigger_cleanup(q);
+       else
+               xe_guc_exec_queue_wake_ufence(q);
+}
+
 static void xe_guc_exec_queue_group_stop(struct xe_exec_queue *q)
 {
        struct xe_exec_queue *primary = xe_exec_queue_multi_queue_primary(q);
@@ -653,7 +675,8 @@ static void xe_guc_exec_queue_group_trigger_cleanup(struct 
xe_exec_queue *q)
        mutex_unlock(&group->list_lock);
 }
 
-static void xe_guc_exec_queue_reset_trigger_cleanup(struct xe_exec_queue *q)
+static void xe_guc_exec_queue_reset_trigger_cleanup(struct xe_exec_queue *q,
+                                                   bool trigger_tdr)
 {
        if (xe_exec_queue_is_multi_queue(q)) {
                struct xe_exec_queue *primary = 
xe_exec_queue_multi_queue_primary(q);
@@ -664,20 +687,17 @@ static void 
xe_guc_exec_queue_reset_trigger_cleanup(struct xe_exec_queue *q)
                WRITE_ONCE(group->banned, true);
 
                set_exec_queue_reset(primary);
-               if (!exec_queue_banned(primary))
-                       xe_guc_exec_queue_trigger_cleanup(primary);
+               xe_queue_trigger_cleanup_for_reset(primary, trigger_tdr);
 
                mutex_lock(&group->list_lock);
                list_for_each_entry(eq, &group->list, multi_queue.link) {
                        set_exec_queue_reset(eq);
-                       if (!exec_queue_banned(eq))
-                               xe_guc_exec_queue_trigger_cleanup(eq);
+                       xe_queue_trigger_cleanup_for_reset(eq, trigger_tdr);
                }
                mutex_unlock(&group->list_lock);
        } else {
                set_exec_queue_reset(q);
-               if (!exec_queue_banned(q))
-                       xe_guc_exec_queue_trigger_cleanup(q);
+               xe_queue_trigger_cleanup_for_reset(q, trigger_tdr);
        }
 }
 
@@ -3523,7 +3543,7 @@ int xe_guc_exec_queue_reset_handler(struct xe_guc *guc, 
u32 *msg, u32 len)
         * jobs by setting timeout of the job to the minimum value kicking
         * guc_exec_queue_timedout_job.
         */
-       xe_guc_exec_queue_reset_trigger_cleanup(q);
+       xe_guc_exec_queue_reset_trigger_cleanup(q, true);
 
        return 0;
 }
@@ -3601,8 +3621,12 @@ int xe_guc_exec_queue_memory_cat_error_handler(struct 
xe_guc *guc, u32 *msg,
 
        trace_xe_exec_queue_memory_cat_error(q);
 
-       /* Treat the same as engine reset */
-       xe_guc_exec_queue_reset_trigger_cleanup(q);
+       /*
+        * Starting the TDR here can send a scheduling-disable request before
+        * the context-reset notification arrives. Mark the queue reset and
+        * wake user-fence waiters, leaving that notification to trigger 
cleanup.
+        */
+       xe_guc_exec_queue_reset_trigger_cleanup(q, false);
 
        return 0;
 }
@@ -3644,7 +3668,7 @@ int xe_guc_uncorrectable_error_handler(struct xe_guc 
*guc, u32 *msg, u32 len)
        trace_xe_guc_uncorrectable_error(q);
 
        /* Treat the same as engine reset */
-       xe_guc_exec_queue_reset_trigger_cleanup(q);
+       xe_guc_exec_queue_reset_trigger_cleanup(q, true);
 
        return 0;
 }
@@ -3696,7 +3720,7 @@ int xe_guc_exec_queue_cgp_context_error_handler(struct 
xe_guc *guc, u32 *msg,
        trace_xe_exec_queue_cgp_context_error(q);
 
        /* Treat the same as engine reset */
-       xe_guc_exec_queue_reset_trigger_cleanup(q);
+       xe_guc_exec_queue_reset_trigger_cleanup(q, true);
 
        return 0;
 }
-- 
2.43.0

Reply via email to