]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.10.42/mm-thp-close-race-between-mremap-and-split_huge_page.patch
drop queue-4.14/mips-make-sure-dt-memory-regions-are-valid.patch
[thirdparty/kernel/stable-queue.git] / releases / 3.10.42 / mm-thp-close-race-between-mremap-and-split_huge_page.patch
CommitLineData
9fae0da3
GKH
1From dd18dbc2d42af75fffa60c77e0f02220bc329829 Mon Sep 17 00:00:00 2001
2From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
3Date: Fri, 9 May 2014 15:37:00 -0700
4Subject: mm, thp: close race between mremap() and split_huge_page()
5
6From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
7
8commit dd18dbc2d42af75fffa60c77e0f02220bc329829 upstream.
9
10It's critical for split_huge_page() (and migration) to catch and freeze
11all PMDs on rmap walk. It gets tricky if there's concurrent fork() or
12mremap() since usually we copy/move page table entries on dup_mm() or
13move_page_tables() without rmap lock taken. To get it work we rely on
14rmap walk order to not miss any entry. We expect to see destination VMA
15after source one to work correctly.
16
17But after switching rmap implementation to interval tree it's not always
18possible to preserve expected walk order.
19
20It works fine for dup_mm() since new VMA has the same vma_start_pgoff()
21/ vma_last_pgoff() and explicitly insert dst VMA after src one with
22vma_interval_tree_insert_after().
23
24But on move_vma() destination VMA can be merged into adjacent one and as
25result shifted left in interval tree. Fortunately, we can detect the
26situation and prevent race with rmap walk by moving page table entries
27under rmap lock. See commit 38a76013ad80.
28
29Problem is that we miss the lock when we move transhuge PMD. Most
30likely this bug caused the crash[1].
31
32[1] http://thread.gmane.org/gmane.linux.kernel.mm/96473
33
34Fixes: 108d6642ad81 ("mm anon rmap: remove anon_vma_moveto_tail")
35
36Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
37Reviewed-by: Andrea Arcangeli <aarcange@redhat.com>
38Cc: Rik van Riel <riel@redhat.com>
39Acked-by: Michel Lespinasse <walken@google.com>
40Cc: Dave Jones <davej@redhat.com>
41Cc: David Miller <davem@davemloft.net>
42Acked-by: Johannes Weiner <hannes@cmpxchg.org>
43Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
44Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
45Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46
47---
48 mm/mremap.c | 9 ++++++++-
49 1 file changed, 8 insertions(+), 1 deletion(-)
50
51--- a/mm/mremap.c
52+++ b/mm/mremap.c
53@@ -175,10 +175,17 @@ unsigned long move_page_tables(struct vm
54 break;
55 if (pmd_trans_huge(*old_pmd)) {
56 int err = 0;
57- if (extent == HPAGE_PMD_SIZE)
58+ if (extent == HPAGE_PMD_SIZE) {
59+ VM_BUG_ON(vma->vm_file || !vma->anon_vma);
60+ /* See comment in move_ptes() */
61+ if (need_rmap_locks)
62+ anon_vma_lock_write(vma->anon_vma);
63 err = move_huge_pmd(vma, new_vma, old_addr,
64 new_addr, old_end,
65 old_pmd, new_pmd);
66+ if (need_rmap_locks)
67+ anon_vma_unlock_write(vma->anon_vma);
68+ }
69 if (err > 0) {
70 need_flush = true;
71 continue;