Blob Blame History Raw
From: =?UTF-8?q?Christian=20K=C3=B6nig?= <christian.koenig@amd.com>
Date: Thu, 12 Oct 2017 19:28:42 +0200
Subject: drm/ttm: fix the fix for huge compound pages
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Git-commit: 5c42c64f7d54ba560b0b001e4e73e4a1aeed1355
Patch-mainline: v4.15-rc1
References: FATE#326289 FATE#326079 FATE#326049 FATE#322398 FATE#326166

We don't use compound pages at the moment. Take this into account when
freeing them.

Signed-off-by: Christian König <christian.koenig@amd.comd>
Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Petr Tesarik <ptesarik@suse.com>
---
 drivers/gpu/drm/ttm/ttm_page_alloc.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -733,22 +733,33 @@ static void ttm_put_pages(struct page **
 		/* No pool for this memory type so free the pages */
 		i = 0;
 		while (i < npages) {
-			unsigned order;
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+			struct page *p = pages[i];
+#endif
+			unsigned order = 0, j;
 
 			if (!pages[i]) {
 				++i;
 				continue;
 			}
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+			for (j = 0; j < HPAGE_PMD_NR; ++j)
+				if (p++ != pages[i + j])
+				    break;
+
+			if (j == HPAGE_PMD_NR)
+				order = HPAGE_PMD_ORDER;
+#endif
+
 			if (page_count(pages[i]) != 1)
 				pr_err("Erroneous page count. Leaking pages.\n");
-			order = compound_order(pages[i]);
 			__free_pages(pages[i], order);
 
-			order = 1 << order;
-			while (order) {
+			j = 1 << order;
+			while (j) {
 				pages[i++] = NULL;
-				--order;
+				--j;
 			}
 		}
 		return;