Skip to content

Commit 811a240

Browse files
Konstantin KhlebnikovRussell King
authored andcommitted
ARM: 8115/1: LPAE: reduce damage caused by idmap to virtual memory layout
On LPAE, each level 1 (pgd) page table entry maps 1GiB, and the level 2 (pmd) entries map 2MiB. When the identity mapping is created on LPAE, the pgd pointers are copied from the swapper_pg_dir. If we find that we need to modify the contents of a pmd, we allocate a new empty pmd table and insert it into the appropriate 1GB slot, before then filling it with the identity mapping. However, if the 1GB slot covers the kernel lowmem mappings, we obliterate those mappings. When replacing a PMD, first copy the old PMD contents to the new PMD, so that we preserve the existing mappings, particularly the mappings of the kernel itself. [rewrote commit message and added code comment -- rmk] Fixes: ae2de10 ("ARM: LPAE: Add identity mapping support for the 3-level page table format") Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 823a19c commit 811a240

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/arm/mm/idmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
2525
pr_warning("Failed to allocate identity pmd.\n");
2626
return;
2727
}
28+
/*
29+
* Copy the original PMD to ensure that the PMD entries for
30+
* the kernel image are preserved.
31+
*/
32+
if (!pud_none(*pud))
33+
memcpy(pmd, pmd_offset(pud, 0),
34+
PTRS_PER_PMD * sizeof(pmd_t));
2835
pud_populate(&init_mm, pud, pmd);
2936
pmd += pmd_index(addr);
3037
} else

0 commit comments

Comments
 (0)