Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: fei.yang@intel.com
To: intel-xe@lists.freedesktop.org
Cc: matthew.brost@intel.com, stuart.summers@intel.com,
	Fei Yang <fei.yang@intel.com>
Subject: [PATCH] drm/xe: Serialize migrate ULLS enter against a pending exit
Date: Thu, 19 Nov 2026 16:46:35 -0800	[thread overview]
Message-ID: <20261120004635.3902529-1-fei.yang@intel.com> (raw)

From: Fei Yang <fei.yang@intel.com>

xe_migrate_ulls_exit() clears ulls.enabled as soon as the ULLS_EXIT job is
pushed, and drops job_mutex without waiting for it. A page fault arriving
in that window finds ULLS disabled and pushes a ULLS_ENTER job while the
previous ULLS chain is still executing.

ULLS_ENTER is not chained, so submit_exec_queue() publishes its ring tail
with xe_lrc_set_ring_tail(). That only updates the saved tail in the
context image, which is what a context restore loads RING_TAIL from. It is
therefore correct for a context that is off the hardware - but the context
only leaves the hardware once the exit job has retired.

Submitted before then, that write races the postamble of the job preceding
the exit job. The postamble publishes the same saved tail, and RING_TAIL,
at the end of the exit job. If it lands after the CPU's write the tail is
rewound behind the enter job, which the command streamer never executes.
Its fence never signals, so job_cnt never drops, xe_exec_queue_is_idle()
stays false and the exit worker re-arms itself forever while the context
sits parked on the engine.

Wait for the exit job's fence in the exit worker before dropping
job_mutex. xe_migrate_ulls_enter() takes job_mutex to submit, so it is
serialized behind the exit job retiring. The exit job carries no batch
and is only pushed once the queue is idle, so the wait is short and
depends on nothing else on the queue.

Fixes: 8ab0d5ca31ca ("drm/xe: Add ULLS migration job support to migration layer")
Assisted-by: LLM
Signed-off-by: Fei Yang <fei.yang@intel.com>
---
 drivers/gpu/drm/xe/xe_migrate.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index d7a8d8ecffe63..a8deb5fa714ca 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -188,6 +188,18 @@
  * The PM reference is then dropped. If the queue was not idle, the worker
  * simply re-arms itself.
  *
+ * The worker waits for the "last" job to retire before dropping
+ * @xe_migrate.job_mutex, so a subsequent enter is serialized behind it. A
+ * "first" job is not chained, so it publishes its own ring tail with
+ * xe_lrc_set_ring_tail(), which updates the saved tail in the context image
+ * only. That is enough for a context which is off the hardware, since a
+ * context restore loads RING_TAIL from there, but the context is only off the
+ * hardware once the "last" job has retired. Submitted before then, the write
+ * races the postamble of the job preceding the "last" one, which puts that
+ * same saved tail - and RING_TAIL - at the end of the "last" job. The
+ * postamble landing second rewinds the tail behind the "first" job, which the
+ * command streamer then never executes.
+ *
  * Job state
  * ---------
  *
@@ -768,6 +780,9 @@ static void xe_migrate_ulls_exit(struct work_struct *work)
 	scoped_guard(mutex, &m->job_mutex) {
 		if (xe_exec_queue_is_idle(m->q, 1)) {
 			fence = __xe_migrate_job_push(m, job, ULLS_EXIT);
+
+			/* Keep enter out until the context is off the HW */
+			dma_fence_wait(fence, false);
 			dma_fence_put(fence);
 
 			xe_pm_runtime_put(xe);	/* Pairs with PM get in enter */
-- 
2.43.0


             reply	other threads:[~2026-11-20  0:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  0:46 fei.yang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-20  0:10 [PATCH] drm/xe: Serialize migrate ULLS enter against a pending exit fei.yang
2026-11-20  0:15 ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120004635.3902529-1-fei.yang@intel.com \
    --to=fei.yang@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=stuart.summers@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox