Skip to contentSkip to conversation

drm/amdgpu: use ttm pool first

PATCH In review Chunming Zhou 5 participants 9 messages Jan 24, 2018 7 messages not in the archive

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

PATCH 1/1 drm/amdgpu: use ttm pool first

dma path is low than ttm pool.

Question:
But why need two path? What spicific problem can be solved by dma path?

Change-Id I4a9fc7103658e643f33e267616fc69743b20b09e
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +6 -4
index d32f48259c40..8d8a616bf4f5 100644
@@ -996,6 +996,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
 	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
+	int r;
 
 	if (ttm->state != tt_unpopulated)
 		return 0;
@@ -1017,13 +1018,14 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
 		return 0;
 	}
 
+	r = ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+
 #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
-		return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
+	if ((r == -EFAULT) && swiotlb_nr_tbl()) {
+		r = ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
 	}
 #endif
-
-	return ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+	return r;
 }
 
 static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
Signature · 6 lines
2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#2 lore raw
In reply to a message not in the archive

Am 24.01.2018 um 10:17 schrieb Chunming Zhou:

Quoted 1 line

dma path is low than ttm pool.

That won't work correctly in some cases.

Quoted 2 lines

Question:
But why need two path? What spicific problem can be solved by dma path?

That is mostly for ARM and some (rare) x86 platforms without IOMMU where some memory is above the 40bit limit in the PCIe address space.

Our GPUs can unfortunately only deal with 40bits of address space, so on those systems we need to go the slow path and make sure that we don't try to touch that high memory.

What we could really improve is the detection using swiotlb_nr_tbl(), cause that is actually completely wrong.

Regards,
Christian.

Quoted 28 lines
Change-Id I4a9fc7103658e643f33e267616fc69743b20b09e
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -2
index d32f48259c40..8d8a616bf4f5 100644
@@ -996,6 +996,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
  	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
  	struct amdgpu_ttm_tt *gtt = (void *)ttm;
  	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
+	int r;
 
  	if (ttm->state != tt_unpopulated)
  		return 0;
@@ -1017,13 +1018,14 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
  		return 0;
  	}
 
+	r = ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+
  #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
-		return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm, · line 1031

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -2
+	if ((r == -EFAULT) && swiotlb_nr_tbl()) {
+		r = ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
  	}
  #endif
-
-	return ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+	return r;
  }
 
  static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)

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

#4 lore raw
In reply to a message not in the archive
Quoted 5 lines · Christian König

Am 24.01.2018 um 10:17 schrieb Chunming Zhou:

Quoted 1 line

dma path is low than ttm pool.

That won't work correctly in some cases.

Quoted 8 lines
Quoted 2 lines

Question:
But why need two path? What spicific problem can be solved by dma path?

That is mostly for ARM and some (rare) x86 platforms without IOMMU where some memory is above the 40bit limit in the PCIe address space.

Our GPUs can unfortunately only deal with 40bits of address space, so on those systems we need to go the slow path and make sure that we don't try to touch that high memory.

What we could really improve is the detection using swiotlb_nr_tbl(), cause that is actually completely wrong.

OK, the patch is trying to use ttm pool first, if dma_map_page fails, then fallback to swtlb path, is that ok?

Regards,
David Zhou

Quoted 38 lines

Regards,
Christian.

Quoted 34 lines
Change-Id I4a9fc7103658e643f33e267616fc69743b20b09e

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++++++----

  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -4
index d32f48259c40..8d8a616bf4f5 100644
@@ -996,6 +996,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt 
 *ttm,
       struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
       struct amdgpu_ttm_tt *gtt = (void *)ttm;
       bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
+    int r;
         if (ttm->state != tt_unpopulated)
           return 0;
@@ -1017,13 +1018,14 @@ static int amdgpu_ttm_tt_populate(struct 
 ttm_tt *ttm,
           return 0;
       }
   +    r = ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+
   #ifdef CONFIG_SWIOTLB
-    if (swiotlb_nr_tbl()) {
-        return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
+    if ((r == -EFAULT) && swiotlb_nr_tbl()) {
+        r = ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
       }
   #endif
-
-    return ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm, · line 1031

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
+    return r;
   }
     static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)

_______________________________________________
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

#13 lore raw
In reply to a message not in the archive
Quoted 11 lines · Christian König

Am 24.01.2018 um 10:17 schrieb Chunming Zhou:

Quoted 1 line

dma path is low than ttm pool.

That won't work correctly in some cases.

Quoted 2 lines

Question:
But why need two path? What spicific problem can be solved by dma path?

That is mostly for ARM and some (rare) x86 platforms without IOMMU where some memory is above the 40bit limit in the PCIe address space.

Quoted 6 lines

Our GPUs can unfortunately only deal with 40bits of address space, so on those systems we need to go the slow path and make sure that we don't try to touch that high memory.

What we could really improve is the detection using swiotlb_nr_tbl(), cause that is actually completely wrong.

FWIW, there are other cases where SWIOTLB is needed, e.g. Secure Memory
Encryption: https://bugs.freedesktop.org/show_bug.cgi?id=104437

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#6 lore raw
In reply to a message not in the archive

Am 24.01.2018 um 10:48 schrieb Chunming Zhou:

Quoted 11 lines · Christian König
Quoted 8 lines

Am 24.01.2018 um 10:17 schrieb Chunming Zhou:

Quoted 1 line

dma path is low than ttm pool.

That won't work correctly in some cases.

Quoted 2 lines

Question:
But why need two path? What spicific problem can be solved by dma path?

Quoted 6 lines
Quoted 5 lines

That is mostly for ARM and some (rare) x86 platforms without IOMMU where some memory is above the 40bit limit in the PCIe address space.

Our GPUs can unfortunately only deal with 40bits of address space, so on those systems we need to go the slow path and make sure that we don't try to touch that high memory.

What we could really improve is the detection using swiotlb_nr_tbl(), cause that is actually completely wrong.

OK, the patch is trying to use ttm pool first, if dma_map_page fails, then fallback to swtlb path, is that ok?

Nope, as I wrote that won't work. You must improve the detection if we need coherent or not coherent allocation.

Regards,
Christian.

Quoted 50 lines

Regards,
David Zhou

Quoted 46 lines

Regards,
Christian.

Quoted 27 lines
Change-Id I4a9fc7103658e643f33e267616fc69743b20b09e

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++++++----

  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index d32f48259c40..8d8a616bf4f5 100644
@@ -996,6 +996,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt 
 *ttm,
       struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
       struct amdgpu_ttm_tt *gtt = (void *)ttm;
       bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
+    int r;
         if (ttm->state != tt_unpopulated)
           return 0;
@@ -1017,13 +1018,14 @@ static int amdgpu_ttm_tt_populate(struct 
 ttm_tt *ttm,
           return 0;
       }
   +    r = ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+
   #ifdef CONFIG_SWIOTLB
-    if (swiotlb_nr_tbl()) {

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_populate(struct · line 1030

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
-        return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
+    if ((r == -EFAULT) && swiotlb_nr_tbl()) {
+        r = ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
       }
   #endif
-
-    return ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+    return r;
   }
     static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)

_______________________________________________
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

#15 lore raw
In reply to a message not in the archive

Am 24.01.2018 um 10:49 schrieb Michel Dänzer:

Quoted 10 lines · Christian König
Quoted 9 lines

Am 24.01.2018 um 10:17 schrieb Chunming Zhou:

Quoted 1 line

dma path is low than ttm pool.

That won't work correctly in some cases.

Quoted 2 lines

Question:
But why need two path? What spicific problem can be solved by dma path?

That is mostly for ARM and some (rare) x86 platforms without IOMMU where some memory is above the 40bit limit in the PCIe address space.

Quoted 8 lines
Quoted 6 lines

Our GPUs can unfortunately only deal with 40bits of address space, so on those systems we need to go the slow path and make sure that we don't try to touch that high memory.

What we could really improve is the detection using swiotlb_nr_tbl(), cause that is actually completely wrong.

FWIW, there are other cases where SWIOTLB is needed, e.g. Secure Memory
Encryption: https://bugs.freedesktop.org/show_bug.cgi?id=104437

Oh! Good point, didn't noticed that bug before. But yes the rational makes perfect sense.

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

#8 lore raw
In reply to a message not in the archive
Quoted 12 lines · Christian König

Am 24.01.2018 um 10:48 schrieb Chunming Zhou:

Quoted 11 lines · Christian König
Quoted 8 lines

Am 24.01.2018 um 10:17 schrieb Chunming Zhou:

Quoted 1 line

dma path is low than ttm pool.

That won't work correctly in some cases.

Quoted 2 lines

Question:
But why need two path? What spicific problem can be solved by dma path?

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

That is mostly for ARM and some (rare) x86 platforms without IOMMU where some memory is above the 40bit limit in the PCIe address space.

Our GPUs can unfortunately only deal with 40bits of address space, so on those systems we need to go the slow path and make sure that we don't try to touch that high memory.

What we could really improve is the detection using swiotlb_nr_tbl(), cause that is actually completely wrong.

OK, the patch is trying to use ttm pool first, if dma_map_page fails, then fallback to swtlb path, is that ok?

Nope, as I wrote that won't work. You must improve the detection if we need coherent or not coherent allocation.

But how to differentiate coherent or not coherent allocation? check if max io address of system memory under 40bits pcie address space? Do you know how to get the max io address of system memory?

Regards,
David Zhou

Quoted 55 lines

Regards,
Christian.

Quoted 50 lines

Regards,
David Zhou

Quoted 46 lines

Regards,
Christian.

Quoted 27 lines
Change-Id I4a9fc7103658e643f33e267616fc69743b20b09e

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++++++----

  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index d32f48259c40..8d8a616bf4f5 100644
@@ -996,6 +996,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt 
 *ttm,
       struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
       struct amdgpu_ttm_tt *gtt = (void *)ttm;
       bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
+    int r;
         if (ttm->state != tt_unpopulated)
           return 0;
@@ -1017,13 +1018,14 @@ static int amdgpu_ttm_tt_populate(struct 
 ttm_tt *ttm,
           return 0;
       }
   +    r = ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+
   #ifdef CONFIG_SWIOTLB
-    if (swiotlb_nr_tbl()) {

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_populate(struct · line 1030

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
-        return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
+    if ((r == -EFAULT) && swiotlb_nr_tbl()) {
+        r = ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
       }
   #endif
-
-    return ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+    return r;
   }
     static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)

_______________________________________________
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

#10 lore raw
In reply to a message not in the archive

Am 24.01.2018 um 11:32 schrieb Chunming Zhou:

Quoted 4 lines · Christian König
Quoted 2 lines

[SNIP]
Nope, as I wrote that won't work. You must improve the detection if we need coherent or not coherent allocation.

But how to differentiate coherent or not coherent allocation? check if max io address of system memory under 40bits pcie address space? Do you know how to get the max io address of system memory?

Well that is a good question, which nobody had an answer for so far (and a couple of people already looked into it).

We could start by checking if max_pfn is <= the 40bits limit or if IOMMU is enabled instead of SWIOTLB.

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

#12 lore raw
In reply to a message not in the archive
Quoted 9 lines · Christian König

Am 24.01.2018 um 11:32 schrieb Chunming Zhou:

Quoted 4 lines · Christian König
Quoted 2 lines

[SNIP]
Nope, as I wrote that won't work. You must improve the detection if we need coherent or not coherent allocation.

But how to differentiate coherent or not coherent allocation? check if max io address of system memory under 40bits pcie address space? Do you know how to get the max io address of system memory?

Well that is a good question, which nobody had an answer for so far (and a couple of people already looked into it).

We could start by checking if max_pfn is <= the 40bits limit or if IOMMU is enabled instead of SWIOTLB.

How to get max_pfn?

btw, seems only amdgpu and radeon driver use dma path.

Regards,
David Zhou

Quoted 3 lines

Regards,
Christian.

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