[3.16.y-ckt stable] Patch "mm/hugetlb: add migration/hwpoisoned entry check in hugetlb_change_protection" has been added to staging queue

Luis Henriques luis.henriques at canonical.com
Mon Mar 2 13:37:20 UTC 2015

This is a note to let you know that I have just added a patch titled

    mm/hugetlb: add migration/hwpoisoned entry check in hugetlb_change_protection

to the linux-3.16.y-queue branch of the 3.16.y-ckt extended stable tree 
which can be found at:


This patch is scheduled to be released in version 3.16.7-ckt8.

If you, or anyone else, feels it should not be added to this tree, please 
reply to this email.

For more information about the 3.16.y-ckt tree, see



>From cefc5fb5dfc8d6eb29bfa2a33b67b5c9d3e40384 Mon Sep 17 00:00:00 2001
From: Naoya Horiguchi <n-horiguchi at ah.jp.nec.com>
Date: Wed, 11 Feb 2015 15:25:28 -0800
Subject: mm/hugetlb: add migration/hwpoisoned entry check in

commit a8bda28d87c38c6aa93de28ba5d30cc18e865a11 upstream.

There is a race condition between hugepage migration and
change_protection(), where hugetlb_change_protection() doesn't care about
migration entries and wrongly overwrites them.  That causes unexpected
results like kernel crash.  HWPoison entries also can cause the same

This patch adds is_hugetlb_entry_(migration|hwpoisoned) check in this
function to do proper actions.

Fixes: 290408d4a2 ("hugetlb: hugepage migration core")
Signed-off-by: Naoya Horiguchi <n-horiguchi at ah.jp.nec.com>
Cc: Hugh Dickins <hughd at google.com>
Cc: James Hogan <james.hogan at imgtec.com>
Cc: David Rientjes <rientjes at google.com>
Cc: Mel Gorman <mel at csn.ul.ie>
Cc: Johannes Weiner <hannes at cmpxchg.org>
Cc: Michal Hocko <mhocko at suse.cz>
Cc: Rik van Riel <riel at redhat.com>
Cc: Andrea Arcangeli <aarcange at redhat.com>
Cc: Luiz Capitulino <lcapitulino at redhat.com>
Cc: Nishanth Aravamudan <nacc at linux.vnet.ibm.com>
Cc: Lee Schermerhorn <lee.schermerhorn at hp.com>
Cc: Steve Capper <steve.capper at linaro.org>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
Signed-off-by: Luis Henriques <luis.henriques at canonical.com>
 mm/hugetlb.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 9508a818f496..5aab37914cbd 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3392,7 +3392,26 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
-		if (!huge_pte_none(huge_ptep_get(ptep))) {
+		pte = huge_ptep_get(ptep);
+		if (unlikely(is_hugetlb_entry_hwpoisoned(pte))) {
+			spin_unlock(ptl);
+			continue;
+		}
+		if (unlikely(is_hugetlb_entry_migration(pte))) {
+			swp_entry_t entry = pte_to_swp_entry(pte);
+			if (is_write_migration_entry(entry)) {
+				pte_t newpte;
+				make_migration_entry_read(&entry);
+				newpte = swp_entry_to_pte(entry);
+				set_huge_pte_at(mm, address, ptep, newpte);
+				pages++;
+			}
+			spin_unlock(ptl);
+			continue;
+		}
+		if (!huge_pte_none(pte)) {
 			pte = huge_ptep_get_and_clear(mm, address, ptep);
 			pte = pte_mkhuge(huge_pte_modify(pte, newprot));
 			pte = arch_make_huge_pte(pte, vma, NULL, 0);

More information about the kernel-team mailing list