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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DECFC433EF for ; Mon, 15 Nov 2021 11:21:59 +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 CC8CD61C15 for ; Mon, 15 Nov 2021 11:21:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CC8CD61C15 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=BLd1/qDqa3oTF8gnGPIF1wX0n0r83x9v/24uxkUkMyY=; b=hyOYYar8CCxgwF zSZXDMJJOonE6MqbUueveNAkFiM1UF/EANn9T51X277MT4eK+q+H8BZXBczOIZ49bdZMYZBd1Uhij eeGxBz5MENsqoVua7aMeeFlR7OKRqqwvEsHvvnXwSD9SvJmQooLXG5JZ9JuPlfmJfPudXCcrHK4EW c8OgDsDUWQk/pys/5TyUQU1IXjKGEe84TJa38QzCCrWlpDcjz1ZkEEASO60PuNPdPBAkGNuiFpJOt f/7gf074+0WmFKDJk7KaPKOWLV5iTA93pirFCmE9w/L41464ud4lvjFi+3U3rFgMh5jIevtkjuFJB 46N9iIa54AoqbONJArsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mma1G-00FKLN-5g; Mon, 15 Nov 2021 11:19:26 +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 1mma0U-00FKAS-T3 for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 11:18:40 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id A015461C32; Mon, 15 Nov 2021 11:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636975118; bh=k61pz6/5mA9JpreJmQHXeypu88DofYhu8Mq0fJ/Pa3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzhJqlgvUZ+FQnFmH1n5swy4YEqiUE6MyRMykQKfv43ERkCIt+0E7FxrS3phM1Hd8 WlRdjE4ve3vVbw1Ermm8DYkhyQirAwX/9IrKUYmYhm8B0gerhL93lPLQYh7wFLpaSH gSzX3LoCm4GQt34AzvQa/V6TK2vXbB0vORCiZK430D/lyqbTfwvEDbqxd/8CkZ6lF9 7TVkcxGcNQ9Fn3I06RQgZHkcExXl+2d1PzOg8L0bO114euPSYl7d0WBKfTS2QxCRaK slBX3sNNSRP4JQTBMujW+RWjwlZTwKYynpVI1hJP20dZVog1Z9zuPfdtZ+6Fwp83uX t9aq04Y6+YEFA== 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 v3 5/7] ARM: switch_to: clean up Thumb2 code path Date: Mon, 15 Nov 2021 12:18:14 +0100 Message-Id: <20211115111816.3911213-6-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211115111816.3911213-1-ardb@kernel.org> References: <20211115111816.3911213-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/pANAwAKAcNPIjmS2Y8kAcsmYgBhkkHz9vQTIsIq7O6TmBfliMSGcVWr5NHNImQ72TNt YUkQWRCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYZJB8wAKCRDDTyI5ktmPJH8TC/ 9uDwWcwnaUnIeuNCQASZbpoLjITLFuxvBOtipXYjTla7IwrGDCYW1gDScLyuzjPTOCHdH8rRiAFZZA ixrvYYWAN6inrJfvaZFez+TzecsO06hCR8mvQ0aFtNdRYLaMQzdzCNKkS0Pjl3SWNHoC6EVTmHfaTu HLDkXc9RbQo1U8CCrhIhAPC3j62tmFwUT6EDp9PoUzPt8thQiD3Q9OeVLr4Gf9fdeyuzMVJNdezIat aSxwxxIn5WDNzIRhduvvO5alBIgedqfKXgreKcJ3r+YSIKHxOGohAc8zgv92I6W4OpLxnsg+lAiY3I lSID2kouZH8C0cZcxMnwar7/U738TXHFOrn2HM6nVjJBpw0zn3yJElSJ7pZXdayP/Lpvje96wq47hB 9yhdgHDmuuPonFO4+xkTdjXWe/gf3VxYyAkdAKShpPVp3b3Zqel35a01mQGcO8Z6iNsy/5H2TrfQ4L V4pHDmorzcOL36eYGfWT3a7VKw9E2o4dcl2xYWzjBa5nQ= 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-20211115_031838_998159_AED44B06 X-CRM114-Status: GOOD ( 14.36 ) 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