]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.19.2/mm-hugetlb-add-migration-hwpoisoned-entry-check-in-hugetlb_change_protection.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.19.2 / mm-hugetlb-add-migration-hwpoisoned-entry-check-in-hugetlb_change_protection.patch
CommitLineData
13a0632a
GKH
1From a8bda28d87c38c6aa93de28ba5d30cc18e865a11 Mon Sep 17 00:00:00 2001
2From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
3Date: Wed, 11 Feb 2015 15:25:28 -0800
4Subject: mm/hugetlb: add migration/hwpoisoned entry check in hugetlb_change_protection
5
6From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
7
8commit a8bda28d87c38c6aa93de28ba5d30cc18e865a11 upstream.
9
10There is a race condition between hugepage migration and
11change_protection(), where hugetlb_change_protection() doesn't care about
12migration entries and wrongly overwrites them. That causes unexpected
13results like kernel crash. HWPoison entries also can cause the same
14problem.
15
16This patch adds is_hugetlb_entry_(migration|hwpoisoned) check in this
17function to do proper actions.
18
19Fixes: 290408d4a2 ("hugetlb: hugepage migration core")
20Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
21Cc: Hugh Dickins <hughd@google.com>
22Cc: James Hogan <james.hogan@imgtec.com>
23Cc: David Rientjes <rientjes@google.com>
24Cc: Mel Gorman <mel@csn.ul.ie>
25Cc: Johannes Weiner <hannes@cmpxchg.org>
26Cc: Michal Hocko <mhocko@suse.cz>
27Cc: Rik van Riel <riel@redhat.com>
28Cc: Andrea Arcangeli <aarcange@redhat.com>
29Cc: Luiz Capitulino <lcapitulino@redhat.com>
30Cc: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
31Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
32Cc: Steve Capper <steve.capper@linaro.org>
33Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
34Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
35Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36
37---
38 mm/hugetlb.c | 21 ++++++++++++++++++++-
39 1 file changed, 20 insertions(+), 1 deletion(-)
40
41--- a/mm/hugetlb.c
42+++ b/mm/hugetlb.c
43@@ -3384,7 +3384,26 @@ unsigned long hugetlb_change_protection(
44 spin_unlock(ptl);
45 continue;
46 }
47- if (!huge_pte_none(huge_ptep_get(ptep))) {
48+ pte = huge_ptep_get(ptep);
49+ if (unlikely(is_hugetlb_entry_hwpoisoned(pte))) {
50+ spin_unlock(ptl);
51+ continue;
52+ }
53+ if (unlikely(is_hugetlb_entry_migration(pte))) {
54+ swp_entry_t entry = pte_to_swp_entry(pte);
55+
56+ if (is_write_migration_entry(entry)) {
57+ pte_t newpte;
58+
59+ make_migration_entry_read(&entry);
60+ newpte = swp_entry_to_pte(entry);
61+ set_huge_pte_at(mm, address, ptep, newpte);
62+ pages++;
63+ }
64+ spin_unlock(ptl);
65+ continue;
66+ }
67+ if (!huge_pte_none(pte)) {
68 pte = huge_ptep_get_and_clear(mm, address, ptep);
69 pte = pte_mkhuge(huge_pte_modify(pte, newprot));
70 pte = arch_make_huge_pte(pte, vma, NULL, 0);