From patchwork Wed Apr 27 12:56:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 1185 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:50:00 -0000 Delivered-To: patches@linaro.org Received: by 10.224.2.73 with SMTP id 9cs107943qai; Wed, 27 Apr 2011 05:56:35 -0700 (PDT) Received: by 10.52.173.195 with SMTP id bm3mr5734vdc.86.1303908995236; Wed, 27 Apr 2011 05:56:35 -0700 (PDT) Received: from mho-01-ewr.mailhop.org (mho-03-ewr.mailhop.org [204.13.248.66]) by mx.google.com with ESMTPS id m17si1041815vcr.125.2011.04.27.05.56.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 27 Apr 2011 05:56:35 -0700 (PDT) Received-SPF: neutral (google.com: 204.13.248.66 is neither permitted nor denied by best guess record for domain of tony@atomide.com) client-ip=204.13.248.66; Authentication-Results: mx.google.com; spf=neutral (google.com: 204.13.248.66 is neither permitted nor denied by best guess record for domain of tony@atomide.com) smtp.mail=tony@atomide.com Received: from c-98-234-237-12.hsd1.ca.comcast.net ([98.234.237.12] helo=localhost.localdomain) by mho-01-ewr.mailhop.org with esmtpa (Exim 4.72) (envelope-from ) id 1QF4IE-0006uy-LQ; Wed, 27 Apr 2011 12:56:34 +0000 Received: from Mutt by mutt-smtp-wrapper.pl 1.2 (www.zdo.com/articles/mutt-smtp-wrapper.shtml) X-Mail-Handler: MailHop Outbound by DynDNS X-Originating-IP: 98.234.237.12 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/mailhop/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1+iz6Yrbr1/BaMvnXUfSAN+ Date: Wed, 27 Apr 2011 05:56:31 -0700 From: Tony Lindgren To: Nicolas Pitre Cc: Shawn Guo , linux-arm-kernel@lists.infradead.org, patches@linaro.org, Aaro Koskinen , linux-omap@vger.kernel.org Subject: Re: [PATCH] ARM: Fix relocation if image end past uncompressed kernel end Message-ID: <20110427125631.GF3755@atomide.com> References: <1303272904-31392-1-git-send-email-nicolas.pitre@linaro.org> <20110420072156.GA28679@atomide.com> <20110420165514.GE10402@atomide.com> <20110421055945.GB13688@atomide.com> <20110421104954.GH13688@atomide.com> <20110427124726.GE3755@atomide.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110427124726.GE3755@atomide.com> User-Agent: Mutt/1.5.20 (2009-06-14) * Tony Lindgren [110427 05:44]: > * Nicolas Pitre [110421 06:18]: > > On Thu, 21 Apr 2011, Tony Lindgren wrote: > > > > > Otherwise we end up overwriting ourselves. This fixes booting > > > on n900 after commit 6d7d0ae51574943bf571d269da3243257a2d15db > > > (ARM: 6750/1: improvements to compressed/head.S). > > > > > > Signed-off-by: Tony Lindgren > > > > I don't understand why this is needed. The copy loop is explicitly > > copying from the end going backward exactly to cope with this > > possibility. > > This one is starting to make sense now too after the stack corrupting > the image issue is out of the way :) > > We can't overwrite the running code when relocating only a small amount, > say 0x100 or so. > > There's no need to relocate all the way past the compressed kernel, > we just need to relocate past the size of the code in head.o. > > Updated patch below using the GOT end instead of the compressed > image end. Oops, the mov should be movle of course. Updated patch below. Tony From: Tony Lindgren Date: Wed, 27 Apr 2011 02:06:13 -0700 Subject: [PATCH] ARM: Fix relocation to move past the running code Otherwise we end up overwriting ourselves partially when relocating less than size of the running code in head.S. Without this patch, a system will not boot if the compressed image load address is slightly less than where the compressed image gets relocated. For example, using mkimage to set the load address to something like zreladdr + uncompressed image size - 0x100 will make the system hang without this patch. Signed-off-by: Tony Lindgren --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -286,6 +286,7 @@ dtb_check_done: * r5 = start of this image * r9 = size of decompressed image * r10 = end of this image, including bss/stack/malloc space if non XIP + * r12 = GOT end, corrupted if relocating * We basically want: * r4 - 16k page directory >= r10 -> OK * r4 + image length <= r5 -> OK @@ -297,11 +298,20 @@ dtb_check_done: cmp r10, r5 bls wont_overwrite + /* + * Check if the relocate address overlaps the running code in + * head.S. In that case we need to relocate past the code + * to avoid overwriting some of the running code. + */ + add r12, r12, r5 @ use GOT end for upper limit + cmp r10, r12 @ relocating less than GOT end? + movle r10, r12 @ if so, relocate past GOT end + /* * Relocate ourselves past the end of the decompressed kernel. * r5 = start of this image * r6 = _edata - * r10 = end of the decompressed kernel + * r10 = end of the decompressed kernel or end of GOT end if larger * Because we always copy ahead, we need to do it from the end and go * backward in case the source and destination overlap. */