All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: fix size calculation in amdgpu_ttm_copy_mem_to_mem
@ 2020-04-03 15:21 Christian König
  2020-04-03 16:02 ` Felix Kuehling
  0 siblings, 1 reply; 2+ messages in thread
From: Christian König @ 2020-04-03 15:21 UTC (permalink / raw)
  To: amd-gfx; +Cc: Felix.Kuehling, Candice.Li

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

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

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 029b661faef6..1b658e905620 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -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,
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu: fix size calculation in amdgpu_ttm_copy_mem_to_mem
  2020-04-03 15:21 [PATCH] drm/amdgpu: fix size calculation in amdgpu_ttm_copy_mem_to_mem Christian König
@ 2020-04-03 16:02 ` Felix Kuehling
  0 siblings, 0 replies; 2+ messages in thread
From: Felix Kuehling @ 2020-04-03 16:02 UTC (permalink / raw)
  To: Christian König, amd-gfx; +Cc: Candice.Li


[-- Attachment #1.1: Type: text/plain, Size: 1571 bytes --]

Am 2020-04-03 um 11:21 a.m. schrieb Christian König:
> When the node is larger than 4GB we overrun the size calculation.
>
> Fix this by correctly limiting the size to the window as well.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 029b661faef6..1b658e905620 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -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

Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>


>  
>  		/* Map src to window 0 and dst to window 1. */
>  		r = amdgpu_ttm_map_buffer(src->bo, src->mem, src_mm,

[-- Attachment #1.2: Type: text/html, Size: 2282 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-03 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 15:21 [PATCH] drm/amdgpu: fix size calculation in amdgpu_ttm_copy_mem_to_mem Christian König
2020-04-03 16:02 ` Felix Kuehling

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.