Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe: Serialize migrate ULLS enter against a pending exit
@ 2026-11-20  0:46 fei.yang
  0 siblings, 0 replies; 3+ messages in thread
From: fei.yang @ 2026-11-20  0:46 UTC (permalink / raw)
  To: intel-xe; +Cc: matthew.brost, stuart.summers, Fei Yang

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH] drm/xe: Serialize migrate ULLS enter against a pending exit
@ 2026-11-20  0:10 fei.yang
  2026-11-20  0:15 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: fei.yang @ 2026-11-20  0:10 UTC (permalink / raw)
  To: intel-xe; +Cc: matthew.brost, stuart.summers, Fei Yang

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.

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20  0:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  0:46 [PATCH] drm/xe: Serialize migrate ULLS enter against a pending exit fei.yang
  -- strict thread matches above, loose matches on Subject: below --
2026-11-20  0:10 fei.yang
2026-11-20  0:15 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox