diff mbox

[2/2] drm/radeon: fix userptr BO unpin bug

Message ID 1430476453-3045-2-git-send-email-deathsimple@vodafone.de (mailing list archive)
State New, archived
Headers show

Commit Message

Christian König May 1, 2015, 10:34 a.m. UTC
From: "monk.liu" <monk.liu@amd.com>

Fixing a memory leak with userptrs.

Signed-off-by: monk.liu <monk.liu@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
CC: stable@vger.kernel.org
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Ilia Mirkin May 1, 2015, 4:40 p.m. UTC | #1
On Fri, May 1, 2015 at 6:34 AM, Christian König <deathsimple@vodafone.de> wrote:
> From: "monk.liu" <monk.liu@amd.com>
>
> Fixing a memory leak with userptrs.
>
> Signed-off-by: monk.liu <monk.liu@amd.com>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> CC: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/radeon/radeon_ttm.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index b292aca..e661841 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -606,13 +606,18 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
>         dma_unmap_sg(rdev->dev, ttm->sg->sgl, ttm->sg->nents, direction);
>
>         for_each_sg(ttm->sg->sgl, sg, ttm->sg->nents, i) {
> +               int len = sg->length >> PAGE_SHIFT;
>                 struct page *page = sg_page(sg);
> +               while (len > 0) {

This is a really awkward loop... IMO it'd be a lot clearer as

for (i = 0; i < sg->length >> PAGE_SHIFT; i++, page++)

[Also I assume that sg->length is never less than a page?]

> +                       if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
> +                               set_page_dirty(page);
>
> -               if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
> -                       set_page_dirty(page);
> +                       mark_page_accessed(page);
> +                       page_cache_release(page);
>
> -               mark_page_accessed(page);
> -               page_cache_release(page);
> +                       page++;
> +                       len--;
> +               }
>         }
>
>         sg_free_table(ttm->sg);
> --
> 1.9.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index b292aca..e661841 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -606,13 +606,18 @@  static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
 	dma_unmap_sg(rdev->dev, ttm->sg->sgl, ttm->sg->nents, direction);
 
 	for_each_sg(ttm->sg->sgl, sg, ttm->sg->nents, i) {
+		int len = sg->length >> PAGE_SHIFT;
 		struct page *page = sg_page(sg);
+		while (len > 0) {
+			if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
+				set_page_dirty(page);
 
-		if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
-			set_page_dirty(page);
+			mark_page_accessed(page);
+			page_cache_release(page);
 
-		mark_page_accessed(page);
-		page_cache_release(page);
+			page++;
+			len--;
+		}
 	}
 
 	sg_free_table(ttm->sg);