From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B70CC433F5 for ; Mon, 22 Nov 2021 09:55:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BLd1/qDqa3oTF8gnGPIF1wX0n0r83x9v/24uxkUkMyY=; b=EGeLhfWF61MBi7 IBu1AL1vL+EVeu74UbGlVFOTrNyZSDkDZgliwuDTx1Gq2kRsJCbTy9lvQ92o6IKT7lNjUruGv5qSL PxwWoRNAkSBc/cJV7MzlAvU5U9JPgIdpl1P0gr+TctlxMt4BxZeu4xjwNICJua8tZe+TEylqy1paZ F9IIVnYqC4NFlqhXJTcBuZSt7A5OsiCJcKh3c7OFCREgBl8adpXQz1I2WJhVkTZRrimm6srBtEOdg Yl6YSYp0NZ8TJka02V9d3c7A/3N7/eHVHZNi1ptgECthMGzQXNNIfVxCtwwZ2AzMXiqFDHYz8//Z4 lH6TFGmY1z4M4xtXHtIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp61L-00FhhS-BO; Mon, 22 Nov 2021 09:53:56 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp5ct-00FaRc-Uy for linux-arm-kernel@lists.infradead.org; Mon, 22 Nov 2021 09:28:45 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1A35E604DA; Mon, 22 Nov 2021 09:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637573319; bh=k61pz6/5mA9JpreJmQHXeypu88DofYhu8Mq0fJ/Pa3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CjVFpcEOwXbZse6T8cHixLyWxsyywXwLjK77bL3uSQPg6p36GP8OUa0/AVm9hU8Nr rYcIIa2Zy2GGl1fKUP/AYwAVlcPAAxnCO37Vj0qAop6NGmJ+QTYyI7Ea5jrlfqXJJ1 pSQT6EfqUYo7mCSxjozEY0BVC9x6/d6KYDPCvzN4Tu6f5TCl5xJDOxDP0Ei8KegfxD p2qf5q5Vt78Q3dz5fC1Bjhy7+EPjnoNU7smmSct5xNrmETGRl5/ufYB0eBpwy1eOlL tEikWeYpdVloAlTaTKxmHrxMRphn8uqbHfWB7fRwdMoOiL23IJBcMUlV/LtPOw4ndO dHa2XD6FaPEcw== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Russell King , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Tony Lindgren Subject: [PATCH v4 5/7] ARM: switch_to: clean up Thumb2 code path Date: Mon, 22 Nov 2021 10:28:14 +0100 Message-Id: <20211122092816.2865873-6-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122092816.2865873-1-ardb@kernel.org> References: <20211122092816.2865873-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2642; h=from:subject; bh=k61pz6/5mA9JpreJmQHXeypu88DofYhu8Mq0fJ/Pa3s=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhm2Ks9vQTIsIq7O6TmBfliMSGcVWr5NHNImQ72TNt YUkQWRCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYZtirAAKCRDDTyI5ktmPJMa7C/ 9HHpRzHMQWc4VW030J8Ne7/Q6zPsZQax1zQImd5Q4dPFmWnSITpnHuyLruPPhAddX6gEOhh+oWQ9EI UF/oJ95Rg/Jim1DN1xX6E+b6NHcqWR4nbQQzBspbVRj/TuQQAt76AUv3sGdNHtC7cHbHPDL3APFcYP NTtYcUL6p71cr+00QteeWKijR82P5XF4Sg///65DHbzO03gEllcyL7W9tEBPqgH3o4cXCSzQEG5/n/ nxtsa32qcIOj8iwhfxXRySde0hsgOsqVdbufzSfJCFRnVBS2RB15Pz2AHb70mDfq6Gn0IiDGGoqC0P qMgQvWzsw7KxVl6n6rGnE2Ulke6rV8p1E5hBo9OJtKGdGJoDReZItcWdX9rznvUWCRo/BMjZQ7WwTN ScpB3wwC840e3CBsHsWiTDymDgvLEllfw/xpoI7ljuPapdq3Oh9Z8bFkTGhv5i/6tyV7HeZYmhaZQE PCyxUMx4Lkhwy125gxB2s6xqa/zBXETPdqltBlM8I+ApI= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211122_012840_097369_101FA991 X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The load-multiple instruction that essentially performs the switch_to operation in ARM mode, by loading all callee save registers as well the stack pointer and the program counter, is split into 3 separate loads for Thumb-2, with the IP register used as a temporary to capture the value of R4 before it gets overwritten. We can clean this up a bit, by sticking with a single LDMIA instruction, but one that pops SP and PC into IP and LR, respectively, and by using ordinary move register and branch instructions to get those values into SP and PC. This also allows us to move the set_current call closer to the assignment of SP, reducing the window where those are mutually out of sync. This is especially relevant for CONFIG_VMAP_STACK, which is being introduced in a subsequent patch, where we need to issue a load that might fault from the new stack while running from the old one, to ensure that stale PMD entries in the VMALLOC space are synced up. Signed-off-by: Ard Biesheuvel Tested-by: Keith Packard --- arch/arm/kernel/entry-armv.S | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 1c7590eef712..ce8ca29461de 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -823,13 +823,26 @@ ENTRY(__switch_to) #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) str r7, [r8] #endif - THUMB( mov ip, r4 ) mov r0, r5 +#if !defined(CONFIG_THUMB2_KERNEL) set_current r7 - ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously - THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously - THUMB( ldr sp, [ip], #4 ) - THUMB( ldr pc, [ip] ) + ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously +#else + mov r1, r7 + ldmia r4, {r4 - sl, fp, ip, lr} @ Load all regs saved previously + + @ When CONFIG_THREAD_INFO_IN_TASK=n, the update of SP itself is what + @ effectuates the task switch, as that is what causes the observable + @ values of current and current_thread_info to change. When + @ CONFIG_THREAD_INFO_IN_TASK=y, setting current (and therefore + @ current_thread_info) is done explicitly, and the update of SP just + @ switches us to another stack, with few other side effects. In order + @ to prevent this distinction from causing any inconsistencies, let's + @ keep the 'set_current' call as close as we can to the update of SP. + set_current r1 + mov sp, ip + ret lr +#endif UNWIND(.fnend ) ENDPROC(__switch_to) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel