Skip to contentSkip to conversation

Patch "thp: use is_zero_pfn() only after pte_present() check" has been added to the 4.2-stable tree

PATCH [email protected] 1 participant 1 message Nov 6, 2015

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

thp: use is_zero_pfn() only after pte_present() check

to the 4.2-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
thp-use-is_zero_pfn-only-after-pte_present-check.patch
and it can be found in the queue-4.2 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

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: thp: use is_zero_pfn() only after pte_present() check

From: Minchan Kim <[email protected]>

commit 47aee4d8e314384807e98b67ade07f6da476aa75 upstream.

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]>
---
 mm/huge_memory.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/huge_memory.c +2 -1
@@ -2132,7 +2132,8 @@ static int __collapse_huge_page_isolate(
 	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

Patches currently in stable-queue which might be from [email protected] are

queue-4.2/thp-use-is_zero_pfn-only-after-pte_present-check.patch