From patchwork Thu Aug 21 21:42:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 4760031 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B4D6EC0338 for ; Thu, 21 Aug 2014 21:44:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2AD6201BA for ; Thu, 21 Aug 2014 21:44:34 +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 9996E201B9 for ; Thu, 21 Aug 2014 21:44:33 +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 1XKa7x-0007UB-Sv; Thu, 21 Aug 2014 21:42:37 +0000 Received: from smtp.codeaurora.org ([198.145.11.231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XKa7u-0007Qi-NH for linux-arm-kernel@lists.infradead.org; Thu, 21 Aug 2014 21:42:35 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id CA6F613FBE9; Thu, 21 Aug 2014 21:42:13 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id BAF9913FBDF; Thu, 21 Aug 2014 21:42:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from [10.42.111.116] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: lauraa@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3275D13FBE7; Thu, 21 Aug 2014 21:42:13 +0000 (UTC) Message-ID: <53F667B5.6010609@codeaurora.org> Date: Thu, 21 Aug 2014 14:42:13 -0700 From: Laura Abbott User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Mark Rutland Subject: Re: [PATCHv3 4/7] arm64: Move some head.text functions to executable section References: <1408584039-12735-1-git-send-email-lauraa@codeaurora.org> <1408584039-12735-5-git-send-email-lauraa@codeaurora.org> <20140821103455.GJ21734@leverpostej> In-Reply-To: <20140821103455.GJ21734@leverpostej> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140821_144234_847608_A5946331 X-CRM114-Status: GOOD ( 23.90 ) X-Spam-Score: -0.7 (/) Cc: Will Deacon , Steve Capper , Kees Cook , "linux-arm-kernel@lists.infradead.org" , Catalin Marinas 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-Virus-Scanned: ClamAV using ClamSMTP On 8/21/2014 3:34 AM, Mark Rutland wrote: > Hi Laura, > > On Thu, Aug 21, 2014 at 02:20:36AM +0100, Laura Abbott wrote: >> The code in the head.text section of the kernel exists in the >> same section as the swapper_pg_dir which means it needs the >> same page table permissions. The swapper_pg_dir needs to be >> writeable but shouldn't be executable. > > I think we can drop the above. As far as I can tell as of commit > bd00cd5f8c8c (arm64: place initial page tables above the kernel) it's no > longer relevant. > Yes, this should be changed. Instead of citing swapper_pg_dir, I need to cite the fact that there may still be memory outside of stext which will get freed to the buddy allocator and therefore should be RW/NX. >> The head.text section >> is intended to be run at early bootup before any of the regular >> kernel mappings have been setup so there is no issue at bootup. >> The suspend/resume/hotplug code path requires some of these >> head.S functions to run however which means they need to be >> executable. We can't easily move all of the head.text to >> an executable section, so split it into two parts: that which >> is used only at early head.S bootup and that which is used >> after bootup. There is a small bit of code duplication because >> of some relocation issues related to accessing code more than >> 1MB away. > > From a cursory glance it looks like the only things we need write access > to in .head.text are __cpu_boot_mode and __switch_data. Can't we instead > place those in .data and make .head.text executable? > > We currently find them with adr, which should be easy to replace with > adrp + add to get around relocation issues. > __boot_cpu_mode should be placed in data with a push section and __switch_data is only modified before the permissions are set up. I took a closer look at the code and the only thing that actually needs to be executable from head.S is __secondary_switched so the following patch should be sufficient to cover it: I think I was a bit over zealous in determining that everything needed to be placed in .text vs. not. Thanks, Laura diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index caa9557..5c17599 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -414,12 +414,14 @@ ENTRY(secondary_startup) b __enable_mmu ENDPROC(secondary_startup) + .pushsection .text, "ax" ENTRY(__secondary_switched) ldr x0, [x21] // get secondary_data.stack mov sp, x0 mov x29, #0 b secondary_start_kernel ENDPROC(__secondary_switched) + .popsection #endif /* CONFIG_SMP */ /*