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

Ilia Mirkin imirkin at alum.mit.edu
Fri May 1 09:40:30 PDT 2015


On Fri, May 1, 2015 at 6:34 AM, Christian König <deathsimple at vodafone.de> wrote:
> From: "monk.liu" <monk.liu at amd.com>
>
> Fixing a memory leak with userptrs.
>
> Signed-off-by: monk.liu <monk.liu at amd.com>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> CC: stable at 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 at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel


More information about the dri-devel mailing list