From patchwork Thu Apr 28 08:12:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 1208 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:11 -0000 Delivered-To: patches@linaro.org Received: by 10.224.2.73 with SMTP id 9cs138598qai; Thu, 28 Apr 2011 01:12:08 -0700 (PDT) Received: by 10.229.127.144 with SMTP id g16mr2519610qcs.152.1303978328495; Thu, 28 Apr 2011 01:12:08 -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 n7si4271836qcu.68.2011.04.28.01.12.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Apr 2011 01:12:08 -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 1QFMKV-000LWG-Uy; Thu, 28 Apr 2011 08:12:08 +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+iC2I2rJqQ85a/ewgXmb1B Date: Thu, 28 Apr 2011 01:12:04 -0700 From: Tony Lindgren To: Nicolas Pitre Cc: linux-omap@vger.kernel.org, Aaro Koskinen , linux-arm-kernel@lists.infradead.org, Shawn Guo , patches@linaro.org Subject: Re: [PATCH] ARM: Fix relocation if image end past uncompressed kernel end Message-ID: <20110428081204.GL3755@atomide.com> References: <20110420165514.GE10402@atomide.com> <20110421055945.GB13688@atomide.com> <20110421104954.GH13688@atomide.com> <20110427124726.GE3755@atomide.com> <20110427125631.GF3755@atomide.com> <20110428063808.GK16892@atomide.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110428063808.GK16892@atomide.com> User-Agent: Mutt/1.5.20 (2009-06-14) * Tony Lindgren [110427 23:35]: > * Nicolas Pitre [110428 01:12]: > > On Wed, 27 Apr 2011, Tony Lindgren wrote: > > > > > * Tony Lindgren [110427 05:44]: > > > > 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. > > > > This is wrong. You're using r12 before it is fixed up with the > > proper offset. > > Hmm I see. I guess I was thinking it only needs to be fixed up after > the relocation. Here's this one with r12 calculation fixed using r0 delta. Also updated it to use movlt instead of movle as that should be sufficient. Regards, 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 @@ -282,10 +282,12 @@ dtb_check_done: /* * Check to see if we will overwrite ourselves. + * r0 = delta * r4 = final kernel address * 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, fixed up with delta in r0 if relocating * We basically want: * r4 - 16k page directory >= r10 -> OK * r4 + image length <= r5 -> OK @@ -297,11 +299,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, r0 @ fixup GOT end with delta + cmp r10, r12 @ relocating less than GOT end? + movlt r10, r12 @ if so, relocate to 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. */