drm/amdgpu: grab an additional reference on the gang fence v2
authorChristian König <christian.koenig@amd.com>
Tue, 14 Jan 2025 12:51:39 +0000 (13:51 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 19 Mar 2025 19:51:31 +0000 (15:51 -0400)
We keep the gang submission fence around in adev, make sure that it
stays alive.

v2: fix memory leak on retry

Signed-off-by: Christian König <christian.koenig@amd.com>
Acked-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

index e63bcd5edab9787277f38e04e4c902fe511d6435..35ace1368b9ca7f30160c982023d3d6c68be5eb8 100644 (file)
@@ -6913,18 +6913,26 @@ struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
 {
        struct dma_fence *old = NULL;
 
+       dma_fence_get(gang);
        do {
                dma_fence_put(old);
                old = amdgpu_device_get_gang(adev);
                if (old == gang)
                        break;
 
-               if (!dma_fence_is_signaled(old))
+               if (!dma_fence_is_signaled(old)) {
+                       dma_fence_put(gang);
                        return old;
+               }
 
        } while (cmpxchg((struct dma_fence __force **)&adev->gang_submit,
                         old, gang) != old);
 
+       /*
+        * Drop it once for the exchanged reference in adev and once for the
+        * thread local reference acquired in amdgpu_device_get_gang().
+        */
+       dma_fence_put(old);
        dma_fence_put(old);
        return NULL;
 }