From patchwork Thu Dec 8 09:12:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 13068160 X-Patchwork-Delegate: palmer@dabbelt.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BFA48C4332F for ; Thu, 8 Dec 2022 09:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9xAJtqIDmTVA/ceKvNt4WP+wM9uFp7+iZvE2Ing3yW8=; b=JRpsB4tOfW54TU i//upH431l8owaTf4OurY04oeZVfwaFI6iLXV2aYwotgGo7eD4xDNesFpH3hRHR8Yf4ktVhEHUVWP vw1mr+gLaF2m+ggEp82MQSyphDQIZx+rnNKFr5gKvvYKUu6LuY6BCpFisKbhAKtzV5fnPZvVL4gHW cXbZYyPjT4VETPhXhrcfbwAIrMJTqn5PrDjor53I5tH0uQJRsr2Tnhv+QAoeGpO0fWCAx8UlTZWdu /lHtuW1FM6J8fQ9lWXLEnYYRbC/C0C7nVY6N8b8NDyPVHazi7DgCi4rCr/SSvAXjB1qBnixgmDCA2 dzyhf63fg05aTvV1Umug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3DGB-00AvXn-Sf; Thu, 08 Dec 2022 09:32:07 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3Cxy-00AhOT-Jk for linux-riscv@lists.infradead.org; Thu, 08 Dec 2022 09:13:20 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2A05561DE4; Thu, 8 Dec 2022 09:13:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C31B4C433D6; Thu, 8 Dec 2022 09:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670490797; bh=Rx1oBfcnRsUOmU2Ykw57vJhrHUEAojxg5V7zc9OjoGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ik+1eVCJw1fqBH7gyupxEfuRB+mfrXQIlD823HF+CMg2WBFuZr/dMejGWi82ZTnDu INuwU3wvAVC83KfTTG65RpS8oe9pl9YYpNknuYqdhvVSzg1F3JuuWnLoyka7jQmPbq Kb23CqVuVSr9jGeLoeTiLOQCGTRNrz9oQbk/ipkfSXuQNDQxJtIt1CIsE+gFsupY2y l8md3pBPvE9PTQeOFRZAuqJwR7RHoOi/XPZ81+WZSmK+DgAVwMLvKTlh48q2L7HD3L 3tmuQsmGrqO68BlK4lhOcaQ+wW9M0/JIUzo/l+qrs2LWwy3Yd6ifU9k/ZhunOFH49b fPSB6wcwJelSw== From: guoren@kernel.org To: anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, conor.dooley@microchip.com, heiko@sntech.de, rostedt@goodmis.org, mhiramat@kernel.org, jolsa@redhat.com, bp@suse.de, jpoimboe@kernel.org, suagrfillet@gmail.com, andy.chiu@sifive.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Guo Ren Subject: [PATCH -next V5 4/7] riscv: ftrace: Add ftrace_graph_func Date: Thu, 8 Dec 2022 04:12:41 -0500 Message-Id: <20221208091244.203407-5-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221208091244.203407-1-guoren@kernel.org> References: <20221208091244.203407-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221208_011318_765267_F7C58DF9 X-CRM114-Status: GOOD ( 12.20 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Song Shuai Here implements ftrace_graph_func as the function graph tracing function with FTRACE_WITH_REGS defined. function_graph_func gets the point of the parent IP and the frame pointer from fregs and call prepare_ftrace_return for function graph tracing. If FTRACE_WITH_REGS isn't defined, the enable/disable helpers of ftrace_graph_[regs]_call are revised for serving only ftrace_graph_call in the !FTRACE_WITH_REGS version ftrace_caller. Signed-off-by: Song Shuai Tested-by: Guo Ren Signed-off-by: Guo Ren --- arch/riscv/include/asm/ftrace.h | 13 +++++++++++-- arch/riscv/kernel/ftrace.c | 30 +++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index 9e73922e1e2e..84f856a3286e 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -107,8 +107,17 @@ do { \ struct dyn_ftrace; int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #define ftrace_init_nop ftrace_init_nop -#endif -#endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +struct ftrace_ops; +struct ftrace_regs; +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs); +#define ftrace_graph_func ftrace_graph_func +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ + +#endif /* __ASSEMBLY__ */ + +#endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* _ASM_RISCV_FTRACE_H */ diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index 61b24d767e2e..20bf86557698 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -169,32 +169,28 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, } #ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs) +{ + struct pt_regs *regs = arch_ftrace_get_regs(fregs); + unsigned long *parent = (unsigned long *)®s->ra; + + prepare_ftrace_return(parent, ip, frame_pointer(regs)); +} +#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ extern void ftrace_graph_call(void); -extern void ftrace_graph_regs_call(void); int ftrace_enable_ftrace_graph_caller(void) { - int ret; - - ret = __ftrace_modify_call((unsigned long)&ftrace_graph_call, - (unsigned long)&prepare_ftrace_return, true, true); - if (ret) - return ret; - - return __ftrace_modify_call((unsigned long)&ftrace_graph_regs_call, + return __ftrace_modify_call((unsigned long)&ftrace_graph_call, (unsigned long)&prepare_ftrace_return, true, true); } int ftrace_disable_ftrace_graph_caller(void) { - int ret; - - ret = __ftrace_modify_call((unsigned long)&ftrace_graph_call, - (unsigned long)&prepare_ftrace_return, false, true); - if (ret) - return ret; - - return __ftrace_modify_call((unsigned long)&ftrace_graph_regs_call, + return __ftrace_modify_call((unsigned long)&ftrace_graph_call, (unsigned long)&prepare_ftrace_return, false, true); } +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */