Skip to contentSkip to conversation

drm/amdgpu: fix max_entries calculation v2

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

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

PATCH 1/1 drm/amdgpu: fix max_entries calculation v2

Calculate the correct value for max_entries or we might run after the page_address array.

v2: Xinhui pointed out we don't need the shift

Fixes 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 8bc2253939be..be886bdca5c6 100644
@@ -1697,7 +1697,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
 				AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 		} else {
 			addr = 0;
-			max_entries = S64_MAX;
+			max_entries = mapping->last - mapping->start + 1;
 		}
 
 		if (pages_addr) {
Signature · 6 lines
2.17.1

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

[AMD Official Use Only - Internal Distribution Only]

________________________________
From: amd-gfx <[email protected]> on behalf of Christian König <[email protected]>
Sent: Wednesday, September 2, 2020 10:05 AM
To: Pan, Xinhui <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] drm/amdgpu: fix max_entries calculation v2

Calculate the correct value for max_entries or we might run after the page_address array.

v2: Xinhui pointed out we don't need the shift

Fixes 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 8bc2253939be..be886bdca5c6 100644
@@ -1697,7 +1697,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
                                 AMDGPU_GPU_PAGES_IN_CPU_PAGE;
                 } else {
                         addr = 0;
-                       max_entries = S64_MAX;
+                       max_entries = mapping->last - mapping->start + 1;
                 }
 
                 if (pages_addr) {

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Calexander.deucher%40amd.com%7Ce5239f6d94a9480e27e008d84f4939b5%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637346523216694548&amp;sdata=OF7UX%2FLbWPJXkymt1QsdVVrQCZxI2Avj%2BBv1HYWPzxo%3D&amp;reserved=0

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

#2 lore raw
In reply to Christian König
Quoted 20 lines

2020年9月2日 22:05,Christian König <[email protected]> 写道:

Calculate the correct value for max_entries or we might run after the page_address array.

v2: Xinhui pointed out we don't need the shift

Fixes 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes

---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 8bc2253939be..be886bdca5c6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1700

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -1697,7 +1697,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
 				AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 		} else {
 			addr = 0;
-			max_entries = S64_MAX;
+			max_entries = mapping->last - mapping->start + 1;

You need minus pfn here.

The range we are going to touch is [start + offset, last].
so the max_entries is last - (start + offset) + 1. and offset is pfn in this case.

I still hit panic with this patch in practice.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
 		}
 
 		if (pages_addr) {
Signature · 1 line
2.17.1

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

#3 lore raw

Am 02.09.20 um 16:27 schrieb Pan, Xinhui:

Quoted 14 lines
Quoted 14 lines

2020年9月2日 22:05,Christian König <[email protected]> 写道:

Calculate the correct value for max_entries or we might run after the page_address array.

v2: Xinhui pointed out we don't need the shift

Fixes 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes

---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1700

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 8bc2253939be..be886bdca5c6 100644
@@ -1697,7 +1697,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
 				AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 		} else {
 			addr = 0;
-			max_entries = S64_MAX;
+			max_entries = mapping->last - mapping->start + 1;

You need minus pfn here.

That doesn't sound correct either. The pfn is the destination of the mapping, e.g. the offset inside the BO and not related to the virtual address range we map.

Quoted 4 lines

The range we are going to touch is [start + offset, last].
so the max_entries is last - (start + offset) + 1. and offset is pfn in this case.

I still hit panic with this patch in practice.

Thanks for testing, I think I know what the problem is.

We need to start instead of mapping->start or otherwise the values is to large after the first iteration.

Give me a second for a v3.

Christian.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
 		}
 
 		if (pages_addr) {
Signature · 1 line
2.17.1

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

#4 lore raw
Quoted 31 lines

2020年9月2日 22:31,Christian König <[email protected]> 写道:

Am 02.09.20 um 16:27 schrieb Pan, Xinhui:

Quoted 14 lines
Quoted 14 lines

2020年9月2日 22:05,Christian König <[email protected]> 写道:

Calculate the correct value for max_entries or we might run after the page_address array.

v2: Xinhui pointed out we don't need the shift

Fixes 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes

---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1700

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 8bc2253939be..be886bdca5c6 100644
@@ -1697,7 +1697,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
 				AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 		} else {
 			addr = 0;
-			max_entries = S64_MAX;
+			max_entries = mapping->last - mapping->start + 1;

You need minus pfn here.

Quoted 1 line

That doesn't sound correct either. The pfn is the destination of the mapping, e.g. the offset inside the BO and not related to the virtual address range we map.

I mean we need minus pfn too. pfn is mapping->offset >> PAGE_SHIFT.

In amdgpu_vm_bo_map(), there is a check below
if (bo && offset + size > amdgpu_bo_size(bo))
return -EINVAL;
so mapping->offset is just an offset_in_bytes inside the BO as you said.

mapping->start and mapping->last are virtual addresses in pfns, the range we are going to touch then is [start+ offset_in_pfns, last].

Quoted 6 lines
Quoted 5 lines

The range we are going to touch is [start + offset, last].
so the max_entries is last - (start + offset) + 1. and offset is pfn in this case.

I still hit panic with this patch in practice.

Quoted 16 lines

Thanks for testing, I think I know what the problem is.

We need to start instead of mapping->start or otherwise the values is to large after the first iteration.

Give me a second for a v3.

Christian.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
 		}
 
 		if (pages_addr) {
Signature · 1 line
2.17.1

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

#5 lore raw

Am 02.09.20 um 16:53 schrieb Pan, Xinhui:

Quoted 28 lines
Quoted 28 lines

2020年9月2日 22:31,Christian König <[email protected]> 写道:

Am 02.09.20 um 16:27 schrieb Pan, Xinhui:

Quoted 24 lines
Quoted 18 lines

2020年9月2日 22:05,Christian König <[email protected]> 写道:

Calculate the correct value for max_entries or we might run after the page_address array.

v2: Xinhui pointed out we don't need the shift

Fixes 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes

---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 8bc2253939be..be886bdca5c6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1700

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -1697,7 +1697,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
 				AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 		} else {
 			addr = 0;
-			max_entries = S64_MAX;
+			max_entries = mapping->last - mapping->start + 1;

You need minus pfn here.

Quoted 7 lines
Quoted 1 line

That doesn't sound correct either. The pfn is the destination of the mapping, e.g. the offset inside the BO and not related to the virtual address range we map.

I mean we need minus pfn too. pfn is mapping->offset >> PAGE_SHIFT.

In amdgpu_vm_bo_map(), there is a check below
if (bo && offset + size > amdgpu_bo_size(bo))
return -EINVAL;
so mapping->offset is just an offset_in_bytes inside the BO as you said.

Correct, but this is the destination of the mapping and not the covered VA space.

In other words start can be 4, last be 5 and offset 64k and it would still be valid as long as the bo is at leat 64k+2 pages in size.

Quoted 1 line

mapping->start and mapping->last are virtual addresses in pfns, the range we are going to touch then is [start+ offset_in_pfns, last].

No, that is completely unrelated.

Christian.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines

The range we are going to touch is [start + offset, last].
so the max_entries is last - (start + offset) + 1. and offset is pfn in this case.

I still hit panic with this patch in practice.

Thanks for testing, I think I know what the problem is.

We need to start instead of mapping->start or otherwise the values is to large after the first iteration.

Give me a second for a v3.

Christian.

Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
 		}
 
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
 		if (pages_addr) {
Signature · 1 line
2.17.1

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

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