From patchwork Tue Feb 16 17:32:26 2016 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: 8329901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 01B2F9F399 for ; Tue, 16 Feb 2016 17:34:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F187520260 for ; Tue, 16 Feb 2016 17:34:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C865202A1 for ; Tue, 16 Feb 2016 17:34:41 +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 1aVjUi-0006Tr-V4; Tue, 16 Feb 2016 17:33:00 +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 1aVjUf-0006Fj-E1 for linux-arm-kernel@lists.infradead.org; Tue, 16 Feb 2016 17:32:59 +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=0sq3uuLsEV/XzDzUW6T2x2q3II8PUUvacPMcgTcu65M=; b=VGVM/IXFBOQm5ObCsB/jefwr5tefx1ctAenwRQPvOKtNeaC7BHjt3ivvgaJQdDzqXGkPWCHE3vCTAr+2bOYtD1UOAF3ERvsBfTETqXyrgzjFpQBcL2c1GsSyEn38CNYyr+csUZKWthaoKreeRpogDZoPQc9IUBURdAGEDNSLdzw=; Received: from n2100.arm.linux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:35496) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aVjUD-0007vl-CI; Tue, 16 Feb 2016 17:32:29 +0000 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1aVjUA-0007iB-Dy; Tue, 16 Feb 2016 17:32:26 +0000 Date: Tue, 16 Feb 2016 17:32:26 +0000 From: Russell King - ARM Linux To: Nicolas Pitre Subject: Re: [PATCH v2] ARM: proc-v7.S: Adjust stack address when XIP_KERNEL Message-ID: <20160216173225.GE19428@n2100.arm.linux.org.uk> References: <1454105474-3009-1-git-send-email-chris.brandt@renesas.com> <1454335736-10084-1-git-send-email-chris.brandt@renesas.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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-20160216_093257_883503_45DD35F6 X-CRM114-Status: GOOD ( 18.72 ) X-Spam-Score: -4.3 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chris Brandt , linux-arm-kernel@lists.infradead.org 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,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Mon, Feb 01, 2016 at 04:15:38PM -0500, Nicolas Pitre wrote: > On Mon, 1 Feb 2016, Chris Brandt wrote: > > > From: Nicolas Pitre > > > > When XIP_KERNEL is enabled, the virt to phys address translation for RAM > > is not the same as the virt to phys address translation for .text. > > The only way to know where physical RAM is located is to use > > PLAT_PHYS_OFFSET. > > The MACRO will be useful for other places where there is a similar problem. > > > > Signed-off-by: Nicolas Pitre > > Signed-off-by: Chris Brandt > > Looks fine. You may submit it here: ... > > +#ifdef CONFIG_XIP_KERNEL > > +#define PHYS_OFFSET_FIXUP \ > > + ( XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR) - PAGE_OFFSET + \ > > + PLAT_PHYS_OFFSET - CONFIG_XIP_PHYS_ADDR ) > > +#else > > +#define PHYS_OFFSET_FIXUP 0 > > +#endif > > + > > #ifndef __ASSEMBLY__ > > > > /* > > diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S > > index 0f92d57..1595fb2 100644 > > --- a/arch/arm/mm/proc-v7.S > > +++ b/arch/arm/mm/proc-v7.S > > @@ -487,7 +487,7 @@ __errata_finish: > > > > .align 2 > > __v7_setup_stack_ptr: > > - .word __v7_setup_stack - . > > + .word __v7_setup_stack - . + PHYS_OFFSET_FIXUP I keep looking at this patch, and I really find that I detest this PHYS_OFFSET_FIXUP thing - it's really not obvious what's going on here. It's taken a _long_ time to work this out, which _really_ isn't good going forward. Let's instead change things to make it much more obvious - see the patch below. diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h index ebdaaf7dd19f..593e5613184d 100644 --- a/arch/arm/include/asm/memory.h +++ b/arch/arm/include/asm/memory.h @@ -135,11 +135,18 @@ #define PLAT_PHYS_OFFSET UL(CONFIG_PHYS_OFFSET) #ifdef CONFIG_XIP_KERNEL -#define PHYS_OFFSET_FIXUP \ - ( XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR) - PAGE_OFFSET + \ - PLAT_PHYS_OFFSET - CONFIG_XIP_PHYS_ADDR ) +/* + * When referencing data in RAM from the XIP region in a relative manner + * with the MMU off, we need the relative offset between the two physical + * addresses. The macro below achieves this, which is: + * __pa(v_data) - __xip_pa(v_text) + */ +#define PHYS_RELATIVE(v_data, v_text) \ + (((v_data) - PAGE_OFFSET + PLAT_PHYS_OFFSET) - \ + ((v_text) - XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR) + \ + CONFIG_XIP_PHYS_ADDR)) #else -#define PHYS_OFFSET_FIXUP 0 +#define PHYS_RELATIVE(v_data, v_text) (v_data) - (v_text) #endif #ifndef __ASSEMBLY__ diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index 1595fb29ec12..0f8963a7e7d9 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -487,7 +487,7 @@ __errata_finish: .align 2 __v7_setup_stack_ptr: - .word __v7_setup_stack - . + PHYS_OFFSET_FIXUP + .word PHYS_RELATIVE(__v7_setup_stack, .) ENDPROC(__v7_setup) .bss