* [PATCH] drm/amdkfd: fix double free mem structure
@ 2021-11-26 23:58 Philip Yang
2021-11-29 17:58 ` Felix Kuehling
2021-11-29 19:14 ` [PATCH v2] " Philip Yang
0 siblings, 2 replies; 4+ messages in thread
From: Philip Yang @ 2021-11-26 23:58 UTC (permalink / raw)
To: amd-gfx; +Cc: Philip Yang, Felix.Kuehling
drm_gem_object_put calls release_notify callback to free the mem
structure and unreserve_mem_limit, move it down after the last access
of mem and make it conditional call.
Signed-off-by: Philip Yang <Philip.Yang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index c5362c23e687..e592a2067133 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1582,14 +1582,16 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
err_pin_bo:
drm_vma_node_revoke(&gobj->vma_node, drm_priv);
err_node_allow:
- drm_gem_object_put(gobj);
/* Don't unreserve system mem limit twice */
goto err_reserve_limit;
err_bo_create:
unreserve_mem_limit(adev, size, flags);
err_reserve_limit:
mutex_destroy(&(*mem)->lock);
- kfree(*mem);
+ if (gobj)
+ drm_gem_object_put(gobj);
+ else
+ kfree(*mem);
err:
if (sg) {
sg_free_table(sg);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdkfd: fix double free mem structure
2021-11-26 23:58 [PATCH] drm/amdkfd: fix double free mem structure Philip Yang
@ 2021-11-29 17:58 ` Felix Kuehling
2021-11-29 19:14 ` [PATCH v2] " Philip Yang
1 sibling, 0 replies; 4+ messages in thread
From: Felix Kuehling @ 2021-11-29 17:58 UTC (permalink / raw)
To: Philip Yang, amd-gfx
Am 2021-11-26 um 6:58 p.m. schrieb Philip Yang:
> drm_gem_object_put calls release_notify callback to free the mem
> structure and unreserve_mem_limit, move it down after the last access
> of mem and make it conditional call.
>
> Signed-off-by: Philip Yang <Philip.Yang@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index c5362c23e687..e592a2067133 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1582,14 +1582,16 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
> err_pin_bo:
> drm_vma_node_revoke(&gobj->vma_node, drm_priv);
> err_node_allow:
> - drm_gem_object_put(gobj);
> /* Don't unreserve system mem limit twice */
> goto err_reserve_limit;
> err_bo_create:
> unreserve_mem_limit(adev, size, flags);
> err_reserve_limit:
> mutex_destroy(&(*mem)->lock);
> - kfree(*mem);
> + if (gobj)
For this to work you need to initialize gobj = NULL at the start of the
function. I think you should also see an "uninitialized variable"
warning without that.
Regards,
Felix
> + drm_gem_object_put(gobj);
> + else
> + kfree(*mem);
> err:
> if (sg) {
> sg_free_table(sg);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] drm/amdkfd: fix double free mem structure
2021-11-26 23:58 [PATCH] drm/amdkfd: fix double free mem structure Philip Yang
2021-11-29 17:58 ` Felix Kuehling
@ 2021-11-29 19:14 ` Philip Yang
2021-11-29 19:24 ` Felix Kuehling
1 sibling, 1 reply; 4+ messages in thread
From: Philip Yang @ 2021-11-29 19:14 UTC (permalink / raw)
To: amd-gfx; +Cc: Philip Yang, Felix.Kuehling
drm_gem_object_put calls release_notify callback to free the mem
structure and unreserve_mem_limit, move it down after the last access
of mem and make it conditional call.
Signed-off-by: Philip Yang <Philip.Yang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index c5362c23e687..5df89a295177 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1460,7 +1460,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
struct sg_table *sg = NULL;
uint64_t user_addr = 0;
struct amdgpu_bo *bo;
- struct drm_gem_object *gobj;
+ struct drm_gem_object *gobj = NULL;
u32 domain, alloc_domain;
u64 alloc_flags;
int ret;
@@ -1582,14 +1582,16 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
err_pin_bo:
drm_vma_node_revoke(&gobj->vma_node, drm_priv);
err_node_allow:
- drm_gem_object_put(gobj);
/* Don't unreserve system mem limit twice */
goto err_reserve_limit;
err_bo_create:
unreserve_mem_limit(adev, size, flags);
err_reserve_limit:
mutex_destroy(&(*mem)->lock);
- kfree(*mem);
+ if (gobj)
+ drm_gem_object_put(gobj);
+ else
+ kfree(*mem);
err:
if (sg) {
sg_free_table(sg);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/amdkfd: fix double free mem structure
2021-11-29 19:14 ` [PATCH v2] " Philip Yang
@ 2021-11-29 19:24 ` Felix Kuehling
0 siblings, 0 replies; 4+ messages in thread
From: Felix Kuehling @ 2021-11-29 19:24 UTC (permalink / raw)
To: Philip Yang, amd-gfx
Am 2021-11-29 um 2:14 p.m. schrieb Philip Yang:
> drm_gem_object_put calls release_notify callback to free the mem
> structure and unreserve_mem_limit, move it down after the last access
> of mem and make it conditional call.
>
> Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index c5362c23e687..5df89a295177 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1460,7 +1460,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
> struct sg_table *sg = NULL;
> uint64_t user_addr = 0;
> struct amdgpu_bo *bo;
> - struct drm_gem_object *gobj;
> + struct drm_gem_object *gobj = NULL;
> u32 domain, alloc_domain;
> u64 alloc_flags;
> int ret;
> @@ -1582,14 +1582,16 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
> err_pin_bo:
> drm_vma_node_revoke(&gobj->vma_node, drm_priv);
> err_node_allow:
> - drm_gem_object_put(gobj);
> /* Don't unreserve system mem limit twice */
> goto err_reserve_limit;
> err_bo_create:
> unreserve_mem_limit(adev, size, flags);
> err_reserve_limit:
> mutex_destroy(&(*mem)->lock);
> - kfree(*mem);
> + if (gobj)
> + drm_gem_object_put(gobj);
> + else
> + kfree(*mem);
> err:
> if (sg) {
> sg_free_table(sg);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-29 19:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 23:58 [PATCH] drm/amdkfd: fix double free mem structure Philip Yang
2021-11-29 17:58 ` Felix Kuehling
2021-11-29 19:14 ` [PATCH v2] " Philip Yang
2021-11-29 19:24 ` Felix Kuehling
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.