From patchwork Sun Apr 19 19:28:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 6238841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B00DBBF4A6 for ; Sun, 19 Apr 2015 19:31:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BBF4D20306 for ; Sun, 19 Apr 2015 19:31:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AFCAA20303 for ; Sun, 19 Apr 2015 19:31:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yjutz-0006uU-JE; Sun, 19 Apr 2015 19:29:11 +0000 Received: from pandora.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yjutv-0006qV-SK for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2015 19:29:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=NJuDfpPyR4DXT6wpE0mcDG9xdKz9tbc9qe9640a3d8g=; b=MF+txvj06jHXPH5bfRKz4NgRIpl5v8RxU8uUm/CPId4GkKF1/Z/A3OE/z5UGGPQI9lBpqEYUNGzbYDScfmhLcaavjdw5XSr6QCnSv34T5zfqxiKQb23iLgKYmDyHzr7HyDFcY2hLS+rJbjER0LC0yn/PoZDEdYipj5K11+6Q/FI=; Received: from n2100.arm.linux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:60942) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1YjutU-0007JL-Ow; Sun, 19 Apr 2015 20:28:40 +0100 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1YjutR-00088z-Ig; Sun, 19 Apr 2015 20:28:37 +0100 Date: Sun, 19 Apr 2015 20:28:37 +0100 From: Russell King - ARM Linux To: Ard Biesheuvel Subject: Re: [PATCH v2 1/8] ARM: replace PROCINFO embedded branch with relative offset Message-ID: <20150419192836.GO12732@n2100.arm.linux.org.uk> References: <1426248452-4773-1-git-send-email-ard.biesheuvel@linaro.org> <1426248452-4773-2-git-send-email-ard.biesheuvel@linaro.org> <20150419170819.GN12732@n2100.arm.linux.org.uk> <6D2381CE-C6EB-4B18-972D-DA07FD77C2D4@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <6D2381CE-C6EB-4B18-972D-DA07FD77C2D4@linaro.org> 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-20150419_122908_244900_165996E2 X-CRM114-Status: GOOD ( 11.96 ) X-Spam-Score: -0.1 (/) Cc: Joachim Eastwood , Arnd Bergmann , "linux-arm-kernel@lists.infradead.org" , "nico@linaro.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sun, Apr 19, 2015 at 07:41:08PM +0200, Ard Biesheuvel wrote: > I am away from my work pc so i can't check but i wonder if all setup > functions are correctly annotated as thumb2 when built in thumb2 mode. > If not, it would explain why a plain branch works but doing arithmetic > on the address doesn't. Yes, it's a Thumb2 kernel, but more importantly, it's a nommu kernel, and the nommu code wasn't touched. So, the entry code looks like this: 28008000: f8df 9024 ldr.w r9, [pc, #36] ; 28008028 <__after_proc_init+0x4> 28008004: f8d9 9000 ldr.w r9, [r9] 28008008: f001 f926 bl 28009258 <__lookup_processor_type> 2800800c: ea5f 0a05 movs.w sl, r5 28008010: f001 8164 beq.w 280092dc <__error_p> 28008014: f8df d014 ldr.w sp, [pc, #20] ; 2800802c <__after_proc_init+0x8> 28008018: f20f 0e07 addw lr, pc, #7 2800801c: f10a 0c10 add.w ip, sl, #16 28008020: 46e7 mov pc, ip 28008022: e7ff b.n 28008024 <__after_proc_init> which results in us jumping to: 2822091c <__proc_info_begin>: 2822091c: 000f0000 andeq r0, pc, r0 28220920: 000f0000 andeq r0, pc, r0 ... 2822092c: fff5ce6d ; instruction: 0xfff5ce6d ^^^ here. That's an offset from the beginning of the structure, which gives us an address of 0x2817d789, which would be correct: 2817d788 <__v7m_setup>: 2817d788: 4829 ldr r0, [pc, #164] ; (2817d830 ) 2817d78a: f8df c0a8 ldr.w ip, [pc, #168] ; 2817d834 2817d78e: f8c0 c008 str.w ip, [r0, #8] The patch below should resolve it - Joachim, please confirm: Tested-by: Joachim Eastwood diff --git a/arch/arm/kernel/head-nommu.S b/arch/arm/kernel/head-nommu.S index 455033110078..5925449f6f04 100644 --- a/arch/arm/kernel/head-nommu.S +++ b/arch/arm/kernel/head-nommu.S @@ -80,9 +80,9 @@ ENTRY(stext) ldr r13, =__mmap_switched @ address to jump to after @ initialising sctlr adr lr, BSYM(1f) @ return (PIC) address - ARM( add pc, r10, #PROCINFO_INITFUNC ) - THUMB( add r12, r10, #PROCINFO_INITFUNC ) - THUMB( ret r12 ) + ldr r12, [r10, #PROCINFO_INITFUNC] + add r12, r12, r10 + ret r12 1: b __after_proc_init ENDPROC(stext) @@ -117,9 +117,9 @@ ENTRY(secondary_startup) adr lr, BSYM(__after_proc_init) @ return address mov r13, r12 @ __secondary_switched address - ARM( add pc, r10, #PROCINFO_INITFUNC ) - THUMB( add r12, r10, #PROCINFO_INITFUNC ) - THUMB( ret r12 ) + ldr r12, [r10, #PROCINFO_INITFUNC] + add r12, r12, r10 + ret r12 ENDPROC(secondary_startup) ENTRY(__secondary_switched)