From patchwork Wed Jun 21 16:29:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 111182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4498302vqr; Wed, 21 Jun 2023 09:41:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tbHVjjwny7vWaZXNyuWaHyoylH6/FSq3D1fvOFGM3e2e+M3adOn7hkLZjFNqS8GN3JAIm X-Received: by 2002:a17:902:b491:b0:1b2:a63:95aa with SMTP id y17-20020a170902b49100b001b20a6395aamr14478051plr.54.1687365691467; Wed, 21 Jun 2023 09:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687365691; cv=none; d=google.com; s=arc-20160816; b=sYFHKNBcv+9qei9AYS4IkeL5+CvuABXy30cCt+1yFkNEbNYD39b6vTuLFycnwiJx/J y8i4YUwsca/ye4659qNfJlej/BCeNdKuJcixAe0jeCnG1N4Z/d1gJUAhgl/sYcALb0LE JscRv+mGXaeg4VjJ1T8z3DKSNqHhBeDVKWSzBEJhKSkue4IyvbOS5JmBsO+3GfMYKLVi YvqLSvU/xAtKX5s9fAXU0rcFhNrvSfEVTzPJZ9qwcGJD83TZLqLR64+W9L2qmFjVYXu/ MgC41IjDTn99OoKT94lPzoR72fiMEppQOvLvfBkQOsx3IKV1Z/+u0DCq4r8LoIFSdW/o qJEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=h11+n/FSThYtD1FyV7k6cpcNKQ325SDl3HVdqrsFDzo=; b=BUzSVg95Q5EOe8zR6/J9vKcckM9o361E12RDLHQb1TVglrFm6ON4YKfPvO+QBNcE8W 5JSi+77vSgH/7fm86bVWucEklaAXnI6OtYt7MwTjNG5mwH/GVRnN8qHcEtiZm7BICQCn c2Z/p/c6042QIDc4Bs+9zXKNtVYwy2iiKE6prfYIZ4SszHsH1AA6EVMRXCvuwlZDZh3N BwK5V2Nq1bpQKdWKK0JtLJKvRgn3q3ocA6OCIY7LJCZRIWGcBzaeYfErv/frZ3prOpWc 3m6uJYeIGjyI1lU+H+vC6YLPfmws5ghNYMpFBKuR5f+rT+MAoYihkbHAIP7Y1NcYrDhy cE/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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a170902e84100b001b382b2d311si1782246plg.471.2023.06.21.09.41.18; Wed, 21 Jun 2023 09:41:31 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbjFUQap (ORCPT + 99 others); Wed, 21 Jun 2023 12:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbjFUQ36 (ORCPT ); Wed, 21 Jun 2023 12:29:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83D6410C2 for ; Wed, 21 Jun 2023 09:29:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 968CA6162D for ; Wed, 21 Jun 2023 16:29:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B4FCC433CC; Wed, 21 Jun 2023 16:29:48 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qC0iJ-001ypa-0O; Wed, 21 Jun 2023 12:29:47 -0400 Message-ID: <20230621162946.937067675@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 21 Jun 2023 12:29:36 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Donglin Peng , Palmer Dabbelt Subject: [for-next][PATCH 13/13] riscv: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL References: <20230621162923.953123395@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769331167397358210?= X-GMAIL-MSGID: =?utf-8?q?1769331167397358210?= From: Donglin Peng 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. Link: https://lore.kernel.org/linux-trace-kernel/a8d71b12259f90e7e63d0ea654fcac95b0232bbc.1680954589.git.pengdonglin@sangfor.com.cn Signed-off-by: Donglin Peng Acked-by: Palmer Dabbelt Signed-off-by: Steven Rostedt (Google) --- 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 2bb0c38419ff..62c1e375183c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -146,6 +146,7 @@ config RISCV select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER + select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION config CLANG_SUPPORTS_DYNAMIC_FTRACE 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