riscv/ftrace: fix ftrace_modify_call bug
PATCH 1/1 riscv/ftrace: fix ftrace_modify_call bug
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.
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 ]------------ ```
--- arch/riscv/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/ftrace.c +1 -1
@@ -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);
Signature · 1 line
2.20.1
Quoted 9 lines · Song Shuai
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_callwas assigned byrec->ipwith 4 offset failing the code replacing at function entry. And the caller should be assigned byrec->ipdirectly 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?
Quoted 37 lines
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 <[email protected]>--- arch/riscv/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/ftrace.c +1
-2@@ -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
Signature · 2 lines
Best Regards Guo Ren
Quoted 19 lines · Guo Ren <[email protected]> 于2022年11月22日周二 08:57写道:
Quoted 9 lines · Song Shuai
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_callwas assigned byrec->ipwith 4 offset failing the code replacing at function entry. And the caller should be assigned byrec->ipdirectly 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)
Quoted 6 lines
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 ```
Quoted 33 lines
Quoted 33 lines
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 <[email protected]>--- arch/riscv/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/ftrace.c +1
-1@@ -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;
Quoted 9 lines
Quoted 4 lines
arch/riscv/kernel/ftrace.c +0
-1make_call_t0 (caller, old_addr, call); --2.20.1
--
Best Regards
Guo Ren
Thanks,
Song
_______________________________________________
linux-riscv mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
A message that is not in the archive (sent off-list or not yet received): CAJF2gTT=r4VeWqpe+Tw2JDdTDU+r2mJiPmHq_i8eV5YRmrrLRA@mail.gmail.com
Quoted 41 lines · Guo Ren <[email protected]> 于2022年11月22日周二 09:29写道:
Quoted 27 lines · Song Shuai
Quoted 19 lines · Guo Ren <[email protected]> 于2022年11月22日周二 08:57写道:
Quoted 9 lines · Song Shuai
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_callwas assigned byrec->ipwith 4 offset failing the code replacing at function entry. And the caller should be assigned byrec->ipdirectly 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)Quoted 6 lines
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?Quoted 8 lines
Yes, you're right.
Here's my simple test case for your convenience. ```
echokernel_read>set_ftrace_filterecho function >current_tracer
echo 'p:mypkernel_read' >kprobe_eventsecho 1 > events/kprobes/myp/enable # ftrace bug
Quoted 4 lines
Thx, I would fold the patch into (riscv: ftrace: Reduce the detour code size to half). And add Co-developed-by: Song Shuai <[email protected]> tag on that.
I would send the v3 series involving your patches.
That's an honor for me.
Thanks,
Song
Quoted 52 lines
Quoted 44 lines
```
Quoted 33 lines
Quoted 33 lines
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 <[email protected]>--- arch/riscv/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/ftrace.c +1
-1@@ -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;Quoted 9 lines
Quoted 4 lines
arch/riscv/kernel/ftrace.c +0
-1make_call_t0 (caller, old_addr, call); --2.20.1
--
Best Regards
Guo RenQuoted 2 lines
Thanks,
Song--
Best Regards
Guo Ren
Quoted 1 line · Song Shuai
With this commit (riscv: ftrace: Reduce the detour code size to half)
AFAICT the above patch has not been applied & this patch here should be folded into the offending patch?
I've marked this one as "Not Applicable" in patchwork as a result, but let me know if that is an incorrect assumption.
Thanks,
Conor.
Quoted 44 lines
patched, ftrace bug occurred When hosting kprobe and function tracer at the same function.
Obviously, the variable caller in
ftrace_modify_callwas assigned byrec->ipwith 4 offset failing the code replacing at function entry. And the caller should be assigned byrec->ipdirectly to indicate the function entry.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 <[email protected]>--- arch/riscv/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/ftrace.c +1
-1@@ -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);Signature · 1 line
2.20.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 4 lines · Conor Dooley <[email protected]> 于2022年11月22日周二 08:57写道:
Quoted 1 line · Song Shuai
With this commit (riscv: ftrace: Reduce the detour code size to half)
Quoted 8 lines
AFAICT the above patch has not been applied & this patch here should be folded into the offending patch?
I've marked this one as "Not Applicable" in patchwork as a result, but let me know if that is an incorrect assumption.Thanks,
Conor.
Hi, Conor:
Sorry to disturb you with this patch without against the merged commit list,
This patch actually is created for fixing (riscv: ftrace: Reduce the detour code size to half)
which has not been merged yet.
As Guo replied, he will fold it in the target patch. You can ignore this one. Sorry again.
BTW, for dispelling your confusion about my email name. Actually, it was misspelled when registering, but I keep it for daily use. So you can send it without concern. :P
-- Song
Sorry for bothering you with the
Quoted 40 lines
Quoted 40 lines
patched, ftrace bug occurred When hosting kprobe and function tracer at the same function.
Obviously, the variable caller in
ftrace_modify_callwas assigned byrec->ipwith 4 offset failing the code replacing at function entry. And the caller should be assigned byrec->ipdirectly to indicate the function entry.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 <[email protected]>--- arch/riscv/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/ftrace.c +1
-1@@ -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;
Quoted 4 lines
Quoted 4 lines
arch/riscv/kernel/ftrace.c +0
-1make_call_t0 (caller, old_addr, call); --2.20.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv