drm/amdgpu: Fix fence signaling race condition in userqueue
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: Fix fence signaling race condition in userqueue
This commit fixes a potential race condition in the userqueue fence signaling mechanism by replacing dma_fence_is_signaled_locked() with dma_fence_is_signaled().
The issue occurred because:
1. dma_fence_is_signaled_locked() should only be used when holding the fence's individual lock, not just the fence list lock
2. Using the locked variant without the proper fence lock could lead to double-signaling scenarios:
- Hardware completion signals the fence
- Software path also tries to signal the same fence
By using dma_fence_is_signaled() instead, we properly handle the locking hierarchy and avoid the race condition while still maintaining the necessary synchronization through the fence_list_lock.
v2: drop the comment (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
@@ -289,7 +289,7 @@ static int amdgpu_userq_fence_create(struct amdgpu_usermode_queue *userq,/* Check if hardware has already processed the job */ spin_lock_irqsave (&fence_drv->fence_list_lock, flags); -if (!dma_fence_is_signaled_locked (fence)) +if (!dma_fence_is_signaled (fence))list_add_tail (&userq_fence->link, &fence_drv->fences);else dma_fence_put (fence);
Signature · 1 line
2.49.0
Quoted 12 lines · Jesse.Zhang
This commit fixes a potential race condition in the userqueue fence signaling mechanism by replacing
dma_fence_is_signaled_locked()withdma_fence_is_signaled().The issue occurred because:
1.dma_fence_is_signaled_locked()should only be used when holding the fence's individual lock, not just the fence list lock
2. Using the locked variant without the proper fence lock could lead to double-signaling scenarios:
- Hardware completion signals the fence
- Software path also tries to signal the same fence
Quoted 7 lines
By using
dma_fence_is_signaled()instead, we properly handle the locking hierarchy and avoid the race condition while still maintaining the necessary synchronization through thefence_list_lock.v2: drop the comment (Christian)
Signed-off-by Jesse Zhang <[email protected]>
Quoted 17 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-1@@ -289,7 +289,7 @@ static int amdgpu_userq_fence_create(struct amdgpu_usermode_queue *userq,/* Check if hardware has already processed the job */ spin_lock_irqsave (&fence_drv->fence_list_lock, flags); -if (!dma_fence_is_signaled_locked (fence)) +if (!dma_fence_is_signaled (fence))list_add_tail (&userq_fence->link, &fence_drv->fences);else dma_fence_put (fence);