Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1976917rwl; Sat, 8 Apr 2023 05:45:10 -0700 (PDT) X-Google-Smtp-Source: AKy350azrzSXBI9Mp0tWxyIkwi8FFxUKGxNMpb39u0NTjvGj8qtZlnSnJ183PGdOOACrCEh3OarR X-Received: by 2002:a17:906:b756:b0:8b1:88aa:46da with SMTP id fx22-20020a170906b75600b008b188aa46damr2250603ejb.48.1680957910220; Sat, 08 Apr 2023 05:45:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680957910; cv=none; d=google.com; s=arc-20160816; b=CCsLKAg9DiRtzLXK34TbYd2qWc/l1Xc5HVgDhFrNihKTQ2/Yo0x32aLFq1erm1/TjQ F0hVTqnLFl02Z/5Za0UBwxZpC0X1tEzjFnAyGCnj240ev3Lo6QtuCOrtVd3NAG+pZxPe nwYmf/ThfBAuRuSfn74rjmZ0sUIMLtk8lrRowXS8sK/8ipxcjBNR1XKn3o5/x1EcE6As z/jkReagysNV22JQ2ga6D6DxJUrg1+fWsJdC68D+UOhbz7/3jkYzhwvUUpdOG3YhIy6b D6Gy7qWvUiTGuVbBsL8LYsa8e7gXMmeqJA38dmv1cvTayaWWqfHttcnimE98EkPr9+05 YzPQ== 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=b8pTeX+THbPeoNv/c4jT42gIN0s/nQSGIYfeqPKc+InzUj/8J9cELeYmLux8f35lrU 12l3ShoyWspM3nuXbxEduchZ9j38WBI1I28uG1TwdPgXZ9F7WhTwBk/fFnzFcupdgfdQ IKWSVAfwTlI2qvgvKI5zDOgTVmTpVrQW3uDjFSeU7N/s+oFNpNG3zK8YgPA7eycD7dro YCKOKz1lmVGED0VyAvwav/jJxpYJlC8qif80hzQSzmqZhzn7Nz6sqdZrj6qJyW0IvRRz nw84Dp8DjEhmt9ghP2f4QBBC4bJ4CWYR+IzlZh2KiRoUKArpT/3kDMVd3hbCZUGk+Fwr Ttqg== 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 ne18-20020a1709077b9200b0093dfd2eab9dsi6980337ejc.2.2023.04.08.05.44.38; Sat, 08 Apr 2023 05:45:10 -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 S230176AbjDHMms (ORCPT + 99 others); Sat, 8 Apr 2023 08:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjDHMmr (ORCPT ); Sat, 8 Apr 2023 08:42:47 -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 50E1AAF12; Sat, 8 Apr 2023 05:42:44 -0700 (PDT) Received: from ubuntu.localdomain (unknown [121.32.254.147]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id B85045802A0; Sat, 8 Apr 2023 20:42:31 +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 v11 3/8] ARM: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL Date: Sat, 8 Apr 2023 05:42:17 -0700 Message-Id: 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 tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCGUMeVh0fGh0fTBpOHk1CGlUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJSlVISVVJTk9VSk9MWVdZFhoPEhUdFFlBWU9LSFVKSktPSEhVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OEk6Mhw5GD0SMDcyShNOVhQe Pi8aCRZVSlVKTUNLQk5MTE5ISUJKVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSklKVUhJVUlOT1VKT0xZV1kIAVlBTUhOTDcG X-HM-Tid: 0a8760e3c6062eb7kusnb85045802a0 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