From: Song Shuai <suagrfillet@gmail.com>
To: Guo Ren <guoren@kernel.org>
Cc: rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv/ftrace: fix ftrace_modify_call bug
Date: Tue, 22 Nov 2022 09:51:11 +0000 [thread overview]
Message-ID: <CAAYs2=gBfKPBMBVpkOYfixavkANhBnArSdCdHDgv8219sR4BzA@mail.gmail.com> (raw)
In-Reply-To: <CAJF2gTT=r4VeWqpe+Tw2JDdTDU+r2mJiPmHq_i8eV5YRmrrLRA@mail.gmail.com>
Guo Ren <guoren@kernel.org> 于2022年11月22日周二 09:29写道:
>
>
>
> On Tue, Nov 22, 2022 at 5:11 PM Song Shuai <suagrfillet@gmail.com> wrote:
>>
>> Guo Ren <guoren@kernel.org> 于2022年11月22日周二 08:57写道:
>> >
>> > On Tue, Nov 22, 2022 at 3:54 PM Song Shuai <suagrfillet@gmail.com> wrote:
>> > >
>> > > With this commit (riscv: ftrace: Reduce the detour code size to half)
>> > > patched, ftrace bug occurred When hosting kprobe and function tracer
>> > > at the same function.
>> > >
>> > > Obviously, the variable caller in ftrace_modify_call was assigned by
>> > > rec->ip with 4 offset failing the code replacing at function entry.
>> > > And the caller should be assigned by rec->ip directly to indicate
>> > > the function entry.
>> > Thank you, it's my fault, but I think the problem is:
>> >
>> > Before (riscv: ftrace: Reduce the detour code size to half)
>> > 0: REG_S ra, -SZREG(sp)
>> > 4: auipc ra, ? <- We need "rec->ip + 4" here
>> > 8: jalr ?(ra)
>> > 12: REG_L ra, -SZREG(sp)
>> >
>> > After (riscv: ftrace: Reduce the detour code size to half)
>> > 0: auipc t0, ? <- We needn't "rec->ip + 4" anymore
>> > 4: jalr t0, ?(t0)
>> >
>> > I copied rec->ip + 4 blindly, then caused the bug. Right?
>> >
>> Yes, you're right.
>>
>> Here's my simple test case for your convenience.
>> ```
>> echo kernel_read > set_ftrace_filter
>> echo function > current_tracer
>> echo 'p:myp kernel_read' > kprobe_events
>> echo 1 > events/kprobes/myp/enable # ftrace bug
>
>
> Thx, I would fold the patch into (riscv: ftrace: Reduce the detour code size to half). And add Co-developed-by: Song Shuai <suagrfillet@gmail.com> tag on that.
>
> I would send the v3 series involving your patches.
>
That's an honor for me.
Thanks,
Song
>>
>> ```
>> > >
>> > > The following is the ftrace bug log.
>> > >
>> > > ```
>> > > [ 419.632855] 00000000f8776803: expected (ffe00297 1a4282e7) but got (1a8282e7 f0227179)
>> > > [ 419.633390] ------------[ ftrace bug ]------------
>> > > [ 419.633553] ftrace failed to modify
>> > > [ 419.633569] [<ffffffff802091cc>] kernel_read+0x0/0x52
>> > > [ 419.633863] actual: 97:02:e0:ff:e7:82:82:1a
>> > > [ 419.634087] Updating ftrace call site to call a different ftrace function
>> > > [ 419.634279] ftrace record flags: e0000002
>> > > [ 419.634487] (2) R
>> > > [ 419.634487] expected tramp: ffffffff800093cc
>> > > [ 419.634935] ------------[ cut here ]------------
>> > > ```
>> > >
>> > > Signed-off-by: Song Shuai <suagrfillet@gmail.com>
>> > > ---
>> > > arch/riscv/kernel/ftrace.c | 2 +-
>> > > 1 file changed, 1 insertion(+), 1 deletion(-)
>> > >
>> > > diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c
>> > > index 8c77f236fc71..61b24d767e2e 100644
>> > > --- a/arch/riscv/kernel/ftrace.c
>> > > +++ b/arch/riscv/kernel/ftrace.c
>> > > @@ -132,7 +132,7 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
>> > > unsigned long addr)
>> > > {
>> > > unsigned int call[2];
>> > > - unsigned long caller = rec->ip + 4;
>> > > + unsigned long caller = rec->ip;
>> > > int ret;
>> > >
>> > > make_call_t0(caller, old_addr, call);
>> > > --
>> > > 2.20.1
>> > >
>> >
>> >
>> > --
>> > Best Regards
>> > Guo Ren
>> Thanks,
>> Song
>
>
>
> --
> Best Regards
> Guo Ren
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2022-11-22 9:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 7:54 [PATCH] riscv/ftrace: fix ftrace_modify_call bug Song Shuai
2022-11-22 8:57 ` Guo Ren
2022-11-22 9:11 ` Song Shuai
[not found] ` <CAJF2gTT=r4VeWqpe+Tw2JDdTDU+r2mJiPmHq_i8eV5YRmrrLRA@mail.gmail.com>
2022-11-22 9:51 ` Song Shuai [this message]
2022-11-22 8:57 ` Conor Dooley
2022-11-22 9:46 ` Song Shuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAYs2=gBfKPBMBVpkOYfixavkANhBnArSdCdHDgv8219sR4BzA@mail.gmail.com' \
--to=suagrfillet@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).