From 46d635e8bd0e797be6b64876d5ea513f8e5aead4 Mon Sep 17 00:00:00 2001 From: Arun KS Date: Fri, 15 Sep 2017 13:52:00 +0530 Subject: [PATCH 1/2] arm64: Honor limits set by bootloader Introduce a variable to save bootloader enforced memory limits and restricts adding beyond this boundary during a memory hotplug. Also, export this symbol so that other kernel module have access to it. Change-Id: I28c100644b7287ec4625c4c018b5fffc865e2e72 Signed-off-by: Arun KS [sudaraja@codeaurora.org: check limit with physical address of page] Signed-off-by: Sudarshan Rajagopalan [swatsrid@codeaurora.org: Fix merge conflicts] Signed-off-by: Swathi Sridhar [isaacm@codeaurora.org: Fix merge conflicts/use generic page onlining] Signed-off-by: Isaac J. Manjarres --- arch/arm64/include/asm/memory.h | 3 +++ arch/arm64/mm/init.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index c23c47360664..715d3a770b76 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -189,6 +189,9 @@ extern u64 kimage_vaddr; /* the offset between the kernel virtual and physical mappings */ extern u64 kimage_voffset; +/* physical memory limit imposed by the booloader */ +extern phys_addr_t bootloader_memory_limit; + static inline unsigned long kaslr_offset(void) { return kimage_vaddr - KIMAGE_VADDR; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 45c00a54909c..3184ceccc288 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -257,6 +257,7 @@ int pfn_valid(unsigned long pfn) EXPORT_SYMBOL(pfn_valid); static phys_addr_t memory_limit = PHYS_ADDR_MAX; +phys_addr_t bootloader_memory_limit; /* * Limit the memory size that was specified via FDT. @@ -349,6 +350,12 @@ void __init arm64_memblock_init(void) memblock_remove(0, memstart_addr); } + /* + * Save bootloader imposed memory limit before we overwirte + * memblock. + */ + bootloader_memory_limit = memblock_end_of_DRAM(); + /* * Apply the memory limit if it was set. Since the kernel may be loaded * high up in memory, add back the kernel region that must be accessible From d4dd236a95468bcb76f46afe3dd35d3cd401909e Mon Sep 17 00:00:00 2001 From: Arun KS Date: Mon, 9 Oct 2017 16:39:57 +0530 Subject: [PATCH 2/2] arm64: Add fallback option during memory hot add Section mapping is good for TLB. But sometimes, when system is low on physically continuous memory, this can cause memory allocation failures. Add a fallback option to allocate vmemmap pages from discontinuous pages. Change-Id: Ide921c36c1e8980a8af047e2c991310405804858 Signed-off-by: Arun KS Signed-off-by: Vinayak Menon Signed-off-by: Sudarshan Rajagopalan [swatsrid@codeaurora.org: Fix merge conflicts] Signed-off-by: Swathi Sridhar [isaacm@codeaurora.org: resolve build errors due to API changes] Signed-off-by: Isaac J. Manjarres --- arch/arm64/mm/mmu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index cf2547349826..5f61af947e46 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1116,6 +1116,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, pgd_t *pgdp; pud_t *pudp; pmd_t *pmdp; + int ret = 0; do { next = pmd_addr_end(addr, end); @@ -1133,15 +1134,23 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, void *p = NULL; p = vmemmap_alloc_block_buf(PMD_SIZE, node); - if (!p) - return -ENOMEM; + if (!p) { +#ifdef CONFIG_MEMORY_HOTPLUG + vmemmap_free(start, end, altmap); +#endif + ret = -ENOMEM; + break; + } pmd_set_huge(pmdp, __pa(p), __pgprot(PROT_SECT_NORMAL)); } else vmemmap_verify((pte_t *)pmdp, node, addr, next); } while (addr = next, addr != end); - return 0; + if (ret) + return vmemmap_populate_basepages(start, end, node); + else + return ret; } #endif /* !ARM64_SWAPPER_USES_SECTION_MAPS */ void vmemmap_free(unsigned long start, unsigned long end,