From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9233F606A32C for ; Thu, 3 Dec 2026 08:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ewMLlBqH Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 588E110E562; Thu, 3 Dec 2026 08:18:40 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 25B1B10FF11 for ; Thu, 3 Dec 2026 08:18:34 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 30006622AD; Thu, 3 Dec 2026 08:18:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD53E1F000C1; Thu, 3 Dec 2026 08:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796285912; bh=M1al4bj3G5kObq5WRPxgp9FTYVk7BojBd841cRD527o=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=ewMLlBqHQpYGo2OoYG/WMyvI6V3aYVpguo4Z8+d0m2sSVnbrycfGLnZWAPfofXMiK mmvI7XQ22Q9hIFr9PydG/FSiqw9WFUyddjMzf/JG8t8F3qrgSGePSVrEToIU3Ou4AZ h+nW4jhzPRioFVquvmzQsfwh75PEKHo6qLQHLtmZ3n1291kSaim/3cyF7+Sp13ZGlr 3cIhiqE7mB3Ip0U807bKk3lZASVTM0c/Am6mPgKQB2wZ2aHaCQiupDdNbyVBl6KDSv 4FGWOe5WlsJmut1ZqmKwb6TQDvGiJLjJDQ3JdYSdWFou34HSMEQ0DAfIbfd7gJWR4t 4ttVKRs5joh5A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/xe/hw_engine_group: Fix resume racing a pending suspend To: "Bommu Krishnaiah" , intel-xe@lists.freedesktop.org In-Reply-To: <20261203080016.3093097-1-krishnaiah.bommu@intel.com> References: <20261203080016.3093097-1-krishnaiah.bommu@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 08:18:32 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] drm/xe: queuing RESUME while stopped breaks GuC scheduling state machine - [High] drm/xe: repeated suspend/resume while stopped collides static msg slots - [High] drm/xe: stale lr.suspended on skipped resume stalls future mode switches - [Medium] drm/xe: TOCTOU race across xe_guc_submit_start() still trips resume assert - [Medium] drm/xe: skipping resume() on banned secondary leaks primary suspend_count -- commit 7adb9851ce0a8492837d8f79554f2c25836d3de5 Author: Bommu Krishnaiah drm/xe/hw_engine_group: Fix resume racing a pending suspend This commit drains pending queue suspends in hw_engine_group_resume_lr_jobs_func() before resuming faulting LR queues, a= nd relaxes the suspend_pending assertion in __guc_exec_queue_resume() while GuC submission is stopped. > diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_g= uc_submit.c > index fce39dd4e1177..7421731d912c2 100644 > --- a/drivers/gpu/drm/xe/xe_guc_submit.c > +++ b/drivers/gpu/drm/xe/xe_guc_submit.c > @@ -2463,10 +2463,13 @@ static bool __guc_exec_queue_resume(struct xe_exe= c_queue *q) > xe_sched_msg_lock(sched); > /* > * A killed, banned or wedged queue keeps suspend_pending set until it > - * is torn down, so only assert the flag is clear otherwise. > + * is torn down. While submission is stopped (GT reset) a queued SUSPEND > + * cannot run, so the flag stays set; it is processed before this RESUME > + * once submission restarts. Only assert the flag is clear otherwise. > */ > xe_gt_assert(guc_to_gt(guc), !ge->suspend_pending || > - exec_queue_killed_or_banned_or_wedged(q)); > + exec_queue_killed_or_banned_or_wedged(q) || > + xe_guc_read_stopped(guc)); [Severity: High] Can queuing STATIC_MSG_RESUME behind a pending STATIC_MSG_SUSPEND while submission is stopped corrupt the GuC scheduling state machine? When xe_guc_submit_start() runs guc_exec_queue_start(), xe_sched_resubmit_jobs() runs before work_process_msg and can register and enable the queue. When work_process_msg then processes STATIC_MSG_SUSPEND, disable_scheduling() sends GUC_CONTEXT_DISABLE asynchronously and returns with EXEC_QUEUE_STATE_PENDING_DISABLE set. work_process_msg GuC __guc_exec_queue_process_msg_suspend() set_exec_queue_suspended(q) disable_scheduling(q, false) send GUC_CONTEXT_DISABLE (async) __guc_exec_queue_process_msg_resume() clear_exec_queue_suspended(q) enable_scheduling(q) <-- asserts !pending_disable SCHED_DONE(0) arrives handle_sched_done() sees !exec_queue_suspended(q) __guc_exec_queue_process_msg_resume() does not wait for !exec_queue_pending_disable(q), so it trips the enable_scheduling() assert, sends an overlapping GUC_CONTEXT_ENABLE, and makes handle_sched_done() skip suspend_fence_signal(), leaving suspend_pending stuck true. In the pre-stop reset window (after xe_uc_reset_prepare() sets stopped and before guc_exec_queue_stop() stops the scheduler), STATIC_MSG_SUSPEND skips disable_scheduling() and STATIC_MSG_RESUME is consumed immediately. guc_exec_queue_stop() then still sees suspend_pending set and preserves EXEC_QUEUE_STATE_SUSPENDED across reset with no resume left to clear it, so submit_exec_queue() silently drops all future submissions on the queue. > xe_gt_assert(guc_to_gt(guc), ge->suspend_count > 0); > last =3D (--ge->suspend_count =3D=3D 0); > if (last) { [Severity: High] What happens if another suspend/resume cycle runs before xe_guc_submit_start() drains sched->msgs? Allowing __guc_exec_queue_resume() to decrement ge->suspend_count to 0 while stopped leaves both STATIC_MSG_SUSPEND and STATIC_MSG_RESUME linked on sched->msgs. A second DMA-fence mode switch before restart then hits guc_exec_queue_try_add_msg() for STATIC_MSG_SUSPEND with !list_empty(), tripping xe_gt_assert(..., added) in __guc_exec_queue_suspend(). On non-debug builds the second suspend is silently dropped, so restart runs SUSPEND followed by RESUME and re-enables the faulting LR queue while the engine group is in EXEC_MODE_DMA_FENCE. A second resume before drain similarly drops STATIC_MSG_RESUME. > diff --git a/drivers/gpu/drm/xe/xe_hw_engine_group.c b/drivers/gpu/drm/xe= /xe_hw_engine_group.c > index 418ff427ae308..4113ee52e8405 100644 > --- a/drivers/gpu/drm/xe/xe_hw_engine_group.c > +++ b/drivers/gpu/drm/xe/xe_hw_engine_group.c > @@ -44,6 +44,10 @@ hw_engine_group_resume_lr_jobs_func(struct work_struct= *w) > if (!READ_ONCE(q->lr.suspended)) > continue; > =20 > + /* resume() asserts the suspend fence has signalled, so drain it first= . */ > + if (q->ops->suspend_wait_blocking(q) || q->ops->reset_status(q)) > + continue; > + > WRITE_ONCE(q->lr.suspended, false); > q->ops->resume(q); > } [Severity: High] Does skipping WRITE_ONCE(q->lr.suspended, false) on a failed wait or non-ze= ro reset_status() stall every future DMA-fence mode switch on the group? When suspend_wait_blocking() times out, guc_exec_queue_suspend_timeout_ban() bans the queue and leaves suspend_pending set until teardown. The queue stays on group->exec_queue_list with q->lr.suspended set until closed. On the next DMA-fence mode switch, xe_hw_engine_group_suspend_faulting_lr_jobs() skips the banned queue in its first loop without clearing q->lr.suspended, then waits on it in the second loop. Because guc_exec_queue_wait_suspend_done() does not wake on EXEC_QUEUE_STATE_BANNED or EXEC_QUEUE_STATE_WEDGED, every mode switch sleeps 5 seconds in suspend_wait() holding group->mode_sem write-locked, fails with -ETIME, and sleeps another 5 seconds in err_resume. Also, if reset_status() is non-zero only due to EXEC_QUEUE_STATE_RESET, skipping resume() while guc_exec_queue_suspend() still succeeds on the next switch leaks an unbalanced ge->suspend_count increment. [Severity: Medium] Can xe_guc_submit_start() still race between suspend_wait_blocking() and resume() and trip the __guc_exec_queue_resume() assertion? hw_engine_group_resume_lr_jobs_func() only holds group->mode_sem for reading and does not serialize against xe_guc_submit_start(), which clears guc->submission_state.stopped before work_process_msg clears suspend_pendin= g: CPU0 (resume worker) CPU1 (GT reset) suspend_wait_blocking(q) xe_guc_read_stopped() !=3D 0 returns 0 (suspend_pending=3D1) xe_guc_submit_start() atomic_dec(&stopped) -> 0 q->ops->resume(q) __guc_exec_queue_resume(q) <-- assert fails: stopped=3D0, pending=3D1 Once stopped drops to 0 before STATIC_MSG_SUSPEND finishes, all three claus= es of the xe_gt_assert() in __guc_exec_queue_resume() evaluate to false. [Severity: Medium] If reset_status() skips resume() on a banned multi-queue secondary, does th= is leak the secondary's forwarded suspend reference on the primary queue? guc_exec_queue_suspend() increments primary->guc->suspend_count on a secondary's 0->1 transition, and that reference is only dropped by guc_exec_queue_resume() or on teardown in guc_exec_queue_fini(). During a GT reset, a secondary can be banned individually without banning i= ts primary (for example in guc_exec_queue_stop() when a completed job hits xe_sched_invalidate_job(), so TDR exits early without banning the group). Skipping q->ops->resume(q) then leaves primary->guc->suspend_count pinned at 1 until userspace closes the secondary, either leaving the healthy primary permanently suspended or preventing later DMA-fence mode switches from suspending the group (incrementing suspend_count 1->2 instead of 0->1). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203080016.3093= 097-1-krishnaiah.bommu@intel.com?part=3D1