From patchwork Fri Mar 24 12:37:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pengdonglin X-Patchwork-Id: 13186744 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 1EAA8C77B61 for ; Fri, 24 Mar 2023 12:38:36 +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=rpdWCA62c7hQCGDwLgj30yVhaTrAljI57WYc+xCgcFQ=; b=qO/bB3o0x/YMM8 CIVxC6JQfm1Md0LyxSWCJwrlRcs5RouDqU4aFoSrY+Cln4vWK6wZTDQs+EJEdOkC1UN5UtwwI61nf D2AHjHw6b5M01uoEhcyGTbwmus3OG5bfkT4ZKc/+tF/b2YVhrgEd9/ydVrA4S8fAxwYQk/1bM0Qae ZwUz28ojUWuBa2n6Pu0xjmCHE2k3CXkSa9VAsFRBavJ07IY3ebpcE5oR6mMMyvatHZLDF39gn4AA8 juGDHn95WzEw0/y5T1mup5o4sNCTJ4oh0TsWqvh3D1gkZPy7FP2DoRDGwJ4YHQK1SaAl2A9mTHJJx ZOhvb21X+//SHLLbJxTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfggf-004NN1-2o; Fri, 24 Mar 2023 12:38:29 +0000 Received: from mail-m118111.qiye.163.com ([115.236.118.111]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfggR-004N8W-18; Fri, 24 Mar 2023 12:38:17 +0000 Received: from ubuntu.localdomain (unknown [117.133.56.22]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id 56892580A58; Fri, 24 Mar 2023 20:37:40 +0800 (CST) From: Donglin Peng To: mhiramat@kernel.org, rostedt@goodmis.org, linux@armlinux.org.uk, mark.rutland@arm.com, will@kernel.org, catalin.marinas@arm.com, palmer@dabbelt.com, paul.walmsley@sifive.com, tglx@linutronix.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, chenhuacai@kernel.org, zhangqing@loongson.cn, kernel@xen0n.name, mingo@redhat.com, peterz@infradead.org, xiehuan09@gmail.com, dinghui@sangfor.com.cn, huangcun@sangfor.com.cn, dolinux.peng@gmail.com Cc: linux-trace-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Donglin Peng Subject: [PATCH v7 3/8] ARM: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL Date: Fri, 24 Mar 2023 05:37:26 -0700 Message-Id: <20230324123731.3801920-4-pengdonglin@sangfor.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324123731.3801920-1-pengdonglin@sangfor.com.cn> References: <20230324123731.3801920-1-pengdonglin@sangfor.com.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaTUJDVk4ZTU8fTBgYGR8YGVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKTFVKSEhVTk1VSUlZV1kWGg8SFR0UWUFZT0tIVUpKS09ISFVKS0tVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Oj46DAw5Sj0IMQ88CkgtEQ8U DD8KCxhVSlVKTUxCTU1KT01KQ09JVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSkpMVUpISFVOTVVJSVlXWQgBWUFPQ05LNwY+ X-HM-Tid: 0a87139fefa02eb7kusn56892580a58 X-HM-MType: 1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230324_053815_614601_3E2E6047 X-CRM114-Status: GOOD ( 10.87 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The commit d4815c5d1bbd ("function_graph: Support recording and printing the return value of function") laid the groundwork for the for the funcgraph-retval, and this modification makes it available on the ARM platform. We introduce a new structure called fgraph_ret_regs for the ARM platform to hold return registers and the frame pointer. We then fill its content in the return_to_handler and pass its address to the function ftrace_return_to_handler to record the return value. Signed-off-by: Donglin Peng --- arch/arm/Kconfig | 1 + arch/arm/include/asm/ftrace.h | 22 ++++++++++++++++++++++ arch/arm/kernel/entry-ftrace.S | 6 +++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index e24a9820e12f..73061379855a 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -98,6 +98,7 @@ config ARM select HAVE_FAST_GUP if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_ERROR_INJECTION + select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL select HAVE_GCC_PLUGINS diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 7e9251ca29fe..e3bed4949558 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -77,4 +77,26 @@ static inline bool arch_syscall_match_sym_name(const char *sym, #endif /* ifndef __ASSEMBLY__ */ + +#ifndef __ASSEMBLY__ + +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_RETVAL +struct fgraph_ret_regs { + unsigned long regs[4]; + unsigned long fp; +}; + +static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs) +{ + return ret_regs->regs[0]; +} + +static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs) +{ + return ret_regs->fp; +} +#endif + +#endif + #endif /* _ASM_ARM_FTRACE */ diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S index 3e7bcaca5e07..5f1e74555b25 100644 --- a/arch/arm/kernel/entry-ftrace.S +++ b/arch/arm/kernel/entry-ftrace.S @@ -257,11 +257,15 @@ ENDPROC(ftrace_graph_regs_caller) #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(return_to_handler) + sub sp, sp, #4 stmdb sp!, {r0-r3} - add r0, sp, #16 @ sp at exit of instrumented routine + add r0, sp, #20 @ sp at exit of instrumented routine + str r0, [sp, #16] + mov r0, sp bl ftrace_return_to_handler mov lr, r0 @ r0 has real ret addr ldmia sp!, {r0-r3} + add sp, sp, #4 @ skip fp ret lr ENDPROC(return_to_handler) #endif