drm/amdgpu: handle the return for sync wait
Subsystems (3)
PATCH 1/2 drm/amdgpu: handle the return for sync wait
Add error handling for amdgpu_sync_wait.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6 -3
@@ -2668,7 +2668,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info) unreserve_out:ttm_eu_backoff_reservation (&ticket, &resv_list); -amdgpu_sync_wait (&sync, false); + ret =amdgpu_sync_wait (&sync, false);amdgpu_sync_free (&sync); out_free:kfree (pd_bo_list_entries);
@@ -2939,8 +2939,11 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) }/* Wait for validate and PT updates to finish */ -amdgpu_sync_wait (&sync_obj, false); - + ret =amdgpu_sync_wait (&sync_obj, false); +if (ret) { +pr_err ("Failed to wait for validate and PT updates to finish\n" ); + goto validate_map_fail; + }/* Release old eviction fence and create new one, because fence only * goes from unsignaled to signaled, fence cannot be reused. * Use context and mm from the old fence.
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
@@ -1153,7 +1153,11 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev, }amdgpu_sync_fence (&sync, vm->last_update); -amdgpu_sync_wait (&sync, false); + r =amdgpu_sync_wait (&sync, false); +if (r) { +DRM_ERROR ("failed to wait sync\n" ); + goto error; + }ttm_eu_backoff_reservation (&ticket, &list);amdgpu_sync_free (&sync);
Signature · 1 line
2.36.1
PATCH 2/2 drm/amdgpu: Add timeout for sync wait
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset->flush_delayed_work-> amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_wait
It is because the amdgpu_sync_wait is waiting for the bad job's fence, and never return, so the recover couldn't continue.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +9 -2
@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr)int i, r;hash_for_each_safe (sync->fences, i, tmp, e, node) { - r =dma_fence_wait (e->fence, intr); -if (r) +struct drm_sched_fence *s_fence =to_drm_sched_fence (e->fence); +long timeout =msecs_to_jiffies (10000 ); + +if (s_fence) + timeout = s_fence->sched->timeout; + r =dma_fence_wait_timeout (e->fence, intr, timeout); +if (r ==0 ) + r = -ETIMEDOUT ; +if (r <0 )return r;amdgpu_sync_entry_free (e);
Signature · 1 line
2.36.1
Re: [PATCH 2/2] drm/amdgpu: Add timeout for sync wait
Am 20.10.23 um 11:59 schrieb Emily Deng:
Quoted 4 lines
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset->flush_delayed_work->
amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_wait
Resolving a deadlock with a timeout is illegal in general. So this patch here is an obvious no-go.
Additional to this problem Xinhu already investigated that the delayed work is causing issues during suspend because because flushing doesn't guarantee that a new one isn't started right after doing that.
After talking with Felix about this the correct solution is to stop flushing the delayed work and instead submitting it to the freezable work queue.
Regards,
Christian.
Quoted 31 lines
It is because the
amdgpu_sync_waitis waiting for the bad job's fence, and never return, so the recover couldn't continue.Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +9
-2@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr)int i, r;hash_for_each_safe (sync->fences, i, tmp, e, node) { - r =dma_fence_wait (e->fence, intr); -if (r) +struct drm_sched_fence *s_fence =to_drm_sched_fence (e->fence); +long timeout =msecs_to_jiffies (10000 ); + +if (s_fence) + timeout = s_fence->sched->timeout; + r =dma_fence_wait_timeout (e->fence, intr, timeout); +if (r ==0 ) + r = -ETIMEDOUT ; +if (r <0 )return r;amdgpu_sync_entry_free (e);
Am 20.10.23 um 11:59 schrieb Emily Deng:
Quoted 3 lines
Add error handling for
amdgpu_sync_wait.Signed-off-by Emily Deng <[email protected]>
Going to discuss with Felix later today what we do with the timeout.
Christian.
Quoted 49 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6
-3@@ -2668,7 +2668,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info) unreserve_out:ttm_eu_backoff_reservation (&ticket, &resv_list); -amdgpu_sync_wait (&sync, false); + ret =amdgpu_sync_wait (&sync, false);amdgpu_sync_free (&sync); out_free:kfree (pd_bo_list_entries);@@ -2939,8 +2939,11 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) }/* Wait for validate and PT updates to finish */ -amdgpu_sync_wait (&sync_obj, false); - + ret =amdgpu_sync_wait (&sync_obj, false); +if (ret) { +pr_err ("Failed to wait for validate and PT updates to finish\n" ); + goto validate_map_fail; + }/* Release old eviction fence and create new one, because fence only * goes from unsignaled to signaled, fence cannot be reused. * Use context and mm from the old fence. drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5
-1@@ -1153,7 +1153,11 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev, }amdgpu_sync_fence (&sync, vm->last_update); -amdgpu_sync_wait (&sync, false); + r =amdgpu_sync_wait (&sync, false); +if (r) { +DRM_ERROR ("failed to wait sync\n" ); + goto error; + }ttm_eu_backoff_reservation (&ticket, &list);amdgpu_sync_free (&sync);