Commit 4af22ded authored by Mike Rapoport's avatar Mike Rapoport Committed by Vineet Gupta

arc: fix memory initialization for systems with two memory banks

Rework of memory map initialization broke initialization of ARC systems
with two memory banks. Before these changes, memblock was not aware of
nodes configuration and the memory map was always allocated from the
"lowmem" bank. After the addition of node information to memblock, the core
mm attempts to allocate the memory map for the "highmem" bank from its
node. The access to this memory using __va() fails because it can be only
accessed using kmap.

Anther problem that was uncovered is that {min,max}_high_pfn are calculated
from u64 high_mem_start variable which prevents truncation to 32-bit
physical address and the PFN values are above the node and zone boundaries.

Use phys_addr_t type for high_mem_start and high_mem_size to ensure
correspondence between PFNs and highmem zone boundaries and reserve the
entire highmem bank until mem_init() to avoid accesses to it before highmem
is enabled.

To test this:
1. Enable HIGHMEM in ARC config
2. Enable 2 memory banks in haps_hs.dts (uncomment the 2nd bank)

Fixes: 51930df5 ("mm: free_area_init: allow defining max_zone_pfn in descending order")
Cc: stable@vger.kernel.org   [5.8]
Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
[vgupta: added instructions to test highmem]
parent 89d29997
...@@ -26,8 +26,8 @@ static unsigned long low_mem_sz; ...@@ -26,8 +26,8 @@ static unsigned long low_mem_sz;
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
static unsigned long min_high_pfn, max_high_pfn; static unsigned long min_high_pfn, max_high_pfn;
static u64 high_mem_start; static phys_addr_t high_mem_start;
static u64 high_mem_sz; static phys_addr_t high_mem_sz;
#endif #endif
#ifdef CONFIG_DISCONTIGMEM #ifdef CONFIG_DISCONTIGMEM
...@@ -69,6 +69,7 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size) ...@@ -69,6 +69,7 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)
high_mem_sz = size; high_mem_sz = size;
in_use = 1; in_use = 1;
memblock_add_node(base, size, 1); memblock_add_node(base, size, 1);
memblock_reserve(base, size);
#endif #endif
} }
...@@ -157,7 +158,7 @@ void __init setup_arch_memory(void) ...@@ -157,7 +158,7 @@ void __init setup_arch_memory(void)
min_high_pfn = PFN_DOWN(high_mem_start); min_high_pfn = PFN_DOWN(high_mem_start);
max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz); max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz);
max_zone_pfn[ZONE_HIGHMEM] = max_high_pfn; max_zone_pfn[ZONE_HIGHMEM] = min_low_pfn;
high_memory = (void *)(min_high_pfn << PAGE_SHIFT); high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
kmap_init(); kmap_init();
...@@ -166,22 +167,26 @@ void __init setup_arch_memory(void) ...@@ -166,22 +167,26 @@ void __init setup_arch_memory(void)
free_area_init(max_zone_pfn); free_area_init(max_zone_pfn);
} }
/* static void __init highmem_init(void)
* mem_init - initializes memory
*
* Frees up bootmem
* Calculates and displays memory available/used
*/
void __init mem_init(void)
{ {
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
unsigned long tmp; unsigned long tmp;
reset_all_zones_managed_pages(); memblock_free(high_mem_start, high_mem_sz);
for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++) for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++)
free_highmem_page(pfn_to_page(tmp)); free_highmem_page(pfn_to_page(tmp));
#endif #endif
}
/*
* mem_init - initializes memory
*
* Frees up bootmem
* Calculates and displays memory available/used
*/
void __init mem_init(void)
{
memblock_free_all(); memblock_free_all();
highmem_init();
mem_init_print_info(NULL); mem_init_print_info(NULL);
} }
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