From patchwork Wed Dec 14 02:11:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9473611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12B2560823 for ; Wed, 14 Dec 2016 02:14:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00F2B286D4 for ; Wed, 14 Dec 2016 02:14:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8327286E6; Wed, 14 Dec 2016 02:14:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 76FE8286D4 for ; Wed, 14 Dec 2016 02:14:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cGz3J-0003dZ-NY; Wed, 14 Dec 2016 02:12:17 +0000 Received: from mail-pg0-f49.google.com ([74.125.83.49]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cGz3D-0003b8-LU for linux-arm-kernel@lists.infradead.org; Wed, 14 Dec 2016 02:12:14 +0000 Received: by mail-pg0-f49.google.com with SMTP id p66so2271901pga.2 for ; Tue, 13 Dec 2016 18:11:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Y/XBJ9Crbc5jferFds4iPbYXbLGO3WFuzdsS8D5cbSY=; b=oLaEsAjSwwVyhWyC8Pw9rckGHjssiOzfohYNAKryIo3pJytjAEqcxxchnEzIC4UvU9 18M0a1oeR2yOR0RasmQPmLgVWY99N+lEI2S/jSrM2oNcxGh61zRp8ieMEVVY8YhYcruV XgL5jrZowrKPzqu1i+jvG6xHBKqH+9ho7pXMCT/qvbvD90+9gkqWytniPz/UKYkOWKIJ SplpX6Cvnlr7WzRtYMIuJg0Kr8LY2AApTbsznWRbjRBe1cpnRpNqoCmesefSoWT+YJh/ aRg6RntdcuPhPwKgBupDXdUtij1AcyGQDHd3JLhbs9Xp0SnzUds+unL24qymG1bPzptG j50A== X-Gm-Message-State: AKaTC00awTE7HHOU/xiDDcOfMeQLXbABjW6mjTA0/onFbg+GVGFL+ySSgqR5L2ajAt3LSbCQ X-Received: by 10.99.21.65 with SMTP id 1mr181929639pgv.163.1481681509472; Tue, 13 Dec 2016 18:11:49 -0800 (PST) Received: from labbott-redhat-machine.hsd1.wa.comcast.net ([2601:602:9800:177f::df9b]) by smtp.gmail.com with ESMTPSA id b71sm82628309pfj.62.2016.12.13.18.11.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 18:11:48 -0800 (PST) From: Laura Abbott To: Russell King , Nicolas Pitre Subject: [PATCH] arm: Adjust memory boundaries after reservations Date: Tue, 13 Dec 2016 18:11:41 -0800 Message-Id: <1481681501-13788-1-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161213_181211_800141_B5329609 X-CRM114-Status: GOOD ( 15.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lilja.magnus@gmail.com, Laura Abbott , festevam@gmail.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The poorly named sanity_check_meminfo is responsible for setting up the boundary for lowmem/highmem. This needs to be set up before memblock reservations can occur. At the time memblock reservations can occur, memory can also be removed from the system. This can throw off the calculation of the lowmem/highmem boundary. On some systems this may be harmless, on others this may result in incorrect ranges being passed to the main memory allocator. Correct this by recalcuating the lowmem/highmem boundary after all reservations have been made. As part of this, rename sanity_check_meminfo to actually refect what the function is doing. Reported-by: Magnus Lilja Signed-off-by: Laura Abbott Tested-by: Magnus Lilja Acked-by: Nicolas Pitre --- The particular issue I reproduced for https://marc.info/?l=linux-arm-kernel&m=148145259511248 involved the lowmem boundary being greater than the end of ram thanks to the memblock_steal. The re-calcuation should have no effect unless memory was actually removed from the system. Putting it in arm_memblock_steal doesn't cover all cases either since the devicetree memory map can also remove memory. --- arch/arm/kernel/setup.c | 12 ++++++++++-- arch/arm/mm/mmu.c | 15 +++++++++------ arch/arm/mm/nommu.c | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 34e3f3c..62f91bd 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -81,7 +81,7 @@ __setup("fpe=", fpe_setup); extern void init_default_cache_policy(unsigned long); extern void paging_init(const struct machine_desc *desc); extern void early_paging_init(const struct machine_desc *); -extern void sanity_check_meminfo(void); +extern void update_memory_bounds(void); extern enum reboot_mode reboot_mode; extern void setup_dma_zone(const struct machine_desc *desc); @@ -1093,8 +1093,16 @@ void __init setup_arch(char **cmdline_p) setup_dma_zone(mdesc); xen_early_init(); efi_init(); - sanity_check_meminfo(); + /* + * We need to make sure the calculation for lowmem/highmem is set + * appropriately before reserving/allocating any memory + */ + update_memory_bounds(); arm_memblock_init(mdesc); + /* + * Memory may have been removed so the bounds need to be recalcuated. + */ + update_memory_bounds(); early_ioremap_reset(); diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 4001dd1..666e789 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1152,13 +1152,14 @@ early_param("vmalloc", early_vmalloc); phys_addr_t arm_lowmem_limit __initdata = 0; -void __init sanity_check_meminfo(void) +void __init update_memory_bounds(void) { phys_addr_t memblock_limit = 0; int highmem = 0; u64 vmalloc_limit; struct memblock_region *reg; bool should_use_highmem = false; + phys_addr_t lowmem_limit = 0; /* * Let's use our own (unoptimized) equivalent of __pa() that is @@ -1196,18 +1197,18 @@ void __init sanity_check_meminfo(void) pr_notice("Truncating RAM at %pa-%pa", &block_start, &block_end); block_end = vmalloc_limit; - pr_cont(" to -%pa", &block_end); + pr_cont(" to -%pa\n", &block_end); memblock_remove(vmalloc_limit, overlap_size); should_use_highmem = true; } } if (!highmem) { - if (block_end > arm_lowmem_limit) { + if (block_end > lowmem_limit) { if (reg->size > size_limit) - arm_lowmem_limit = vmalloc_limit; + lowmem_limit = vmalloc_limit; else - arm_lowmem_limit = block_end; + lowmem_limit = block_end; } /* @@ -1227,12 +1228,14 @@ void __init sanity_check_meminfo(void) if (!IS_ALIGNED(block_start, PMD_SIZE)) memblock_limit = block_start; else if (!IS_ALIGNED(block_end, PMD_SIZE)) - memblock_limit = arm_lowmem_limit; + memblock_limit = lowmem_limit; } } } + arm_lowmem_limit = lowmem_limit; + if (should_use_highmem) pr_notice("Consider using a HIGHMEM enabled kernel.\n"); diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index 2740967..e5bc874 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c @@ -295,7 +295,7 @@ void __init arm_mm_memblock_reserve(void) #endif } -void __init sanity_check_meminfo(void) +void __init update_memory_bounds(void) { phys_addr_t end; sanity_check_meminfo_mpu();