Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1978327rwl; Sat, 8 Apr 2023 05:46:40 -0700 (PDT) X-Google-Smtp-Source: AKy350YR5osMv57IZRutGgjWKvRlX9Ux1MBsmJWc7nEbLYzzO9a2YqfWmLvDLS2OQFwTAIgf5VJn X-Received: by 2002:a17:906:1753:b0:92b:3c78:91fa with SMTP id d19-20020a170906175300b0092b3c7891famr2115535eje.28.1680958000671; Sat, 08 Apr 2023 05:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680958000; cv=none; d=google.com; s=arc-20160816; b=1FEKpmXt/BintCgsdkqRQ2+ydHnauqvdnd03lrecUMoVHScEa7WvqHdHDHXDU58QKw sGk7cTtc4X5LnDrB5Sv4Ltnh3QcB7F/UpxJJWUIQzP+eTHpvPI4hJXE+iSgpdBplkSvX g8DCtH3zkT863ZMYgPqTDpjMF7Sjn0p/gAdWBw1aVZYPcbqJFfsDUWN7WzjWND9zXnuI BB2rnRsv6PvyeHw3x7eDN5coht72aknDzSl0G5OrV78E04BMQ/lS3E9+xHCZsUvCleF0 Qdak/IVsyIBdDh7XS2AEw5IQ/rgUU80X29kQBycDJLtK4vMfFA2GS8gOXp6JHkniq+uq wTXA== 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=3wyEdbkDEhibJj7a6hWZZHqEsL1pJfCx66S+5waMces=; b=Pc9huTZAjwjPUfyDNxK1hcZYoR8Pp/HJVkTAQ2cVDUTI5vu3Vxh662O8bTdDHIGxjS xgcZOh9X+MUFrWHXqB1YqbM6NZVIsSrklP4bZx6kXhSBY6k+DmgIotGaMmKedGDhofvi kZemuGBZgyNgKKpwK4akCQfV11opBO7lsCcdXdpHLrwi1hqcMDU3xraNbAkvINeW1Aai LjIPFZJERkZ81yTbF+yeR3gXXaG0cfhrh3VM4NWbDflr5gpDDzipbzGXEAQ/o3kD3NSA 35DtNpC2gO1mPYQcK/oRYwDEtIkWxpYftPXdQctvBUsH3lM3ys3LYgKYpdcdSeEFuZyg NvSQ== 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 d2-20020a05640208c200b004fd23c0fceasi5017983edz.545.2023.04.08.05.46.16; Sat, 08 Apr 2023 05:46:40 -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 S230213AbjDHMnO (ORCPT + 99 others); Sat, 8 Apr 2023 08:43:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjDHMmx (ORCPT ); Sat, 8 Apr 2023 08:42:53 -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 809D6FF36; Sat, 8 Apr 2023 05:42:50 -0700 (PDT) Received: from ubuntu.localdomain (unknown [121.32.254.147]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id 289A85802E3; Sat, 8 Apr 2023 20:42:35 +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 5/8] riscv: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL Date: Sat, 8 Apr 2023 05:42:19 -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 tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaTx0aVk4fTBpIT0wdGhpIHVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJSlVISVVJTk9VSk9MWVdZFhoPEhUdFFlBWU9LSFVKSktPSEhVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Pjo6DCo6Hz0XMDc#ShxMVhY4 GT9PCh1VSlVKTUNLQk5MTE5NTE1IVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSklKVUhJVUlOT1VKT0xZV1kIAVlBTkhJSjcG X-HM-Tid: 0a8760e3d3422eb7kusn289a85802e3 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 RISC-V platform. We introduce a new structure called fgraph_ret_regs for the RISC-V 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/riscv/Kconfig | 1 + arch/riscv/include/asm/ftrace.h | 21 +++++++++++++++++++++ arch/riscv/kernel/mcount.S | 7 +------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index eb7f29a412f8..108538815309 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -139,6 +139,7 @@ config RISCV select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8) select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL + select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index d47d87c2d7e3..740a979171e5 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -111,4 +111,25 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #endif /* CONFIG_DYNAMIC_FTRACE */ +#ifndef __ASSEMBLY__ +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +struct fgraph_ret_regs { + unsigned long a1; + unsigned long a0; + unsigned long s0; + unsigned long ra; +}; + +static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs) +{ + return ret_regs->a0; +} + +static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs) +{ + return ret_regs->s0; +} +#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ +#endif + #endif /* _ASM_RISCV_FTRACE_H */ diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S index 30102aadc4d7..8a6e5a9e842a 100644 --- a/arch/riscv/kernel/mcount.S +++ b/arch/riscv/kernel/mcount.S @@ -65,13 +65,8 @@ ENTRY(return_to_handler) * So alternatively we check the *old* frame pointer position, that is, the * value stored in -16(s0) on entry, and the s0 on return. */ -#ifdef HAVE_FUNCTION_GRAPH_FP_TEST - mv t6, s0 -#endif SAVE_RET_ABI_STATE -#ifdef HAVE_FUNCTION_GRAPH_FP_TEST - mv a0, t6 -#endif + mv a0, sp call ftrace_return_to_handler mv a2, a0 RESTORE_RET_ABI_STATE -- 2.25.1