Skip to contentSkip to conversation

drm/amdgpu: fix size calculation in amdgpu_ttm_copy_mem_to_mem

PATCH In review Christian König 2 participants 2 messages Apr 3, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix size calculation in amdgpu_ttm_copy_mem_to_mem

When the node is larger than 4GB we overrun the size calculation.

Fix this by correctly limiting the size to the window as well.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
index 029b661faef6..1b658e905620 100644
@@ -454,9 +454,9 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
 		/* Copy size cannot exceed GTT_MAX_BYTES. So if src or dst
 		 * begins at an offset, then adjust the size accordingly
 		 */
-		cur_size = min3(src_node_size, dst_node_size, size);
-		cur_size = min(GTT_MAX_BYTES - src_page_offset, cur_size);
-		cur_size = min(GTT_MAX_BYTES - dst_page_offset, cur_size);
+		cur_size = max(src_page_offset, dst_page_offset);
+		cur_size = min(min3(src_node_size, dst_node_size, size),
+			       (uint64_t)(GTT_MAX_BYTES - cur_size));
 
 		/* Map src to window 0 and dst to window 1. */
 		r = amdgpu_ttm_map_buffer(src->bo, src->mem, src_mm,
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw

Am 2020-04-03 um 11:21 a.m. schrieb Christian König:

Quoted 14 lines

When the node is larger than 4GB we overrun the size calculation.

Fix this by correctly limiting the size to the window as well.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index 029b661faef6..1b658e905620 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, · line 459

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
@@ -454,9 +454,9 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
 		/* Copy size cannot exceed GTT_MAX_BYTES. So if src or dst
 		 * begins at an offset, then adjust the size accordingly
 		 */
-		cur_size = min3(src_node_size, dst_node_size, size);
-		cur_size = min(GTT_MAX_BYTES - src_page_offset, cur_size);
-		cur_size = min(GTT_MAX_BYTES - dst_page_offset, cur_size);
+		cur_size = max(src_page_offset, dst_page_offset);
+		cur_size = min(min3(src_node_size, dst_node_size, size),
+			       (uint64_t)(GTT_MAX_BYTES - cur_size));

This makes me wish for a min4 macro. I think the most efficient way to write this would be

	cur_size = min(min(src_node_size, dst_node_size),
		       min(size, (uint64_t)(GTT_MAX_BYTES - cur_size)));

Either way, this patch is

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, · line 462

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
 		/* Map src to window 0 and dst to window 1. */
 		r = amdgpu_ttm_map_buffer(src->bo, src->mem, src_mm,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx