accel/amdxdna: Fix deadlock between context destroy and job timeout
Lizhi Hou
maintainerPATCH 1/1 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.
--- drivers/accel/amdxdna/aie2_ctx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/accel/amdxdna/aie2_ctx.c +4 -2
@@ -690,17 +690,19 @@ void aie2_hwctx_fini(struct amdxdna_hwctx *hwctx) xdna = hwctx->client->xdna;XDNA_DBG (xdna,"%s sequence number %lld" , hwctx->name, hwctx->priv->seq); -drm_sched_entity_destroy (&hwctx->priv->entity); -aie2_hwctx_wait_for_idle (hwctx);/* Request fw to destroy hwctx and cancel the rest pending requests */ aie2_release_resource (hwctx); +mutex_unlock (&xdna->dev_lock); +drm_sched_entity_destroy (&hwctx->priv->entity); +/* Wait for all submitted jobs to be completed or canceled */ wait_event (hwctx->priv->job_free_wq,atomic64_read (&hwctx->job_submit_cnt) ==atomic64_read (&hwctx->job_free_cnt)); +mutex_lock (&xdna->dev_lock);drm_sched_fini (&hwctx->priv->sched);aie2_ctx_syncobj_destroy (hwctx);
Signature · 1 line
2.34.1
You could add some lockdep assertions for dev_lock to better track its state.
Best regards,
Maciej
Quoted 39 lines · Lizhi Hou
Hardware context destroy function holds
dev_lockwhile waiting for all jobs to complete. The timeout job also needs to acquiredev_lock, this leads to a deadlock.Fix the issue by temporarily releasing
dev_lockbefore waiting for all jobs to finish, and reacquiring it afterward.Fixes 4fd6ca90fc7f ("accel/amdxdna: Refactor hardware context destroy routine")Signed-off-by Lizhi Hou <[email protected]>--- drivers/accel/amdxdna/aie2_ctx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/accel/amdxdna/aie2_ctx.c +4
-2@@ -690,17 +690,19 @@ void aie2_hwctx_fini(struct amdxdna_hwctx *hwctx) xdna = hwctx->client->xdna;XDNA_DBG (xdna,"%s sequence number %lld" , hwctx->name, hwctx->priv->seq); -drm_sched_entity_destroy (&hwctx->priv->entity); -aie2_hwctx_wait_for_idle (hwctx);/* Request fw to destroy hwctx and cancel the rest pending requests */ aie2_release_resource (hwctx); +mutex_unlock (&xdna->dev_lock); +drm_sched_entity_destroy (&hwctx->priv->entity); +/* Wait for all submitted jobs to be completed or canceled */ wait_event (hwctx->priv->job_free_wq,atomic64_read (&hwctx->job_submit_cnt) ==atomic64_read (&hwctx->job_free_cnt)); +mutex_lock (&xdna->dev_lock);drm_sched_fini (&hwctx->priv->sched);aie2_ctx_syncobj_destroy (hwctx);
Lizhi Hou
maintainerQuoted 3 lines · Maciej
Reviewed-by Maciej Falkowski <[email protected]>You could add some lockdep assertions for
dev_lockto better track its state.
Thanks :) Added lockdep_assert_held check and applied to drm-misc-next.
Lizhi
Quoted 40 lines
Best regards,
MaciejQuoted 35 lines · Lizhi Hou
Hardware context destroy function holds
dev_lockwhile waiting for all jobs to complete. The timeout job also needs to acquiredev_lock, this leads to a deadlock.Fix the issue by temporarily releasing
dev_lockbefore waiting for all jobs to finish, and reacquiring it afterward.Fixes 4fd6ca90fc7f ("accel/amdxdna: Refactor hardware context destroy routine")Signed-off-by Lizhi Hou <[email protected]>---
drivers/accel/amdxdna/aie2_ctx.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)drivers/accel/amdxdna/aie2_ctx.c +2
-2@@ -690,17 +690,19 @@ void aie2_hwctx_fini(struct amdxdna_hwctx *hwctx) xdna = hwctx->client->xdna; XDNA_DBG(xdna, "%s sequence number %lld", hwctx->name, hwctx->priv->seq); - drm_sched_entity_destroy(&hwctx->priv->entity); - aie2_hwctx_wait_for_idle(hwctx); /* Request fw to destroy hwctx and cancel the rest pending requests */ aie2_release_resource(hwctx); + mutex_unlock(&xdna->dev_lock); + drm_sched_entity_destroy(&hwctx->priv->entity); + /* Wait for all submitted jobs to be completed or canceled */ wait_event(hwctx->priv->job_free_wq,
atomic64_read(&hwctx->job_submit_cnt)==atomic64_read(&hwctx->job_free_cnt)); +mutex_lock(&xdna->dev_lock);drm_sched_fini(&hwctx->priv->sched);aie2_ctx_syncobj_destroy(hwctx);