From patchwork Fri Oct 24 18:16:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 5149201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 790869F30B for ; Fri, 24 Oct 2014 18:19:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EF1B2025B for ; Fri, 24 Oct 2014 18:19:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DC272025A for ; Fri, 24 Oct 2014 18:19:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhjPv-0007pq-C1; Fri, 24 Oct 2014 18:16:51 +0000 Received: from smtp.codeaurora.org ([198.145.11.231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhjPr-0007m6-Om for linux-arm-kernel@lists.infradead.org; Fri, 24 Oct 2014 18:16:48 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id A4177140096; Fri, 24 Oct 2014 18:16:26 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id 9458714009E; Fri, 24 Oct 2014 18:16:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from [10.42.111.116] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: lauraa@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C9F1A140096; Fri, 24 Oct 2014 18:16:25 +0000 (UTC) Message-ID: <544A9779.90102@codeaurora.org> Date: Fri, 24 Oct 2014 11:16:25 -0700 From: Laura Abbott User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Russell King - ARM Linux , Grygorii Strashko Subject: Re: ARM: issue with memory reservation from DT References: <543EAC5A.6050209@ti.com> <20141015175025.GJ27405@n2100.arm.linux.org.uk> <54400123.7040806@ti.com> <5440FF54.5080905@gmail.com> <544691A3.9060901@ti.com> <20141021171658.GA27405@n2100.arm.linux.org.uk> In-Reply-To: <20141021171658.GA27405@n2100.arm.linux.org.uk> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141024_111647_854895_88394945 X-CRM114-Status: GOOD ( 29.63 ) X-Spam-Score: -1.4 (-) Cc: Rob Herring , Santosh Shilimkar , "Karicheri, Muralidharan" , ssantosh@kernel.org, Grant Likely , linux-arm X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 On 10/21/2014 10:16 AM, Russell King - ARM Linux wrote: > On Tue, Oct 21, 2014 at 08:02:27PM +0300, Grygorii Strashko wrote: >> Oh. Yes you are right in general - I've just not expected from kernel >> to crash silently, so my intention was to report issue first of all. > > The problem here is that each time someone finds a new way to break it, > the code gets more complicated, which means there's yet more ways to > break it. > > As an example, try reading through sanity_check_meminfo() and working > out exactly what each variable in there does - it'll take some > considerable time to work it out. It /used/ to be pretty obvious. > > It's pretty scary too that it's walking a list of memblock regions, > while modifying that list, potentially removing the entry that it's > currently at. I suspect that would cause it to skip a region given > how the for() loop works. > > Either way, I think we need to get some of this stuff back to being > coded in a simple and obvious-to-understand manner. > The removal while iterating is pretty ugly. I was trying to match the behavior of meminfo, perhaps a little bit too closely. Here's one attempt to simplify (net 20 lines removal) -----8<----- From bfb57bb087537432acef0a109fa93f6360e6615a Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Thu, 23 Oct 2014 18:00:23 -0700 Subject: [PATCH 1/2] arm: Clean up sanity_check_meminfo The logic for sanity_check_meminfo has become difficult to follow. Clean up the code so it's more obvious what the code is actually trying to do. Additionally, meminfo is now removed so rename the function to better describe it's purpose. Signed-off-by: Laura Abbott --- arch/arm/kernel/setup.c | 4 ++-- arch/arm/mm/mmu.c | 50 +++++++++++++++---------------------------------- arch/arm/mm/nommu.c | 2 +- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 84db893d..155c69d 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -76,7 +76,7 @@ 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 *, struct proc_info_list *); -extern void sanity_check_meminfo(void); +extern void adjust_lowmem_bounds(void); extern enum reboot_mode reboot_mode; extern void setup_dma_zone(const struct machine_desc *desc); @@ -911,7 +911,7 @@ void __init setup_arch(char **cmdline_p) early_paging_init(mdesc, lookup_processor_type(read_cpuid_id())); setup_dma_zone(mdesc); - sanity_check_meminfo(); + adjust_lowmem_bounds(); arm_memblock_init(mdesc); paging_init(mdesc); diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 8348ed6..f6dfcde 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1072,50 +1072,20 @@ early_param("vmalloc", early_vmalloc); phys_addr_t arm_lowmem_limit __initdata = 0; -void __init sanity_check_meminfo(void) +void __init adjust_lowmem_bounds(void) { phys_addr_t memblock_limit = 0; - int highmem = 0; phys_addr_t vmalloc_limit = __pa(vmalloc_min - 1) + 1; struct memblock_region *reg; for_each_memblock(memory, reg) { phys_addr_t block_start = reg->base; phys_addr_t block_end = reg->base + reg->size; - phys_addr_t size_limit = reg->size; - if (reg->base >= vmalloc_limit) - highmem = 1; - else - size_limit = vmalloc_limit - reg->base; - - - if (!IS_ENABLED(CONFIG_HIGHMEM) || cache_is_vipt_aliasing()) { - - if (highmem) { - pr_notice("Ignoring RAM at %pa-%pa (!CONFIG_HIGHMEM)\n", - &block_start, &block_end); - memblock_remove(reg->base, reg->size); - continue; - } - - if (reg->size > size_limit) { - phys_addr_t overlap_size = reg->size - size_limit; - - pr_notice("Truncating RAM at %pa-%pa to -%pa", - &block_start, &block_end, &vmalloc_limit); - memblock_remove(vmalloc_limit, overlap_size); - block_end = vmalloc_limit; - } - } - - if (!highmem) { - if (block_end > arm_lowmem_limit) { - if (reg->size > size_limit) - arm_lowmem_limit = vmalloc_limit; - else - arm_lowmem_limit = block_end; - } + if (reg->base < vmalloc_limit) { + if (block_end > arm_lowmem_limit) + arm_lowmem_limit = min(vmalloc_limit, + block_end); /* * Find the first non-section-aligned page, and point @@ -1152,6 +1122,16 @@ void __init sanity_check_meminfo(void) if (!memblock_limit) memblock_limit = arm_lowmem_limit; + if (!IS_ENABLED(CONFIG_HIGHMEM) || cache_is_vipt_aliasing()) { + if (memblock_end_of_DRAM() > arm_lowmem_limit) { + phys_addr_t end = memblock_end_of_DRAM(); + + pr_notice("Ignoring RAM at %pa-%pa (!CONFIG_HIGHMEM)\n", + &memblock_limit, &end); + memblock_remove(memblock_limit, end); + } + } + memblock_set_current_limit(memblock_limit); } diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index a014dfa..f94443b 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c @@ -294,7 +294,7 @@ void __init arm_mm_memblock_reserve(void) #endif } -void __init sanity_check_meminfo(void) +void __init adjust_lowmem_bounds(void) { phys_addr_t end; sanity_check_meminfo_mpu();