Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14844033rwb; Mon, 28 Nov 2022 05:37:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf5NhYJCaF1S7BAMKWA1SX9WFb3O5MeBO/ReyZOG22GpTc+1DqxqAV1gUb/Kiu7smNKKVOyj X-Received: by 2002:a17:90a:307:b0:213:dce7:e1fe with SMTP id 7-20020a17090a030700b00213dce7e1femr61286318pje.110.1669642636335; Mon, 28 Nov 2022 05:37:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669642636; cv=none; d=google.com; s=arc-20160816; b=fByYEx81g8cnmYM28+cnNQRL8EM/a1l1kTZDXp8UHHjiWRdYqxxwn421kogLmCWvZ6 PZsNBxzbPHlTa2A6VJ91Kuxsbp1yQV/Km4gKSpvcp2CyvYgibP/mzXyKCSzq+jkLIaCp wupEP5MnGy+C9qyfaXkBydTRUZtC+7IZn9MTYuz5c1eb53/m8v1Ff4nVaIGFPOreyysg RadvtBJ4lCuqTjx2gZ48Q5at0SScAxw6XW3t51llVPcUG27vxN7TiDj9nrOLZgMbvGmc 1lg2v8jqabqyCYwolCS0UgEXXmCGlweo/iLiqEMDYUelf9K9x0Q5MmNel6jCl3hMVhth lDLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=uBdU9MBKjL0Xadg7p+abX3ZuC4Gb0AyqB1eHg7GazfE=; b=jApVEIpiOvgapoIfw5p94jXognRC2rqIuDCSIfGmciQHUIt6tNovhqAIc8RdpA97s4 nl5hN3+3rdgmc74lPvWQ9ZgLoKGiiLeA4lt9iWgu8w4xc4SMWg7BEePG6Tq8QjqiT6Qo inkR3Oly9eW7WhvMrKi1KhOMGeQlaZIM39YbH9e8aXpGCT0sYGJJDzryVIoURBPRkPbC vQg78vYdcQUz/KUz5Ai+O6VeMCB6pO+wr08032yzYeKbYxkY/MmCzUmMnKrzW6P7b2qC zmG9q/fSN8B2hf1UM5DDX3fIxBmUBSRhSvhGqjVKWMSVJOFt2YCbwPU7KwzgErU4b0Bi TDIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VCINWH96; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a056a001acf00b0056cf72b41cdsi12447673pfv.1.2022.11.28.05.37.05; Mon, 28 Nov 2022 05:37:16 -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=@gmail.com header.s=20210112 header.b=VCINWH96; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231853AbiK1N3X (ORCPT + 85 others); Mon, 28 Nov 2022 08:29:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231855AbiK1N3U (ORCPT ); Mon, 28 Nov 2022 08:29:20 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 215301D678 for ; Mon, 28 Nov 2022 05:29:18 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id t17so9459463pjo.3 for ; Mon, 28 Nov 2022 05:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uBdU9MBKjL0Xadg7p+abX3ZuC4Gb0AyqB1eHg7GazfE=; b=VCINWH96hYF2LyLNKubViZIaiQbd8s8WBUNpDH0jKjBHGQ2ryA3XM+U+YvaM960KNY 1XjgWvAPbtsLVmAOO9/8cZF3vLbu5Yx6pOElAAhbAa2UCE8eI/tiZGyJ0BjKi+GUAiLj XhgdlNXLrMk1rCnDa/Ppo/1slTy9fm8Ja3oSjkljS6tWDdmNrrp6kb4kxuorPxHUl5ui YLOe4hfK45AeBcIiY99PhpcxAuDQTgD+f/oCOphxl+BNeyKBNha//e4Pnxoshhm1aLAy DayLfXLnDwEgUErBD7Ve2vjk922foGo4dDjr9Xm5h8WKNJ5KtCzRAMbX2AicnZZ7chDg kdHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uBdU9MBKjL0Xadg7p+abX3ZuC4Gb0AyqB1eHg7GazfE=; b=pIkkrElE+2Q4KsQVIbL34H2fSnfrJln7mA+avmmbXVhWrhIJ+nvP0JSgfDFg0c2QKd r2Ppcdue676CbGkZpuXuMMs6aqeaKiGV3QDd6XxR709sVPXdfhEpW1XmI2NXlC6FF9uF WI8B/6IMkdV061G6SIdifS/45adsX7fwXB4vaJ5admTUuFhWxGS3boAt+4a+QOram8B/ YZFJyWo7Ds/4sU51+lLi3ViDWMUXqmEk9mQS0vQIgN0+CtCkinSrTFe1NJ0jZLF7sO7z xT2yh4VCNj0qjW1spWcno4swNG4lEFOxLH08HLL/1AsdNs/rFd5eSbxSBWgOxKJK9gse 7KhA== X-Gm-Message-State: ANoB5pmGTeOI1zefV6+mi+drAWZv7bRItIWxR9zHDfvTuic7IN4kqOlp UkQGcSBvjXd0rkn38sJXchUYzozLLKoZCovX1xI= X-Received: by 2002:a17:903:2351:b0:189:6574:a4b7 with SMTP id c17-20020a170903235100b001896574a4b7mr17567737plh.107.1669642157574; Mon, 28 Nov 2022 05:29:17 -0800 (PST) MIME-Version: 1.0 References: <20221123142025.1504030-1-suagrfillet@gmail.com> <20221123142025.1504030-2-suagrfillet@gmail.com> In-Reply-To: From: Song Shuai Date: Mon, 28 Nov 2022 13:29:05 +0000 Message-ID: Subject: Re: [PATCH 1/2] riscv/ftrace: add DYNAMIC_FTRACE_WITH_DIRECT_CALLS support To: Guo Ren 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Guo Ren =E4=BA=8E2022=E5=B9=B411=E6=9C=8828=E6=97=A5=E5= =91=A8=E4=B8=80 13:17=E5=86=99=E9=81=93=EF=BC=9A > > 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/fgra= ph > > 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=3D8) > > 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/f= trace.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 =3D 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? That seems ok to me. Just move it. > > > 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 --=20 Thanks, Song