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 EE73AC433EF for ; Fri, 8 Oct 2021 07:43:47 +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 B257E60FF2 for ; Fri, 8 Oct 2021 07:43:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B257E60FF2 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=9k05EVC8PSMd1ghacjUuYA3JJHkpHmLJU7pb/2COgIY=; b=jphTwpVRqKg59W ps2gN2zQWharqXTMUVizX62TNqYq4f1yMQIb2hsIpNang0uuwaf7j9cN0mMJYXEmfBRG85+T52rDe DnmqrwxGMK2syf3e+QZkV7LgQ57MdSTKHJBQ/D7g+R9cGqXHnbiX8WhjR4M6TLaOJsEw+4XBfjpyg 71wY/svXq0x20F1dioV8phYVRrCRl+HYgq6kEzM/KzXHcsz1AcqO74otr8VC7NISBMt3Hzcdzv81I x8FuPr6Fnx2xqa7l0qWooJjnfhNhaWGXeGGMqwCnawNKCSXieqN2Blh66kMch0HcxsQZ1+O1Lws77 zG5GwNziIqmCWiNJax3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYkW0-001tN3-5R; Fri, 08 Oct 2021 07:42:00 +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 1mYkVm-001tKn-Bs for linux-arm-kernel@lists.infradead.org; Fri, 08 Oct 2021 07:41:47 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id C1F3660FF2; Fri, 8 Oct 2021 07:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633678905; bh=ux+iTj0+NReYiCilabeoJuT6KjFRWGx/7UeJoYQFu1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=POXdiGwYhqu/oM76WX85WX6Lalb7vX+CJw5g1PoKK5CxOT4OwxF4aAANkD8ghGCxy /Rnyqwe2GM2I8D6r2qnDIiVPNIyTLCXLDVMBcBxr3Q/W+2onYTyWXkZfIgtti/J7m2 HO5qXtp+5e7/aH4VoFmzCibnNLxe7fGxBDINywBjj58obRrDBOF5R0ZRF1vOr/g9cr pLKPt81iDnO9an+Qzj8yFxF5ARX5jRmzsr3TuFcdMnd3ARx4ABil+CiXW+EIrkKuIF ocgEljRbYAlXhUrULVU0q2FemWvaP3EqovMe5hkgDiOn5EofGhYrUo2//2TU4EvfBK J0ntwB2FxtXZA== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: Ard Biesheuvel , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij Subject: [PATCH 1/5] ARM: memcpy: use frame pointer as unwind anchor Date: Fri, 8 Oct 2021 09:41:23 +0200 Message-Id: <20211008074127.435364-2-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211008074127.435364-1-ardb@kernel.org> References: <20211008074127.435364-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6501; h=from:subject; bh=ux+iTj0+NReYiCilabeoJuT6KjFRWGx/7UeJoYQFu1s=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhX/YXu3rU7R9GJA0VJHVo/wHbDOg50J2PuOOKEbQG RZpaxAGJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYV/2FwAKCRDDTyI5ktmPJG8OC/ 4l7aN+ccJYy0amPSpQc5G67l/o4JYXz0GNIz6PV7AaXw8hwkCsCb6uK5AHPHfPnIfXkaPvIFQNdEoq n8F79vt5ODf6LupC6uQUVI9WtYV7bXFa6x6OfiNLhLMyChxD5oqdax+35Uu6fTtoTzEYA+H43uWOtC Q/cRSfH39R20RPQ1AN9edR0s2gg87C+hl09/pznb32dOlHJnBAV4PhPpQw9tiAqboU1ecKgoRn0j/B z/QjRKzwC07y8RMeLF5p3qRJvvnNOYHR4gYqh1VfaKu79jDAgMNUpcTFcrDBAq3jO+mINqjla53iOD uTglsPBqjMUReKVKfI/7GPd/U5qt+oP/SrqFz0bhf0b6aIDMfbGX9LauvcwoRfYwbhDhVZLFAv1qWt Z9dlNpBWOVEkRlcXm4AyZrH1AHhR52GgsbOulIJFw/cPe/R0YIEV+CX+klQmO7eZA4j4NGGt+NwagC 0t6lzeZca2ZWhC5Ct8zRxDCm8cJBtTKPY8RAcQ39c0wew= 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-20211008_004146_459524_375A1090 X-CRM114-Status: GOOD ( 17.17 ) 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 memcpy template is a bit unusual in the way it manages the stack pointer: depending on the execution path through the function, the SP assumes different values as different subsets of the register file are preserved and restored again. This is problematic when it comes to EHABI unwind info, as it is not instruction accurate, and does not allow tracking the SP value as it changes. Commit 279f487e0b471 ("ARM: 8225/1: Add unwinding support for memory copy functions") addressed this by carving up the function in different chunks as far as the unwinder is concerned, and keeping a set of unwind directives for each of them, each corresponding with the state of the stack pointer during execution of the chunk in question. This not only duplicates unwind info unnecessarily, but it also complicates unwinding the stack upon overflow. Instead, let's do what the compiler does when the SP is updated halfway through a function, which is to use a frame pointer and emit the appropriate unwind directives to communicate this to the unwinder. Note that Thumb-2 uses R7 for this, while ARM uses R11 aka FP. So let's avoid touching R7 in the body of the template, so that Thumb-2 can use it as the frame pointer. R11 was not modified in the first place. Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/assembler.h | 4 ++ arch/arm/lib/copy_template.S | 66 ++++++++------------ 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index abb8202ef0da..405950494208 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -86,6 +86,10 @@ #define IMM12_MASK 0xfff +/* the frame pointer used for stack unwinding */ +ARM( fpreg .req r11 ) +THUMB( fpreg .req r7 ) + /* * Enable and disable interrupts */ diff --git a/arch/arm/lib/copy_template.S b/arch/arm/lib/copy_template.S index 810a805d36dc..08c311fc70e0 100644 --- a/arch/arm/lib/copy_template.S +++ b/arch/arm/lib/copy_template.S @@ -69,13 +69,13 @@ * than one 32bit instruction in Thumb-2) */ - UNWIND( .fnstart ) enter r4, lr - UNWIND( .fnend ) - - UNWIND( .fnstart ) - usave r4, lr @ in first stmdb block + usave r4, lr + UNWIND( .save {fpreg} ) + UNWIND( push {fpreg} ) + UNWIND( .setfp fpreg, sp ) + UNWIND( mov fpreg, sp ) subs r2, r2, #4 blt 8f @@ -86,12 +86,7 @@ bne 10f 1: subs r2, r2, #(28) - stmfd sp!, {r5 - r8} - UNWIND( .fnend ) - - UNWIND( .fnstart ) - usave r4, lr - UNWIND( .save {r5 - r8} ) @ in second stmfd block + stmfd sp!, {r5, r6, r8, r9} blt 5f CALGN( ands ip, r0, #31 ) @@ -110,9 +105,9 @@ PLD( pld [r1, #92] ) 3: PLD( pld [r1, #124] ) -4: ldr8w r1, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f +4: ldr8w r1, r3, r4, r5, r6, r8, r9, ip, lr, abort=20f subs r2, r2, #32 - str8w r0, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f + str8w r0, r3, r4, r5, r6, r8, r9, ip, lr, abort=20f bge 3b PLD( cmn r2, #96 ) PLD( bge 4b ) @@ -132,8 +127,8 @@ ldr1w r1, r4, abort=20f ldr1w r1, r5, abort=20f ldr1w r1, r6, abort=20f - ldr1w r1, r7, abort=20f ldr1w r1, r8, abort=20f + ldr1w r1, r9, abort=20f ldr1w r1, lr, abort=20f #if LDR1W_SHIFT < STR1W_SHIFT @@ -150,17 +145,14 @@ str1w r0, r4, abort=20f str1w r0, r5, abort=20f str1w r0, r6, abort=20f - str1w r0, r7, abort=20f str1w r0, r8, abort=20f + str1w r0, r9, abort=20f str1w r0, lr, abort=20f CALGN( bcs 2b ) -7: ldmfd sp!, {r5 - r8} - UNWIND( .fnend ) @ end of second stmfd block +7: ldmfd sp!, {r5, r6, r8, r9} - UNWIND( .fnstart ) - usave r4, lr @ still in first stmdb block 8: movs r2, r2, lsl #31 ldr1b r1, r3, ne, abort=21f ldr1b r1, r4, cs, abort=21f @@ -169,6 +161,7 @@ str1b r0, r4, cs, abort=21f str1b r0, ip, cs, abort=21f + UNWIND( pop {fpreg} ) exit r4, pc 9: rsb ip, ip, #4 @@ -189,13 +182,10 @@ ldr1w r1, lr, abort=21f beq 17f bgt 18f - UNWIND( .fnend ) .macro forward_copy_shift pull push - UNWIND( .fnstart ) - usave r4, lr @ still in first stmdb block subs r2, r2, #28 blt 14f @@ -205,12 +195,8 @@ CALGN( subcc r2, r2, ip ) CALGN( bcc 15f ) -11: stmfd sp!, {r5 - r9} - UNWIND( .fnend ) +11: stmfd sp!, {r5, r6, r8 - r10} - UNWIND( .fnstart ) - usave r4, lr - UNWIND( .save {r5 - r9} ) @ in new second stmfd block PLD( pld [r1, #0] ) PLD( subs r2, r2, #96 ) PLD( pld [r1, #28] ) @@ -219,35 +205,32 @@ PLD( pld [r1, #92] ) 12: PLD( pld [r1, #124] ) -13: ldr4w r1, r4, r5, r6, r7, abort=19f +13: ldr4w r1, r4, r5, r6, r8, abort=19f mov r3, lr, lspull #\pull subs r2, r2, #32 - ldr4w r1, r8, r9, ip, lr, abort=19f + ldr4w r1, r9, r10, ip, lr, abort=19f orr r3, r3, r4, lspush #\push mov r4, r4, lspull #\pull orr r4, r4, r5, lspush #\push mov r5, r5, lspull #\pull orr r5, r5, r6, lspush #\push mov r6, r6, lspull #\pull - orr r6, r6, r7, lspush #\push - mov r7, r7, lspull #\pull - orr r7, r7, r8, lspush #\push + orr r6, r6, r8, lspush #\push mov r8, r8, lspull #\pull orr r8, r8, r9, lspush #\push mov r9, r9, lspull #\pull - orr r9, r9, ip, lspush #\push + orr r9, r9, r10, lspush #\push + mov r10, r10, lspull #\pull + orr r10, r10, ip, lspush #\push mov ip, ip, lspull #\pull orr ip, ip, lr, lspush #\push - str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, abort=19f + str8w r0, r3, r4, r5, r6, r8, r9, r10, ip, abort=19f bge 12b PLD( cmn r2, #96 ) PLD( bge 13b ) - ldmfd sp!, {r5 - r9} - UNWIND( .fnend ) @ end of the second stmfd block + ldmfd sp!, {r5, r6, r8 - r10} - UNWIND( .fnstart ) - usave r4, lr @ still in first stmdb block 14: ands ip, r2, #28 beq 16f @@ -262,7 +245,6 @@ 16: sub r1, r1, #(\push / 8) b 8b - UNWIND( .fnend ) .endm @@ -273,6 +255,7 @@ 18: forward_copy_shift pull=24 push=8 + UNWIND( .fnend ) /* * Abort preamble and completion macros. @@ -282,10 +265,11 @@ */ .macro copy_abort_preamble -19: ldmfd sp!, {r5 - r9} +19: ldmfd sp!, {r5, r6, r8 - r10} b 21f -20: ldmfd sp!, {r5 - r8} +20: ldmfd sp!, {r5, r6, r8, r9} 21: +UNWIND( pop {fpreg} ) .endm .macro copy_abort_end -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel