drm/amdgpu: fix possible fence leaks from job structure
Subsystems (2)
Alex Deucher
maintainerPATCH 1/1 drm/amdgpu: fix possible fence leaks from job structure
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2 -0
@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);if (ring->funcs->insert_end) ring->funcs->insert_end (ring);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +18 -0
@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }
@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Signature · 1 line
2.51.0
Ping?
Quoted 80 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +18
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) { --2.51.0
Christian König
maintainerQuoted 19 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);
I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +
This way that here can just be a kfree(..).
Regards,
Christian.
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Quoted 16 lines · Christian König
Quoted 14 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
We need the pointer for the job timed out handling.
Alex
Quoted 60 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +This way that here can just be a kfree(..).
Regards,
Christian.Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Christian König
maintainerQuoted 31 lines · Alex Deucher
Quoted 16 lines · Christian König
Quoted 14 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
Quoted 1 line
We need the pointer for the job timed out handling.
I don't think that is true. During a timeout we should have job->s_fence->parent for the HW fence.
But even when we go down that route here, you only grab a reference to the hw_fence but not the hw_vm_fence.
That looks broken to me.
Christian.
Quoted 63 lines
Alex
Quoted 60 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +This way that here can just be a kfree(..).
Regards,
Christian.Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Quoted 33 lines · Christian König
Quoted 31 lines · Alex Deucher
Quoted 28 lines · Christian König
Quoted 19 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
Quoted 7 lines
Quoted 1 line
We need the pointer for the job timed out handling.
I don't think that is true. During a timeout we should have
job->s_fence->parentfor the HW fence.But even when we go down that route here, you only grab a reference to the
hw_fencebut not thehw_vm_fence.That looks broken to me.
I also grab a reference to the vm fence. See the last hunk of the patch below.
Alex
Quoted 67 lines
Christian.
Quoted 63 lines
Alex
Quoted 60 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +This way that here can just be a kfree(..).
Regards,
Christian.Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Quoted 33 lines · Christian König
Quoted 31 lines · Alex Deucher
Quoted 28 lines · Christian König
Quoted 19 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
Quoted 3 lines
Quoted 1 line
We need the pointer for the job timed out handling.
I don't think that is true. During a timeout we should have
job->s_fence->parentfor the HW fence.
We also need to keep it around for job_submit_direct() so we can free the IBs used for that.
Alex
Quoted 71 lines
But even when we go down that route here, you only grab a reference to the
hw_fencebut not thehw_vm_fence.That looks broken to me.
Christian.
Quoted 63 lines
Alex
Quoted 60 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +This way that here can just be a kfree(..).
Regards,
Christian.Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Christian König
maintainerQuoted 35 lines · Alex Deucher
Quoted 33 lines · Christian König
Quoted 31 lines · Alex Deucher
Quoted 28 lines · Christian König
Quoted 19 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
We need the pointer for the job timed out handling.
I don't think that is true. During a timeout we should have
job->s_fence->parentfor the HW fence.We also need to keep it around for
job_submit_direct()so we can free the IBs used for that.
Good point, but that handling here is really not straight forward.
Anyway feel free to add my rb for now, but we need to re-visite that at some point.
Regards,
Christian.
Quoted 74 lines
Alex
Quoted 71 lines
But even when we go down that route here, you only grab a reference to the
hw_fencebut not thehw_vm_fence.That looks broken to me.
Christian.
Quoted 63 lines
Alex
Quoted 60 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +This way that here can just be a kfree(..).
Regards,
Christian.Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {
Quoted 39 lines · Christian König
Quoted 37 lines · Alex Deucher
Quoted 35 lines · Christian König
Quoted 32 lines · Alex Deucher
Quoted 16 lines · Christian König
Quoted 14 lines · Alex Deucher
If we don't end up initializing the fences, free them when we free the job.
v2: take a reference to the fences if we emit them
Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")Reviewed-by Jesse Zhang <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 3 files changed, 22 insertions(+)Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-0@@ -302,6 +302,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,return r; } *f = &af->base; +/* get a ref for the job */ +dma_fence_get (*f);I think it would be better to set the fence inside the job to NULL as soon as it is consumed/initialized.
We need the pointer for the job timed out handling.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I don't think that is true. During a timeout we should have
job->s_fence->parentfor the HW fence.We also need to keep it around for
job_submit_direct()so we can free the IBs used for that.Good point, but that handling here is really not straight forward.
Anyway feel free to add my rb for now, but we need to re-visite that at some point.
Thanks. I found a leak of the non-job fence. Please see the latest revision of the patch.
Alex
Quoted 79 lines
Regards,
Christian.Quoted 74 lines
Alex
Quoted 71 lines
But even when we go down that route here, you only grab a reference to the
hw_fencebut not thehw_vm_fence.That looks broken to me.
Christian.
Quoted 63 lines
Alex
Quoted 60 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0if (ring->funcs->insert_end) ring->funcs->insert_end (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -295,6 +295,15 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)amdgpu_sync_free (&job->explicit_sync);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static void amdgpu_job_free_cb(struct drm_sched_job *s_job) · line 306
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0+if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +This way that here can just be a kfree(..).
Regards,
Christian.Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0kfree (job); }@@ -324,6 +333,15 @@ void amdgpu_job_free(struct amdgpu_job *job)if (job->gang_submit != &job->base.s_fence->scheduled)dma_fence_put (job->gang_submit); +if (job->hw_fence->base.ops) +dma_fence_put (&job->hw_fence->base); +else +kfree (job->hw_fence); +if (job->hw_vm_fence->base.ops) +dma_fence_put (&job->hw_vm_fence->base); +else +kfree (job->hw_vm_fence); +kfree (job); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -845,6 +845,8 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (r)return r; fence = &job->hw_vm_fence->base; +/* get a ref for the job */ +dma_fence_get (fence); }if (vm_flush_needed) {