Skip to contentSkip to conversation

drm/amdgpu: Fix mutex handling in amdgpu_benchmark_do_move() v3

PATCH In review Srinivasan Shanmugam 2 participants 2 messages Mar 2 – Mar 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 drm/amdgpu: Fix mutex handling in amdgpu_benchmark_do_move() v3

amdgpu_benchmark_do_move() can exit the loop early if amdgpu_copy_buffer() or dma_fence_wait() fails.

In the error path, the function jumps to the exit label without releasing adev->mman.default_entity.lock, which leaves the mutex held and results in a lock imbalance.

This can block subsequent users of default_entity and potentially cause deadlocks.

Move the mutex_unlock() to the common exit path so the lock is released on both success and error returns.

This fixes:
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c:57 amdgpu_benchmark_do_move()
warn: inconsistent returns '&adev->mman.default_entity.lock'.

v2:
- Drop unrelated initialization of 'r'
- Keep the change focused on the mutex imbalance fix (Pierre).

v3:
- Remove empty line

Fixes 64c9e5ec16fa ("drm/amdgpu: add missing lock in amdgpu_benchmark_do_move")
Cc Pierre-Eric Pelloux-Prayer <[email protected]>
Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +1 -1
index 98ccd7ab9e9a..6f3c68cde75e 100644
@@ -48,9 +48,9 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
 		if (r)
 			goto exit_do_move;
 	}
-	mutex_unlock(&adev->mman.default_entity.lock);
 
 exit_do_move:
+	mutex_unlock(&adev->mman.default_entity.lock);
 	etime = ktime_get();
 	*time_ms = ktime_ms_delta(etime, stime);
 
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw

Le 02/03/2026 à 16:26, Srinivasan Shanmugam a écrit :

Quoted 17 lines

amdgpu_benchmark_do_move() can exit the loop early if amdgpu_copy_buffer() or dma_fence_wait() fails.

In the error path, the function jumps to the exit label without releasing adev->mman.default_entity.lock, which leaves the mutex held and results in a lock imbalance.

This can block subsequent users of default_entity and potentially cause deadlocks.

Move the mutex_unlock() to the common exit path so the lock is released on both success and error returns.

This fixes:
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c:57 amdgpu_benchmark_do_move()
warn: inconsistent returns '&adev->mman.default_entity.lock'.

Quoted 6 lines

v2:
- Drop unrelated initialization of 'r'
- Keep the change focused on the mutex imbalance fix (Pierre).

v3:
- Remove empty line

Thanks!

Quoted 26 lines
Fixes 64c9e5ec16fa ("drm/amdgpu: add missing lock in amdgpu_benchmark_do_move")
Cc Pierre-Eric Pelloux-Prayer <[email protected]>
Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +1 -1
index 98ccd7ab9e9a..6f3c68cde75e 100644
@@ -48,9 +48,9 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
  		if (r)
  			goto exit_do_move;
  	}
-	mutex_unlock(&adev->mman.default_entity.lock);
 
  exit_do_move:
+	mutex_unlock(&adev->mman.default_entity.lock);
  	etime = ktime_get();
  	*time_ms = ktime_ms_delta(etime, stime);