Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1976959rwl; Sat, 8 Apr 2023 05:45:12 -0700 (PDT) X-Google-Smtp-Source: AKy350b667HgvX8rFs1pDk44zaee0rIpLbaLluVDujdGLnZ4vEaQhWD2tGpvsdU2Yqc0u7JLlDSL X-Received: by 2002:a17:906:16d3:b0:932:8cd:1021 with SMTP id t19-20020a17090616d300b0093208cd1021mr1825995ejd.33.1680957911978; Sat, 08 Apr 2023 05:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680957911; cv=none; d=google.com; s=arc-20160816; b=tNkEMcZyhkj/Dq2t/LOL+mdWxGlDiLWK9XZ2Q0PeI5Ws6zRy70u582KX+0T8kSBnsJ 6Esnp7FpGvwH857rvtRva/FAU/Eu/QLlaOB44IPX1yX/dGsGChZ2ToYlDRhwt2RlYbFF 0imw0oCARXpsb41yu5H6noA/I29aoT29JeqKJC/eOLwOA+fIOs/rCttr5iUwkMihLNPz pUxpu9Tpxb4bteD4ys58PM2FQJoCQogp/xeqlyAsJiRN4Kng1GNGBHO3I9BWH8XKIfcd nAM8YesuK5EI/yQon3bHwPc4Cfo5O/i2+2jS2o7/d5uivrBL4KnNAFxU/wAZ9xyUyxpd Xq6A== 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=tqSsnjF5r68S8J1xOlXuNfc4yohVv205cM9AV7JqDhU=; b=fUJoG9xgJnYG5o7MnLbFYBHQoMoHpflWyQ1h9rgLQW8dAarw5QF1fnOopTnK9B7fTX 6BIykhsKu0i7gtPvxvcDwt3f4YUasxYJEoEArcAVtwPgjQ/vYyje51EF4KCxAg3+PQjr mt6IL1bqRZog3DHghXzYd3/+/iCNyBZyEVTPb0H5ueNxNb/MrcmN1hvkfvhGZMatJwx7 HHV+dL8Z/hVy64XltZ1kExCtT6xah573OZ3vLq5Y+M75QU/3Cv1YE0FmRvYpJ5JWe62t k9HxycA3IJoPDh6Hg3G0o0YJWztgYjUWuy8Nl8/yEtRSN5mltxkhRFlkDsqk7AEU68Lu mMGw== 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 n4-20020a170906724400b009220173aa75si4482588ejk.456.2023.04.08.05.44.47; Sat, 08 Apr 2023 05:45:11 -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 S230426AbjDHMmx (ORCPT + 99 others); Sat, 8 Apr 2023 08:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbjDHMmr (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 79FDBAF26; 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 CDEFD5802E7; Sat, 8 Apr 2023 20:42:36 +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 6/8] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL Date: Sat, 8 Apr 2023 05:42:20 -0700 Message-Id: <53a506f0f18ff4b7aeb0feb762f1c9a5e9b83ee9.1680954589.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 tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCQ0oaVkNDSEhLTEMdGRpDTVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJSlVISVVJTk9VSk9MWVdZFhoPEhUdFFlBWU9LSFVKSktPSEhVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6KxQ6Ehw4OD0KDjdNFRxKVhAO CD4KCzZVSlVKTUNLQk5MTE5DSE1KVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSklKVUhJVUlOT1VKT0xZV1kIAVlBTUtITzcG X-HM-Tid: 0a8760e3d9dc2eb7kusncdefd5802e7 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 x86 platform. We introduce a new structure called fgraph_ret_regs for the x86 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: - Update the commit message v8: - Modify the control range of CONFIG_HAVE_FUNCTION_GRAPH_RETVAL --- arch/x86/Kconfig | 1 + arch/x86/include/asm/ftrace.h | 20 ++++++++++++++++++++ arch/x86/kernel/ftrace_32.S | 8 +++++--- arch/x86/kernel/ftrace_64.S | 7 ++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index a825bf031f49..956cc988bdf9 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -214,6 +214,7 @@ config X86 select HAVE_FAST_GUP select HAVE_FENTRY if X86_64 || DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD + select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_GRAPH_TRACER if X86_32 || (X86_64 && DYNAMIC_FTRACE) select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h index 5061ac98ffa1..38d1df9aed37 100644 --- a/arch/x86/include/asm/ftrace.h +++ b/arch/x86/include/asm/ftrace.h @@ -147,4 +147,24 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) #endif /* !COMPILE_OFFSETS */ #endif /* !__ASSEMBLY__ */ +#ifndef __ASSEMBLY__ +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +struct fgraph_ret_regs { + unsigned long ax; + unsigned long dx; + unsigned long bp; +}; + +static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs) +{ + return ret_regs->ax; +} + +static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs) +{ + return ret_regs->bp; +} +#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ +#endif + #endif /* _ASM_X86_FTRACE_H */ diff --git a/arch/x86/kernel/ftrace_32.S b/arch/x86/kernel/ftrace_32.S index a0ed0e4a2c0c..5a9cc723f81f 100644 --- a/arch/x86/kernel/ftrace_32.S +++ b/arch/x86/kernel/ftrace_32.S @@ -182,12 +182,14 @@ SYM_CODE_END(ftrace_graph_caller) .globl return_to_handler return_to_handler: - pushl %eax + pushl $0 pushl %edx - movl $0, %eax + pushl %eax + movl %esp, %eax call ftrace_return_to_handler movl %eax, %ecx - popl %edx popl %eax + popl %edx + addl $4, %esp # skip ebp JMP_NOSPEC ecx #endif diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index fb4f1e01b64a..ef78c0bbae62 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -344,12 +344,13 @@ STACK_FRAME_NON_STANDARD_FP(__fentry__) SYM_CODE_START(return_to_handler) UNWIND_HINT_EMPTY ANNOTATE_NOENDBR - subq $16, %rsp + subq $24, %rsp /* Save the return values */ movq %rax, (%rsp) movq %rdx, 8(%rsp) - movq %rbp, %rdi + movq %rbp, 16(%rsp) + movq %rsp, %rdi call ftrace_return_to_handler @@ -357,7 +358,7 @@ SYM_CODE_START(return_to_handler) movq 8(%rsp), %rdx movq (%rsp), %rax - addq $16, %rsp + addq $24, %rsp /* * Jump back to the old return address. This cannot be JMP_NOSPEC rdi * since IBT would demand that contain ENDBR, which simply isn't so for -- 2.25.1