<div dir="ltr"><div>Probably my previous emails went into the spam folder. Another friendly</div><div>reminder using web version of my Gmail. Thank you. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 25, 2019 at 2:22 PM Yu Zhao <<a href="mailto:yuzhao@google.com">yuzhao@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">dma_unmap_page() must be called with exactly the same dma address<br>
and size returned by dma_map_page(). Otherwise, the function may<br>
fail.<br>
<br>
This is at least the case for debug_dma_unmap_page() and AMD iommu<br>
unmap_page callback.<br>
<br>
Signed-off-by: Yu Zhao <<a href="mailto:yuzhao@google.com" target="_blank">yuzhao@google.com</a>><br>
---<br>
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 11 ++++++++++-<br>
 1 file changed, 10 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c<br>
index f841accc2c00..c1636595f63c 100644<br>
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c<br>
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c<br>
@@ -1118,10 +1118,19 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,<br>
                                                  0, num_pages * PAGE_SIZE,<br>
                                                  DMA_BIDIRECTIONAL);<br>
                if (dma_mapping_error(dev, tt->dma_address[i])) {<br>
+                       num_pages = 1;<br>
                        while (i--) {<br>
+                               if (i && tt->ttm.pages[i] -<br>
+                                        tt->ttm.pages[i - 1] == 1) {<br>
+                                       tt->dma_address[i] = 0;<br>
+                                       num_pages++;<br>
+                                       continue;<br>
+                               }<br>
                                dma_unmap_page(dev, tt->dma_address[i],<br>
-                                              PAGE_SIZE, DMA_BIDIRECTIONAL);<br>
+                                              num_pages * PAGE_SIZE,<br>
+                                              DMA_BIDIRECTIONAL);<br>
                                tt->dma_address[i] = 0;<br>
+                               num_pages = 1;<br>
                        }<br>
                        ttm_pool_unpopulate(&tt->ttm);<br>
                        return -EFAULT;<br>
-- <br>
2.21.0.392.gf8f6787159e-goog<br>
<br>
</blockquote></div></div>