Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1022932rwl; Fri, 31 Mar 2023 05:53:23 -0700 (PDT) X-Google-Smtp-Source: AKy350a46vOwIts7ahI7Mfici4O2U08N7cgFnUMtUQGo2SBQuRGH73wAakMncqrtp/doxfFN70cS X-Received: by 2002:a05:6402:40d6:b0:502:367:d5b8 with SMTP id z22-20020a05640240d600b005020367d5b8mr6478087edb.4.1680267203362; Fri, 31 Mar 2023 05:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680267203; cv=none; d=google.com; s=arc-20160816; b=MBQeZe8uYcmq0MHFXH50OIXEnptWXrFoM+5p6O9nVLu8Mrx5Spyid8Ek71iTEafNRT wv+YY6yRfJcUNLNMQ7pU23R5A1tctQmtFKMXAneSa62dvjewhp/CxOYTDWk7v+GvaeVN yNkCSE7W3qSdy0onJH0YSk+7aSfeZKSdTsq/J5iJ+cBS4B4pefytqdOuf/D66v/czxjQ B53Ed8TXsfmU5wxHqIGLOps2ElSPoAvDXU2sEvRk2bniBm0IyikGFN6s+slYBOk8tpFu yfWrwDmWM7q5E3FB/fxUX86NR0n9fugpw0r4PourDaDJcxPx22OeE3WrfYXcEbpMF/Dx 8uUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YkYon3uPkhoSZDk7BpyC/Em+PJJrPGtsa037aUJEZb4=; b=Q/A4tO549FX/uGwy5SqsfJq7dX8I/ksHlOoSG+idiWbY8tPMxjSjmy5ww7Iyc67krO if2v7WjvE9bBuB/WpqoU3Bv8fnMN2hNlvSdYGC5w7Mx5EXl2MoCDgs73Cvl3VEn8EJqF dEJvYCo8HxzEK2nFVAImSAnZoNaXykehkin+9g/idfiA/vz/LIluQRxkQ0HIV/P/ohF5 XGqYwp9bGh9T0UAe2jbXF3J5+kMwb+ikfdBTN+3Bvt/za1D0DnVmFT4c7OJ0Ffwaecaq SizxQrWiJTSOXT5VN9tVsf6IV67asVOzmCoZf9geTIOP71fRyyIln0A7vSIajJeG5+eE AI+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a05640206c700b004fbae1637fcsi2283829edy.479.2023.03.31.05.52.59; Fri, 31 Mar 2023 05:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232505AbjCaMtk (ORCPT + 99 others); Fri, 31 Mar 2023 08:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbjCaMtR (ORCPT ); Fri, 31 Mar 2023 08:49:17 -0400 Received: from mail-m118111.qiye.163.com (mail-m118111.qiye.163.com [115.236.118.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D321721A8F; Fri, 31 Mar 2023 05:48:53 -0700 (PDT) Received: from ubuntu.localdomain (unknown [117.133.56.22]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id 5001158015C; Fri, 31 Mar 2023 20:48:06 +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, rmk+kernel@armlinux.org.uk, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, tglx@linutronix.de, dave.hansen@linux.intel.com, x86@kernel.org, bp@alien8.de, 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 v10 3/8] ARM: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL Date: Fri, 31 Mar 2023 05:47:39 -0700 Message-Id: <4737b3d08e1a4a7218e16c99f8ac308881d695c9.1680265828.git.pengdonglin@sangfor.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaGRlIVh8dHR9NSklPQk9PTVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKTFVKSEhVTk1VSUlZV1kWGg8SFR0UWUFZT0tIVUpKS0hKTFVKS0tVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OD46NTo5PD0OLU09QjkeITgW HUgKCj9VSlVKTUNLSU1NQ0NMQklIVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSkpMVUpISFVOTVVJSVlXWQgBWUFNSE5MNwY+ X-HM-Tid: 0a8737b601162eb7kusn5001158015c X-HM-MType: 1 X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The previous patch ("function_graph: Support recording and printing the return value of function") has 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 --- v10: - Use CONFIG_FUNCTION_GRAPH_TRACER to control fgraph_ret_regs definition v9: - Fix stack pointer align issues - Update the commit message v8: - Modify the control range of CONFIG_HAVE_FUNCTION_GRAPH_RETVAL --- arch/arm/Kconfig | 1 + arch/arm/include/asm/ftrace.h | 22 ++++++++++++++++++++++ arch/arm/kernel/asm-offsets.c | 8 +++++++- arch/arm/kernel/entry-ftrace.S | 10 ++++++---- 4 files changed, 36 insertions(+), 5 deletions(-) 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..3c457902b355 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_FUNCTION_GRAPH_TRACER +struct fgraph_ret_regs { + /* r0 - r3 */ + unsigned long regs[4]; + + unsigned long fp; + unsigned long __unused; +}; + +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 /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ +#endif + #endif /* _ASM_ARM_FTRACE */ diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index 38121c59cbc2..18bb85115b21 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include "signal.h" @@ -170,5 +171,10 @@ int main(void) DEFINE(KEXEC_INDIR_PAGE, offsetof(struct kexec_relocate_data, kexec_indirection_page)); DEFINE(KEXEC_MACH_TYPE, offsetof(struct kexec_relocate_data, kexec_mach_type)); DEFINE(KEXEC_R2, offsetof(struct kexec_relocate_data, kexec_r2)); - return 0; +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + BLANK(); + DEFINE(FGRET_REGS_SIZE, sizeof(struct fgraph_ret_regs)); + BLANK(); +#endif + return 0; } diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S index 3e7bcaca5e07..d41a1676608c 100644 --- a/arch/arm/kernel/entry-ftrace.S +++ b/arch/arm/kernel/entry-ftrace.S @@ -257,11 +257,13 @@ ENDPROC(ftrace_graph_regs_caller) #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(return_to_handler) - stmdb sp!, {r0-r3} - add r0, sp, #16 @ sp at exit of instrumented routine + mov ip, sp @ sp at exit of instrumented routine + stmdb sp!, {r0-r3, ip, lr} @ fill fgraph_ret_regs + mov r0, sp bl ftrace_return_to_handler - mov lr, r0 @ r0 has real ret addr - ldmia sp!, {r0-r3} + mov lr, r0 @ r0 has real ret addr + ldmia sp, {r0-r3} + add sp, sp, #FGRET_REGS_SIZE @ restore stack pointer ret lr ENDPROC(return_to_handler) #endif -- 2.25.1