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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1C9C6C433F5 for ; Mon, 31 Jan 2022 17:23:29 +0000 (UTC) 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=nMDT8p4aAKiBgOcWrWNUctO3ddpDFgSY0R65LM1IGgE=; b=H5nLASp5UmesUk Ht+3IbMRmXRhiXo2Bqe4MUYIfbMA58FyPq1+x2SOJdzCnQlWsBCCUvi4npiqwqK4YZFVn94ki91JW r5cr+lpzNZdN5vcvF1Z8/gOX3ud+VLU53OEa/DBoD+arCxNDkmbKaF30UPJ2IBXz0ZCM39A8xGM91 BA7wfGe+bNCLi5GvJCtoAKWm1KDKQCtQRBk3oFPiLBQtNp0I/ybUQ62xJnbw2Rkme4at6+AvU3EgQ Up5zPGbG30b4lAdx7CAcpWyrhTT3cw5PoUr+P5LlHrh+yl6jl+0/LVfGcF6oTPB08Xjyvfj3c2jfm G6aS2gR3FsnE6oNRyGYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEaNJ-00A4kD-Ji; Mon, 31 Jan 2022 17:21:58 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEa6C-009zJO-CC for linux-arm-kernel@lists.infradead.org; Mon, 31 Jan 2022 17:04:21 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E7558B82BB2; Mon, 31 Jan 2022 17:04:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 502D4C340F1; Mon, 31 Jan 2022 17:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643648653; bh=jc7I3Z+IG06CAL+tjTQKf67tnYV2+jk9Yn8fdREYNmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=av1mou+VXnHWFBj+V/UMlu4/R01YDSOoe/q4yv8mgWWeRjRGG6eCuRu4wzTuLXKOH jOH65Vrt4ddkyy0oXrC3rmCCCVAcmuQFVkXMa3kSk1vS3cpK7xAXnHSzSCRFDbEJzM cJtMfMzfILhJFqWCJjIdJv5KZl0BLveydoWq0Mwzo1TC9s0is41pb9mBwvE5kza7rh ya9yh6FePSmW3XqT1bumez07boKjEM1Iv2f0FLwHK5K1zuac0QKjRgP2WYiPO//oI+ 6/nMCwCe3xZNZpu5xSHBp2nX/EVuxvFq7wcSQXC720/7/Ar4Bj1Ue1ZnzNFSxoafbR gEbfS6lVxYiWw== From: Ard Biesheuvel To: linux@armlinux.org.uk Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Steven Rostedt , Sudeep Holla , Cristian Marussi , Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Linus Walleij , Masami Hiramatsu Subject: [PATCH v2 07/12] ARM: unwind: track location of LR value in stack frame Date: Mon, 31 Jan 2022 18:03:42 +0100 Message-Id: <20220131170347.381551-8-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220131170347.381551-1-ardb@kernel.org> References: <20220131170347.381551-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3473; h=from:subject; bh=jc7I3Z+IG06CAL+tjTQKf67tnYV2+jk9Yn8fdREYNmw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh+BZoN6G+ODk7ZMot5aDcwguopnHKEW5droQBE2eN icesTASJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYfgWaAAKCRDDTyI5ktmPJKCuDA CwOGDVn+g5hKlY4mHev4skcvJLXI8xvtcef9hWQiCSX8Akx02aYsddOpfs0b7LvTOazFYenW64fkbU U5SfA+umZdCWGeW2llqdRZFAL+saJ2+jga7pqrQEylnwVuIyvmWno983HceELUTfdQzspFPlOnwrbc z5+Z3QS8Z4LTx6ZWQbJX/5fpIBUzyDqfKDI9b7BoJp1zP9UfxpBpSucNxo4VHc6iRofJ9oSJN/aFz+ bT+LNHCvYxEB134Sy8/I+0/aNv8XU2jotC7zGAagaCFRf7jzmx3mXfkIkJ0jblsyOzh0iQ0vwtcCT9 LuC2afWYQpNY9rbUvI1aP8T92NTjLarntpCDa/lRwF+/dKXlgJ6nEjNtIkQRKXObLLPKqHeKf+VN0w 3cfhbjlJnwQTG934ClV31KzB5ZR/dzRXzr/47QkNrwyii1MSmqbwWcWbyZUV9rCFmcW8TN5EJXRKRd ERB2U/dMREFiIT8op9lTrccD0KiNX9wDyxEvESpH9MLp4= 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-20220131_090416_762496_774EC728 X-CRM114-Status: GOOD ( 22.68 ) 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 ftrace graph tracer needs to override the return address of an instrumented function, in order to install a hook that gets invoked when the function returns again. Currently, we only support this when building for ARM using GCC with frame pointers, as in this case, it is guaranteed that the function will reload LR from [FP, #-4] in all cases, and we can simply pass that address to the ftrace code. In order to support this for configurations that rely on the EABI unwinder, such as Thumb2 builds, make the unwinder keep track of the address from which LR was unwound, permitting ftrace to make use of this in a subsequent patch. Drop the call to is_kernel_text_address(), which is problematic in terms of ftrace recursion, given that it may be instrumented itself. The call is redundant anyway, as no unwind directives will be found unless the PC points to memory that is known to contain executable code. Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/stacktrace.h | 3 +++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/unwind.c | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stacktrace.h index d87d60532b86..e56503fd9447 100644 --- a/arch/arm/include/asm/stacktrace.h +++ b/arch/arm/include/asm/stacktrace.h @@ -14,6 +14,9 @@ struct stackframe { unsigned long sp; unsigned long lr; unsigned long pc; + + /* address of the LR value on the stack */ + unsigned long *lr_addr; #ifdef CONFIG_KRETPROBES struct llist_node *kr_cur; struct task_struct *tsk; diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index ae295a3bcfef..56511856ff9d 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -10,6 +10,7 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_insn.o = -pg CFLAGS_REMOVE_patch.o = -pg +CFLAGS_REMOVE_unwind.o = -pg endif CFLAGS_REMOVE_return_address.o = -pg diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index c5ea328c428d..b4e468a7674b 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -55,6 +55,7 @@ struct unwind_ctrl_block { const unsigned long *insn; /* pointer to the current instructions word */ unsigned long sp_low; /* lowest value of sp allowed */ unsigned long sp_high; /* highest value of sp allowed */ + unsigned long *lr_addr; /* address of LR value on the stack */ /* * 1 : check for stack overflow for each register pop. * 0 : save overhead if there is plenty of stack remaining. @@ -239,6 +240,8 @@ static int unwind_pop_register(struct unwind_ctrl_block *ctrl, * from being tracked by KASAN. */ ctrl->vrs[reg] = READ_ONCE_NOCHECK(*(*vsp)); + if (reg == 14) + ctrl->lr_addr = *vsp; (*vsp)++; return URC_OK; } @@ -395,9 +398,6 @@ int unwind_frame(struct stackframe *frame) pr_debug("%s(pc = %08lx lr = %08lx sp = %08lx)\n", __func__, frame->pc, frame->lr, frame->sp); - if (!kernel_text_address(frame->pc)) - return -URC_FAILURE; - idx = unwind_find_idx(frame->pc); if (!idx) { pr_warn("unwind: Index not found %08lx\n", frame->pc); @@ -476,6 +476,7 @@ int unwind_frame(struct stackframe *frame) frame->lr = ctrl.vrs[LR]; frame->pc = ctrl.vrs[PC]; frame->sp_low = ctrl.sp_low; + frame->lr_addr = ctrl.lr_addr; return URC_OK; } -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel