drm/amdgpu: user pages array memory leak fix
Subsystems (2)
PATCH 1/1 drm/amdgpu: user pages array memory leak fix
user_pages array should be freed regardless if user pages are invalidated after bo is created because HMM change to always allocate user pages array to get user pages while parsing user page bo.
Don't need to to get user pages while creating bo because user pages will only be used after parsing user page bo.
Bugzilla: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1844962
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 23 +---------------------- 2 files changed, 2 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -498,7 +498,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,if (r)return r; -if (binding_userptr) { +if (lobj->user_pages) {kvfree (lobj->user_pages); lobj->user_pages =NULL ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -22
@@ -283,7 +283,6 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) { -struct ttm_operation_ctx ctx = { true, false };struct amdgpu_device *adev = dev->dev_private;struct drm_amdgpu_gem_userptr *args = data;struct drm_gem_object *gobj;
@@ -326,32 +325,12 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, goto release_object; } -if (args->flags &AMDGPU_GEM_USERPTR_VALIDATE ) { - r =amdgpu_ttm_tt_get_user_pages (bo, bo->tbo.ttm->pages); -if (r) - goto release_object; - - r =amdgpu_bo_reserve (bo, true); -if (r) - goto user_pages_done; - -amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); - r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); -amdgpu_bo_unreserve (bo); -if (r) - goto user_pages_done; - } - r =drm_gem_handle_create (filp, gobj, &handle);if (r) - goto user_pages_done; + goto release_object; args->handle = handle; -user_pages_done: -if (args->flags &AMDGPU_GEM_USERPTR_VALIDATE ) -amdgpu_ttm_tt_get_user_pages_done (bo->tbo.ttm); - release_object:drm_gem_object_put_unlocked (gobj);
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
I've tested applying v2 of this patch against a v5.3 tagged kernel and it appears to fix the issue I reported.
Thanks,
-Joe
Quoted 80 lines · Philip
user_pagesarray should be freed regardless if user pages are invalidated after bo is created because HMM change to always allocate user pages array to get user pages while parsing user page bo.Don't need to to get user pages while creating bo because user pages will only be used after parsing user page bo.
Bugzilla: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1844962
Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 23 +---------------------- 2 files changed, 2 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -498,7 +498,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p, if (r) return r; -if (binding_userptr) { +if (lobj->user_pages) {kvfree (lobj->user_pages); lobj->user_pages =NULL ;}drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-1@@ -283,7 +283,6 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev,void *data, int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { - struct ttm_operation_ctx ctx = { true, false }; struct amdgpu_device *adev = dev->dev_private;struct drm_amdgpu_gem_userptr *args = data;struct drm_gem_object *gobj;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-22@@ -326,32 +325,12 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev,void *data, goto release_object; } -if (args->flags &AMDGPU_GEM_USERPTR_VALIDATE ) { - r =amdgpu_ttm_tt_get_user_pages (bo, bo->tbo.ttm->pages); -if (r) - goto release_object; - - r =amdgpu_bo_reserve (bo, true); -if (r) - goto user_pages_done; - -amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); - r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); -amdgpu_bo_unreserve (bo); -if (r) - goto user_pages_done; - } - r =drm_gem_handle_create (filp, gobj, &handle);if (r) - goto user_pages_done; + goto release_object; args->handle = handle; -user_pages_done: -if (args->flags &AMDGPU_GEM_USERPTR_VALIDATE ) -amdgpu_ttm_tt_get_user_pages_done (bo->tbo.ttm); - release_object:drm_gem_object_put_unlocked (gobj); --
Quoted 3 lines
2.17.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx