drm/amdgpu: free hw_vm_fence when fail in amdgpu_job_alloc
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: free hw_vm_fence when fail in amdgpu_job_alloc
If drm_sched_job_init fails, hw_vm_fence is not freed currently, then cause memory leak.
---v1->v2 changes:
* assign the return code of drm_sched_job_init and check that instead.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -2
@@ -219,8 +219,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!entity)return 0 ; -return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); + r =drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id); +if (!r) +return 0 ; + +kfree ((*job)->hw_vm_fence); err_fence:kfree ((*job)->hw_fence);
Signature · 1 line
2.34.1
Quoted 17 lines · Jiqian Chen
If
drm_sched_job_initfails,hw_vm_fenceis not freed currently, then cause memory leak.Signed-off-by Jiqian Chen <[email protected]>---
v1->v2changes:
* assign the return code ofdrm_sched_job_initand check that instead.--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 220
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -219,8 +219,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!entity)return 0 ;
I have a question that may not be related to the PATCH.
Why not check 'entity' at the beginning of function amdgpu_job_alloc()? Currently if the 'entity' is invalid, the allocated 3 structs won't be released.
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 226
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5
-2-return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); + r =drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id); +if (!r) +return 0 ; + +kfree ((*job)->hw_vm_fence);
The V2 looks good, it's already addressed the problem mentioned by Christian.
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-1err_fence:kfree ((*job)->hw_fence); --2.34.1
Quoted 23 lines · Amos Jianjun Kong
Quoted 17 lines · Jiqian Chen
If
drm_sched_job_initfails,hw_vm_fenceis not freed currently, then cause memory leak.Signed-off-by Jiqian Chen <[email protected]>---
v1->v2changes:
* assign the return code ofdrm_sched_job_initand check that instead.--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 220
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -219,8 +219,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!entity)return 0 ;I have a question that may not be related to the PATCH.
Quoted 2 lines
Why not check 'entity' at the beginning of function
amdgpu_job_alloc()? Currently if the 'entity' is invalid, the allocated 3 structs won't be released.
What I can see is not all jobs need to be associated with an entity when they are allocated. It allows entity to be NULL when allocate a new job, then return the job, like amdgpu_amdkfd_submit_ib().
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 226
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5
-2-return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); + r =drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id); +if (!r) +return 0 ; + +kfree ((*job)->hw_vm_fence);
Quoted 3 lines
The V2 looks good, it's already addressed the problem mentioned by Christian.
Reviewed-by Amos Kong <[email protected]>
Thanks.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-1err_fence:kfree ((*job)->hw_fence); --2.34.1
Signature · 2 lines
Best regards, Jiqian Chen.
Christian König
maintainerQuoted 23 lines · Amos Jianjun Kong
Quoted 17 lines · Jiqian Chen
If
drm_sched_job_initfails,hw_vm_fenceis not freed currently, then cause memory leak.Signed-off-by Jiqian Chen <[email protected]>---
v1->v2changes:
* assign the return code ofdrm_sched_job_initand check that instead.--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 220
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -219,8 +219,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!entity)return 0 ;I have a question that may not be related to the PATCH.
Quoted 2 lines
Why not check 'entity' at the beginning of function
amdgpu_job_alloc()? Currently if the 'entity' is invalid, the allocated 3 structs won't be released.
That you don't have an entity is not an error but normal condition.
It just means that the job is pushed directly to the HW without going through the scheduler.
Regards,
Christian.
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 226
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5
-2-return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); + r =drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id); +if (!r) +return 0 ; + +kfree ((*job)->hw_vm_fence);The V2 looks good, it's already addressed the problem mentioned by Christian.
Reviewed-by Amos Kong <[email protected]>Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-1err_fence:kfree ((*job)->hw_fence); --2.34.1
Quoted 4 lines · Jiqian Chen
If
drm_sched_job_initfails,hw_vm_fenceis not freed currently, then cause memory leak.Signed-off-by Jiqian Chen <[email protected]>
Quoted 3 lines
---
v1->v2changes:
* assign the return code ofdrm_sched_job_initand check that instead.
That's actually v3.
In general we keep the change log in the commit message for amdgpu changes, but doesn't really matter for such a trivial change.
Regards,
Christian.
Quoted 22 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5
-2@@ -219,8 +219,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!entity)return 0 ; -return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); + r =drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id); +if (!r) +return 0 ; + +kfree ((*job)->hw_vm_fence); err_fence:kfree ((*job)->hw_fence);