From patchwork Thu Nov 10 17:46:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9421837 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 D5B4560484 for ; Thu, 10 Nov 2016 17:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B66EA29783 for ; Thu, 10 Nov 2016 17:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9CE9297EB; Thu, 10 Nov 2016 17:48:58 +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 B5CFB29783 for ; Thu, 10 Nov 2016 17:48:56 +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 1c4tRZ-0006zF-LL; Thu, 10 Nov 2016 17:47: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 1c4tRU-0006kd-57 for linux-arm-kernel@lists.infradead.org; Thu, 10 Nov 2016 17:47:18 +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-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=B1IlqtPXRBIvz4LRbGgEtK0/NOVLObx00hwbAE0LIts=; b=irlKB5ORB2XHyaxMLSwZhfpTEKn8iG81bExulaahpX1mOqBujDodfJU3SzmiKWqlVN+uKKQ76oTor6rP8s+zAmocO0sEZpkz0dOJuEtR0bekzm1v5XwDfDt3djF1skCOWCZlrnvqMXn0sUyeTJT2yQCLClwVFcWEsClFJZRoKr8=; Received: from n2100.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:37156) by pandora.armlinux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1c4tR3-0008WR-Ho; Thu, 10 Nov 2016 17:46:49 +0000 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.76) (envelope-from ) id 1c4tR0-0002OB-9X; Thu, 10 Nov 2016 17:46:46 +0000 Date: Thu, 10 Nov 2016 17:46:45 +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: <20161110174645.GB1041@n2100.armlinux.org.uk> References: <592F4D3D062D79449F140027567F70E8FE080A79@exchmbx03> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <592F4D3D062D79449F140027567F70E8FE080A79@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-20161110_094716_757090_FF260348 X-CRM114-Status: GOOD ( 23.83 ) 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 Wed, Nov 09, 2016 at 04:35:37PM +0000, william.helsby@stfc.ac.uk wrote: > A boot time system crash was noticed with a segmentation fault just after the initrd image had been used to initialise the ramdisk. > This occurred when the U-Boot loaded the ramdisk image from a FAT partition, but not when loaded by TFTPBOOT. This is not understood? > However the problem was caused by free_initrd_mem freeing and "poisoning" memory that had been allocted to init/main.c to store the saved_command_line > This patch reverses "ARM: 8167/1: extend the reserved memory for initrd to be page aligned" because it is safer to leave a partial head or tail page reserved (wasted) than to free a page which is partially still in use. > If this is not acceptable (particularly if wanting large contiguous physical areas for DMA) then a better solution is required. > This would extend the region reserved to page boundaries, if possible without overlapping other regions. My previous attempt to fix this coded this scheme, to grow the are reserved. > However, this  again is not safe if in growing the area it then overlaps a region that is in use. > Note this path is against the 4.6 kernel, but as far as I can tell applies equally to 4.8. Please wrap commit messages at or before column 72, the exception is for lines with a URL. > diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c > index 370581a..ff3e9c3 100644 > --- a/arch/arm/mm/init.c > +++ b/arch/arm/mm/init.c > @@ -770,12 +770,6 @@ static int keep_initrd; > void free_initrd_mem(unsigned long start, unsigned long end) > { >         if (!keep_initrd) { > -               if (start == initrd_start) > -                       start = round_down(start, PAGE_SIZE); > -               if (end == initrd_end) > -                       end = round_up(end, PAGE_SIZE); > - > -               poison_init_mem((void *)start, PAGE_ALIGN(end) - start); We're definitely not getting rid of the poisoning of the pages - the poisoning there is to detect accesses to this memory which should not be made. The point of rounding up and down is to ensure that the partly-used pages (which would have been previously reserved) are freed. Probably a better fix is to round the start up/end down of the initrd when reserving the memory region: arch/arm/mm/init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) and this should ensure that memblock_alloc() doesn't try to allocate memory overlapping the pages containing the initrd. Intentionally using pages overlapping the initrd is a recipe for problems... diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 370581aeb871..ee8509e4329d 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -255,7 +255,11 @@ void __init arm_memblock_init(const struct machine_desc *mdesc) phys_initrd_start = phys_initrd_size = 0; } if (phys_initrd_size) { - memblock_reserve(phys_initrd_start, phys_initrd_size); + phys_addr_t start, size; + + start = round_down(phys_initrd_start, PAGE_SIZE); + end = round_up(phys_initrd_start + phys_initrd_size, PAGE_SIZE); + memblock_reserve(start, end - start); /* Now convert initrd to virtual addresses */ initrd_start = __phys_to_virt(phys_initrd_start);