Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

accel/amdxdna: Fix deadlock between context destroy and job timeout

Hardware context destroy function holds dev_lock while waiting for all jobs
to complete. The timeout job also needs to acquire dev_lock, this leads to
a deadlock.

Fix the issue by temporarily releasing dev_lock before waiting for all
jobs to finish, and reacquiring it afterward.

Fixes: 4fd6ca90fc7f ("accel/amdxdna: Refactor hardware context destroy routine")
Reviewed-by: Maciej Falkowski <maciej.falkowski@linux.intel.com>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Link: https://patch.msgid.link/20251107181050.1293125-1-lizhi.hou@amd.com

Lizhi Hou ca258341 6ff9385c

+4 -2
+4 -2
drivers/accel/amdxdna/aie2_ctx.c
··· 690 690 xdna = hwctx->client->xdna; 691 691 692 692 XDNA_DBG(xdna, "%s sequence number %lld", hwctx->name, hwctx->priv->seq); 693 - drm_sched_entity_destroy(&hwctx->priv->entity); 694 - 695 693 aie2_hwctx_wait_for_idle(hwctx); 696 694 697 695 /* Request fw to destroy hwctx and cancel the rest pending requests */ 698 696 aie2_release_resource(hwctx); 699 697 698 + mutex_unlock(&xdna->dev_lock); 699 + drm_sched_entity_destroy(&hwctx->priv->entity); 700 + 700 701 /* Wait for all submitted jobs to be completed or canceled */ 701 702 wait_event(hwctx->priv->job_free_wq, 702 703 atomic64_read(&hwctx->job_submit_cnt) == 703 704 atomic64_read(&hwctx->job_free_cnt)); 705 + mutex_lock(&xdna->dev_lock); 704 706 705 707 drm_sched_fini(&hwctx->priv->sched); 706 708 aie2_ctx_syncobj_destroy(hwctx);