Commit 66907633 authored by Thomas Hellström's avatar Thomas Hellström

drm/ttm, drm/i915: Update ttm_move_memcpy for async use

The buffer object argument to ttm_move_memcpy was only used to
determine whether the destination memory should be cleared only
or whether we should copy data. Replace it with a "clear" bool, and
update the callers.

The intention here is to be able to use ttm_move_memcpy() async under
a dma-fence as a fallback if an accelerated blit fails in a security-
critical path where data might leak if the blit is not properly
performed. For that purpose the bo is an unsuitable argument since
its relevant members might already have changed at call time.

Finally, update the ttm_move_memcpy kerneldoc that seems to have
ended up with a stale version.

Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20210813144331.372957-3-thomas.hellstrom@linux.intel.com
Link: https://patchwork.freedesktop.org/patch/msgid/20210813144331.372957-3-thomas.hellstrom@linux.intel.com
parent d8ac30fd
...@@ -518,7 +518,7 @@ static void __i915_ttm_move(struct ttm_buffer_object *bo, bool clear, ...@@ -518,7 +518,7 @@ static void __i915_ttm_move(struct ttm_buffer_object *bo, bool clear,
obj->ttm.cached_io_st, obj->ttm.cached_io_st,
src_reg->region.start); src_reg->region.start);
ttm_move_memcpy(bo, dst_mem->num_pages, dst_iter, src_iter); ttm_move_memcpy(clear, dst_mem->num_pages, dst_iter, src_iter);
} }
} }
......
...@@ -75,22 +75,21 @@ void ttm_mem_io_free(struct ttm_device *bdev, ...@@ -75,22 +75,21 @@ void ttm_mem_io_free(struct ttm_device *bdev,
/** /**
* ttm_move_memcpy - Helper to perform a memcpy ttm move operation. * ttm_move_memcpy - Helper to perform a memcpy ttm move operation.
* @bo: The struct ttm_buffer_object. * @clear: Whether to clear rather than copy.
* @new_mem: The struct ttm_resource we're moving to (copy destination). * @num_pages: Number of pages of the operation.
* @new_iter: A struct ttm_kmap_iter representing the destination resource. * @dst_iter: A struct ttm_kmap_iter representing the destination resource.
* @src_iter: A struct ttm_kmap_iter representing the source resource. * @src_iter: A struct ttm_kmap_iter representing the source resource.
* *
* This function is intended to be able to move out async under a * This function is intended to be able to move out async under a
* dma-fence if desired. * dma-fence if desired.
*/ */
void ttm_move_memcpy(struct ttm_buffer_object *bo, void ttm_move_memcpy(bool clear,
u32 num_pages, u32 num_pages,
struct ttm_kmap_iter *dst_iter, struct ttm_kmap_iter *dst_iter,
struct ttm_kmap_iter *src_iter) struct ttm_kmap_iter *src_iter)
{ {
const struct ttm_kmap_iter_ops *dst_ops = dst_iter->ops; const struct ttm_kmap_iter_ops *dst_ops = dst_iter->ops;
const struct ttm_kmap_iter_ops *src_ops = src_iter->ops; const struct ttm_kmap_iter_ops *src_ops = src_iter->ops;
struct ttm_tt *ttm = bo->ttm;
struct dma_buf_map src_map, dst_map; struct dma_buf_map src_map, dst_map;
pgoff_t i; pgoff_t i;
...@@ -99,10 +98,7 @@ void ttm_move_memcpy(struct ttm_buffer_object *bo, ...@@ -99,10 +98,7 @@ void ttm_move_memcpy(struct ttm_buffer_object *bo,
return; return;
/* Don't move nonexistent data. Clear destination instead. */ /* Don't move nonexistent data. Clear destination instead. */
if (src_ops->maps_tt && (!ttm || !ttm_tt_is_populated(ttm))) { if (clear) {
if (ttm && !(ttm->page_flags & TTM_PAGE_FLAG_ZERO_ALLOC))
return;
for (i = 0; i < num_pages; ++i) { for (i = 0; i < num_pages; ++i) {
dst_ops->map_local(dst_iter, &dst_map, i); dst_ops->map_local(dst_iter, &dst_map, i);
if (dst_map.is_iomem) if (dst_map.is_iomem)
...@@ -146,6 +142,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, ...@@ -146,6 +142,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
struct ttm_kmap_iter_linear_io io; struct ttm_kmap_iter_linear_io io;
} _dst_iter, _src_iter; } _dst_iter, _src_iter;
struct ttm_kmap_iter *dst_iter, *src_iter; struct ttm_kmap_iter *dst_iter, *src_iter;
bool clear;
int ret = 0; int ret = 0;
if (ttm && ((ttm->page_flags & TTM_PAGE_FLAG_SWAPPED) || if (ttm && ((ttm->page_flags & TTM_PAGE_FLAG_SWAPPED) ||
...@@ -169,7 +166,10 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, ...@@ -169,7 +166,10 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
goto out_src_iter; goto out_src_iter;
} }
ttm_move_memcpy(bo, dst_mem->num_pages, dst_iter, src_iter); clear = src_iter->ops->maps_tt && (!ttm || !ttm_tt_is_populated(ttm));
if (!(clear && ttm && !(ttm->page_flags & TTM_PAGE_FLAG_ZERO_ALLOC)))
ttm_move_memcpy(clear, dst_mem->num_pages, dst_iter, src_iter);
src_copy = *src_mem; src_copy = *src_mem;
ttm_bo_move_sync_cleanup(bo, dst_mem); ttm_bo_move_sync_cleanup(bo, dst_mem);
......
...@@ -322,7 +322,7 @@ int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem); ...@@ -322,7 +322,7 @@ int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem);
*/ */
void ttm_bo_tt_destroy(struct ttm_buffer_object *bo); void ttm_bo_tt_destroy(struct ttm_buffer_object *bo);
void ttm_move_memcpy(struct ttm_buffer_object *bo, void ttm_move_memcpy(bool clear,
u32 num_pages, u32 num_pages,
struct ttm_kmap_iter *dst_iter, struct ttm_kmap_iter *dst_iter,
struct ttm_kmap_iter *src_iter); struct ttm_kmap_iter *src_iter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment