Skip to content

Commit 96a86dc

Browse files
Jie1zhangalexdeucher
authored andcommitted
drm/amdgpu: Fix circular locking in userq creation
A circular locking dependency was detected between the global `adev->userq_mutex` and per-file `userq_mgr->userq_mutex` when creating user queues. The issue occurs because: 1. `amdgpu_userq_suspend()` and `amdgpu_userq_resume` take `adev->userq_mutex` first, then `userq_mgr->userq_mutex` 2. While `amdgpu_userq_create()` takes them in reverse order This patch resolves the issue by: 1. Moving the `adev->userq_mutex` lock earlier in `amdgpu_userq_create()` to cover the `amdgpu_userq_ensure_ev_fence()` call 2. Releasing it after we're done with both queue creation and the scheduling halt check v2: remove unused adev->userq_mutex lock (Prike) Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> Reviewed-by: Prike Liang <Prike.Liang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 07c9db0 commit 96a86dc

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
394394
*
395395
* This will also make sure we have a valid eviction fence ready to be used.
396396
*/
397+
mutex_lock(&adev->userq_mutex);
397398
amdgpu_userq_ensure_ev_fence(&fpriv->userq_mgr, &fpriv->evf_mgr);
398399

399400
uq_funcs = adev->userq_funcs[args->in.ip_type];
@@ -456,7 +457,6 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
456457
}
457458

458459
/* don't map the queue if scheduling is halted */
459-
mutex_lock(&adev->userq_mutex);
460460
if (adev->userq_halt_for_enforce_isolation &&
461461
((queue->queue_type == AMDGPU_HW_IP_GFX) ||
462462
(queue->queue_type == AMDGPU_HW_IP_COMPUTE)))
@@ -466,7 +466,6 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
466466
if (!skip_map_queue) {
467467
r = amdgpu_userq_map_helper(uq_mgr, queue);
468468
if (r) {
469-
mutex_unlock(&adev->userq_mutex);
470469
drm_file_err(uq_mgr->file, "Failed to map Queue\n");
471470
idr_remove(&uq_mgr->userq_idr, qid);
472471
amdgpu_userq_fence_driver_free(queue);
@@ -475,13 +474,13 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
475474
goto unlock;
476475
}
477476
}
478-
mutex_unlock(&adev->userq_mutex);
479477

480478

481479
args->out.queue_id = qid;
482480

483481
unlock:
484482
mutex_unlock(&uq_mgr->userq_mutex);
483+
mutex_unlock(&adev->userq_mutex);
485484

486485
return r;
487486
}

0 commit comments

Comments
 (0)