Message ID | 20221115025527.13382-6-zhangqing@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2485175wru; Mon, 14 Nov 2022 18:59:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf5VEOtFC2Sk54l0lUsAgzwBgi98iQaQ9RFrTQbDvMuCVE/p6g1B7zdIIiLLQKEqoVX3S8Wi X-Received: by 2002:a17:906:b142:b0:7ae:2964:72dc with SMTP id bt2-20020a170906b14200b007ae296472dcmr12687017ejb.111.1668481160243; Mon, 14 Nov 2022 18:59:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668481160; cv=none; d=google.com; s=arc-20160816; b=Ao9IHISr6gCGxhz3ST4zjZ+XoKD1c/P/JBjsqLdZSvblKkwaiR+i11Mt5BqD28Qsau iYIKNhTcKMQLEzg4tq9SSewEm+pJtKwEe2V4G1sLNF/qBHuhGTxAI5Z614+vvoihd7bO A9BobIat4RIXBovwETRe+OsbCfiUBwIp8Lv5JGo3NKh/AfxdWtMjJU5ARAX+GVmUQS7Z NpzupYmt8Lr4MrrmskSFO2v0HlKn0Nj4soocCE/CISyWUfe4q0Pjdy/6Mg+9lAX7/Zjf 7lTSSIrXfEUEK2vtvzN60ujVq73PC1oRIVKZyuAd2ORNqKv7p0RTH6h/UaLeyYM9kwv9 quVw== 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; bh=+rfa01mtB8Lhq+iHxYEFjeYRH95+SxYnuY38Y5PV35I=; b=s4IQBuI/25cAb8RlCtuM4u59rlCgkJzLp7ZzLfK8fpZbUt9+KIraN95/oGdgdYmwqN oPMY/ENo6C/0zgmFYF63QSHmcNuSieMbMZ67kTMZx31kTYkrKZY8PL3pVePiMl3QY8L4 hRY85VyTtx+IbmqAvh4UXE7Wc/CuCmYE6omzka/9noO6iTXr0V3I6QVtty1xUr3FuSjh U8XZlrq7AYFVf+uTBNUhPUJT12PGxga4XfxhUApBbCnMrMEPzoiYIOiLRMYKYAkCWLlE /nDCUmhaa+GgxdspqKd6crGIpRQSUAyomb/d1QVHbPedL3AORkLp7Glrz+V/oLW8NmlE uh6Q== 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 x7-20020a05640226c700b004520e27e5b9si12358188edd.626.2022.11.14.18.58.56; Mon, 14 Nov 2022 18:59:20 -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; 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 S237789AbiKOC5c (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Mon, 14 Nov 2022 21:57:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232592AbiKOC45 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 14 Nov 2022 21:56:57 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B151E1EC56 for <linux-kernel@vger.kernel.org>; Mon, 14 Nov 2022 18:55:35 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Axz7ek_3Jjex8HAA--.16482S3; Tue, 15 Nov 2022 10:55:32 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxLuKf_3JjmywTAA--.51398S7; Tue, 15 Nov 2022 10:55:31 +0800 (CST) From: Qing Zhang <zhangqing@loongson.cn> To: Huacai Chen <chenhuacai@kernel.org>, Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@redhat.com> Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Jinyang He <hejinyang@loongson.cn> Subject: [PATCH v6 5/9] LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Date: Tue, 15 Nov 2022 10:55:23 +0800 Message-Id: <20221115025527.13382-6-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221115025527.13382-1-zhangqing@loongson.cn> References: <20221115025527.13382-1-zhangqing@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxLuKf_3JjmywTAA--.51398S7 X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCF43Gry5Zr1ktr17XFWUJwb_yoWrWw1Dpr 97Arn5GFWj9FsagrWfK3s5Wrs8JrWvg34ava9rAFyrGr4qqF15Z3y8Cr1DZFyIq3yxG3yx XF1fCr4Yya17XwUanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b3AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E 87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2Iq xVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r 126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY 6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67 AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuY vjxU4AhLUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749529301095993686?= X-GMAIL-MSGID: =?utf-8?q?1749529301095993686?= |
Series |
LoongArch: Add ftrace support
|
|
Commit Message
Qing Zhang
Nov. 15, 2022, 2:55 a.m. UTC
This patch implements DYNAMIC_FTRACE_WITH_REGS on LoongArch, which allows a traced function's arguments (and some other registers) to be captured into a struct pt_regs, allowing these to be inspected and modified. Co-developed-by: Jinyang He <hejinyang@loongson.cn> Signed-off-by: Jinyang He <hejinyang@loongson.cn> Signed-off-by: Qing Zhang <zhangqing@loongson.cn> --- arch/loongarch/Kconfig | 1 + arch/loongarch/include/asm/ftrace.h | 3 +++ arch/loongarch/kernel/ftrace_dyn.c | 17 ++++++++++++++ arch/loongarch/kernel/mcount-dyn.S | 36 +++++++++++++++++++++++++++-- 4 files changed, 55 insertions(+), 2 deletions(-)
Comments
Hi, Qing, Patch5 and Patch6 are small and related, maybe they can be combined with a name "LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_{ARGS,REGS} support" Huacai On Tue, Nov 15, 2022 at 10:55 AM Qing Zhang <zhangqing@loongson.cn> wrote: > > This patch implements DYNAMIC_FTRACE_WITH_REGS on LoongArch, which allows > a traced function's arguments (and some other registers) to be captured > into a struct pt_regs, allowing these to be inspected and modified. > > Co-developed-by: Jinyang He <hejinyang@loongson.cn> > Signed-off-by: Jinyang He <hejinyang@loongson.cn> > Signed-off-by: Qing Zhang <zhangqing@loongson.cn> > --- > arch/loongarch/Kconfig | 1 + > arch/loongarch/include/asm/ftrace.h | 3 +++ > arch/loongarch/kernel/ftrace_dyn.c | 17 ++++++++++++++ > arch/loongarch/kernel/mcount-dyn.S | 36 +++++++++++++++++++++++++++-- > 4 files changed, 55 insertions(+), 2 deletions(-) > > diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig > index 615ce62422b8..12e3e91a68ae 100644 > --- a/arch/loongarch/Kconfig > +++ b/arch/loongarch/Kconfig > @@ -90,6 +90,7 @@ config LOONGARCH > select HAVE_DEBUG_STACKOVERFLOW > select HAVE_DMA_CONTIGUOUS > select HAVE_DYNAMIC_FTRACE > + select HAVE_DYNAMIC_FTRACE_WITH_REGS > select HAVE_EBPF_JIT > select HAVE_EXIT_THREAD > select HAVE_FAST_GUP > diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h > index 76ca58767f4d..a3f974a7a5ce 100644 > --- a/arch/loongarch/include/asm/ftrace.h > +++ b/arch/loongarch/include/asm/ftrace.h > @@ -28,6 +28,9 @@ struct dyn_ftrace; > int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); > #define ftrace_init_nop ftrace_init_nop > > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > +#define ARCH_SUPPORTS_FTRACE_OPS 1 > +#endif > #endif /* CONFIG_DYNAMIC_FTRACE */ > #endif /* __ASSEMBLY__ */ > #endif /* CONFIG_FUNCTION_TRACER */ > diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c > index 3fe791b6783e..ec3d951be50c 100644 > --- a/arch/loongarch/kernel/ftrace_dyn.c > +++ b/arch/loongarch/kernel/ftrace_dyn.c > @@ -99,6 +99,23 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, > return ftrace_modify_code(pc, old, new, true); > } > > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, > + unsigned long addr) > +{ > + unsigned long pc; > + long offset; > + u32 old, new; > + > + pc = rec->ip + LOONGARCH_INSN_SIZE; > + > + old = larch_insn_gen_bl(pc, old_addr); > + new = larch_insn_gen_bl(pc, addr); > + > + return ftrace_modify_code(pc, old, new, true); > +} > +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ > + > void arch_ftrace_update_code(int command) > { > command |= FTRACE_MAY_SLEEP; > diff --git a/arch/loongarch/kernel/mcount-dyn.S b/arch/loongarch/kernel/mcount-dyn.S > index 0c12cc108e6f..02835186b463 100644 > --- a/arch/loongarch/kernel/mcount-dyn.S > +++ b/arch/loongarch/kernel/mcount-dyn.S > @@ -27,7 +27,7 @@ > * follows the LoongArch psABI well. > */ > > - .macro ftrace_regs_entry > + .macro ftrace_regs_entry allregs=0 > PTR_ADDI sp, sp, -PT_SIZE > /* Save trace function ra at PT_ERA */ > PTR_S ra, sp, PT_ERA > @@ -43,16 +43,48 @@ > PTR_S a7, sp, PT_R11 > PTR_S fp, sp, PT_R22 > > + .if \allregs > + PTR_S t0, sp, PT_R12 > + PTR_S t1, sp, PT_R13 > + PTR_S t2, sp, PT_R14 > + PTR_S t3, sp, PT_R15 > + PTR_S t4, sp, PT_R16 > + PTR_S t5, sp, PT_R17 > + PTR_S t6, sp, PT_R18 > + PTR_S t7, sp, PT_R19 > + PTR_S t8, sp, PT_R20 > + PTR_S s0, sp, PT_R23 > + PTR_S s1, sp, PT_R24 > + PTR_S s2, sp, PT_R25 > + PTR_S s3, sp, PT_R26 > + PTR_S s4, sp, PT_R27 > + PTR_S s5, sp, PT_R28 > + PTR_S s6, sp, PT_R29 > + PTR_S s7, sp, PT_R30 > + PTR_S s8, sp, PT_R31 > + PTR_S tp, sp, PT_R2 > + /* Clear it for later use as a flag sometimes. */ > + PTR_S zero, sp, PT_R0 > + PTR_S $r21, sp, PT_R21 > + .endif > + > PTR_ADDI t8, sp, PT_SIZE > PTR_S t8, sp, PT_R3 > > .endm > > SYM_CODE_START(ftrace_caller) > - ftrace_regs_entry > + ftrace_regs_entry allregs=0 > b ftrace_common > SYM_CODE_END(ftrace_caller) > > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > +SYM_CODE_START(ftrace_regs_caller) > + ftrace_regs_entry allregs=1 > + b ftrace_common > +SYM_CODE_END(ftrace_regs_caller) > +#endif > + > SYM_CODE_START(ftrace_common) > PTR_ADDI a0, ra, -8 /* arg0: ip */ > move a1, t0 /* arg1: parent_ip */ > -- > 2.36.0 > >
Hi, Huacai On 2022/11/15 下午4:41, Huacai Chen wrote: > Hi, Qing, > > Patch5 and Patch6 are small and related, maybe they can be combined > with a name "LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_{ARGS,REGS} > support" I think they should be independent due to different use scenarios. Thanks, -Qing > > Huacai > > On Tue, Nov 15, 2022 at 10:55 AM Qing Zhang <zhangqing@loongson.cn> wrote: >> >> This patch implements DYNAMIC_FTRACE_WITH_REGS on LoongArch, which allows >> a traced function's arguments (and some other registers) to be captured >> into a struct pt_regs, allowing these to be inspected and modified. >> >> Co-developed-by: Jinyang He <hejinyang@loongson.cn> >> Signed-off-by: Jinyang He <hejinyang@loongson.cn> >> Signed-off-by: Qing Zhang <zhangqing@loongson.cn> >> --- >> arch/loongarch/Kconfig | 1 + >> arch/loongarch/include/asm/ftrace.h | 3 +++ >> arch/loongarch/kernel/ftrace_dyn.c | 17 ++++++++++++++ >> arch/loongarch/kernel/mcount-dyn.S | 36 +++++++++++++++++++++++++++-- >> 4 files changed, 55 insertions(+), 2 deletions(-) >> >> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig >> index 615ce62422b8..12e3e91a68ae 100644 >> --- a/arch/loongarch/Kconfig >> +++ b/arch/loongarch/Kconfig >> @@ -90,6 +90,7 @@ config LOONGARCH >> select HAVE_DEBUG_STACKOVERFLOW >> select HAVE_DMA_CONTIGUOUS >> select HAVE_DYNAMIC_FTRACE >> + select HAVE_DYNAMIC_FTRACE_WITH_REGS >> select HAVE_EBPF_JIT >> select HAVE_EXIT_THREAD >> select HAVE_FAST_GUP >> diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h >> index 76ca58767f4d..a3f974a7a5ce 100644 >> --- a/arch/loongarch/include/asm/ftrace.h >> +++ b/arch/loongarch/include/asm/ftrace.h >> @@ -28,6 +28,9 @@ struct dyn_ftrace; >> int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); >> #define ftrace_init_nop ftrace_init_nop >> >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS >> +#define ARCH_SUPPORTS_FTRACE_OPS 1 >> +#endif >> #endif /* CONFIG_DYNAMIC_FTRACE */ >> #endif /* __ASSEMBLY__ */ >> #endif /* CONFIG_FUNCTION_TRACER */ >> diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c >> index 3fe791b6783e..ec3d951be50c 100644 >> --- a/arch/loongarch/kernel/ftrace_dyn.c >> +++ b/arch/loongarch/kernel/ftrace_dyn.c >> @@ -99,6 +99,23 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, >> return ftrace_modify_code(pc, old, new, true); >> } >> >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS >> +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, >> + unsigned long addr) >> +{ >> + unsigned long pc; >> + long offset; >> + u32 old, new; >> + >> + pc = rec->ip + LOONGARCH_INSN_SIZE; >> + >> + old = larch_insn_gen_bl(pc, old_addr); >> + new = larch_insn_gen_bl(pc, addr); >> + >> + return ftrace_modify_code(pc, old, new, true); >> +} >> +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ >> + >> void arch_ftrace_update_code(int command) >> { >> command |= FTRACE_MAY_SLEEP; >> diff --git a/arch/loongarch/kernel/mcount-dyn.S b/arch/loongarch/kernel/mcount-dyn.S >> index 0c12cc108e6f..02835186b463 100644 >> --- a/arch/loongarch/kernel/mcount-dyn.S >> +++ b/arch/loongarch/kernel/mcount-dyn.S >> @@ -27,7 +27,7 @@ >> * follows the LoongArch psABI well. >> */ >> >> - .macro ftrace_regs_entry >> + .macro ftrace_regs_entry allregs=0 >> PTR_ADDI sp, sp, -PT_SIZE >> /* Save trace function ra at PT_ERA */ >> PTR_S ra, sp, PT_ERA >> @@ -43,16 +43,48 @@ >> PTR_S a7, sp, PT_R11 >> PTR_S fp, sp, PT_R22 >> >> + .if \allregs >> + PTR_S t0, sp, PT_R12 >> + PTR_S t1, sp, PT_R13 >> + PTR_S t2, sp, PT_R14 >> + PTR_S t3, sp, PT_R15 >> + PTR_S t4, sp, PT_R16 >> + PTR_S t5, sp, PT_R17 >> + PTR_S t6, sp, PT_R18 >> + PTR_S t7, sp, PT_R19 >> + PTR_S t8, sp, PT_R20 >> + PTR_S s0, sp, PT_R23 >> + PTR_S s1, sp, PT_R24 >> + PTR_S s2, sp, PT_R25 >> + PTR_S s3, sp, PT_R26 >> + PTR_S s4, sp, PT_R27 >> + PTR_S s5, sp, PT_R28 >> + PTR_S s6, sp, PT_R29 >> + PTR_S s7, sp, PT_R30 >> + PTR_S s8, sp, PT_R31 >> + PTR_S tp, sp, PT_R2 >> + /* Clear it for later use as a flag sometimes. */ >> + PTR_S zero, sp, PT_R0 >> + PTR_S $r21, sp, PT_R21 >> + .endif >> + >> PTR_ADDI t8, sp, PT_SIZE >> PTR_S t8, sp, PT_R3 >> >> .endm >> >> SYM_CODE_START(ftrace_caller) >> - ftrace_regs_entry >> + ftrace_regs_entry allregs=0 >> b ftrace_common >> SYM_CODE_END(ftrace_caller) >> >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS >> +SYM_CODE_START(ftrace_regs_caller) >> + ftrace_regs_entry allregs=1 >> + b ftrace_common >> +SYM_CODE_END(ftrace_regs_caller) >> +#endif >> + >> SYM_CODE_START(ftrace_common) >> PTR_ADDI a0, ra, -8 /* arg0: ip */ >> move a1, t0 /* arg1: parent_ip */ >> -- >> 2.36.0 >> >>
On Tue, Nov 15, 2022 at 5:22 PM Qing Zhang <zhangqing@loongson.cn> wrote: > > Hi, Huacai > > On 2022/11/15 下午4:41, Huacai Chen wrote: > > Hi, Qing, > > > > Patch5 and Patch6 are small and related, maybe they can be combined > > with a name "LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_{ARGS,REGS} > > support" > I think they should be independent due to different use scenarios. From the commit message it seems DYNAMIC_FTRACE_WITH_ARGS depend on DYNAMIC_FTRACE_WITH_REGS. Huacai > > Thanks, > -Qing > > > > Huacai > > > > On Tue, Nov 15, 2022 at 10:55 AM Qing Zhang <zhangqing@loongson.cn> wrote: > >> > >> This patch implements DYNAMIC_FTRACE_WITH_REGS on LoongArch, which allows > >> a traced function's arguments (and some other registers) to be captured > >> into a struct pt_regs, allowing these to be inspected and modified. > >> > >> Co-developed-by: Jinyang He <hejinyang@loongson.cn> > >> Signed-off-by: Jinyang He <hejinyang@loongson.cn> > >> Signed-off-by: Qing Zhang <zhangqing@loongson.cn> > >> --- > >> arch/loongarch/Kconfig | 1 + > >> arch/loongarch/include/asm/ftrace.h | 3 +++ > >> arch/loongarch/kernel/ftrace_dyn.c | 17 ++++++++++++++ > >> arch/loongarch/kernel/mcount-dyn.S | 36 +++++++++++++++++++++++++++-- > >> 4 files changed, 55 insertions(+), 2 deletions(-) > >> > >> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig > >> index 615ce62422b8..12e3e91a68ae 100644 > >> --- a/arch/loongarch/Kconfig > >> +++ b/arch/loongarch/Kconfig > >> @@ -90,6 +90,7 @@ config LOONGARCH > >> select HAVE_DEBUG_STACKOVERFLOW > >> select HAVE_DMA_CONTIGUOUS > >> select HAVE_DYNAMIC_FTRACE > >> + select HAVE_DYNAMIC_FTRACE_WITH_REGS > >> select HAVE_EBPF_JIT > >> select HAVE_EXIT_THREAD > >> select HAVE_FAST_GUP > >> diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h > >> index 76ca58767f4d..a3f974a7a5ce 100644 > >> --- a/arch/loongarch/include/asm/ftrace.h > >> +++ b/arch/loongarch/include/asm/ftrace.h > >> @@ -28,6 +28,9 @@ struct dyn_ftrace; > >> int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); > >> #define ftrace_init_nop ftrace_init_nop > >> > >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > >> +#define ARCH_SUPPORTS_FTRACE_OPS 1 > >> +#endif > >> #endif /* CONFIG_DYNAMIC_FTRACE */ > >> #endif /* __ASSEMBLY__ */ > >> #endif /* CONFIG_FUNCTION_TRACER */ > >> diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c > >> index 3fe791b6783e..ec3d951be50c 100644 > >> --- a/arch/loongarch/kernel/ftrace_dyn.c > >> +++ b/arch/loongarch/kernel/ftrace_dyn.c > >> @@ -99,6 +99,23 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, > >> return ftrace_modify_code(pc, old, new, true); > >> } > >> > >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > >> +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, > >> + unsigned long addr) > >> +{ > >> + unsigned long pc; > >> + long offset; > >> + u32 old, new; > >> + > >> + pc = rec->ip + LOONGARCH_INSN_SIZE; > >> + > >> + old = larch_insn_gen_bl(pc, old_addr); > >> + new = larch_insn_gen_bl(pc, addr); > >> + > >> + return ftrace_modify_code(pc, old, new, true); > >> +} > >> +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ > >> + > >> void arch_ftrace_update_code(int command) > >> { > >> command |= FTRACE_MAY_SLEEP; > >> diff --git a/arch/loongarch/kernel/mcount-dyn.S b/arch/loongarch/kernel/mcount-dyn.S > >> index 0c12cc108e6f..02835186b463 100644 > >> --- a/arch/loongarch/kernel/mcount-dyn.S > >> +++ b/arch/loongarch/kernel/mcount-dyn.S > >> @@ -27,7 +27,7 @@ > >> * follows the LoongArch psABI well. > >> */ > >> > >> - .macro ftrace_regs_entry > >> + .macro ftrace_regs_entry allregs=0 > >> PTR_ADDI sp, sp, -PT_SIZE > >> /* Save trace function ra at PT_ERA */ > >> PTR_S ra, sp, PT_ERA > >> @@ -43,16 +43,48 @@ > >> PTR_S a7, sp, PT_R11 > >> PTR_S fp, sp, PT_R22 > >> > >> + .if \allregs > >> + PTR_S t0, sp, PT_R12 > >> + PTR_S t1, sp, PT_R13 > >> + PTR_S t2, sp, PT_R14 > >> + PTR_S t3, sp, PT_R15 > >> + PTR_S t4, sp, PT_R16 > >> + PTR_S t5, sp, PT_R17 > >> + PTR_S t6, sp, PT_R18 > >> + PTR_S t7, sp, PT_R19 > >> + PTR_S t8, sp, PT_R20 > >> + PTR_S s0, sp, PT_R23 > >> + PTR_S s1, sp, PT_R24 > >> + PTR_S s2, sp, PT_R25 > >> + PTR_S s3, sp, PT_R26 > >> + PTR_S s4, sp, PT_R27 > >> + PTR_S s5, sp, PT_R28 > >> + PTR_S s6, sp, PT_R29 > >> + PTR_S s7, sp, PT_R30 > >> + PTR_S s8, sp, PT_R31 > >> + PTR_S tp, sp, PT_R2 > >> + /* Clear it for later use as a flag sometimes. */ > >> + PTR_S zero, sp, PT_R0 > >> + PTR_S $r21, sp, PT_R21 > >> + .endif > >> + > >> PTR_ADDI t8, sp, PT_SIZE > >> PTR_S t8, sp, PT_R3 > >> > >> .endm > >> > >> SYM_CODE_START(ftrace_caller) > >> - ftrace_regs_entry > >> + ftrace_regs_entry allregs=0 > >> b ftrace_common > >> SYM_CODE_END(ftrace_caller) > >> > >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > >> +SYM_CODE_START(ftrace_regs_caller) > >> + ftrace_regs_entry allregs=1 > >> + b ftrace_common > >> +SYM_CODE_END(ftrace_regs_caller) > >> +#endif > >> + > >> SYM_CODE_START(ftrace_common) > >> PTR_ADDI a0, ra, -8 /* arg0: ip */ > >> move a1, t0 /* arg1: parent_ip */ > >> -- > >> 2.36.0 > >> > >> > >
Hi, huacai On 2022/11/15 下午5:24, Huacai Chen wrote: > On Tue, Nov 15, 2022 at 5:22 PM Qing Zhang <zhangqing@loongson.cn> wrote: >> >> Hi, Huacai >> >> On 2022/11/15 下午4:41, Huacai Chen wrote: >>> Hi, Qing, >>> >>> Patch5 and Patch6 are small and related, maybe they can be combined >>> with a name "LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_{ARGS,REGS} >>> support" >> I think they should be independent due to different use scenarios. > From the commit message it seems DYNAMIC_FTRACE_WITH_ARGS depend on > DYNAMIC_FTRACE_WITH_REGS. DYNAMIC_FTRACE_WITH_REGS : which allows trace function saved registers, It means that these registers can be modified, eg: Kprobe、Livepatch. DYNAMIC_FTRACE_WITH_ARGS: uses pt_regs as a parameter for get sp, which means it can be used to access registers on the stack, and use graph_ops::func to install return_hooker to replace the special hook, eg: Livepatch. From the following Kconfig, they are reasonable as separate patches. config LIVEPATCH bool "Kernel Live Patching" depends on DYNAMIC_FTRACE_WITH_REGS || DYNAMIC_FTRACE_WITH_ARGS Thanks - Qing > > Huacai >> >> Thanks, >> -Qing >>> >>> Huacai >>> >>> On Tue, Nov 15, 2022 at 10:55 AM Qing Zhang <zhangqing@loongson.cn> wrote: >>>> >>>> This patch implements DYNAMIC_FTRACE_WITH_REGS on LoongArch, which allows >>>> a traced function's arguments (and some other registers) to be captured >>>> into a struct pt_regs, allowing these to be inspected and modified. >>>> >>>> Co-developed-by: Jinyang He <hejinyang@loongson.cn> >>>> Signed-off-by: Jinyang He <hejinyang@loongson.cn> >>>> Signed-off-by: Qing Zhang <zhangqing@loongson.cn> >>>> --- >>>> arch/loongarch/Kconfig | 1 + >>>> arch/loongarch/include/asm/ftrace.h | 3 +++ >>>> arch/loongarch/kernel/ftrace_dyn.c | 17 ++++++++++++++ >>>> arch/loongarch/kernel/mcount-dyn.S | 36 +++++++++++++++++++++++++++-- >>>> 4 files changed, 55 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig >>>> index 615ce62422b8..12e3e91a68ae 100644 >>>> --- a/arch/loongarch/Kconfig >>>> +++ b/arch/loongarch/Kconfig >>>> @@ -90,6 +90,7 @@ config LOONGARCH >>>> select HAVE_DEBUG_STACKOVERFLOW >>>> select HAVE_DMA_CONTIGUOUS >>>> select HAVE_DYNAMIC_FTRACE >>>> + select HAVE_DYNAMIC_FTRACE_WITH_REGS >>>> select HAVE_EBPF_JIT >>>> select HAVE_EXIT_THREAD >>>> select HAVE_FAST_GUP >>>> diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h >>>> index 76ca58767f4d..a3f974a7a5ce 100644 >>>> --- a/arch/loongarch/include/asm/ftrace.h >>>> +++ b/arch/loongarch/include/asm/ftrace.h >>>> @@ -28,6 +28,9 @@ struct dyn_ftrace; >>>> int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); >>>> #define ftrace_init_nop ftrace_init_nop >>>> >>>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS >>>> +#define ARCH_SUPPORTS_FTRACE_OPS 1 >>>> +#endif >>>> #endif /* CONFIG_DYNAMIC_FTRACE */ >>>> #endif /* __ASSEMBLY__ */ >>>> #endif /* CONFIG_FUNCTION_TRACER */ >>>> diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c >>>> index 3fe791b6783e..ec3d951be50c 100644 >>>> --- a/arch/loongarch/kernel/ftrace_dyn.c >>>> +++ b/arch/loongarch/kernel/ftrace_dyn.c >>>> @@ -99,6 +99,23 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, >>>> return ftrace_modify_code(pc, old, new, true); >>>> } >>>> >>>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS >>>> +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, >>>> + unsigned long addr) >>>> +{ >>>> + unsigned long pc; >>>> + long offset; >>>> + u32 old, new; >>>> + >>>> + pc = rec->ip + LOONGARCH_INSN_SIZE; >>>> + >>>> + old = larch_insn_gen_bl(pc, old_addr); >>>> + new = larch_insn_gen_bl(pc, addr); >>>> + >>>> + return ftrace_modify_code(pc, old, new, true); >>>> +} >>>> +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ >>>> + >>>> void arch_ftrace_update_code(int command) >>>> { >>>> command |= FTRACE_MAY_SLEEP; >>>> diff --git a/arch/loongarch/kernel/mcount-dyn.S b/arch/loongarch/kernel/mcount-dyn.S >>>> index 0c12cc108e6f..02835186b463 100644 >>>> --- a/arch/loongarch/kernel/mcount-dyn.S >>>> +++ b/arch/loongarch/kernel/mcount-dyn.S >>>> @@ -27,7 +27,7 @@ >>>> * follows the LoongArch psABI well. >>>> */ >>>> >>>> - .macro ftrace_regs_entry >>>> + .macro ftrace_regs_entry allregs=0 >>>> PTR_ADDI sp, sp, -PT_SIZE >>>> /* Save trace function ra at PT_ERA */ >>>> PTR_S ra, sp, PT_ERA >>>> @@ -43,16 +43,48 @@ >>>> PTR_S a7, sp, PT_R11 >>>> PTR_S fp, sp, PT_R22 >>>> >>>> + .if \allregs >>>> + PTR_S t0, sp, PT_R12 >>>> + PTR_S t1, sp, PT_R13 >>>> + PTR_S t2, sp, PT_R14 >>>> + PTR_S t3, sp, PT_R15 >>>> + PTR_S t4, sp, PT_R16 >>>> + PTR_S t5, sp, PT_R17 >>>> + PTR_S t6, sp, PT_R18 >>>> + PTR_S t7, sp, PT_R19 >>>> + PTR_S t8, sp, PT_R20 >>>> + PTR_S s0, sp, PT_R23 >>>> + PTR_S s1, sp, PT_R24 >>>> + PTR_S s2, sp, PT_R25 >>>> + PTR_S s3, sp, PT_R26 >>>> + PTR_S s4, sp, PT_R27 >>>> + PTR_S s5, sp, PT_R28 >>>> + PTR_S s6, sp, PT_R29 >>>> + PTR_S s7, sp, PT_R30 >>>> + PTR_S s8, sp, PT_R31 >>>> + PTR_S tp, sp, PT_R2 >>>> + /* Clear it for later use as a flag sometimes. */ >>>> + PTR_S zero, sp, PT_R0 >>>> + PTR_S $r21, sp, PT_R21 >>>> + .endif >>>> + >>>> PTR_ADDI t8, sp, PT_SIZE >>>> PTR_S t8, sp, PT_R3 >>>> >>>> .endm >>>> >>>> SYM_CODE_START(ftrace_caller) >>>> - ftrace_regs_entry >>>> + ftrace_regs_entry allregs=0 >>>> b ftrace_common >>>> SYM_CODE_END(ftrace_caller) >>>> >>>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS >>>> +SYM_CODE_START(ftrace_regs_caller) >>>> + ftrace_regs_entry allregs=1 >>>> + b ftrace_common >>>> +SYM_CODE_END(ftrace_regs_caller) >>>> +#endif >>>> + >>>> SYM_CODE_START(ftrace_common) >>>> PTR_ADDI a0, ra, -8 /* arg0: ip */ >>>> move a1, t0 /* arg1: parent_ip */ >>>> -- >>>> 2.36.0 >>>> >>>> >> >>
On Tue, Nov 15, 2022 at 6:44 PM Qing Zhang <zhangqing@loongson.cn> wrote: > > > Hi, huacai > On 2022/11/15 下午5:24, Huacai Chen wrote: > > On Tue, Nov 15, 2022 at 5:22 PM Qing Zhang <zhangqing@loongson.cn> wrote: > >> > >> Hi, Huacai > >> > >> On 2022/11/15 下午4:41, Huacai Chen wrote: > >>> Hi, Qing, > >>> > >>> Patch5 and Patch6 are small and related, maybe they can be combined > >>> with a name "LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_{ARGS,REGS} > >>> support" > >> I think they should be independent due to different use scenarios. > > From the commit message it seems DYNAMIC_FTRACE_WITH_ARGS depend on > > DYNAMIC_FTRACE_WITH_REGS. > > DYNAMIC_FTRACE_WITH_REGS : which allows trace function saved registers, > It means that these registers can be modified, eg: Kprobe、Livepatch. > > DYNAMIC_FTRACE_WITH_ARGS: uses pt_regs as a parameter for get sp, > which means it can be used to access registers on the stack, and > use graph_ops::func to install return_hooker to replace the special > hook, eg: Livepatch. > > From the following Kconfig, they are reasonable as separate patches. > config LIVEPATCH > bool "Kernel Live Patching" > depends on DYNAMIC_FTRACE_WITH_REGS || DYNAMIC_FTRACE_WITH_ARGS > OK, then keeping them separately is reasonable. Huacai > Thanks > - Qing > > > > Huacai > >> > >> Thanks, > >> -Qing > >>> > >>> Huacai > >>> > >>> On Tue, Nov 15, 2022 at 10:55 AM Qing Zhang <zhangqing@loongson.cn> wrote: > >>>> > >>>> This patch implements DYNAMIC_FTRACE_WITH_REGS on LoongArch, which allows > >>>> a traced function's arguments (and some other registers) to be captured > >>>> into a struct pt_regs, allowing these to be inspected and modified. > >>>> > >>>> Co-developed-by: Jinyang He <hejinyang@loongson.cn> > >>>> Signed-off-by: Jinyang He <hejinyang@loongson.cn> > >>>> Signed-off-by: Qing Zhang <zhangqing@loongson.cn> > >>>> --- > >>>> arch/loongarch/Kconfig | 1 + > >>>> arch/loongarch/include/asm/ftrace.h | 3 +++ > >>>> arch/loongarch/kernel/ftrace_dyn.c | 17 ++++++++++++++ > >>>> arch/loongarch/kernel/mcount-dyn.S | 36 +++++++++++++++++++++++++++-- > >>>> 4 files changed, 55 insertions(+), 2 deletions(-) > >>>> > >>>> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig > >>>> index 615ce62422b8..12e3e91a68ae 100644 > >>>> --- a/arch/loongarch/Kconfig > >>>> +++ b/arch/loongarch/Kconfig > >>>> @@ -90,6 +90,7 @@ config LOONGARCH > >>>> select HAVE_DEBUG_STACKOVERFLOW > >>>> select HAVE_DMA_CONTIGUOUS > >>>> select HAVE_DYNAMIC_FTRACE > >>>> + select HAVE_DYNAMIC_FTRACE_WITH_REGS > >>>> select HAVE_EBPF_JIT > >>>> select HAVE_EXIT_THREAD > >>>> select HAVE_FAST_GUP > >>>> diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h > >>>> index 76ca58767f4d..a3f974a7a5ce 100644 > >>>> --- a/arch/loongarch/include/asm/ftrace.h > >>>> +++ b/arch/loongarch/include/asm/ftrace.h > >>>> @@ -28,6 +28,9 @@ struct dyn_ftrace; > >>>> int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); > >>>> #define ftrace_init_nop ftrace_init_nop > >>>> > >>>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > >>>> +#define ARCH_SUPPORTS_FTRACE_OPS 1 > >>>> +#endif > >>>> #endif /* CONFIG_DYNAMIC_FTRACE */ > >>>> #endif /* __ASSEMBLY__ */ > >>>> #endif /* CONFIG_FUNCTION_TRACER */ > >>>> diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c > >>>> index 3fe791b6783e..ec3d951be50c 100644 > >>>> --- a/arch/loongarch/kernel/ftrace_dyn.c > >>>> +++ b/arch/loongarch/kernel/ftrace_dyn.c > >>>> @@ -99,6 +99,23 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, > >>>> return ftrace_modify_code(pc, old, new, true); > >>>> } > >>>> > >>>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > >>>> +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, > >>>> + unsigned long addr) > >>>> +{ > >>>> + unsigned long pc; > >>>> + long offset; > >>>> + u32 old, new; > >>>> + > >>>> + pc = rec->ip + LOONGARCH_INSN_SIZE; > >>>> + > >>>> + old = larch_insn_gen_bl(pc, old_addr); > >>>> + new = larch_insn_gen_bl(pc, addr); > >>>> + > >>>> + return ftrace_modify_code(pc, old, new, true); > >>>> +} > >>>> +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ > >>>> + > >>>> void arch_ftrace_update_code(int command) > >>>> { > >>>> command |= FTRACE_MAY_SLEEP; > >>>> diff --git a/arch/loongarch/kernel/mcount-dyn.S b/arch/loongarch/kernel/mcount-dyn.S > >>>> index 0c12cc108e6f..02835186b463 100644 > >>>> --- a/arch/loongarch/kernel/mcount-dyn.S > >>>> +++ b/arch/loongarch/kernel/mcount-dyn.S > >>>> @@ -27,7 +27,7 @@ > >>>> * follows the LoongArch psABI well. > >>>> */ > >>>> > >>>> - .macro ftrace_regs_entry > >>>> + .macro ftrace_regs_entry allregs=0 > >>>> PTR_ADDI sp, sp, -PT_SIZE > >>>> /* Save trace function ra at PT_ERA */ > >>>> PTR_S ra, sp, PT_ERA > >>>> @@ -43,16 +43,48 @@ > >>>> PTR_S a7, sp, PT_R11 > >>>> PTR_S fp, sp, PT_R22 > >>>> > >>>> + .if \allregs > >>>> + PTR_S t0, sp, PT_R12 > >>>> + PTR_S t1, sp, PT_R13 > >>>> + PTR_S t2, sp, PT_R14 > >>>> + PTR_S t3, sp, PT_R15 > >>>> + PTR_S t4, sp, PT_R16 > >>>> + PTR_S t5, sp, PT_R17 > >>>> + PTR_S t6, sp, PT_R18 > >>>> + PTR_S t7, sp, PT_R19 > >>>> + PTR_S t8, sp, PT_R20 > >>>> + PTR_S s0, sp, PT_R23 > >>>> + PTR_S s1, sp, PT_R24 > >>>> + PTR_S s2, sp, PT_R25 > >>>> + PTR_S s3, sp, PT_R26 > >>>> + PTR_S s4, sp, PT_R27 > >>>> + PTR_S s5, sp, PT_R28 > >>>> + PTR_S s6, sp, PT_R29 > >>>> + PTR_S s7, sp, PT_R30 > >>>> + PTR_S s8, sp, PT_R31 > >>>> + PTR_S tp, sp, PT_R2 > >>>> + /* Clear it for later use as a flag sometimes. */ > >>>> + PTR_S zero, sp, PT_R0 > >>>> + PTR_S $r21, sp, PT_R21 > >>>> + .endif > >>>> + > >>>> PTR_ADDI t8, sp, PT_SIZE > >>>> PTR_S t8, sp, PT_R3 > >>>> > >>>> .endm > >>>> > >>>> SYM_CODE_START(ftrace_caller) > >>>> - ftrace_regs_entry > >>>> + ftrace_regs_entry allregs=0 > >>>> b ftrace_common > >>>> SYM_CODE_END(ftrace_caller) > >>>> > >>>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > >>>> +SYM_CODE_START(ftrace_regs_caller) > >>>> + ftrace_regs_entry allregs=1 > >>>> + b ftrace_common > >>>> +SYM_CODE_END(ftrace_regs_caller) > >>>> +#endif > >>>> + > >>>> SYM_CODE_START(ftrace_common) > >>>> PTR_ADDI a0, ra, -8 /* arg0: ip */ > >>>> move a1, t0 /* arg1: parent_ip */ > >>>> -- > >>>> 2.36.0 > >>>> > >>>> > >> > >> > >
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 615ce62422b8..12e3e91a68ae 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -90,6 +90,7 @@ config LOONGARCH select HAVE_DEBUG_STACKOVERFLOW select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE + select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_EBPF_JIT select HAVE_EXIT_THREAD select HAVE_FAST_GUP diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h index 76ca58767f4d..a3f974a7a5ce 100644 --- a/arch/loongarch/include/asm/ftrace.h +++ b/arch/loongarch/include/asm/ftrace.h @@ -28,6 +28,9 @@ struct dyn_ftrace; int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #define ftrace_init_nop ftrace_init_nop +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +#define ARCH_SUPPORTS_FTRACE_OPS 1 +#endif #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* __ASSEMBLY__ */ #endif /* CONFIG_FUNCTION_TRACER */ diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c index 3fe791b6783e..ec3d951be50c 100644 --- a/arch/loongarch/kernel/ftrace_dyn.c +++ b/arch/loongarch/kernel/ftrace_dyn.c @@ -99,6 +99,23 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, return ftrace_modify_code(pc, old, new, true); } +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long pc; + long offset; + u32 old, new; + + pc = rec->ip + LOONGARCH_INSN_SIZE; + + old = larch_insn_gen_bl(pc, old_addr); + new = larch_insn_gen_bl(pc, addr); + + return ftrace_modify_code(pc, old, new, true); +} +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ + void arch_ftrace_update_code(int command) { command |= FTRACE_MAY_SLEEP; diff --git a/arch/loongarch/kernel/mcount-dyn.S b/arch/loongarch/kernel/mcount-dyn.S index 0c12cc108e6f..02835186b463 100644 --- a/arch/loongarch/kernel/mcount-dyn.S +++ b/arch/loongarch/kernel/mcount-dyn.S @@ -27,7 +27,7 @@ * follows the LoongArch psABI well. */ - .macro ftrace_regs_entry + .macro ftrace_regs_entry allregs=0 PTR_ADDI sp, sp, -PT_SIZE /* Save trace function ra at PT_ERA */ PTR_S ra, sp, PT_ERA @@ -43,16 +43,48 @@ PTR_S a7, sp, PT_R11 PTR_S fp, sp, PT_R22 + .if \allregs + PTR_S t0, sp, PT_R12 + PTR_S t1, sp, PT_R13 + PTR_S t2, sp, PT_R14 + PTR_S t3, sp, PT_R15 + PTR_S t4, sp, PT_R16 + PTR_S t5, sp, PT_R17 + PTR_S t6, sp, PT_R18 + PTR_S t7, sp, PT_R19 + PTR_S t8, sp, PT_R20 + PTR_S s0, sp, PT_R23 + PTR_S s1, sp, PT_R24 + PTR_S s2, sp, PT_R25 + PTR_S s3, sp, PT_R26 + PTR_S s4, sp, PT_R27 + PTR_S s5, sp, PT_R28 + PTR_S s6, sp, PT_R29 + PTR_S s7, sp, PT_R30 + PTR_S s8, sp, PT_R31 + PTR_S tp, sp, PT_R2 + /* Clear it for later use as a flag sometimes. */ + PTR_S zero, sp, PT_R0 + PTR_S $r21, sp, PT_R21 + .endif + PTR_ADDI t8, sp, PT_SIZE PTR_S t8, sp, PT_R3 .endm SYM_CODE_START(ftrace_caller) - ftrace_regs_entry + ftrace_regs_entry allregs=0 b ftrace_common SYM_CODE_END(ftrace_caller) +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +SYM_CODE_START(ftrace_regs_caller) + ftrace_regs_entry allregs=1 + b ftrace_common +SYM_CODE_END(ftrace_regs_caller) +#endif + SYM_CODE_START(ftrace_common) PTR_ADDI a0, ra, -8 /* arg0: ip */ move a1, t0 /* arg1: parent_ip */