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: 738611 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3S8CDtx027606 for ; Thu, 28 Apr 2011 08:12:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755041Ab1D1IML (ORCPT ); Thu, 28 Apr 2011 04:12:11 -0400 Received: from mho-03-ewr.mailhop.org ([204.13.248.66]:51229 "EHLO mho-01-ewr.mailhop.org" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754374Ab1D1IMI (ORCPT ); Thu, 28 Apr 2011 04:12:08 -0400 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) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 28 Apr 2011 08:12:13 +0000 (UTC) * 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 --- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 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. */