Skip to contentSkip to conversation

FAILED: patch "[PATCH] thp: use is_zero_pfn() only after pte_present() check" failed to apply to 4.1-stable tree

PATCH [email protected] 2 participants 2 messages Nov 6, 2015

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 4.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

Quoted 1 line

From 47aee4d8e314384807e98b67ade07f6da476aa75 Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Thu, 22 Oct 2015 13:32:19 -0700
Subject: [PATCH] thp: use is_zero_pfn() only after pte_present() check

Use is_zero_pfn() on pteval only after pte_present() check on pteval (It might be better idea to introduce is_zero_pte() which checks pte_present() first).

Otherwise when working on a swap or migration entry and if pte_pfn's result is equal to zero_pfn by chance, we lose user's data in __collapse_huge_page_copy(). So if you're unlucky, the application segfaults and finally you could see below message on exit:

BUG: Bad rss-counter state mm:ffff88007f099300 idx:2 val:3
Fixes ca0984caa823 ("mm: incorporate zero pages into transparent huge pages")
Cc Mel Gorman <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Rik van Riel <[email protected]>
Cc <[email protected]> [4.1+]
mm/huge_memory.c +2 -1
index 4b06b8db9df2..bbac913f96bc 100644
@@ -2206,7 +2206,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
 	for (_pte = pte; _pte < pte+HPAGE_PMD_NR;
 	     _pte++, address += PAGE_SIZE) {
 		pte_t pteval = *_pte;
-		if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) {
+		if (pte_none(pteval) || (pte_present(pteval) &&
+				is_zero_pfn(pte_pfn(pteval)))) {
 			if (!userfaultfd_armed(vma) &&
 			    ++none_or_zero <= khugepaged_max_ptes_none)
 				continue;
#1 lore raw
Quoted 9 lines · On Thu, Nov 05, 2015 at 04:29:55PM -0800, [email protected] wrote:

The patch below does not apply to the 4.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

This is backport for v4.1.12.
If something is wrong, let me know it.

Thanks.

Quoted 1 line

From e87967c60da35240e161bc04b06c3f02c4bf358d Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Fri, 6 Nov 2015 11:11:08 +0900
Subject: [PATCH] thp: use is_zero_pfn() only after pte_present() check

This is backport for v4.1.12.
Original commit id is 47aee4d8e314384807e98b67ade07f6da476aa75

---
 mm/huge_memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/huge_memory.c +2 -1
index 078832c..8e792ec 100644
@@ -2137,7 +2137,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
 	for (_pte = pte; _pte < pte+HPAGE_PMD_NR;
 	     _pte++, address += PAGE_SIZE) {
 		pte_t pteval = *_pte;
-		if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) {
+		if (pte_none(pteval) || (pte_present(pteval) &&
+			is_zero_pfn(pte_pfn(pteval)))) {
 			if (++none_or_zero <= khugepaged_max_ptes_none)
 				continue;
 			else
Signature · 1 line
1.9.1