Skip to contentSkip to conversation

drm/amdgpu/ttm: Fix memory leak userptr pages

PATCH Applied Daniel Gomez 3 participants 4 messages Mar 17, 2021 – Mar 19, 2021

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

PATCH 1/1 drm/amdgpu/ttm: Fix memory leak userptr pages

If userptr pages have been pinned but not bounded, they remain uncleared.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
index 9fd2157b133a..50c2b4827c13 100644
@@ -1162,13 +1162,13 @@ static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev,
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	int r;
 
-	if (!gtt->bound)
-		return;
-
 	/* if the pages have userptr pinning then clear that first */
 	if (gtt->userptr)
 		amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
 
+	if (!gtt->bound)
+		return;
+
 	if (gtt->offset == AMDGPU_BO_INVALID_OFFSET)
 		return;
 
Signature · 6 lines
2.30.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 17.03.21 um 17:08 schrieb Daniel Gomez:

Quoted 4 lines

If userptr pages have been pinned but not bounded, they remain uncleared.

Good catch, not sure if that can ever happen in practice but better save than sorry.

Quoted 15 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -3
index 9fd2157b133a..50c2b4827c13 100644
@@ -1162,13 +1162,13 @@ static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev,
  	struct amdgpu_ttm_tt *gtt = (void *)ttm;
  	int r;
 
-	if (!gtt->bound)
-		return;
-

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev, · line 1174

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -0
  	/* if the pages have userptr pinning then clear that first */
  	if (gtt->userptr)
  		amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
 
+	if (!gtt->bound)
+		return;
+
  	if (gtt->offset == AMDGPU_BO_INVALID_OFFSET)
  		return;
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw
Quoted 9 lines · Christian König

Am 17.03.21 um 17:08 schrieb Daniel Gomez:

Quoted 4 lines

If userptr pages have been pinned but not bounded, they remain uncleared.

Good catch, not sure if that can ever happen in practice but better save than sorry.

Thanks! We actually had a case with clEnqueueWriteBuffer where the driver was leaking.
I can see the problem also affects to the radeon driver so, I'll send a patch for that one as
well.

Quoted 22 lines
Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -3
index 9fd2157b133a..50c2b4827c13 100644
@@ -1162,13 +1162,13 @@ static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev,
      struct amdgpu_ttm_tt *gtt = (void *)ttm;
      int r;
 
-     if (!gtt->bound)
-             return;
-
      /* if the pages have userptr pinning then clear that first */
      if (gtt->userptr)
              amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev, · line 1174

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -0
+     if (!gtt->bound)
+             return;
+
      if (gtt->offset == AMDGPU_BO_INVALID_OFFSET)
              return;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Applied
#3 lore raw
In reply to Daniel Gomez

Applied. Thanks!

Alex

Quoted 33 lines · Daniel Gomez

If userptr pages have been pinned but not bounded, they remain uncleared.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -4
index 9fd2157b133a..50c2b4827c13 100644
@@ -1162,13 +1162,13 @@ static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev,
        struct amdgpu_ttm_tt *gtt = (void *)ttm;
        int r;
 
-       if (!gtt->bound)
-               return;
-
        /* if the pages have userptr pinning then clear that first */
        if (gtt->userptr)
                amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
 
+       if (!gtt->bound)
+               return;
+
        if (gtt->offset == AMDGPU_BO_INVALID_OFFSET)
                return;
 
--

2.30.2

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx