Skip to content

Commit b9b7092

Browse files
kwachowsgregkh
authored andcommitted
accel/ivpu: Fix locking order in ivpu_job_submit
commit ab680dc upstream. Fix deadlock in job submission and abort handling. When a thread aborts currently executing jobs due to a fault, it first locks the global lock protecting submitted_jobs (#1). After the last job is destroyed, it proceeds to release the related context and locks file_priv (#2). Meanwhile, in the job submission thread, the file_priv lock (#2) is taken first, and then the submitted_jobs lock (#1) is obtained when a job is added to the submitted jobs list. CPU0 CPU1 ---- ---- (for example due to a fault) (jobs submissions keep coming) lock(&vdev->submitted_jobs_lock) #1 ivpu_jobs_abort_all() job_destroy() lock(&file_priv->lock) #2 lock(&vdev->submitted_jobs_lock) #1 file_priv_release() lock(&vdev->context_list_lock) lock(&file_priv->lock) #2 This order of locking causes a deadlock. To resolve this issue, change the order of locking in ivpu_job_submit(). Signed-off-by: Karol Wachowski <[email protected]> Signed-off-by: Maciej Falkowski <[email protected]> Reviewed-by: Jacek Lawrynowicz <[email protected]> Signed-off-by: Jacek Lawrynowicz <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Jacek Lawrynowicz <[email protected]> [ This backport required small adjustments to ivpu_job_submit(), which lacks support for explicit command queue creation added in 6.15. ] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 437b1eb commit b9b7092

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/accel/ivpu/ivpu_job.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,26 +532,25 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
532532
if (ret < 0)
533533
return ret;
534534

535+
mutex_lock(&vdev->submitted_jobs_lock);
535536
mutex_lock(&file_priv->lock);
536537

537538
cmdq = ivpu_cmdq_acquire(file_priv, priority);
538539
if (!cmdq) {
539540
ivpu_warn_ratelimited(vdev, "Failed to get job queue, ctx %d engine %d prio %d\n",
540541
file_priv->ctx.id, job->engine_idx, priority);
541542
ret = -EINVAL;
542-
goto err_unlock_file_priv;
543+
goto err_unlock;
543544
}
544545

545-
mutex_lock(&vdev->submitted_jobs_lock);
546-
547546
is_first_job = xa_empty(&vdev->submitted_jobs_xa);
548547
ret = xa_alloc_cyclic(&vdev->submitted_jobs_xa, &job->job_id, job, file_priv->job_limit,
549548
&file_priv->job_id_next, GFP_KERNEL);
550549
if (ret < 0) {
551550
ivpu_dbg(vdev, JOB, "Too many active jobs in ctx %d\n",
552551
file_priv->ctx.id);
553552
ret = -EBUSY;
554-
goto err_unlock_submitted_jobs;
553+
goto err_unlock;
555554
}
556555

557556
ret = ivpu_cmdq_push_job(cmdq, job);
@@ -574,22 +573,20 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
574573
job->job_id, file_priv->ctx.id, job->engine_idx, priority,
575574
job->cmd_buf_vpu_addr, cmdq->jobq->header.tail);
576575

577-
mutex_unlock(&vdev->submitted_jobs_lock);
578576
mutex_unlock(&file_priv->lock);
579577

580578
if (unlikely(ivpu_test_mode & IVPU_TEST_MODE_NULL_HW)) {
581-
mutex_lock(&vdev->submitted_jobs_lock);
582579
ivpu_job_signal_and_destroy(vdev, job->job_id, VPU_JSM_STATUS_SUCCESS);
583-
mutex_unlock(&vdev->submitted_jobs_lock);
584580
}
585581

582+
mutex_unlock(&vdev->submitted_jobs_lock);
583+
586584
return 0;
587585

588586
err_erase_xa:
589587
xa_erase(&vdev->submitted_jobs_xa, job->job_id);
590-
err_unlock_submitted_jobs:
588+
err_unlock:
591589
mutex_unlock(&vdev->submitted_jobs_lock);
592-
err_unlock_file_priv:
593590
mutex_unlock(&file_priv->lock);
594591
ivpu_rpm_put(vdev);
595592
return ret;

0 commit comments

Comments
 (0)