]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 20 Apr 2025 08:17:52 +0000 (10:17 +0200)
[ Upstream commit 0d9a95099dcb05b5f4719c830d15bf4fdcad0dc2 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

index cb9e627b407d97ccb2e3dd9786addea376b2d079..d29c6716af31a6ecc1c69ce193ad5b3e720a61f3 100644 (file)
@@ -6707,18 +6707,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;
 }