Skip to contentSkip to conversation

drm/ttm: properly unmap dma page upon failure

PATCH In review Yu Zhao 1 participant 3 messages Mar 25, 2019 – Aug 21, 2019

Subsystems (3)
lore
Share & tools
lore

Yu Zhao

author
#0 lore raw

PATCH 1/1 drm/ttm: properly unmap dma page upon failure

dma_unmap_page() must be called with exactly the same dma address and size returned by dma_map_page(). Otherwise, the function may fail.

This is at least the case for debug_dma_unmap_page() and AMD iommu unmap_page callback.

---
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +10 -1
index f841accc2c00..c1636595f63c 100644
@@ -1118,10 +1118,19 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
 						  0, num_pages * PAGE_SIZE,
 						  DMA_BIDIRECTIONAL);
 		if (dma_mapping_error(dev, tt->dma_address[i])) {
+			num_pages = 1;
 			while (i--) {
+				if (i && tt->ttm.pages[i] -
+					 tt->ttm.pages[i - 1] == 1) {
+					tt->dma_address[i] = 0;
+					num_pages++;
+					continue;
+				}
 				dma_unmap_page(dev, tt->dma_address[i],
-					       PAGE_SIZE, DMA_BIDIRECTIONAL);
+					       num_pages * PAGE_SIZE,
+					       DMA_BIDIRECTIONAL);
 				tt->dma_address[i] = 0;
+				num_pages = 1;
 			}
 			ttm_pool_unpopulate(&tt->ttm);
 			return -EFAULT;
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
author
#1 lore raw
Quoted 6 lines · Yu Zhao

dma_unmap_page() must be called with exactly the same dma address and size returned by dma_map_page(). Otherwise, the function may fail.

This is at least the case for debug_dma_unmap_page() and AMD iommu unmap_page callback.

Hi, can we please take this fix? Thanks.

author
#2 lore raw
In reply to Yu Zhao

Probably my previous emails went into the spam folder. Another friendly reminder using web version of my Gmail. Thank you.

Quoted 40 lines · Yu Zhao

dma_unmap_page() must be called with exactly the same dma address and size returned by dma_map_page(). Otherwise, the function may fail.

This is at least the case for debug_dma_unmap_page() and AMD iommu unmap_page callback.

---
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +10 -1
index f841accc2c00..c1636595f63c 100644
@@ -1118,10 +1118,19 @@ int ttm_populate_and_map_pages(struct device *dev,
 struct ttm_dma_tt *tt,
                                                  0, num_pages * PAGE_SIZE,
                                                  DMA_BIDIRECTIONAL);
                if (dma_mapping_error(dev, tt->dma_address[i])) {
+                       num_pages = 1;
                        while (i--) {
+                               if (i && tt->ttm.pages[i] -
+                                        tt->ttm.pages[i - 1] == 1) {
+                                       tt->dma_address[i] = 0;
+                                       num_pages++;
+                                       continue;
+                               }
                                dma_unmap_page(dev, tt->dma_address[i],
-                                              PAGE_SIZE,
 DMA_BIDIRECTIONAL);
+                                              num_pages * PAGE_SIZE,
+                                              DMA_BIDIRECTIONAL);
                                tt->dma_address[i] = 0;
+                               num_pages = 1;
                        }
                        ttm_pool_unpopulate(&tt->ttm);
                        return -EFAULT;
Quoted 4 lines

--
2.21.0.392.gf8f6787159e-goog

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