Skip to contentSkip to conversation

drm/amdgpu: dma_fence finished signaled by unexpected callback

PATCH In review wentalou 2 participants 4 messages Dec 21, 2018 – Dec 27, 2018 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

wentalou

author
#0 lore raw

PATCH 1/1 drm/amdgpu: dma_fence finished signaled by unexpected callback

When 2 rings met timeout at same time, triggered job_timedout separately.
Each job_timedout called gpu_recover, but one of gpu_recover locked by another's mutex_lock. Bad jod’s callback should be removed by dma_fence_remove_callback but locked inside mutex_lock. So dma_fence_remove_callback could not be called immediately.
Then callback drm_sched_process_job triggered unexpectedly, and signaled DMA_FENCE_FLAG_SIGNALED_BIT. After another's mutex_unlock, signaled bad job went through job_run inside drm_sched_job_recovery. job_run would have WARN_ON and Call-Trace, when calling kcl_dma_fence_set_error for signaled bad job.

Change-Id I6366add13f020476882b2b8b03330a58d072dd1a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -1
index 0a17fb1..fc1d3a0 100644
@@ -225,8 +225,11 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)
 
 	trace_amdgpu_sched_run_job(job);
 
-	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter))
+	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter)) {
+		/* flags might be signaled by unexpected callback, clear it */
+		test_and_clear_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &finished->flags);
 		dma_fence_set_error(finished, -ECANCELED);/* skip IB as well if VRAM lost */
+	}
 
 	if (finished->error < 0) {
 		DRM_INFO("Skip scheduling IBs!\n");
Signature · 6 lines
2.7.4

_______________________________________________
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): 1545380754-13715-1-git-send-email-Wentao.Lou-5C7GfCeVMHo@public.gmane.org

#2 lore raw

I believe this issue would be resolved by my pending  in review patch set, specifically 'drm/sched: Refactor ring mirror list handling.' since already on the first TO handler it will go over all the rings including the second timed out ring and will remove all call backs including the bad job cb. In case by this time this bad job will signal for some reason it will be removed from the mirror list already during drm_sched_process_job (take a look at 'drm/sched: Rework HW fence processing.') and hence will not be rerun in drm_sched_job_recovery (drm_sched_resubmit_jobs under the new name).

Andrey

Quoted 21 lines · wentalou

When 2 rings met timeout at same time, triggered job_timedout separately.
Each job_timedout called gpu_recover, but one of gpu_recover locked by another's mutex_lock. Bad jod’s callback should be removed by dma_fence_remove_callback but locked inside mutex_lock. So dma_fence_remove_callback could not be called immediately.
Then callback drm_sched_process_job triggered unexpectedly, and signaled DMA_FENCE_FLAG_SIGNALED_BIT. After another's mutex_unlock, signaled bad job went through job_run inside drm_sched_job_recovery. job_run would have WARN_ON and Call-Trace, when calling kcl_dma_fence_set_error for signaled bad job.

Change-Id I6366add13f020476882b2b8b03330a58d072dd1a
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index 0a17fb1..fc1d3a0 100644
@@ -225,8 +225,11 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)
 
  	trace_amdgpu_sched_run_job(job);

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job) · line 235

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -1
 
-	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter))
+	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter)) {
+		/* flags might be signaled by unexpected callback, clear it */
+		test_and_clear_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &finished->flags);
  		dma_fence_set_error(finished, -ECANCELED);/* skip IB as well if VRAM lost */
+	}
 
  	if (finished->error < 0) {
  		DRM_INFO("Skip scheduling IBs!\n");

_______________________________________________
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): cdaffc60-2261-51ee-91d6-1b265baf7dd0-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Hi Andrey,

In amd-staging-dkms-4.18's merged list, I can't find 'drm/sched: Refactor ring mirror list handling', neither 'drm/sched: Rework HW fence processing'. Now there was still much Call-Trace in new osdb triggered in dma_fence_set_error. Do you have link for these patches?
Thanks.

BR,
Wentao

-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Saturday, December 22, 2018 12:57 AM
To: Lou, Wentao <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: dma_fence finished signaled by unexpected callback

I believe this issue would be resolved by my pending  in review patch set, specifically 'drm/sched: Refactor ring mirror list handling.' since already on the first TO handler it will go over all the rings including the second timed out ring and will remove all call backs including the bad job cb. In case by this time this bad job will signal for some reason it will be removed from the mirror list already during drm_sched_process_job (take a look at 'drm/sched: Rework HW fence processing.') and hence will not be rerun in drm_sched_job_recovery (drm_sched_resubmit_jobs under the new name).

Andrey

Quoted 30 lines · wentalou

When 2 rings met timeout at same time, triggered job_timedout separately.
Each job_timedout called gpu_recover, but one of gpu_recover locked by another's mutex_lock. Bad jod’s callback should be removed by dma_fence_remove_callback but locked inside mutex_lock. So dma_fence_remove_callback could not be called immediately.
Then callback drm_sched_process_job triggered unexpectedly, and signaled DMA_FENCE_FLAG_SIGNALED_BIT. After another's mutex_unlock, signaled bad job went through job_run inside drm_sched_job_recovery. job_run would have WARN_ON and Call-Trace, when calling kcl_dma_fence_set_error for signaled bad job.

Change-Id I6366add13f020476882b2b8b03330a58d072dd1a
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +3 -1
index 0a17fb1..fc1d3a0 100644
@@ -225,8 +225,11 @@ static struct dma_fence *amdgpu_job_run(struct 
 drm_sched_job *sched_job)
 
  	trace_amdgpu_sched_run_job(job);
 
-	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter))
+	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter)) {
+		/* flags might be signaled by unexpected callback, clear it */
+		test_and_clear_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &finished->flags);
  		dma_fence_set_error(finished, -ECANCELED);/* skip IB as well if 

VRAM lost */

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job) · line 235

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -0
+	}
 
  	if (finished->error < 0) {
  		DRM_INFO("Skip scheduling IBs!\n");

_______________________________________________
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): BYAPR12MB27428794B99A9E400880D3A183B50-ZGDeBxoHBPmbrehcvEBedAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

They are still not pushed - I am fixing review comments.

Andrey

Quoted 55 lines · Wentao

Hi Andrey,

In amd-staging-dkms-4.18's merged list, I can't find 'drm/sched: Refactor ring mirror list handling', neither 'drm/sched: Rework HW fence processing'. Now there was still much Call-Trace in new osdb triggered in dma_fence_set_error. Do you have link for these patches?
Thanks.

BR,
Wentao

-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Saturday, December 22, 2018 12:57 AM
To: Lou, Wentao <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: dma_fence finished signaled by unexpected callback

I believe this issue would be resolved by my pending  in review patch set, specifically 'drm/sched: Refactor ring mirror list handling.' since already on the first TO handler it will go over all the rings including the second timed out ring and will remove all call backs including the bad job cb. In case by this time this bad job will signal for some reason it will be removed from the mirror list already during drm_sched_process_job (take a look at 'drm/sched: Rework HW fence processing.') and hence will not be rerun in drm_sched_job_recovery (drm_sched_resubmit_jobs under the new name).

Andrey

Quoted 32 lines · wentalou

When 2 rings met timeout at same time, triggered job_timedout separately.
Each job_timedout called gpu_recover, but one of gpu_recover locked by another's mutex_lock. Bad jod’s callback should be removed by dma_fence_remove_callback but locked inside mutex_lock. So dma_fence_remove_callback could not be called immediately.
Then callback drm_sched_process_job triggered unexpectedly, and signaled DMA_FENCE_FLAG_SIGNALED_BIT. After another's mutex_unlock, signaled bad job went through job_run inside drm_sched_job_recovery. job_run would have WARN_ON and Call-Trace, when calling kcl_dma_fence_set_error for signaled bad job.

Change-Id I6366add13f020476882b2b8b03330a58d072dd1a
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +3 -1
index 0a17fb1..fc1d3a0 100644
@@ -225,8 +225,11 @@ static struct dma_fence *amdgpu_job_run(struct
 drm_sched_job *sched_job)
 
   	trace_amdgpu_sched_run_job(job);
 
-	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter))
+	if (job->vram_lost_counter != atomic_read(&ring->adev->vram_lost_counter)) {
+		/* flags might be signaled by unexpected callback, clear it */
+		test_and_clear_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &finished->flags);
   		dma_fence_set_error(finished, -ECANCELED);/* skip IB as well if

VRAM lost */

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -0
+	}
Quoted 2 lines
Quoted 2 lines
   	if (finished->error < 0) {
   		DRM_INFO("Skip scheduling IBs!\n");

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx