Am 24.08.21 um 23:01 schrieb Andrey Grodzovsky:
This list will be used to capture all non VRAM BOs not
on LRU so when device is hot unplugged we can iterate
the list and unmap DMA mappings before device is removed.
Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@xxxxxxx>
Suggested-by: Christian König <christian.koenig@xxxxxxx>
---
drivers/gpu/drm/ttm/ttm_bo.c | 24 +++++++++++++++++++++---
drivers/gpu/drm/ttm/ttm_resource.c | 1 +
include/drm/ttm/ttm_resource.h | 1 +
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 1b950b45cf4b..84ba76ace58f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -69,16 +69,34 @@ static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo,
}
}
-static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
+static void ttm_bo_del_from_lru_imp(struct ttm_buffer_object *bo, bool final)
I think we should rather inline the only user where we actually need to
delete the BO from the LRU and then rename the function here to
ttm_bo_move_to_pinned().
Apart from that looks good to me.
Regards,
Christian.
{
struct ttm_device *bdev = bo->bdev;
+ struct ttm_resource_manager *man = NULL;
- list_del_init(&bo->lru);
+ if (bo->resource)
+ man = ttm_manager_type(bdev, bo->resource->mem_type);
+
+
+ if (!final && man && man->use_tt)
+ list_move_tail(&bo->lru, &man->pinned);
+ else
+ list_del_init(&bo->lru);
if (bdev->funcs->del_from_lru_notify)
bdev->funcs->del_from_lru_notify(bo);
}
+static inline void ttm_bo_del_from_lru_final(struct ttm_buffer_object *bo)
+{
+ ttm_bo_del_from_lru_imp(bo, true);
+}
+
+static inline void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
+{
+ ttm_bo_del_from_lru_imp(bo, false);
+}
+
static void ttm_bo_bulk_move_set_pos(struct ttm_lru_bulk_move_pos *pos,
struct ttm_buffer_object *bo)
{
@@ -453,7 +471,7 @@ static void ttm_bo_release(struct kref *kref)
}
spin_lock(&bo->bdev->lru_lock);
- ttm_bo_del_from_lru(bo);
+ ttm_bo_del_from_lru_final(bo);
list_del(&bo->ddestroy);
spin_unlock(&bo->bdev->lru_lock);
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 2431717376e7..91165f77fe0e 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -85,6 +85,7 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
INIT_LIST_HEAD(&man->lru[i]);
+ INIT_LIST_HEAD(&man->pinned);
man->move = NULL;
}
EXPORT_SYMBOL(ttm_resource_manager_init);
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index 140b6b9a8bbe..1ec0d5ebb59f 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -130,6 +130,7 @@ struct ttm_resource_manager {
*/
struct list_head lru[TTM_MAX_BO_PRIORITY];
+ struct list_head pinned;
/*
* Protected by @move_lock.