Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1040351rwl; Fri, 24 Mar 2023 05:38:37 -0700 (PDT) X-Google-Smtp-Source: AK7set9BRywqiIVGavQo6H0IU48u7+viA095FWhxU3FfMt4/5Mvb2usFORb7IcqJSJqBkLLC4/up X-Received: by 2002:a05:6a20:92a4:b0:da:17b4:4624 with SMTP id q36-20020a056a2092a400b000da17b44624mr3112507pzg.2.1679661516841; Fri, 24 Mar 2023 05:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679661516; cv=none; d=google.com; s=arc-20160816; b=wGg89hr9hHJdaOvKcpCyYWUjcKdPm6pTckJw2sJK0FtLKQo3fUIPhivEN/X/JcXvHa ZGiUfesBqwhB7KoLKSrH9Mm+4pVPfc4Rzqo3Zb0NPV6EIrbULrgiCcYwBsKUmSWt/GfH UUikHtO+VnRR7U4Gyx8MSvexIdSp6jinnSjROYupCbc1UjT+VeLQqnrHcAbDojFRsC/A 35Yk1hS2F1huDrt1tTLXiRcWrXXCep9TMepwZeSquS/ZVZshSibHY9ZvZyb4k0DfGaSE xD+NO7oHJgS0N7AWVz9hLfLFjih53KjiMcFpS9W1yniXeqxpa8lJske176r1kCccvVba 28+w== 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=TLB05MVxtP0CRR0NXwAfK4K8RuD6toBL+KVfDNhg+Ow=; b=bMGApaf+xooMjw28fMNjtKDMkiHmjsD6cXXBkC9czu3jnruG8jgq6ibcVjNpwT2OeH ep22yIdhIDLX+AP1+SHElzNndTNHf5+MDg/8aqKtpn4LP+s2T03GuJjHFi0L8ozbrSBX ZX43kHAG1t7jg9FFZBb+xplGwclUl/pLXF8IPU/bOn2clYLpR+JC67YAQ2WW5mBfjAsp 9uM5sRvqHkMERtEecTtczLoCyhvsBDETCFXJPS8AvPzTWD+m3VXPHOnAE9Eguopon1MQ DiiwEvupHd+OWMdGdljH1ZM2vP4IlN9bPsYMWOiW1UOcAaGD+lvpjPbQedeiuOzHDWM9 MG7Q== 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 s1-20020a63dc01000000b0050b51e62c20si21629376pgg.793.2023.03.24.05.38.24; Fri, 24 Mar 2023 05:38:36 -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 S231831AbjCXMiF (ORCPT + 99 others); Fri, 24 Mar 2023 08:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231289AbjCXMiA (ORCPT ); Fri, 24 Mar 2023 08:38:00 -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 60BC9421E; Fri, 24 Mar 2023 05:37:58 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaTUJDVk4ZTU8fTBgYGR8YGVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKTFVKSEhVTk1VSUlZV1kWGg8SFR0UWUFZT0tIVUpKS09ISFVKS0tVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Oj46DAw5Sj0IMQ88CkgtEQ8U DD8KCxhVSlVKTUxCTU1KT01KQ09JVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSkpMVUpISFVOTVVJSVlXWQgBWUFPQ05LNwY+ X-HM-Tid: 0a87139fefa02eb7kusn56892580a58 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 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 -- 2.25.1