Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14880819rwb; Mon, 28 Nov 2022 06:00:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ThTJ30l8RfJZHVZ2LcIpQPq12vW/u7l+FXIJHph5tBImXMBh9yJ2wKcpZn1c0MjtQEJ6s X-Received: by 2002:a05:6402:31ee:b0:46a:8bbb:8b0c with SMTP id dy14-20020a05640231ee00b0046a8bbb8b0cmr19182884edb.43.1669644046874; Mon, 28 Nov 2022 06:00:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669644046; cv=none; d=google.com; s=arc-20160816; b=GlO2MY/LVSTyavP4JEqaih7ED9TkXPojLQKmlZCDx/KMNpxarhBkPXESuzfHdVe9I+ IyHUCROHKYXEWrOmGI0yA/zASY5xJnIPYsLNzbNaMOyMPK1vPxopabozgFIA2x8929Lr Kf3eVDkmH1Yzs0TDxk0kz+/gN0cbmmyFM0XPnaV10hk6qFibXZPZ6YzxVScSLpEJNihf kJTjAKs4k5rxh+CuCnQqd31q60nF/WS0coCxc1V1U46SEQeUfSejtDzogA8amtvsbTcm v93Gw8tGEkT+KDeynKkDlOq2BMt64zP8qlYkQDbr/HtQXzmqeV2XhHOeKrGTBBDbLYUJ Dx5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=u5nzbLceYuOqNIYxN1FfveJjuJOTSdKz2ysnqReLko8=; b=pUPFe2NXAOnHnv3z1xhep5HMyVA9rMJqqvpFw3V6ej6hm3V0aAfBEwvk7hVW8bmZgc 9f7tPpG3RwraD67NRIvmouYtUUrRVdS/o5Ex/P3QFVm+vsMynROkaPrUYSBeX545IB0l klT2/Y5aXz1Ql+54Ao34mT9CE3suvTOwZttY6TU1Km9QnOSove1ty9cK0KjnQWzYxd/M 5V5/pvQqhlU6wNTdDUJnZrijMjwMymvKsXsmoixWAhW+UE/Q0QBbnyjf2RF/pj0J7deK yayMXcpFO6q80BaSWM8PxvggitI7Z+G6zbOds6LY32Gzhy9e8Nifz/0eO1j0yFkMompm y5FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="t2/QaDHY"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa6-20020a1709076d0600b0078d93245e34si10093108ejc.793.2022.11.28.06.00.24; Mon, 28 Nov 2022 06:00:46 -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="t2/QaDHY"; 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 S231889AbiK1NTx (ORCPT + 85 others); Mon, 28 Nov 2022 08:19:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbiK1NTf (ORCPT ); Mon, 28 Nov 2022 08:19:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B72C1F2C9 for ; Mon, 28 Nov 2022 05:17:13 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5AB3CB80DB3 for ; Mon, 28 Nov 2022 13:17:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11380C4314C for ; Mon, 28 Nov 2022 13:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669641431; bh=pdjKPY5Vwqu/CAsrLfzJyZMpBhMzVI/GQU7fhz39+/I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=t2/QaDHYL5muLSCpLyHRTB56h9iwXWozFrL26rcmfiGijhezfiMnzvm/YQ56gQQSb jBUIrmzjOvIV4QrKTxj/PGKHP9eVobTSyE9Ut1HKWDzkZDBJC0yqCTjcqzUG8yGCkj 1ESoYxcj6R8j6GP0kg/UVgLWcdYodcC1edpaThcetI8zAA3XVeyZaw1htLBWP+ygXU G74wqLXwwAYqZQGpdvgxIbBiG0p7yEoTiDxYDgwd2NFooY2BFaGDFZRsB2seb1NJK0 Du5Tcmj+siY9oGw5+Bc6Q6tu3jJ+B+Ym582GxVz6+2csZSQRocjacZB4nHeH58owPV aiFPs9FUVfiSg== Received: by mail-ed1-f43.google.com with SMTP id z20so15341678edc.13 for ; Mon, 28 Nov 2022 05:17:10 -0800 (PST) X-Gm-Message-State: ANoB5pm720M2Hji43MN7ZV53Gwnamz0po3lzsRW3SK/iqdk1xWerG6YS jkT7j9ZEAKB1zmx1C9cPiffE+C3uQ5eBC/9onAA= X-Received: by 2002:aa7:c511:0:b0:469:7731:5b29 with SMTP id o17-20020aa7c511000000b0046977315b29mr37242376edq.419.1669641429146; Mon, 28 Nov 2022 05:17:09 -0800 (PST) MIME-Version: 1.0 References: <20221123142025.1504030-1-suagrfillet@gmail.com> <20221123142025.1504030-2-suagrfillet@gmail.com> In-Reply-To: <20221123142025.1504030-2-suagrfillet@gmail.com> From: Guo Ren Date: Mon, 28 Nov 2022 21:16:57 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] riscv/ftrace: add DYNAMIC_FTRACE_WITH_DIRECT_CALLS support To: Song Shuai Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, peterz@infradead.org, jolsa@redhat.com, bp@suse.de, jpoimboe@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 On Wed, Nov 23, 2022 at 10:20 PM Song Shuai wrote: > > This patch adds DYNAMIC_FTRACE_WITH_DIRECT_CALLS support for RISC-V. > > select the DYNAMIC_FTRACE_WITH_DIRECT_CALLS to provide the > register_ftrace_direct[_multi] interfaces allowing users to register > the customed trampoline (direct_caller) as the mcount for one or > more target functions. And modify_ftrace_direct[_multi] are also > provided for modifying direct_caller. > > To make the direct_caller and the other ftrace hooks (eg. function/fgraph > tracer, k[ret]probes) co-exist, a temporary register is nominated to > store the address of direct_caller in ftrace_regs_caller. After the > setting of the address direct_caller by direct_ops->func and the > RESTORE_REGS in ftrace_regs_caller, direct_caller will be jumped to > by the `jr` inst. > > Signed-off-by: Song Shuai > --- > arch/riscv/Kconfig | 1 + > arch/riscv/include/asm/ftrace.h | 6 ++++++ > arch/riscv/kernel/mcount-dyn.S | 4 ++++ > 3 files changed, 11 insertions(+) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 39ec8d628cf6..d083ec08d0b6 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -278,6 +278,7 @@ config ARCH_RV64I > select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 > 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_DYNAMIC_FTRACE_WITH_DIRECT_CALLS > select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL > 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 01bebb28eabe..be4d57566139 100644 > --- a/arch/riscv/include/asm/ftrace.h > +++ b/arch/riscv/include/asm/ftrace.h > @@ -114,6 +114,12 @@ 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 > + > +static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr) > +{ > + regs->t1 = addr; > +} > + > #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ > > #endif /* __ASSEMBLY__ */ > diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S > index 466c6ef217b1..b89c85a58569 100644 > --- a/arch/riscv/kernel/mcount-dyn.S > +++ b/arch/riscv/kernel/mcount-dyn.S > @@ -233,6 +233,7 @@ ENDPROC(ftrace_caller) > #else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ > ENTRY(ftrace_regs_caller) > SAVE_ABI_REGS 1 > + REG_S x0, PT_T1(sp) ENTRY(ftrace_regs_caller) + move t1, zero SAVE_ABI_REGS 1 PREPARE_ARGS Shall we use a move here, instead? > PREPARE_ARGS > > ftrace_regs_call: > @@ -241,7 +242,10 @@ ftrace_regs_call: > > > RESTORE_ABI_REGS 1 > + bnez t1,.Ldirect > jr t0 > +.Ldirect: > + jr t1 > ENDPROC(ftrace_regs_caller) > > ENTRY(ftrace_caller) > -- > 2.20.1 > -- Best Regards Guo Ren