Skip to content

Commit 079d262

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] [ This backport required small adjustments to ivpu_job_submit(), which lacks support for explicit command queue creation added in 6.15. ] Signed-off-by: Jacek Lawrynowicz <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3e3062b commit 079d262

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/accel/ivpu/ivpu_job.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -535,26 +535,25 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
535535
if (ret < 0)
536536
return ret;
537537

538+
mutex_lock(&vdev->submitted_jobs_lock);
538539
mutex_lock(&file_priv->lock);
539540

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

548-
mutex_lock(&vdev->submitted_jobs_lock);
549-
550549
is_first_job = xa_empty(&vdev->submitted_jobs_xa);
551550
ret = xa_alloc_cyclic(&vdev->submitted_jobs_xa, &job->job_id, job, file_priv->job_limit,
552551
&file_priv->job_id_next, GFP_KERNEL);
553552
if (ret < 0) {
554553
ivpu_dbg(vdev, JOB, "Too many active jobs in ctx %d\n",
555554
file_priv->ctx.id);
556555
ret = -EBUSY;
557-
goto err_unlock_submitted_jobs;
556+
goto err_unlock;
558557
}
559558

560559
ret = ivpu_cmdq_push_job(cmdq, job);
@@ -576,22 +575,20 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
576575
job->job_id, file_priv->ctx.id, job->engine_idx, priority,
577576
job->cmd_buf_vpu_addr, cmdq->jobq->header.tail);
578577

579-
mutex_unlock(&vdev->submitted_jobs_lock);
580578
mutex_unlock(&file_priv->lock);
581579

582580
if (unlikely(ivpu_test_mode & IVPU_TEST_MODE_NULL_HW)) {
583-
mutex_lock(&vdev->submitted_jobs_lock);
584581
ivpu_job_signal_and_destroy(vdev, job->job_id, VPU_JSM_STATUS_SUCCESS);
585-
mutex_unlock(&vdev->submitted_jobs_lock);
586582
}
587583

584+
mutex_unlock(&vdev->submitted_jobs_lock);
585+
588586
return 0;
589587

590588
err_erase_xa:
591589
xa_erase(&vdev->submitted_jobs_xa, job->job_id);
592-
err_unlock_submitted_jobs:
590+
err_unlock:
593591
mutex_unlock(&vdev->submitted_jobs_lock);
594-
err_unlock_file_priv:
595592
mutex_unlock(&file_priv->lock);
596593
ivpu_rpm_put(vdev);
597594
return ret;

0 commit comments

Comments
 (0)