Skip to content

Commit e04be23

Browse files
drm/ttm: further cleanup ttm_mem_reg handling
Stop touching the backend private pointer alltogether and make sure we never put the same mem twice by. Signed-off-by: Christian König <[email protected]> Reviewed-by: Madhav Chauhan <[email protected]> Link: https://patchwork.freedesktop.org/patch/375613/
1 parent 7b81490 commit e04be23

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

drivers/gpu/drm/ttm/ttm_bo.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
312312
if (bdev->driver->move_notify)
313313
bdev->driver->move_notify(bo, evict, mem);
314314
bo->mem = *mem;
315-
mem->mm_node = NULL;
316315
goto moved;
317316
}
318317
}
@@ -616,7 +615,6 @@ static void ttm_bo_release(struct kref *kref)
616615
ttm_bo_cleanup_memtype_use(bo);
617616
dma_resv_unlock(bo->base.resv);
618617

619-
BUG_ON(bo->mem.mm_node != NULL);
620618
atomic_dec(&ttm_bo_glob.bo_count);
621619
dma_fence_put(bo->moving);
622620
if (!ttm_bo_uses_embedded_gem_object(bo))
@@ -843,12 +841,29 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
843841
return ret;
844842
}
845843

844+
static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
845+
const struct ttm_place *place,
846+
struct ttm_mem_reg *mem)
847+
{
848+
struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
849+
850+
mem->mm_node = NULL;
851+
if (!man->func || !man->func->get_node)
852+
return 0;
853+
854+
return man->func->get_node(man, bo, place, mem);
855+
}
856+
846857
void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
847858
{
848859
struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
849860

850-
if (mem->mm_node)
851-
(*man->func->put_node)(man, mem);
861+
if (!man->func || !man->func->put_node)
862+
return;
863+
864+
man->func->put_node(man, mem);
865+
mem->mm_node = NULL;
866+
mem->mem_type = TTM_PL_SYSTEM;
852867
}
853868
EXPORT_SYMBOL(ttm_bo_mem_put);
854869

@@ -902,7 +917,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
902917

903918
ticket = dma_resv_locking_ctx(bo->base.resv);
904919
do {
905-
ret = (*man->func->get_node)(man, bo, place, mem);
920+
ret = ttm_bo_mem_get(bo, place, mem);
906921
if (likely(!ret))
907922
break;
908923
if (unlikely(ret != -ENOSPC))
@@ -1032,7 +1047,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
10321047
if (unlikely(ret))
10331048
return ret;
10341049

1035-
mem->mm_node = NULL;
10361050
for (i = 0; i < placement->num_placement; ++i) {
10371051
const struct ttm_place *place = &placement->placement[i];
10381052
struct ttm_mem_type_manager *man;
@@ -1044,20 +1058,16 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
10441058
goto error;
10451059

10461060
type_found = true;
1047-
mem->mm_node = NULL;
1048-
if (mem->mem_type == TTM_PL_SYSTEM)
1049-
return 0;
1050-
1051-
man = &bdev->man[mem->mem_type];
1052-
ret = (*man->func->get_node)(man, bo, place, mem);
1061+
ret = ttm_bo_mem_get(bo, place, mem);
10531062
if (ret == -ENOSPC)
10541063
continue;
10551064
if (unlikely(ret))
10561065
goto error;
10571066

1067+
man = &bdev->man[mem->mem_type];
10581068
ret = ttm_bo_add_move_fence(bo, man, mem, ctx->no_wait_gpu);
10591069
if (unlikely(ret)) {
1060-
(*man->func->put_node)(man, mem);
1070+
ttm_bo_mem_put(bo, mem);
10611071
if (ret == -EBUSY)
10621072
continue;
10631073

@@ -1076,12 +1086,8 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
10761086
goto error;
10771087

10781088
type_found = true;
1079-
mem->mm_node = NULL;
1080-
if (mem->mem_type == TTM_PL_SYSTEM)
1081-
return 0;
1082-
10831089
ret = ttm_bo_mem_force_space(bo, place, mem, ctx);
1084-
if (ret == 0 && mem->mm_node)
1090+
if (likely(!ret))
10851091
return 0;
10861092

10871093
if (ret && ret != -EBUSY)
@@ -1129,7 +1135,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
11291135
goto out_unlock;
11301136
ret = ttm_bo_handle_move_mem(bo, &mem, false, ctx);
11311137
out_unlock:
1132-
if (ret && mem.mm_node)
1138+
if (ret)
11331139
ttm_bo_mem_put(bo, &mem);
11341140
return ret;
11351141
}
@@ -1144,7 +1150,7 @@ static bool ttm_bo_places_compat(const struct ttm_place *places,
11441150
for (i = 0; i < num_placement; i++) {
11451151
const struct ttm_place *heap = &places[i];
11461152

1147-
if (mem->mm_node && (mem->start < heap->fpfn ||
1153+
if ((mem->start < heap->fpfn ||
11481154
(heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn)))
11491155
continue;
11501156

include/drm/ttm/ttm_bo_driver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
564564
struct ttm_operation_ctx *ctx);
565565

566566
void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem);
567-
void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo,
568-
struct ttm_mem_reg *mem);
569567

570568
int ttm_bo_device_release(struct ttm_bo_device *bdev);
571569

0 commit comments

Comments
 (0)