The xe kmd uses ttm_bo_move_null() when moving an unpopulated bo to VRAM. In that case the bo may still carry a ttm_tt that was created for its deferred placement, and it is left dangling on a bo whose new resource doesn't use a ttm_tt. Make ttm_bo_move_null() destroy the bo's ttm_tt when @new_mem is NULL or its memory type manager doesn't use a ttm_tt. ttm_bo_tt_destroy() is internal to TTM and not exported. Rather than exporting it, move ttm_bo_move_null() out to ttm_bo_util.c and export that instead. Patch and commit message was drafted using an LLM. Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs") Cc: Natalie Vock Cc: Arun Pravin Cc: Matthew Auld Cc: Matthew Brost Cc: dri-devel@lists.freedesktop.org Cc: # v6.8+ Signed-off-by: Thomas Hellström --- drivers/gpu/drm/ttm/ttm_bo_util.c | 20 ++++++++++++++++++++ include/drm/ttm/ttm_bo.h | 15 ++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index f9458a4d5a09..7f3459db596a 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -202,6 +202,26 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, } EXPORT_SYMBOL(ttm_bo_move_memcpy); +/** + * ttm_bo_move_null() - assign memory for a buffer object. + * @bo: The bo to assign the memory to. + * @new_mem: The memory to be assigned, or NULL. + * + * Free the current resource of @bo and assign @new_mem to it. If @new_mem is + * NULL or its memory type manager doesn't use a &struct ttm_tt, the bo's + * &struct ttm_tt, if any, is unpopulated and destroyed. + */ +void ttm_bo_move_null(struct ttm_buffer_object *bo, + struct ttm_resource *new_mem) +{ + if (!new_mem || !ttm_manager_type(bo->bdev, new_mem->mem_type)->use_tt) + ttm_bo_tt_destroy(bo); + + ttm_resource_free(bo, &bo->resource); + ttm_bo_assign_mem(bo, new_mem); +} +EXPORT_SYMBOL(ttm_bo_move_null); + static void ttm_transfered_destroy(struct ttm_buffer_object *bo) { struct ttm_transfer_obj *fbo; diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 32791c4db2a9..d525e04893ed 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -356,19 +356,8 @@ static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo, bo->resource = new_mem; } -/** - * ttm_bo_move_null - assign memory for a buffer object. - * @bo: The bo to assign the memory to - * @new_mem: The memory to be assigned. - * - * Assign the memory from new_mem to the memory of the buffer object bo. - */ -static inline void ttm_bo_move_null(struct ttm_buffer_object *bo, - struct ttm_resource *new_mem) -{ - ttm_resource_free(bo, &bo->resource); - ttm_bo_assign_mem(bo, new_mem); -} +void ttm_bo_move_null(struct ttm_buffer_object *bo, + struct ttm_resource *new_mem); /** * ttm_bo_unreserve -- 2.56.1