From patchwork Wed Nov 16 23:47:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9433225 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 9D6D360469 for ; Wed, 16 Nov 2016 23:52:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B6A7291B0 for ; Wed, 16 Nov 2016 23:52:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D792291B2; Wed, 16 Nov 2016 23:52:39 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 5C0A0291B0 for ; Wed, 16 Nov 2016 23:52:37 +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 1c79y9-0001fO-PK; Wed, 16 Nov 2016 23:50:21 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c79y3-00006Z-Jm for linux-arm-kernel@lists.infradead.org; Wed, 16 Nov 2016 23:50:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=NajbIUd4npiswBph5CiTvQbS07g2V/EVWH81lCmSQo8=; b=K2dhYhkeircSdAIZhekPb1M6SfAK+7irlc49M5DsQ9sNd6AOkoF7u4FDtzO7QuwfCXZ88ZVfjwM5uYdMz71fY4Wyhmx75frlFHHqeG6gWaWvSNMUywx2pxJU3/3jYiz4wiBQdK2Rm/+TE7soGZI8xkJVvyWtkB4uKtEQV84cNcY=; Received: from n2100.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:49614) by pandora.armlinux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1c79ve-0003zT-7J; Wed, 16 Nov 2016 23:47:46 +0000 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.76) (envelope-from ) id 1c79va-0005fa-Br; Wed, 16 Nov 2016 23:47:42 +0000 Date: Wed, 16 Nov 2016 23:47:41 +0000 From: Russell King - ARM Linux To: william.helsby@stfc.ac.uk Subject: Re: [PATCH] Replacement for Arm initrd memblock reserve and free inconsistency. Message-ID: <20161116234741.GE1041@n2100.armlinux.org.uk> References: <592F4D3D062D79449F140027567F70E8FE080A79@exchmbx03> <20161110174645.GB1041@n2100.armlinux.org.uk> <592F4D3D062D79449F140027567F70E8FE0810D3@exchmbx03> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <592F4D3D062D79449F140027567F70E8FE0810D3@exchmbx03> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161116_155016_075172_C35028B0 X-CRM114-Status: GOOD ( 17.22 ) 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: linux-arm-kernel@lists.infradead.org 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 Tue, Nov 15, 2016 at 03:45:55PM +0000, william.helsby@stfc.ac.uk wrote: > The option of moving the initrd code later (after > early_init_fdt_reserve_self(); > early_init_fdt_scan_reserved_mem() ) > was tested. Moving stuff around tends to break... I'd prefer to do it this way, as it's much more readable (and we prize readability... see Documentation/CodingStyle.) arch/arm/mm/init.c | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 370581aeb871..ffae20b25929 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -227,6 +227,48 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align) return phys; } +static void __init arm_initrd_init(void) +{ +#ifdef CONFIG_BLK_DEV_INITRD + unsigned long size; + phys_addr_t start; + + /* FDT scan will populate initrd_start */ + if (initrd_start && !phys_initrd_size) { + phys_initrd_start = __virt_to_phys(initrd_start); + phys_initrd_size = initrd_end - initrd_start; + } + + initrd_start = initrd_end = 0; + + if (!phys_initrd_size) + return; + + start = phys_initrd_start & PAGE_MASK; + size = PAGE_ALIGN(phys_initrd_size + phys_initrd_start - start); + + if (!memblock_is_region_memory(start, size)) { + pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n", + (u64)start, size); + phys_initrd_start = phys_initrd_size = 0; + return; + } + + if (memblock_is_region_reserved(start, size)) { + pr_err("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n", + (u64)start, size); + phys_initrd_start = phys_initrd_size = 0; + return; + } + + memblock_reserve(start, size); + + /* Now convert initrd to virtual addresses */ + initrd_start = __phys_to_virt(phys_initrd_start); + initrd_end = initrd_start + phys_initrd_size; +#endif +} + void __init arm_memblock_init(const struct machine_desc *mdesc) { /* Register the kernel text, kernel data and initrd with memblock. */ @@ -235,34 +277,7 @@ void __init arm_memblock_init(const struct machine_desc *mdesc) #else memblock_reserve(__pa(_stext), _end - _stext); #endif -#ifdef CONFIG_BLK_DEV_INITRD - /* FDT scan will populate initrd_start */ - if (initrd_start && !phys_initrd_size) { - phys_initrd_start = __virt_to_phys(initrd_start); - phys_initrd_size = initrd_end - initrd_start; - } - initrd_start = initrd_end = 0; - if (phys_initrd_size && - !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) { - pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n", - (u64)phys_initrd_start, phys_initrd_size); - phys_initrd_start = phys_initrd_size = 0; - } - if (phys_initrd_size && - memblock_is_region_reserved(phys_initrd_start, phys_initrd_size)) { - pr_err("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n", - (u64)phys_initrd_start, phys_initrd_size); - phys_initrd_start = phys_initrd_size = 0; - } - if (phys_initrd_size) { - memblock_reserve(phys_initrd_start, phys_initrd_size); - - /* Now convert initrd to virtual addresses */ - initrd_start = __phys_to_virt(phys_initrd_start); - initrd_end = initrd_start + phys_initrd_size; - } -#endif - + arm_initrd_init(); arm_mm_memblock_reserve(); /* reserve any platform specific memblock areas */