Skip to content

Commit 34b5835

Browse files
Michel Dänzeralexdeucher
authored andcommitted
drm/ttm: Wait for a BO to become idle before unbinding it from GTT
Fixes hangs under memory pressure, e.g. running the piglit test tex3d-maxsize concurrently with other tests. Fixes: 17d33bc ("drm/ttm: drop waiting for idle in ttm_bo_evict.") Reviewed-by: Christian König <[email protected]> Signed-off-by: Michel Dänzer <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent a5a5e30 commit 34b5835

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo,
335335
if (unlikely(r)) {
336336
goto out_cleanup;
337337
}
338-
r = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem);
338+
r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, new_mem);
339339
out_cleanup:
340340
ttm_bo_mem_put(bo, &tmp_mem);
341341
return r;
@@ -368,7 +368,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
368368
if (unlikely(r)) {
369369
return r;
370370
}
371-
r = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem);
371+
r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, &tmp_mem);
372372
if (unlikely(r)) {
373373
goto out_cleanup;
374374
}

drivers/gpu/drm/nouveau/nouveau_bo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
11511151
if (ret)
11521152
goto out;
11531153

1154-
ret = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem);
1154+
ret = ttm_bo_move_ttm(bo, true, intr, no_wait_gpu, new_mem);
11551155
out:
11561156
ttm_bo_mem_put(bo, &tmp_mem);
11571157
return ret;
@@ -1179,7 +1179,7 @@ nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict, bool intr,
11791179
if (ret)
11801180
return ret;
11811181

1182-
ret = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem);
1182+
ret = ttm_bo_move_ttm(bo, true, intr, no_wait_gpu, &tmp_mem);
11831183
if (ret)
11841184
goto out;
11851185

drivers/gpu/drm/radeon/radeon_ttm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
346346
if (unlikely(r)) {
347347
goto out_cleanup;
348348
}
349-
r = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem);
349+
r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, new_mem);
350350
out_cleanup:
351351
ttm_bo_mem_put(bo, &tmp_mem);
352352
return r;
@@ -379,7 +379,7 @@ static int radeon_move_ram_vram(struct ttm_buffer_object *bo,
379379
if (unlikely(r)) {
380380
return r;
381381
}
382-
r = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem);
382+
r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, &tmp_mem);
383383
if (unlikely(r)) {
384384
goto out_cleanup;
385385
}

drivers/gpu/drm/ttm/ttm_bo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
354354

355355
if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) &&
356356
!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED))
357-
ret = ttm_bo_move_ttm(bo, evict, no_wait_gpu, mem);
357+
ret = ttm_bo_move_ttm(bo, evict, interruptible, no_wait_gpu,
358+
mem);
358359
else if (bdev->driver->move)
359360
ret = bdev->driver->move(bo, evict, interruptible,
360361
no_wait_gpu, mem);

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,22 @@ void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
4545
}
4646

4747
int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
48-
bool evict,
48+
bool evict, bool interruptible,
4949
bool no_wait_gpu, struct ttm_mem_reg *new_mem)
5050
{
5151
struct ttm_tt *ttm = bo->ttm;
5252
struct ttm_mem_reg *old_mem = &bo->mem;
5353
int ret;
5454

5555
if (old_mem->mem_type != TTM_PL_SYSTEM) {
56+
ret = ttm_bo_wait(bo, interruptible, no_wait_gpu);
57+
58+
if (unlikely(ret != 0)) {
59+
if (ret != -ERESTARTSYS)
60+
pr_err("Failed to expire sync object before unbinding TTM\n");
61+
return ret;
62+
}
63+
5664
ttm_tt_unbind(ttm);
5765
ttm_bo_free_old_node(bo);
5866
ttm_flag_masked(&old_mem->placement, TTM_PL_FLAG_SYSTEM,

include/drm/ttm/ttm_bo_driver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
962962
*
963963
* @bo: A pointer to a struct ttm_buffer_object.
964964
* @evict: 1: This is an eviction. Don't try to pipeline.
965+
* @interruptible: Sleep interruptible if waiting.
965966
* @no_wait_gpu: Return immediately if the GPU is busy.
966967
* @new_mem: struct ttm_mem_reg indicating where to move.
967968
*
@@ -976,7 +977,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
976977
*/
977978

978979
extern int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
979-
bool evict, bool no_wait_gpu,
980+
bool evict, bool interruptible, bool no_wait_gpu,
980981
struct ttm_mem_reg *new_mem);
981982

982983
/**

0 commit comments

Comments
 (0)