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 1B298C433F5 for ; Mon, 15 Nov 2021 08:51:49 +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 D3D856321A for ; Mon, 15 Nov 2021 08:51:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D3D856321A 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=3Mkkq04MyMHGvYRu7AAk3T7Eu0/yfxmsbNnM1krtC5s=; b=1mJVky4j3daNN8 Cl6JGwLfGI7z7bQ326RHLH36a7aNN6mUZqQsSFCEfNJ7n0MMMD1i/KHlcZ1+/BB9aUoKB5X7rDNUN 85S/iaC6jNiU2IFaokWwGJuq2tY3sGbAR2k+CzALRs/qI0TlbOQmjeoLrF6xjEtmmZ0vZ9+2nGxpO 8OK181bgg0fe/KeH6+7BaqolOIsqVf1ODfClQJxuLDfG/TVvCkqbkSaJzx5M9l9wyADolPFaOuHvF fPPahESSo3k1Bo3abrciWavhQEaBzvlNwBcnLGGA6ndrOhJWmItulgcTFax3+F9ESMYPGlRypAjeG 8oRPY8lPM+72uU0C2xpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmXh4-00EkIq-NU; Mon, 15 Nov 2021 08:50:27 +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 1mmXeh-00Ej9H-Fb for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 08:48:00 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FDC963213; Mon, 15 Nov 2021 08:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636966079; bh=NrjZ8S/wCItSaTiMMN6yaqXmRlC15wwagRUWL1y3LCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G9BgIkFM0cHpdK/Rm3M8HvalocRQwtk5PMOUBE1UddEMQKASvxmldqyghf4j+oi63 R126o2jiU8zAdR2NJG1gcJB27ybVnpaFL1S/nJG4movpNJmDXzIFANotXuXKaGuImk MRzoQKXnKUkOt/MGfw9BuaRDgkkwmcVZg3dVVxx5Tw05MOkJnHte5e2j3RZ0I7aB8L NXGajCIkzPnIiiziwRy9rHdyejFTnCmRg9hjvC6JNutRhFmAv8m7vlbK/Wx+AASLwP V0ZqSFM8wuW3QecJT6woo9pxLbLuv0xrA0+Jvs53qySeYVtRvyy554tBj/Pj4qDwTD f/XaM1LZMb1ew== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Russell King , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Nicolas Pitre Subject: [PATCH v4 8/9] ARM: call_with_stack: add unwind support Date: Mon, 15 Nov 2021 09:47:31 +0100 Message-Id: <20211115084732.3704393-9-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211115084732.3704393-1-ardb@kernel.org> References: <20211115084732.3704393-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2196; h=from:subject; bh=NrjZ8S/wCItSaTiMMN6yaqXmRlC15wwagRUWL1y3LCw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhkh6iBID/Hnto9feb6LRyhoPufIEuE1CtGz02ouiX PQurOrGJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYZIeogAKCRDDTyI5ktmPJP+qC/ 43R0svQPF1pddrEssHXip7xouINQZtLK/XD/65hPYc3H6aNiiQvJUtNgkipxtejFETf/B3NXD8S9qk H0qCTFgF85zwjNXEg4o/CozFOQ0xUnbPIuI1wbsgePpq1z+JOtnG8BvCPtfZe3PNL17eEYeqcv/opY 47IhS6QNmyJsNLmn8krlY2txe6vqHHSRWz9gKK2NeUGqV4tRSSUoFJrm3sNupE4tU2s1i6VhjFrJtI MkLyEUUNXJYnCOTEVGgq3N0Y66huTnJYCLP89E4aIVFRdryqI/6u4gOJbJQqZqZt/rpWlIAQ0zU2jZ QFQJ4mr+uMBpSqRhyNj8k9PffQ62Htx911dtJQH6GOhmQTGm5PN2VSrxJPfk/CUDVdI5x3I1B4A321 YMYNeuj50V00C3ZN6bI4bsp0P3VYqrTSXccl862favQKUK2zFr5AOwYXuodGA6hIDZgD6XK0CJ5zrE 67YAA94KWqKMai8F6MSs7nyTPc81CV+64b8F2LMTicx+Q= 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_004759_587571_F24B48B1 X-CRM114-Status: GOOD ( 14.26 ) 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 Restructure the code and add the unwind annotations so that both the frame pointer unwinder as well as the EHABI unwind info based unwinder will be able to follow the call stack through call_with_stack(). Since GCC and Clang use different formats for the stack frame, two methods are implemented: a GCC version that pushes fp, sp, lr and pc for compatibility with the frame pointer unwinder, and a second version that works with Clang, as well as with the EHABI unwinder both in ARM and Thumb2 modes. Signed-off-by: Ard Biesheuvel Acked-by: Linus Walleij Tested-by: Keith Packard Reviewed-by: Nick Desaulniers --- arch/arm/lib/call_with_stack.S | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/arm/lib/call_with_stack.S b/arch/arm/lib/call_with_stack.S index 28b0341ae786..0a268a6c513c 100644 --- a/arch/arm/lib/call_with_stack.S +++ b/arch/arm/lib/call_with_stack.S @@ -8,25 +8,42 @@ #include #include +#include /* * void call_with_stack(void (*fn)(void *), void *arg, void *sp) * * Change the stack to that pointed at by sp, then invoke fn(arg) with * the new stack. + * + * The sequence below follows the APCS frame convention for frame pointer + * unwinding, and implements the unwinder annotations needed by the EABI + * unwinder. */ -ENTRY(call_with_stack) - str sp, [r2, #-4]! - str lr, [r2, #-4]! +ENTRY(call_with_stack) +#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) + mov ip, sp + push {fp, ip, lr, pc} + sub fp, ip, #4 +#else +UNWIND( .fnstart ) +UNWIND( .save {fpreg, lr} ) + push {fpreg, lr} +UNWIND( .setfp fpreg, sp ) + mov fpreg, sp +#endif mov sp, r2 mov r2, r0 mov r0, r1 - badr lr, 1f - ret r2 + bl_r r2 -1: ldr lr, [sp] - ldr sp, [sp, #4] - ret lr +#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) + ldmdb fp, {fp, sp, pc} +#else + mov sp, fpreg + pop {fpreg, pc} +UNWIND( .fnend ) +#endif ENDPROC(call_with_stack) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel