Commit b9bc3670 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Mike Rapoport

ARM, xtensa: highmem: avoid clobbering non-page aligned memory reservations

free_highpages() iterates over the free memblock regions in high
memory, and marks each page as available for the memory management
system.

Until commit cddb5ddf ("arm, xtensa: simplify initialization of
high memory pages") it rounded beginning of each region upwards and end of
each region downwards.

However, after that commit free_highmem() rounds the beginning and end of
each region downwards, and we may end up freeing a page that is
memblock_reserve()d, resulting in memory corruption.

Restore the original rounding of the region boundaries to avoid freeing
reserved pages.

Fixes: cddb5ddf ("arm, xtensa: simplify initialization of high memory pages")
Link: https://lore.kernel.org/r/20201029110334.4118-1-ardb@kernel.org/
Link: https://lore.kernel.org/r/20201031094345.6984-1-rppt@kernel.orgSigned-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Co-developed-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Acked-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
parent 4ef8451b
...@@ -354,8 +354,8 @@ static void __init free_highpages(void) ...@@ -354,8 +354,8 @@ static void __init free_highpages(void)
/* set highmem page free */ /* set highmem page free */
for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
&range_start, &range_end, NULL) { &range_start, &range_end, NULL) {
unsigned long start = PHYS_PFN(range_start); unsigned long start = PFN_UP(range_start);
unsigned long end = PHYS_PFN(range_end); unsigned long end = PFN_DOWN(range_end);
/* Ignore complete lowmem entries */ /* Ignore complete lowmem entries */
if (end <= max_low) if (end <= max_low)
......
...@@ -89,8 +89,8 @@ static void __init free_highpages(void) ...@@ -89,8 +89,8 @@ static void __init free_highpages(void)
/* set highmem page free */ /* set highmem page free */
for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
&range_start, &range_end, NULL) { &range_start, &range_end, NULL) {
unsigned long start = PHYS_PFN(range_start); unsigned long start = PFN_UP(range_start);
unsigned long end = PHYS_PFN(range_end); unsigned long end = PFN_DOWN(range_end);
/* Ignore complete lowmem entries */ /* Ignore complete lowmem entries */
if (end <= max_low) if (end <= max_low)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment