From patchwork Wed Nov 23 15:39:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 25065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2865712wrr; Wed, 23 Nov 2022 07:45:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf7tdaCgiKYatBuYC3i/BCyrS42uAtrpgGqlcTx3bkZ0XkzXW+PkAhWhTvHWHhVTfNtjwkDi X-Received: by 2002:a17:902:e04b:b0:186:605b:f99b with SMTP id x11-20020a170902e04b00b00186605bf99bmr20852863plx.49.1669218308888; Wed, 23 Nov 2022 07:45:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669218308; cv=none; d=google.com; s=arc-20160816; b=OdF++cyWYSC+Ub4Uj7Oh9zeU0JNpbdF1PTl7RJoNXxo+W0b/etTnYZ8QtBYyfC1t6R HHx+wRE4FBOWnkKmzgpZswc2qmh/8jspz9bKZ/bRjMeYqJyaDBA4ZRpUvOpVFaRm4Wug vNUDZ6V5Ia0qvEY+5tb8BGxENCahuDBMC3R084lacJSJXsKWb4funKlTvvo+mUL4T8Y3 hKZTg7+bqUmon4DXqMhpSXIxYohHxbk4KJft/fTGBLjccGfq8ZH1TLrD/BsBbByjUaAm 5+jgdd44e2vU2jHXLmuWAOi5uX7Z67tR2n5etddLth6fzK0KgeuedDoaSLtjnN1nJoBP INOA== 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 :dkim-signature; bh=JMVqFYFurxz3qdAlvdMelL+qMGxk73h1YfP1hv6Se6E=; b=qhCafHEmJW4vo7iWUuneZuefjSsT0PyP/58DTU6rbaTmF/vjtaEsqjhTe9DySiJ3ym KdvRXeVrVBfCB9PXobwehdgAQ5QOVu8Vc29oquxpzImmLYkdEgvHqgkmgnqHhYD9UqSo 44nvrn+RCs2tOc2ts4KFudMLz+kBA2VxdxEy326CeNXSek8i8S6Cv8yfQoJ1eO58OG44 feoMiqT6p9qkV5xKElejfJWPebQvDmuPVQTqiqn/xDVppc/dwUfIWCoZQuKkl2yHE2TK XQk43YDiGRGtZKzCHSdLqk5PCK2zZY98zwGuGloLV7kByIRhYiEiUacIslsHAgUD9eh0 IYlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fywb5kix; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a170902d2c400b00186b287bd57si18140865plc.190.2022.11.23.07.44.54; Wed, 23 Nov 2022 07:45:08 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fywb5kix; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238781AbiKWPlB (ORCPT + 99 others); Wed, 23 Nov 2022 10:41:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237741AbiKWPk1 (ORCPT ); Wed, 23 Nov 2022 10:40:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 360EA94A6F for ; Wed, 23 Nov 2022 07:40:27 -0800 (PST) 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 C18B061DC0 for ; Wed, 23 Nov 2022 15:40:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F4CC433C1; Wed, 23 Nov 2022 15:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669218026; bh=Rx1oBfcnRsUOmU2Ykw57vJhrHUEAojxg5V7zc9OjoGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fywb5kixMdVHhwwuNTemShcLAq5nMIR9QCcIGsYh8rD8A0ZkkiuJ0rJgW7r9Ji/7j 7MDukIlIlZCRkjgf7YQ6rCSidVq28l1Y3bHAsO213jIey6DbqueiRZkgIp+AjirJCB 3mUDUxBCad+IZ2CbR7Hc4SBq799J+cy27Iwd0MNd8Vrema0txLcfXf062RlDauTS7f fopu69OrpECtv31MvA5Q+QS8gedImdoZb+39GOw0RmNFHfbS+RkrHI/mEkvQ/rJ2Ls gR66Zzx+CywByWqr7vvSfGAR0r+RLoB07DpjO3xqtiq1GPTNCDqqJB1fRr89cXsZOC qqTG66wcrdmCQ== 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 V3 4/5] riscv: ftrace: Add ftrace_graph_func Date: Wed, 23 Nov 2022 10:39:49 -0500 Message-Id: <20221123153950.2911981-5-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221123153950.2911981-1-guoren@kernel.org> References: <20221123153950.2911981-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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?1750302257627273817?= X-GMAIL-MSGID: =?utf-8?q?1750302257627273817?= 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 */