drm/ttm: Fix a deadlock if the target BO is not idle during swap
Subsystems (3)
PATCH 1/2 drm/ttm: Fix a deadlock if the target BO is not idle during swap
The ret value might be -EBUSY, caller will think lru lock is still locked but actually NOT. So return -ENOSPC instead. Otherwise we hit list corruption.
ttm_bo_cleanup_refs might fail too if BO is not idle. If we return 0, caller(ttm_tt_populate -> ttm_global_swapout ->ttm_device_swapout) will be stuck as we actually did not free any BO memory. This usually happens when the fence is not signaled for a long time.
--- drivers/gpu/drm/ttm/ttm_bo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +3 -3
@@ -1159,9 +1159,9 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, }if (bo->deleted) { -ttm_bo_cleanup_refs (bo, false, false, locked); + ret =ttm_bo_cleanup_refs (bo, false, false, locked);ttm_bo_put (bo); -return 0 ; +return ret == -EBUSY ? -ENOSPC : ret; }ttm_bo_move_to_pinned (bo);
@@ -1215,7 +1215,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,if (locked)dma_resv_unlock (bo->base.resv);ttm_bo_put (bo); -return ret; +return ret == -EBUSY ? -ENOSPC : ret; }void ttm_bo_tt_destroy (struct ttm_buffer_object *bo)
Signature · 1 line
2.25.1
Am 03.09.21 um 08:49 schrieb Pan, Xinhui:
Quoted 10 lines
The ret value might be
-EBUSY, caller will think lru lock is still locked but actually NOT. So return-ENOSPCinstead. Otherwise we hit list corruption.
ttm_bo_cleanup_refsmight fail too if BO is not idle. If we return 0,caller(ttm_tt_populate -> ttm_global_swapout ->ttm_device_swapout)will be stuck as we actually did not free any BO memory. This usually happens when the fence is not signaled for a long time.Signed-off-by xinhui pan <[email protected]>
Good catch, wanted to rework this for a very long time because of potential bugs like those.
Quoted 29 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +3
-3@@ -1159,9 +1159,9 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, }if (bo->deleted) { -ttm_bo_cleanup_refs (bo, false, false, locked); + ret =ttm_bo_cleanup_refs (bo, false, false, locked);ttm_bo_put (bo); -return 0 ; +return ret == -EBUSY ? -ENOSPC : ret; }ttm_bo_move_to_pinned (bo);@@ -1215,7 +1215,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,if (locked)dma_resv_unlock (bo->base.resv);ttm_bo_put (bo); -return ret; +return ret == -EBUSY ? -ENOSPC : ret; }void ttm_bo_tt_destroy (struct ttm_buffer_object *bo)
Pan, you're sending patches to [email protected], which doesn't work. You need to send them to [email protected] instead.
Signature · 2 lines
Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and X developer