Make fprobe + rethook immune to recursion
Subsystems (6)
v2 cover Make fprobe + rethook immune to recursion
Hi all,
This is the 2nd version of patch series to fix the ftrace rethook recursion problem.
v1: https://lore.kernel.org/linux-trace-kernel/[email protected]/T/ +++#md4c0bae6a6cae28dadf2a2c6105ff140b35fddea
As Steven suggested, this version removes unnecessary notrace annotations from fprobe and rethook functions from v1 [PATCH 2,3,4/4] and replaces with makefile changes to filter out compiler flags which ftrace depends upon for rethook related objects.
Ze Gao (4):
rethook: use preempt_{disable, enable}_notrace in
rethook_trampoline_handler
fprobe: make fprobe_kprobe_handler recursion free
fprobe: add recursion detection in fprobe_exit_handler rehook, fprobe: do not trace rethook related functions
arch/riscv/kernel/probes/Makefile | 2 + arch/s390/kernel/Makefile | 1 + arch/x86/kernel/Makefile | 1 + kernel/trace/fprobe.c | 72 ++++++++++++++++++++++++------- kernel/trace/rethook.c | 4 +- 5 files changed, 63 insertions(+), 17 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/4 rethook: use preempt_{disable, enable}_notrace in rethook_trampoline_handler
This patch replaces preempt_{disable, enable} with its corresponding notrace version in rethook_trampoline_handler so no worries about stack recursion or overflow introduced by preempt_count_{add, sub} under fprobe + rethook context.
--- kernel/trace/rethook.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/rethook.c +2 -2
@@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,* These loops must be protected from rethook_free_rcu() because those * are accessing 'rhn->rethook'. */ -preempt_disable (); +preempt_disable_notrace ();/* * Run the handler on the shadow stack. Do not unlink the list here because
@@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, first = first->next;rethook_recycle (rhn); } -preempt_enable (); +preempt_enable_notrace ();return correct_ret_addr; }
Signature · 1 line
2.40.1
PATCH v2 2/4 fprobe: make fprobe_kprobe_handler recursion free
In reply to Ze GaoCurrent implementation calls kprobe related functions before doing ftrace recursion check in fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.
Refactor the common part out of fprobe_kprobe_handler and fprobe_ handler and call ftrace recursion detection at the very beginning, so that the whole fprobe_kprobe_handler is free from recursion.
--- kernel/trace/fprobe.c | 59 ++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 15 deletions(-)
kernel/trace/fprobe.c +44 -15
@@ -20,30 +20,22 @@ struct fprobe_rethook_node {char data[]; }; -static void fprobe_handler (unsigned long ip,unsigned long parent_ip, -struct ftrace_ops *ops,struct ftrace_regs *fregs) +static inline void __fprobe_handler (unsigned long ip,unsigned long + parent_ip,struct ftrace_ops *ops,struct ftrace_regs *fregs) {struct fprobe_rethook_node *fpr;struct rethook_node *rh =NULL ;struct fprobe *fp;void *entry_data =NULL ; -int bit, ret; +int ret; fp = container_of(ops, struct fprobe, ops); -if (fprobe_disabled (fp)) -return ; - - bit =ftrace_test_recursion_trylock (ip, parent_ip); -if (bit <0 ) { - fp->nmissed++; -return ; - }if (fp->exit_handler) { rh =rethook_try_get (fp->rethook);if (!rh) { fp->nmissed++; - goto out; +return ; } fpr = container_of(rh, struct fprobe_rethook_node, node); fpr->entry_ip = ip;
@@ -61,23 +53,60 @@ static void fprobe_handler(unsigned long ip, unsigned long parent_ip,else rethook_hook (rh,ftrace_get_regs (fregs), true); } -out: +} + +static void fprobe_handler (unsigned long ip,unsigned long parent_ip, +struct ftrace_ops *ops,struct ftrace_regs *fregs) +{ +struct fprobe *fp; +int bit; + + fp = container_of(ops, struct fprobe, ops); +if (fprobe_disabled (fp)) +return ; + +/* recursion detection has to go before any traceable function and +* all functions before this point should be marked as notrace +*/ + bit =ftrace_test_recursion_trylock (ip, parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + } +__fprobe_handler (ip, parent_ip, ops, fregs);ftrace_test_recursion_unlock (bit); + }NOKPROBE_SYMBOL (fprobe_handler);static void fprobe_kprobe_handler (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *ops,struct ftrace_regs *fregs) { - struct fprobe *fp = container_of(ops, struct fprobe, ops); +struct fprobe *fp; +int bit; + + fp = container_of(ops, struct fprobe, ops); +if (fprobe_disabled (fp)) +return ; + +/* recursion detection has to go before any traceable function and +* all functions called before this point should be marked as notrace +*/ + bit =ftrace_test_recursion_trylock (ip, parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + }if (unlikely (kprobe_running ())) { fp->nmissed++;return ; } +kprobe_busy_begin (); -fprobe_handler (ip, parent_ip, ops, fregs); +__fprobe_handler (ip, parent_ip, ops, fregs);kprobe_busy_end (); +ftrace_test_recursion_unlock (bit); } static void fprobe_exit_handler(struct rethook_node *rh, void *data,
Signature · 1 line
2.40.1
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Quoted 33 lines · Ze Gao
kernel/trace/fprobe.c +25
-1+static void fprobe_handler (unsigned long ip,unsigned long parent_ip, +struct ftrace_ops *ops,struct ftrace_regs *fregs) +{ +struct fprobe *fp; +int bit; + + fp = container_of(ops, struct fprobe, ops); +if (fprobe_disabled (fp)) +return ; + +/* recursion detection has to go before any traceable function and +* all functions before this point should be marked as notrace +*/ + bit =ftrace_test_recursion_trylock (ip, parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + } +__fprobe_handler (ip, parent_ip, ops, fregs);ftrace_test_recursion_unlock (bit); + }NOKPROBE_SYMBOL (fprobe_handler);static void fprobe_kprobe_handler (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *ops,struct ftrace_regs *fregs) { - struct fprobe *fp = container_of(ops, struct fprobe, ops); +struct fprobe *fp; +int bit; + + fp = container_of(ops, struct fprobe, ops); +if (fprobe_disabled (fp))
kernel/trace/fprobe.c static void fprobe_handler(unsigned long ip, unsigned long parent_ip, · line 99
Quoted 10 lines
kernel/trace/fprobe.c +10
-0+return ; + +/* recursion detection has to go before any traceable function and +* all functions called before this point should be marked as notrace +*/ + bit =ftrace_test_recursion_trylock (ip, parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + }
Please don't use this comment style; multi line comments go like:
/* * Multi line comment ... * ... is symmetric. */
Same for your next patch.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Thanks for pointing this out, I'll get it all fixed ASAP.
Regards,
Ze
Quoted 55 lines · Peter Zijlstra
Quoted 33 lines · Ze Gao
kernel/trace/fprobe.c +25
-1+static void fprobe_handler (unsigned long ip,unsigned long parent_ip, +struct ftrace_ops *ops,struct ftrace_regs *fregs) +{ +struct fprobe *fp; +int bit; + + fp = container_of(ops, struct fprobe, ops); +if (fprobe_disabled (fp)) +return ; + +/* recursion detection has to go before any traceable function and +* all functions before this point should be marked as notrace +*/ + bit =ftrace_test_recursion_trylock (ip, parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + } +__fprobe_handler (ip, parent_ip, ops, fregs);ftrace_test_recursion_unlock (bit); + }NOKPROBE_SYMBOL (fprobe_handler);static void fprobe_kprobe_handler (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *ops,struct ftrace_regs *fregs) { - struct fprobe *fp = container_of(ops, struct fprobe, ops); +struct fprobe *fp; +int bit; + + fp = container_of(ops, struct fprobe, ops); +if (fprobe_disabled (fp))kernel/trace/fprobe.c static void fprobe_handler(unsigned long ip, unsigned long parent_ip, · line 99
Quoted 10 lines
kernel/trace/fprobe.c +10
-0+return ; + +/* recursion detection has to go before any traceable function and +* all functions called before this point should be marked as notrace +*/ + bit =ftrace_test_recursion_trylock (ip, parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + }Please don't use this comment style; multi line comments go like:
/*
* Multi line comment ...
* ... is symmetric.
*/Same for your next patch.
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
In reply to Ze GaoQuoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.
Which preempt_count*() are you referring to? The ones you just made _notrace in the previous patch?
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Precisely, these that are called within kprobe_busy_{begin, end}, which the previous patch does not resolve.
I will refine the commit message to make it clear.
FYI, details can checked out here:
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/
Regards,
Ze
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.Which preempt_count*() are you referring to? The ones you just made
_notracein the previous patch?
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Sorry for paste the wrong link, it's this one instead:
It's the original discussions of this problem.
Regards,
Ze
Quoted 21 lines · Ze Gao
Precisely, these that are called within kprobe_busy_{begin, end}, which the previous patch does not resolve.
I will refine the commit message to make it clear.FYI, details can checked out here:
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/Regards,
ZeQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.Which preempt_count*() are you referring to? The ones you just made
_notracein the previous patch?
Masami Hiramatsu (Google)
maintainerRe: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
In reply to Ze GaoQuoted 2 lines · On Tue, 16 May 2023 17:47:52 +0800 Ze Gao <[email protected]> wrote:
Precisely, these that are called within kprobe_busy_{begin, end}, which the previous patch does not resolve.
Note that kprobe_busy_{begin,end} don't need to use notrace version because kprobe itself prohibits probing on preempt_count_{add,sub}.
Thank you,
Quoted 18 lines
I will refine the commit message to make it clear.
FYI, details can checked out here:
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/Regards,
ZeQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.Which preempt_count*() are you referring to? The ones you just made
_notracein the previous patch?
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Oops, I misunderstood your comments before.
Yes, it's not necessary to do this reordering as regards to kprobe.
Thanks for your review.
I'll rebase onto the latest tree and send v3 ASAP.
Regards,
Ze
Quoted 34 lines · Masami Hiramatsu
Quoted 2 lines · On Tue, 16 May 2023 17:47:52 +0800 Ze Gao <[email protected]> wrote:
Precisely, these that are called within kprobe_busy_{begin, end}, which the previous patch does not resolve.
Note that kprobe_busy_{begin,end} don't need to use notrace version because kprobe itself prohibits probing on preempt_count_{add,sub}.
Thank you,
Quoted 18 lines
I will refine the commit message to make it clear.
FYI, details can checked out here:
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/Regards,
ZeQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.Which preempt_count*() are you referring to? The ones you just made
_notracein the previous patch?--
Masami Hiramatsu (Google) <[email protected]>
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Quoted 3 lines · On Wed, 17 May 2023 09:54:53 +0800 Ze Gao <[email protected]> wrote:
Oops, I misunderstood your comments before.
Yes, it's not necessary to do this reordering as regards to kprobe.
Let me confirm, I meant that your current patch is correct. I just mentioned that kprobe_busy_{begin,end} will continue use standard version because kprobe itself handles that. Please update only the patch description and add my ack.
If you add Steve's call graph for the explanation, it will help us to understand what will be fixed.
Thank you,
Quoted 43 lines
Thanks for your review.
I'll rebase onto the latest tree and send v3 ASAP.
Regards,
ZeQuoted 34 lines · Masami Hiramatsu
Quoted 2 lines · On Tue, 16 May 2023 17:47:52 +0800 Ze Gao <[email protected]> wrote:
Precisely, these that are called within kprobe_busy_{begin, end}, which the previous patch does not resolve.
Note that kprobe_busy_{begin,end} don't need to use notrace version because kprobe itself prohibits probing on preempt_count_{add,sub}.
Thank you,
Quoted 18 lines
I will refine the commit message to make it clear.
FYI, details can checked out here:
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/Regards,
ZeQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.Which preempt_count*() are you referring to? The ones you just made
_notracein the previous patch?--
Masami Hiramatsu (Google) <[email protected]>
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Got it! :)
I will improve the commit message and send v3 ASAP.
BTW, which tree should I rebase those patches onto? Is that the for-next branch of git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git. I saw Jiri had troubles
applying those since these works are based on v6.4.0.
THX,
Ze
Quoted 67 lines · Masami Hiramatsu
Quoted 3 lines · On Wed, 17 May 2023 09:54:53 +0800 Ze Gao <[email protected]> wrote:
Oops, I misunderstood your comments before.
Yes, it's not necessary to do this reordering as regards to kprobe.
Let me confirm, I meant that your current patch is correct. I just mentioned that kprobe_busy_{begin,end} will continue use standard version because kprobe itself handles that. Please update only the patch description and add my ack.
If you add Steve's call graph for the explanation, it will help us to understand what will be fixed.
Thank you,
Quoted 43 lines
Thanks for your review.
I'll rebase onto the latest tree and send v3 ASAP.
Regards,
ZeQuoted 34 lines · Masami Hiramatsu
Quoted 2 lines · On Tue, 16 May 2023 17:47:52 +0800 Ze Gao <[email protected]> wrote:
Precisely, these that are called within kprobe_busy_{begin, end}, which the previous patch does not resolve.
Note that kprobe_busy_{begin,end} don't need to use notrace version because kprobe itself prohibits probing on preempt_count_{add,sub}.
Thank you,
Quoted 18 lines
I will refine the commit message to make it clear.
FYI, details can checked out here:
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/Regards,
ZeQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ze Gao
Current implementation calls kprobe related functions before doing ftrace recursion check in
fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable.Which preempt_count*() are you referring to? The ones you just made
_notracein the previous patch?--
Masami Hiramatsu (Google) <[email protected]>--
Masami Hiramatsu (Google) <[email protected]>
Steven Rostedt
maintainerRe: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Quoted 10 lines · On Wed, 17 May 2023 11:10:21 +0800 Ze Gao <[email protected]> wrote:
Got it! :)
I will improve the commit message and send v3 ASAP.
BTW, which tree should I rebase those patches onto? Is that the for-next branch of git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git. I saw Jiri had troubles
applying those since these works are based on v6.4.0.
You can submit against 6.4-rc1. We haven't updated the for-next branch yet. Which will be rebased off of one of the 6.4 rc's.
-- Steve
Masami Hiramatsu (Google)
maintainerRe: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
Quoted 14 lines · On Tue, 16 May 2023 23:25:45 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Wed, 17 May 2023 11:10:21 +0800 Ze Gao <[email protected]> wrote:
Got it! :)
I will improve the commit message and send v3 ASAP.
BTW, which tree should I rebase those patches onto? Is that the for-next branch of git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git. I saw Jiri had troubles
applying those since these works are based on v6.4.0.
Quoted 2 lines
You can submit against 6.4-rc1. We haven't updated the for-next branch yet. Which will be rebased off of one of the 6.4 rc's.
Yeah, I would like to pick it to probes/fixes for 6.4 and stable branches.
Thank you,
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Re: [PATCH v2 2/4] fprobe: make fprobe_kprobe_handler recursion free
In reply to Steven RostedtHi Jiri,
This is the latest version against 6.4-rc1, and you can apply without trouble.
https://lore.kernel.org/linux-trace-kernel/[email protected]/T/#t
Regards,
Ze
Quoted 19 lines · Steven Rostedt
Quoted 10 lines · On Wed, 17 May 2023 11:10:21 +0800 Ze Gao <[email protected]> wrote:
Got it! :)
I will improve the commit message and send v3 ASAP.
BTW, which tree should I rebase those patches onto? Is that the for-next branch of git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git. I saw Jiri had troubles
applying those since these works are based on v6.4.0.You can submit against 6.4-rc1. We haven't updated the for-next branch yet. Which will be rebased off of one of the 6.4 rc's.
-- Steve
PATCH v2 3/4 fprobe: add recursion detection in fprobe_exit_handler
In reply to Ze Gaofprobe_hander and fprobe_kprobe_handler has guarded ftrace recursion detection but fprobe_exit_handler has not, which possibly introduce recursive calls if the fprobe exit callback calls any traceable functions. Checking in fprobe_hander or fprobe_kprobe_handler is not enough and misses this case.
So add recursion free guard the same way as fprobe_hander. Since ftrace recursion check does not employ ip(s), so here use entry_ip and entry_parent_ip the same as fprobe_handler.
--- kernel/trace/fprobe.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/trace/fprobe.c +13 -0
@@ -17,6 +17,7 @@struct fprobe_rethook_node {struct rethook_node node;unsigned long entry_ip; +unsigned long entry_parent_ip;char data[]; };
@@ -39,6 +40,7 @@ static inline void __fprobe_handler(unsigned long ip, unsigned long } fpr = container_of(rh, struct fprobe_rethook_node, node); fpr->entry_ip = ip; + fpr->entry_parent_ip = parent_ip;if (fp->entry_data_size) entry_data = fpr->data; }
@@ -114,14 +116,25 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data, {struct fprobe *fp = (struct fprobe *)data;struct fprobe_rethook_node *fpr; +int bit;if (!fp ||fprobe_disabled (fp))return ; fpr = container_of(rh, struct fprobe_rethook_node, node); +/* we need to assure no calls to traceable functions in-between the +* end of fprobe_handler and the beginning of fprobe_exit_handler. +*/ + bit =ftrace_test_recursion_trylock (fpr->entry_ip, fpr->entry_parent_ip); +if (bit <0 ) { + fp->nmissed++; +return ; + } + fp->exit_handler (fp, fpr->entry_ip, regs, fp->entry_data_size ? (void *)fpr->data :NULL ); +ftrace_test_recursion_unlock (bit); }NOKPROBE_SYMBOL (fprobe_exit_handler);
Signature · 1 line
2.40.1
PATCH v2 4/4 rehook, fprobe: do not trace rethook related functions
In reply to Ze GaoThese functions are already marked as NOKPROBE to prevent recursion and we have the same reason to blacklist them if rethook is used with fprobe, since they are beyond the recursion-free region ftrace can guard.
--- arch/riscv/kernel/probes/Makefile | 2 ++ arch/s390/kernel/Makefile | 1 + arch/x86/kernel/Makefile | 1 + 3 files changed, 4 insertions(+)
arch/riscv/kernel/probes/Makefile +2 -0
@@ -4,3 +4,5 @@ obj-$(CONFIG_RETHOOK) += rethook.o rethook_trampoline.o obj-$(CONFIG_KPROBES_ON_FTRACE) += ftrace.o obj-$(CONFIG_UPROBES) += uprobes.o decode-insn.o simulate-insn.o CFLAGS_REMOVE_simulate-insn.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook_trampoline.o = $(CC_FLAGS_FTRACE)
arch/s390/kernel/Makefile +1 -0
@@ -10,6 +10,7 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) # Do not trace early setup code CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) endif
arch/x86/kernel/Makefile +1 -0
@@ -17,6 +17,7 @@ CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_early_printk.o = -pg CFLAGS_REMOVE_head64.o = -pg CFLAGS_REMOVE_sev.o = -pg +CFLAGS_REMOVE_rethook.o = -pg endif KASAN_SANITIZE_head$(BITS).o := n
Signature · 1 line
2.40.1
Steven Rostedt
maintainerRe: [PATCH v2 4/4] rehook, fprobe: do not trace rethook related functions
Quoted 10 lines · On Tue, 16 May 2023 15:18:30 +0800 Ze Gao <[email protected]> wrote:
CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE)
arch/s390/kernel/Makefile +1
-0+CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) endifarch/x86/kernel/Makefile +0
-0
arch/x86/kernel/Makefile CFLAGS_REMOVE_ftrace.o = -pg · line 20
Quoted 4 lines
arch/x86/kernel/Makefile +1
-0@@ -17,6 +17,7 @@ CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_early_printk.o = -pg CFLAGS_REMOVE_head64.o = -pg CFLAGS_REMOVE_sev.o = -pg +CFLAGS_REMOVE_rethook.o = -pg
Unrelated to this patch, but someday we need to change the -pg above to $(CC_FLAGS_FTRACE).
-- Steve
Quoted 4 lines
arch/x86/kernel/Makefile +0
-0endif KASAN_SANITIZE_head$(BITS).o := n
Re: [PATCH v2 4/4] rehook, fprobe: do not trace rethook related functions
Got it! Thank you, Steevn. Maybe I can give it a try later :)
Regards,
Ze
Quoted 29 lines · Steven Rostedt
Quoted 10 lines · On Tue, 16 May 2023 15:18:30 +0800 Ze Gao <[email protected]> wrote:
CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE)
arch/s390/kernel/Makefile +1
-0+CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) endifarch/x86/kernel/Makefile +0
-0arch/x86/kernel/Makefile CFLAGS_REMOVE_ftrace.o = -pg · line 20
Quoted 4 lines
arch/x86/kernel/Makefile +1
-0@@ -17,6 +17,7 @@ CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_early_printk.o = -pg CFLAGS_REMOVE_head64.o = -pg CFLAGS_REMOVE_sev.o = -pg +CFLAGS_REMOVE_rethook.o = -pgUnrelated to this patch, but someday we need to change the -pg above to $(CC_FLAGS_FTRACE).
-- Steve
Quoted 4 lines
arch/x86/kernel/Makefile +0
-1endif KASAN_SANITIZE_head$(BITS).o := n --
Re: [PATCH v2 4/4] rehook, fprobe: do not trace rethook related functions
In reply to Ze GaoQuoted 5 lines · On Tue, 16 May 2023 15:18:30 +0800 Ze Gao <[email protected]> wrote:
These functions are already marked as NOKPROBE to prevent recursion and we have the same reason to blacklist them if rethook is used with fprobe, since they are beyond the recursion-free region ftrace can guard.
Signed-off-by Ze Gao <[email protected]>
Looks good to me.
Thank you!
Quoted 43 lines
--- arch/riscv/kernel/probes/Makefile | 2 ++ arch/s390/kernel/Makefile | 1 + arch/x86/kernel/Makefile | 1 + 3 files changed, 4 insertions(+)arch/riscv/kernel/probes/Makefile +2
-0@@ -4,3 +4,5 @@ obj-$(CONFIG_RETHOOK) += rethook.o rethook_trampoline.o obj-$(CONFIG_KPROBES_ON_FTRACE) += ftrace.o obj-$(CONFIG_UPROBES) += uprobes.o decode-insn.o simulate-insn.o CFLAGS_REMOVE_simulate-insn.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook_trampoline.o = $(CC_FLAGS_FTRACE)arch/s390/kernel/Makefile +1
-0@@ -10,6 +10,7 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) # Do not trace early setup code CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) endifarch/x86/kernel/Makefile +1
-0@@ -17,6 +17,7 @@ CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_early_printk.o = -pg CFLAGS_REMOVE_head64.o = -pg CFLAGS_REMOVE_sev.o = -pg +CFLAGS_REMOVE_rethook.o = -pg endif KASAN_SANITIZE_head$(BITS).o := nSignature · 1 line
2.40.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 10 lines · Ze Gao
Hi all,
This is the 2nd version of patch series to fix the ftrace rethook recursion problem.
v1: https://lore.kernel.org/linux-trace-kernel/[email protected]/T/ +++#md4c0bae6a6cae28dadf2a2c6105ff140b35fddea
As Steven suggested, this version removes unnecessary notrace annotations from fprobe and rethook functions from v1 [PATCH 2,3,4/4] and replaces with makefile changes to filter out compiler flags which ftrace depends upon for rethook related objects.
Quoted 6 lines
Ze Gao (4):
rethook: use preempt_{disable, enable}_notrace in
rethook_trampoline_handler
fprobe: makefprobe_kprobe_handlerrecursion free
fprobe: add recursion detection infprobe_exit_handlerrehook, fprobe: do not trace rethook related functions
hi,
what tree is this based on? I have troubles to apply that
thanks,
jirka
Quoted 11 lines
arch/riscv/kernel/probes/Makefile | 2 + arch/s390/kernel/Makefile | 1 + arch/x86/kernel/Makefile | 1 + kernel/trace/fprobe.c | 72 ++++++++++++++++++++++++------- kernel/trace/rethook.c | 4 +- 5 files changed, 63 insertions(+), 17 deletions(-)Signature · 1 line
2.40.1