From patchwork Wed Jun 5 02:23:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 2664291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id EFF8440077 for ; Wed, 5 Jun 2013 02:23:45 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uk3Nt-0006lu-W0; Wed, 05 Jun 2013 02:23:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uk3Nq-0003Ud-MK; Wed, 05 Jun 2013 02:23:30 +0000 Received: from mail-qe0-f49.google.com ([209.85.128.49]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uk3Nn-0003U8-HK for linux-arm-kernel@lists.infradead.org; Wed, 05 Jun 2013 02:23:28 +0000 Received: by mail-qe0-f49.google.com with SMTP id cz11so707200qeb.22 for ; Tue, 04 Jun 2013 19:23:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version:content-type:x-gm-message-state; bh=S9IEjUg8kTv8OiewxaWxDacMj/qIzUbQfsKYJ1P2G6I=; b=VXFbzKqdNKBSCcbdSMJo5ik5YnbeYfawiRI5n7el/HJLl5e1ZYRTekkW6vOE3rLtwc f7njstf179YV5tbyeECXIQTJBXvsef+gmaz/lpNHCUWYACAG01kmheQFSclcliDE7a3Q +2EUZEXfRi+TrLjlXA+3/bWdGSFJ2L1wyxknT5o9PtmwWlSaxuCDLOanoKp6N2uPpvnz +6dU6tNGbypY51u51lCMD5518L7oBHQ+VHYCTXggH2Xh8U/HdnPZj7jFeBel2RIFJpN8 S+emHjNcFrzePtPpZBAEXacl1bJnYuR+ctG0pNZmrLqh4gBhw2mh2gs3Qe+lblDvyzhO ERzQ== X-Received: by 10.49.96.10 with SMTP id do10mr19684229qeb.23.1370398983312; Tue, 04 Jun 2013 19:23:03 -0700 (PDT) Received: from xanadu.home (modemcable044.209-83-70.mc.videotron.ca. [70.83.209.44]) by mx.google.com with ESMTPSA id u14sm70778123qao.6.2013.06.04.19.23.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 04 Jun 2013 19:23:02 -0700 (PDT) Date: Tue, 4 Jun 2013 22:23:01 -0400 (EDT) From: Nicolas Pitre To: Stephen Boyd Subject: Re: [PATCH] ARM: avoid mis-detecting some V7 cores in the decompressor In-Reply-To: <20130604214501.GL599@codeaurora.org> Message-ID: References: <20130523231531.GT18614@n2100.arm.linux.org.uk> <20130524220539.GB599@codeaurora.org> <51AD0703.6050408@codeaurora.org> <20130603222321.GP18614@n2100.arm.linux.org.uk> <51AD1AB3.9050908@codeaurora.org> <20130603224555.GR18614@n2100.arm.linux.org.uk> <51AD1FE9.80709@codeaurora.org> <20130604194705.GK599@codeaurora.org> <20130604214501.GL599@codeaurora.org> User-Agent: Alpine 2.03 (LFD 1266 2009-07-14) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmVE8u8spuHD6PRZWkIQ0eSPL9wvUTPBOObn0my8+3fFCEQbItH4AUzRf4E6xW/GOaQ9tQO X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130604_222327_668351_FDCBDE53 X-CRM114-Status: GOOD ( 22.86 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.128.49 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Brian Swetland , Russell King - ARM Linux , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Tue, 4 Jun 2013, Stephen Boyd wrote: > On 06/04, Nicolas Pitre wrote: > > diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S > > index 9a94f344df..773bc35f92 100644 > > --- a/arch/arm/boot/compressed/head.S > > +++ b/arch/arm/boot/compressed/head.S > > @@ -178,11 +178,23 @@ not_angel: > > mov r4, pc > > and r4, r4, #0xf8000000 > > add r4, r4, #TEXT_OFFSET > > + bl cache_on > > #else > > ldr r4, =zreladdr > > -#endif > > > > - bl cache_on > > + /* > > + * Set up a page table only if we don't overwrite ourself. > > + * That means r4 < pc && r4 - 4K > &_end. > > + * Given that r4 > &_en is most unfrequent, we add a rough > > + * additional 1MB of room for a possible appended DTB. > > + */ > > + mov r0, pc > > + cmp r0, r4 > > + ldrcc r0, LC0+32 > > + addcc r0, r0, pc > > + cmpcc r4, r0 > > + blcs cache_on > > +#endif > > But this looks backwards? Shouldn't we put it in the > CONFIG_AUTO_ZRELADDR case? Obviously. I was looking for zreladdr only. In fact this should be done in both cases. > > restart: adr r0, LC0 > > ldmia r0, {r1, r2, r3, r6, r10, r11, r12} > > @@ -464,6 +476,16 @@ not_relocated: mov r0, #0 > > cmp r2, r3 > > blo 1b > > > > +#if defined(CONFIG_AUTO_ZRELADDR) && defined(CONFIG_CPU_CP15) > > + /* > > + * Did we skip the cache setup earlier? > > + * Do it now if so. > > + */ > > + mrc p15, 0, r0, c1, c0, 0 @ read control register > > + tst r0, #1 @ MMU bit set? > > + bleq cache_on @ no: set it up > > +#endif > > Too bad we can't store one more variable into LC0 that says we > turned the caches on. Then we could read that here and detect it > without CP15 accessors required. The LC0 area should be considered read-only as it may be located in flash. Here's what I came with instead: From: Nicolas Pitre Date: Tue, 4 Jun 2013 17:01:30 -0400 Subject: [PATCH] ARM: zImage: don't overwrite ourself with a page table When zImage is loaded into RAM at a low address but TEXT_OFFSET is set higher, we risk overwriting ourself with the page table needed to turn on the cache as it is located relative to the relocation address. Let's defer the cache setup after relocation in that case. Signed-off-by: Nicolas Pitre Reported-by: Stephen Boyd Tested-by: Stephen Boyd diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 9a94f344df..aa909393f2 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -182,7 +182,19 @@ not_angel: ldr r4, =zreladdr #endif - bl cache_on + /* + * Set up a page table only if it won't overwrite ourself. + * That means r4 < pc && r4 - 16k page directory > &_end. + * Given that r4 > &_en is most unfrequent, we add a rough + * additional 1MB of room for a possible appended DTB. + */ + mov r0, pc + cmp r0, r4 + ldrcc r0, LC0+32 + addcc r0, r0, pc + cmpcc r4, r0 + orrcc r4, r4, #1 @ remember we skipped cache_on + blcs cache_on restart: adr r0, LC0 ldmia r0, {r1, r2, r3, r6, r10, r11, r12} @@ -228,7 +240,7 @@ restart: adr r0, LC0 * r0 = delta * r2 = BSS start * r3 = BSS end - * r4 = final kernel address + * r4 = final kernel address (possibly with LSB set) * r5 = appended dtb size (still unknown) * r6 = _edata * r7 = architecture ID @@ -276,6 +288,7 @@ restart: adr r0, LC0 */ cmp r0, #1 sub r0, r4, #TEXT_OFFSET + bic r0, r0, #1 add r0, r0, #0x100 mov r1, r6 sub r2, sp, r6 @@ -322,12 +335,13 @@ dtb_check_done: /* * Check to see if we will overwrite ourselves. - * r4 = final kernel address + * r4 = final kernel address (possibly with LSB set) * r9 = size of decompressed image * r10 = end of this image, including bss/stack/malloc space if non XIP * We basically want: * r4 - 16k page directory >= r10 -> OK * r4 + image length <= address of wont_overwrite -> OK + * Note: the possible LSB in r4 is harmless here. */ add r10, r10, #16384 cmp r4, r10 @@ -389,7 +403,8 @@ dtb_check_done: add sp, sp, r6 #endif - bl cache_clean_flush + tst r4, #1 + bleq cache_clean_flush adr r0, BSYM(restart) add r0, r0, r6 @@ -401,7 +416,7 @@ wont_overwrite: * r0 = delta * r2 = BSS start * r3 = BSS end - * r4 = kernel execution address + * r4 = kernel execution address (possibly with LSB set) * r5 = appended dtb size (0 if not present) * r7 = architecture ID * r8 = atags pointer @@ -464,6 +479,15 @@ not_relocated: mov r0, #0 cmp r2, r3 blo 1b + /* + * Did we skip the cache setup earlier? + * That is indicated by the LSB in r4. + * Do it now if so. + */ + tst r4, #1 + bic r4, r4, #1 + blne cache_on + /* * The C runtime environment should now be setup sufficiently. * Set up some pointers, and start decompressing. @@ -512,6 +536,7 @@ LC0: .word LC0 @ r1 .word _got_start @ r11 .word _got_end @ ip .word .L_user_stack_end @ sp + .word _end - restart + 16384 + 1024*1024 .size LC0, . - LC0 #ifdef CONFIG_ARCH_RPC