Skip to content

Commit efcefc7

Browse files
author
Thomas Hellström
committed
drm/ttm: Fix ttm_bo_move_memcpy() for subclassed struct ttm_resource
The code was making a copy of a struct ttm_resource. However, recently the struct ttm_resources were allowed to be subclassed and also were allowed to be malloced, hence the driver could end up assuming the copy we handed it was subclassed and worse, the original could have been freed at this point. Fix this by using the original struct ttm_resource before it is potentially freed in ttm_bo_move_sync_cleanup() v2: Base on drm-misc-next-fixes rather than drm-tip. Reported-by: Ben Skeggs <[email protected]> Reported-by: Dave Airlie <[email protected]> Cc: Christian König <[email protected]> Cc: <[email protected]> Fixes: 3bf3710 ("drm/ttm: Add a generic TTM memcpy move for page-based iomem") Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Christian König <[email protected]> Reviewed-by: Ben Skeggs <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent bd7ffbc commit efcefc7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
143143
struct ttm_resource *src_mem = bo->resource;
144144
struct ttm_resource_manager *src_man =
145145
ttm_manager_type(bdev, src_mem->mem_type);
146-
struct ttm_resource src_copy = *src_mem;
147146
union {
148147
struct ttm_kmap_iter_tt tt;
149148
struct ttm_kmap_iter_linear_io io;
@@ -173,11 +172,11 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
173172
}
174173

175174
ttm_move_memcpy(bo, dst_mem->num_pages, dst_iter, src_iter);
176-
src_copy = *src_mem;
177-
ttm_bo_move_sync_cleanup(bo, dst_mem);
178175

179176
if (!src_iter->ops->maps_tt)
180-
ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, &src_copy);
177+
ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, src_mem);
178+
ttm_bo_move_sync_cleanup(bo, dst_mem);
179+
181180
out_src_iter:
182181
if (!dst_iter->ops->maps_tt)
183182
ttm_kmap_iter_linear_io_fini(&_dst_iter.io, bdev, dst_mem);

0 commit comments

Comments
 (0)