Skip to contentSkip to conversation

drm/amd: fix memory leak in amdgpu_cs_sync_rings

PATCH Applied Bert Karwatzki 4 participants 7 messages Feb 2, 2023 – Feb 3, 2023

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

PATCH 1/1 drm/amd: fix memory leak in amdgpu_cs_sync_rings

amdgpu_sync_get_fence deletes the returned fence from the syncobj, so the refcount of fence needs to lowered to avoid a memory leak:
https://gitlab.freedesktop.org/drm/amd/-/issues/2360

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 0f4cb41078c1..08eced097bd8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct

amdgpu_cs_parser *p)
* next job actually sees the results from the previous
one
* before we start executing on the same scheduler
ring.

                 */
-               if (!s_fence || s_fence->sched != sched)
+               if (!s_fence || s_fence->sched != sched) {
+                       dma_fence_put(fence);
                        continue;

+ }

                r = amdgpu_sync_fence(&p->gang_leader->explicit_sync,
fence);
+               dma_fence_put(fence);
                if (r)
                        return r;
        }

Bert Karwatzki

Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Bert Karwatzki

amdgpu_sync_get_fence deletes the returned fence from the syncobj, so the refcount of fence needs to lowered to avoid a memory leak:
https://gitlab.freedesktop.org/drm/amd/-/issues/2360

Please send a proper patch using git-format-patch. Also, please add your Signed-off-by line.

With those fixed, the patch is:

Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 0f4cb41078c1..08eced097bd8 100644
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct
 amdgpu_cs_parser *p)
                 * next job actually sees the results from the previous

one
* before we start executing on the same scheduler
ring.

                 */
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
-               if (!s_fence || s_fence->sched != sched)
+               if (!s_fence || s_fence->sched != sched) {
+                       dma_fence_put(fence);
                        continue;
+               }
 
                r = amdgpu_sync_fence(&p->gang_leader->explicit_sync,

fence);

+               dma_fence_put(fence);
                if (r)
                        return r;
        }

Bert Karwatzki

#2 lore raw

I hope I got it right this time:
Here is the fix for

From 6e064c9565ef0da890f3fcb2a4f6a8cd44a12fdb Mon Sep 17 00:00:00 2001
From: Bert Karwatzki <[email protected]>
Date: Thu, 2 Feb 2023 19:50:27 +0100
Subject: [PATCH] Fix memory leak in amdgpu_cs_sync_rings.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 0f4cb41078c1..08eced097bd8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct

amdgpu_cs_parser *p)
* next job actually sees the results from the
previous one
* before we start executing on the same scheduler
ring.
*/

-		if (!s_fence || s_fence->sched != sched)
+		if (!s_fence || s_fence->sched != sched) {

+ dma_fence_put(fence);
continue;
+ }

r = amdgpu_sync_fence(&p->gang_leader->explicit_sync,
fence);
+ dma_fence_put(fence);
if (r)
return r;
}

Signature · 4 lines
2.39.1


Bert Karwatzki
#3 lore raw
Quoted 35 lines · Bert Karwatzki

I hope I got it right this time:
Here is the fix for

From 6e064c9565ef0da890f3fcb2a4f6a8cd44a12fdb Mon Sep 17 00:00:00 2001
From: Bert Karwatzki <[email protected]>
Date: Thu, 2 Feb 2023 19:50:27 +0100
Subject: [PATCH] Fix memory leak in amdgpu_cs_sync_rings.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 0f4cb41078c1..08eced097bd8 100644
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct
 amdgpu_cs_parser *p)
                 * next job actually sees the results from the

previous one
* before we start executing on the same scheduler
ring.

                 */
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
-               if (!s_fence || s_fence->sched != sched)
+               if (!s_fence || s_fence->sched != sched) {
+                       dma_fence_put(fence);
                        continue;
+               }
 
                r = amdgpu_sync_fence(&p->gang_leader->explicit_sync,

fence);

Quoted 7 lines
+               dma_fence_put(fence);
                if (r)
                        return r;
        }

--
2.39.1

As a bug reporter I can confirm this patch fixes a memory leak.

Signature · 2 lines
Best Regards,
Mike Gavrilov.
Reviewed-by
#4 lore raw
In reply to Bert Karwatzki

Am 02.02.23 um 20:02 schrieb Bert Karwatzki:

Quoted 10 lines

I hope I got it right this time:
Here is the fix for

From 6e064c9565ef0da890f3fcb2a4f6a8cd44a12fdb Mon Sep 17 00:00:00 2001
From: Bert Karwatzki <[email protected]>
Date: Thu, 2 Feb 2023 19:50:27 +0100
Subject: [PATCH] Fix memory leak in amdgpu_cs_sync_rings.

Well this patch header is not properly formated, but I think Alex can fix this when he picks it up. If not I will take care of this next week.

Thanks,
Christian.

Quoted 28 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 0f4cb41078c1..08eced097bd8 100644
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct
 amdgpu_cs_parser *p)
  		 * next job actually sees the results from the

previous one
* before we start executing on the same scheduler
ring.
*/

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
-		if (!s_fence || s_fence->sched != sched)
+		if (!s_fence || s_fence->sched != sched) {
+			dma_fence_put(fence);
  			continue;
+		}
 
  		r = amdgpu_sync_fence(&p->gang_leader->explicit_sync,

fence);

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
+		dma_fence_put(fence);
  		if (r)
  			return r;
  	}
#5 lore raw
In reply to Alex Deucher

Here is the fix for (send again to test if I can get it right with Evolution)

From 6e064c9565ef0da890f3fcb2a4f6a8cd44a12fdb Mon Sep 17 00:00:00 2001
From: Bert Karwatzki <[email protected]>
Date: Thu, 2 Feb 2023 19:50:27 +0100
Subject: [PATCH] Fix memory leak in amdgpu_cs_sync_rings.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 0f4cb41078c1..08eced097bd8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct

amdgpu_cs_parser *p)
                 * next job actually sees the results from the previous one
                 * before we start executing on the same scheduler ring.
                 */

-               if (!s_fence || s_fence->sched != sched)
+               if (!s_fence || s_fence->sched != sched) {

+                       dma_fence_put(fence);
                        continue;
+               }

                r = amdgpu_sync_fence(&p->gang_leader->explicit_sync, fence);
+               dma_fence_put(fence);
                if (r)
                        return r;
        }

Applied
#6 lore raw

Applied. Thanks. I forgot to add it to the commit when I pushed it, but for posterity,

Fixes 3bd68b32c911 ("drm/amdgpu: fix pipeline sync v2:)

Alex

Quoted 40 lines · Bert Karwatzki

Here is the fix for (send again to test if I can get it right with Evolution)

From 6e064c9565ef0da890f3fcb2a4f6a8cd44a12fdb Mon Sep 17 00:00:00 2001
From: Bert Karwatzki <[email protected]>
Date: Thu, 2 Feb 2023 19:50:27 +0100
Subject: [PATCH] Fix memory leak in amdgpu_cs_sync_rings.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 0f4cb41078c1..08eced097bd8 100644
@@ -1222,10 +1222,13 @@ static int amdgpu_cs_sync_rings(struct
 amdgpu_cs_parser *p)
                 * next job actually sees the results from the

previous one
* before we start executing on the same scheduler
ring.

                 */
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
-               if (!s_fence || s_fence->sched != sched)
+               if (!s_fence || s_fence->sched != sched) {
+                       dma_fence_put(fence);
                        continue;
+               }
 
                r = amdgpu_sync_fence(&p->gang_leader->explicit_sync,

fence);

+               dma_fence_put(fence);
                if (r)
                        return r;
        }