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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0BB6C433F5 for ; Mon, 18 Oct 2021 14:23:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AB8D360F46 for ; Mon, 18 Oct 2021 14:23:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AB8D360F46 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=SFBU3L5qFtKCe70JEKqShC6fezAh8rnCKleOHqT2r5I=; b=mqzj1quVtyDp7q ydweBLG3Jesve+1cdo0jDXrRrY4TcHpLGT3+1/lxmXIcfLFhGuJrqV8K3ZuVrTKpffFsMs/Ll1xd6 hIq8Y2w6if3vmOftlddguTB7d+11HMB5/4EuqmDEwCVV1VKBQqma4XZgwg071FaG1q0DpV6Eyj0pd pUMAsakOZ8tjFpvgx6kkgBAjDPcKVSeMTeqWdadRGLoQe06DdsGIx3/L9QdJi/NlM+LiJortyes3M eHhornGX5KAOtNiEMM2qPWMGStsj5EcFg2A5DXGqnWCNMn4IyQx/h/8h2DMOdDGDOafUFLjWN+vdI 6cMJAs1t+TijACNW8mlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcTWe-00G4us-P6; Mon, 18 Oct 2021 14:22:05 +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 1mcTRT-00G2oJ-3d for linux-arm-kernel@lists.infradead.org; Mon, 18 Oct 2021 14:16:44 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 63E7560F8F; Mon, 18 Oct 2021 14:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634566602; bh=vEkn4MAZz7C5At20781VdUYCMQ8lqEM/zhlV+YQbgOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uAUe8WGGAEytYzg2RDtzvVCvzuwPy0YGptuGhrlsCGD90u7JxVeBxv/quTt480WoQ 063zccVC3jcNNTVLYLGb9DdCuaR6syr8GfMDWzCTL4utdqcWpIXWSnOIacAQEVMXi/ MYko+Oj1hFzR28fSL2Rd9BL0EA/PC6byrGuFSX69lietGhb6zSzV9g+avRjFouc3HS HBZQRIvxbzwmihT1k75jJfEOmusLqtvMr6lywJ50PUXG43R6ysY6z1wYTrcrLRhLwo IGDTdD1EHAHBpeDS6c24S29fH1c2h98X6ykgYF/Koatx5+mmxZ5UEfmA5/cczOX1ZU qHbE7zboIygHA== 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 Subject: [PATCH v2 5/7] ARM: switch_to: clean up Thumb2 code path Date: Mon, 18 Oct 2021 16:16:13 +0200 Message-Id: <20211018141615.682070-6-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211018141615.682070-1-ardb@kernel.org> References: <20211018141615.682070-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2068; h=from:subject; bh=vEkn4MAZz7C5At20781VdUYCMQ8lqEM/zhlV+YQbgOE=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhbYGqikGsU9abonAw7uexj8UPiwITP2NBfibJqghY IeeCwpyJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYW2BqgAKCRDDTyI5ktmPJNLmC/ 49MpbTxwiytRUrnnR6bQWpYPlnNumxQsVRGB6LvnY3NwzBp9Du8Y4SLCDd04HoUSXMutq4kLjONqCp 8EHvzoiRgXID2mkE4orCFLKbkVU4LG8ryiq4u0YiALK3RmclqllyMHd9VtgaPN4Cd4hWfa4d9RMYdo ff4gpkk2ATfDG2rUR4wR8VajSrQzDgCfaZLq8ky/bfHy4m1IO9eWMwrH3NOL2WzlFnMg9+i+JZhwFb 7SH2/d69yXndP0Ji5dGSMbu7YwAPzhH7g/Elnrgoi1UPggVLQOErPO7ntgI9SIfu9J3wPt5IVFSti0 s2N+vp5mgf1OzOoZ/l4E87T9S+5XKCtNI9lUzpnjSiJheMpDicdPy7xLXMbib7y+gA1FTluk4ohsto h2nKxKgUWKL/0GJNcPOxMkjosKQPRhFjGyH2msP/Bun+N5ohHAfz0x0xp9aM1VveueeFr9n1T+G828 Ymt/Snbafe4rKIq0Lz7NufYznU72PvaP2ma7GE5OnJGDM= 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-20211018_071643_256139_387FD0C1 X-CRM114-Status: GOOD ( 12.57 ) 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 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 2a426bd27a69..18504d7b4d15 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -824,13 +824,17 @@ 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 + 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