drm/xe: Serialize migrate ULLS enter against a pending exit
Subsystems (2)
PATCH 1/1 drm/xe: Serialize migrate ULLS enter against a pending exit
From: Fei Yang <[email protected]>
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.
--- drivers/gpu/drm/xe/xe_migrate.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/xe/xe_migrate.c +15 -0
@@ -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 */
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/xe: missing Fixes trailer for xe_migrate_ulls_exit() race fix --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/xe: missing Fixes trailer for xe_migrate_ulls_exit() race fix
--
commit ec3c80079d880e245d587b5f95313394facd8925
Author: Fei Yang <[email protected]>
Quoted 21 lines
drm/xe: Serialize migrate ULLS enter against a pending exit
xe_migrate_ulls_exit()clears ulls.enabled as soon as theULLS_EXITjob is pushed, and dropsjob_mutexwithout waiting for it. A page fault arriving in that window finds ULLS disabled and pushes aULLS_ENTERjob while the previous ULLS chain is still executing.
ULLS_ENTERis not chained, sosubmit_exec_queue()publishes its ring tail withxe_lrc_set_ring_tail(). That only updates the saved tail in the context image, which is what a context restore loadsRING_TAILfrom. 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, sojob_cntnever drops,xe_exec_queue_is_idle()stays false and the exit worker re-arms itself forever while the context sits parked on the engine.
Quoted 8 lines
Wait for the exit job's fence in the exit worker before dropping
job_mutex.xe_migrate_ulls_enter()takesjob_mutexto 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 LLMSigned-off-by Fei Yang <[email protected]>
[Severity: Low]
This fixes a race in xe_migrate_ulls_exit() that can hang the migration queue. Should this include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1