Skip to content

Commit f137024

Browse files
committed
accel/amdxdna: Stop job scheduling across aie2_release_resource()
Running jobs on a hardware context while it is in the process of releasing resources can lead to use-after-free and crashes. Fix this by stopping job scheduling before calling aie2_release_resource() and restarting it after the release completes. Additionally, aie2_sched_job_run() now checks whether the hardware context is still active. Fixes: 4fd6ca9 ("accel/amdxdna: Refactor hardware context destroy routine") Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Link: https://patch.msgid.link/20260130003255.2083255-1-lizhi.hou@amd.com
1 parent a916243 commit f137024

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/accel/amdxdna/aie2_ctx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ aie2_sched_job_run(struct drm_sched_job *sched_job)
315315
struct dma_fence *fence;
316316
int ret;
317317

318+
if (hwctx->status != HWCTX_STAT_READY)
319+
return NULL;
320+
318321
if (!mmget_not_zero(job->mm))
319322
return ERR_PTR(-ESRCH);
320323

@@ -705,7 +708,10 @@ void aie2_hwctx_fini(struct amdxdna_hwctx *hwctx)
705708
aie2_hwctx_wait_for_idle(hwctx);
706709

707710
/* Request fw to destroy hwctx and cancel the rest pending requests */
711+
drm_sched_stop(&hwctx->priv->sched, NULL);
708712
aie2_release_resource(hwctx);
713+
hwctx->status = HWCTX_STAT_STOP;
714+
drm_sched_start(&hwctx->priv->sched, 0);
709715

710716
mutex_unlock(&xdna->dev_lock);
711717
drm_sched_entity_destroy(&hwctx->priv->entity);

0 commit comments

Comments
 (0)