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 13131C433F5 for ; Tue, 25 Jan 2022 15:56:02 +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=V/V1tbyxcmXPTG/BIM/OG+scUxI8VPQRfoR1cHJ+R8o=; b=DUiZkqCWjgEza+ HYOm/Swxw1e4LbzHni/zKMX+b9gxSh5hwvsaeoWAqQ7ui1sTVtH3hsdAVXkWO2pzABNeeQIvCewlO PYOc7f7j394Pk5zZLFB3XgJpBfpKRmi7m5eUpE/HLVju/Q0NW2LsbXBY3Djptlmirp/rpK0u03XKf 0aTcl6iVRSqUxQHGNUe+S6ZhY2fMSGL6WlYAtd5tmWnpq3oOLnDuLSgKsICu3kfIjEnx2/SZPTUxb yLGO0Mr0ilaSSKXyI0MotEPtOf1yUtXHUAUdzsPcYYrWENRw6tk3YjCrA5vd6AOASZPXezhmcXg8b WFK8X5Pr3aScmNkyRIfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCO99-008Unl-5e; Tue, 25 Jan 2022 15:54:15 +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 1nCNsv-008Q9T-4U for linux-arm-kernel@lists.infradead.org; Tue, 25 Jan 2022 15:37:31 +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 61146B818C6; Tue, 25 Jan 2022 15:37:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B665EC340E9; Tue, 25 Jan 2022 15:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643125046; bh=c1Hyo+603zEV0IymWlgiCJcT3svqdCIjwbJYPeEuTLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u43U+9Yw5y0XqL83GiuoJfjjYz+WhfDG+C+LQyfUkpH7/NLam3RsNv1+sp/gvb1eM NnyJ/wvTbfe+Dm/Wy3eBjMU2sl0hKRy9GIFUrKrMFCvkZEb2bHeuVSO/yAUHRzjSO1 E7PiOAwXcfmOO+sVzXaYcAtdcAGRWZNVuFe0LyBbx3epq6UBLlkXe8bUCntMfcDfIm XKxXWWa/LmZEJiKkCq9FCxoDTLTzKQpX+jW6D6Ww7jV74ktRFZdPqW8KbvGVzfPu1F 5HbTGp82GrC3je8K3fqYST78uowACASmKvKqWM9ENoJHht7jVBxeTjzgN24EZK/k3N 5GhuE4TUFb1aA== From: Ard Biesheuvel To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Arnd Bergmann , Linus Walleij , Nick Desaulniers Subject: [PATCH 7/8] ARM: unwind: track location of LR value in stack frame Date: Tue, 25 Jan 2022 16:36:55 +0100 Message-Id: <20220125153656.1802079-8-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220125153656.1802079-1-ardb@kernel.org> References: <20220125153656.1802079-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3406; h=from:subject; bh=c1Hyo+603zEV0IymWlgiCJcT3svqdCIjwbJYPeEuTLI=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh8BkV17J7D7cEsi5Ig/cGcANl/GVPA0/hSyUdJv1+ gI1JvBOJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYfAZFQAKCRDDTyI5ktmPJHqmDA CucXhJ+i7azy9ZgWp4lNTcls6wJnjjoRmdTyRtpjWeLhlLMRPM1yVaI+O/vJsnyRO171zTS/4buH+Z a35aBmkFgrKl38KDpV/1UH5+qbkM+ICEDJ2mNhXidOl/aZlMmLzoCTh6m8Pe11nsgxfvZ6vZetZnV/ tXpk0YYFlPxi4Z3xy4gyawxHGWn+fyxcRJ69XO9opYmgYZ1q+2O7egAasrfy6UHKsYDgrv7B72K2UF /qB/JB+SrN+FaybKIGsXkivO3QhnCT24pfwfEMvcJtnQkRVRq4XVFv6S/Y2h8ZwdLeFMWEZZz25m/z MCEu0CK9S9Ofo1/XLyvfPzNTKxF+gEOpl1zSFghiiensf/suBmoKM36xwVOSKY87/n9pzz5VuUB+sk piXPhw19bufF+Xxy5q9DC3Y0yH03+cGwuEaDv+TeEqk/Acsl9kSSvyarf5jMnwhwoVOPgxKoFf9Z4a 2Ki1RcaEKA3dygZ05bNRUhu7qG1aeWJR161q8W9lUAu6o= 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-20220125_073729_528282_23C9AD73 X-CRM114-Status: GOOD ( 22.72 ) 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 | 2 ++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/unwind.c | 7 ++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stacktrace.h index d87d60532b86..e5ce7440cba8 100644 --- a/arch/arm/include/asm/stacktrace.h +++ b/arch/arm/include/asm/stacktrace.h @@ -27,6 +27,8 @@ struct stackframe { * executing from another stack. */ unsigned long sp_low; + /* address of the LR value on the stack */ + unsigned long *lr_addr; #endif }; 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