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 X-Spam-Level: X-Spam-Status: No, score=-18.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B2F1C433EF for ; Tue, 21 Sep 2021 09:58:51 +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 BFC7161168 for ; Tue, 21 Sep 2021 09:58:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BFC7161168 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=bDPEG0HkMcKYywE4Xjxib1UxEGHhgcSmGZjdQkn+SI4=; b=oxz2VJgSyHtfJ3 266L8CoG29gGvXzI3mV+/NodNfMzeeRSUPbcIdZxbuMwxCDP2Lf9xc+mmlg8x3pbnw09Lq5/p4pki 8i1O+lwOYGUB4MWSAjbwPBxDBZoQVQTU9b2jA9vK2NGXpYUg9qN1FfuUctvDxreP2mP31mqMGFaen JxR/u8SrLLEQpIy8JGCRWbd4Cp0C5tiQJ6+Tn8MFJ5I6cbW5kycuAtGNn35YF/JvddIIDqMtX1KIk 1z216Rpr+0pg4yzzRHJJVbRZhDlgtJ7cwrpEbVkNZ67rRk8Y8oqoSwhn/iccp8dxSczHKeX41KoVp /sayVEZD6jv8yFy7Z4fw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mScW6-00469M-NA; Tue, 21 Sep 2021 09:56:47 +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 1mScTz-004553-OQ for linux-arm-kernel@lists.infradead.org; Tue, 21 Sep 2021 09:54:37 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B2778610CA; Tue, 21 Sep 2021 09:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632218075; bh=vZnGzFhh9pd5Fc1In8Ahzw0MVjHWyZRDD8bBJQiVRJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nc7sreCybMJOlg+la6brzaQhOrKDHxfUZVnv514qWf8TW5YQM6+/otvX59rZNt/kw Ddly3QfxQIblrAOcZrrQIKwak/04SuytWYn+YcHqHcaizwgoVI9VlwiKU0KuHohhN8 lJ1ZzaPDcP7/cR9W0hd3KPCOxN/fsVLrVJ71N4V5XPa7v0XsU7LZQT58EvAeHzUQeK zC2lE0y6h19MoqPMKCHbOu8A2IVfhD/9NW7glf1QJgbUoJfPXLO0ymZ7+RTfgazocD oCQ2HZiaqtgcy+2YcQS6qXXimW2SjxGEZOvqHz0r7GH+tEYg3IxQEJyEyREjcqlvbK ucciRhmglO1zg== From: Ard Biesheuvel To: linux@armlinux.org.uk Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij Subject: [PATCH 09/10] ARM: call_with_stack: add unwind support Date: Tue, 21 Sep 2021 11:54:07 +0200 Message-Id: <20210921095408.133210-10-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210921095408.133210-1-ardb@kernel.org> References: <20210921095408.133210-1-ardb@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210921_025435_853083_AC2658BB X-CRM114-Status: GOOD ( 16.23 ) 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 ELF unwind info based unwinder will be able to follow the call stack through call_with_stack(). Note that the former cannot support GCC and Clang at the same time, as they use a different idiom for the prologue/epilogue. So the code uses the GCC idiom, adding full frame pointer based unwind support for GCC while preserving the existing behavior of the Clang version, which simply omits call_with_stack() from its call stack. Signed-off-by: Ard Biesheuvel --- arch/arm/lib/call_with_stack.S | 44 +++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/arch/arm/lib/call_with_stack.S b/arch/arm/lib/call_with_stack.S index 28b0341ae786..133dffa2404a 100644 --- a/arch/arm/lib/call_with_stack.S +++ b/arch/arm/lib/call_with_stack.S @@ -8,25 +8,57 @@ #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. + */ + +#if defined(CONFIG_THUMB2_KERNEL) || \ + (defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_CLANG)) +/* + * Thumb-2 builds must use R7 as the frame pointer due to the way our unwind + * info based unwinder is constructed. + * + * The code below uses the GCC idiom for managing the frame pointer in the + * function prologue and epilogue, which Clang does not support. So the best we + * can do here is not touch the frame pointer at all: this will simply omit + * this frame when unwinding the call stack. So use R7 in this case as well, + * and leave R11 unmodified. */ + fpreg .req r7 +#else + fpreg .req fp +#endif + ENTRY(call_with_stack) - str sp, [r2, #-4]! - str lr, [r2, #-4]! +UNWIND( .fnstart ) +UNWIND( .movsp ip ) + mov ip, sp + +UNWIND( .pad #4 ) +UNWIND( .save {fpreg, ip, lr} ) +THUMB( sub sp, #4 ) + push {fpreg, ip, lr ARM(, pc)} + +UNWIND( .setfp fpreg, ip, #-4 ) + sub fpreg, ip, #4 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] + ldmdb fpreg, {fpreg, ip, lr} + mov sp, ip ret lr +UNWIND( .fnend ) 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