From: Minchan Kim Date: Thu, 22 Oct 2015 20:32:19 +0000 (-0700) Subject: thp: use is_zero_pfn() only after pte_present() check X-Git-Tag: v4.1.12-92~201^2~65 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3a44a401dbee902772c2356c61fe5f7a287dc806;p=users%2Fjedix%2Flinux-maple.git thp: use is_zero_pfn() only after pte_present() check Orabug: 22623830 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") Signed-off-by: Minchan Kim Reviewed-by: Andrea Arcangeli Acked-by: Kirill A. Shutemov Cc: Mel Gorman Acked-by: Vlastimil Babka Cc: Hugh Dickins Cc: Rik van Riel Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman (cherry picked from commit dc14f050d2a7bd60b32179f842a72e376cfd467b) Signed-off-by: Dan Duval --- diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 078832cf36365..8e792ec5e84c6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -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