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 E2648C433EF for ; Tue, 5 Oct 2021 07:20:45 +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 A8A4460F59 for ; Tue, 5 Oct 2021 07:20:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A8A4460F59 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=Twibe2fOkHdxrH yVG2a+t4Smv06mw5GKg0yUyzssbIbdkQzmyFWvq6VLjyJ29xRy2TGlRXWALOkUoLEQn6rwUpWGyJ+ ODv4FFLkzs0AVs52n5lAivbkqhr/j75/PN/Ed6m8+/SwJTL5b7QZvMv5PBmajqH7w6lpWXx2OEuXo IOGkgh0uQ189txuGQQfINc4CxOaxVFB5+zvNhiArd3U5oBXOHxTUWQ0wpovnrH+eP6LaHYZXUx5vC HJ7eiDmnSlt5nuf4cGzcSdiZ+UBR+QlABurEQoJLmyxjM/Gj/ER5UNWVot83JMfnj/mISVF89Gnj9 /jzpmbF27jfSbot1IgPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXeiz-009JTq-VR; Tue, 05 Oct 2021 07:18:54 +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 1mXega-009IMR-S2 for linux-arm-kernel@lists.infradead.org; Tue, 05 Oct 2021 07:16:26 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id EA9ED61507; Tue, 5 Oct 2021 07:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633418184; bh=vZnGzFhh9pd5Fc1In8Ahzw0MVjHWyZRDD8bBJQiVRJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QI6NqjEc25b3TV5R1c6XN+T8P977d84OoVzdV9UZ7ifbLz99+oUYajrSvd761Q7OV 3V+U/Rkeu2bYYsC402Mmcn/T9FQo0LdcBInDAezJqkfKMYO+3zEmIMNqgwKCZYr66M uPy/N/Ko6cAJ6sFO8blaUGE87n1l2eqBH21DaGaifXCjTfcDG3F0EfY+xdRVbu/e4t TvrUnAUMpjwhPXgXKLatNHA5RrCLfRt5pym9otusXxdoeRiYVNv7F67nP5ezfq0x2U hn1FBXtJJKaYMPjthTEJc7bVikEAQ2cb/3m2jx4CKEV9udu0fa+hZLOLZ6qwUY8IpI Gb1jJRVsFdheg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij Subject: [PATCH v2 8/9] ARM: call_with_stack: add unwind support Date: Tue, 5 Oct 2021 09:15:41 +0200 Message-Id: <20211005071542.3127341-9-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211005071542.3127341-1-ardb@kernel.org> References: <20211005071542.3127341-1-ardb@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211005_001624_953516_7C2A4A87 X-CRM114-Status: GOOD ( 15.89 ) 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