]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.14.16/arm-8115-1-lpae-reduce-damage-caused-by-idmap-to-virtual-memory-layout.patch
drop queue-4.14/mips-make-sure-dt-memory-regions-are-valid.patch
[thirdparty/kernel/stable-queue.git] / releases / 3.14.16 / arm-8115-1-lpae-reduce-damage-caused-by-idmap-to-virtual-memory-layout.patch
1 From 811a2407a3cf7bbd027fbe92d73416f17485a3d8 Mon Sep 17 00:00:00 2001
2 From: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
3 Date: Fri, 25 Jul 2014 09:17:12 +0100
4 Subject: ARM: 8115/1: LPAE: reduce damage caused by idmap to virtual memory layout
5
6 From: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
7
8 commit 811a2407a3cf7bbd027fbe92d73416f17485a3d8 upstream.
9
10 On LPAE, each level 1 (pgd) page table entry maps 1GiB, and the level 2
11 (pmd) entries map 2MiB.
12
13 When the identity mapping is created on LPAE, the pgd pointers are copied
14 from the swapper_pg_dir. If we find that we need to modify the contents
15 of a pmd, we allocate a new empty pmd table and insert it into the
16 appropriate 1GB slot, before then filling it with the identity mapping.
17
18 However, if the 1GB slot covers the kernel lowmem mappings, we obliterate
19 those mappings.
20
21 When replacing a PMD, first copy the old PMD contents to the new PMD, so
22 that we preserve the existing mappings, particularly the mappings of the
23 kernel itself.
24
25 [rewrote commit message and added code comment -- rmk]
26
27 Fixes: ae2de101739c ("ARM: LPAE: Add identity mapping support for the 3-level page table format")
28 Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
29 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32 ---
33 arch/arm/mm/idmap.c | 7 +++++++
34 1 file changed, 7 insertions(+)
35
36 --- a/arch/arm/mm/idmap.c
37 +++ b/arch/arm/mm/idmap.c
38 @@ -25,6 +25,13 @@ static void idmap_add_pmd(pud_t *pud, un
39 pr_warning("Failed to allocate identity pmd.\n");
40 return;
41 }
42 + /*
43 + * Copy the original PMD to ensure that the PMD entries for
44 + * the kernel image are preserved.
45 + */
46 + if (!pud_none(*pud))
47 + memcpy(pmd, pmd_offset(pud, 0),
48 + PTRS_PER_PMD * sizeof(pmd_t));
49 pud_populate(&init_mm, pud, pmd);
50 pmd += pmd_index(addr);
51 } else