* [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
@ 2025-10-29 2:15 Menglong Dong
2025-10-29 14:00 ` Steven Rostedt
2025-10-30 0:40 ` Masami Hiramatsu
0 siblings, 2 replies; 6+ messages in thread
From: Menglong Dong @ 2025-10-29 2:15 UTC (permalink / raw)
To: mhiramat
Cc: rostedt, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
For now, we will use ftrace for the fprobe if fp->exit_handler not exists
and CONFIG_DYNAMIC_FTRACE_WITH_REGS is enabled.
However, CONFIG_DYNAMIC_FTRACE_WITH_REGS is not supported by some arch,
such as arm. What we need in the fprobe is the function arguments, so we
can use ftrace for fprobe if CONFIG_DYNAMIC_FTRACE_WITH_ARGS is enabled.
Therefore, use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_REGS or
CONFIG_DYNAMIC_FTRACE_WITH_ARGS enabled.
Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
kernel/trace/fprobe.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index ecd623eef68b..9fad0569f521 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -254,7 +254,11 @@ static inline int __fprobe_kprobe_handler(unsigned long ip, unsigned long parent
return ret;
}
-#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+#if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
+#define FPROBE_USE_FTRACE
+#endif
+
+#ifdef FPROBE_USE_FTRACE
/* ftrace_ops callback, this processes fprobes which have only entry_handler. */
static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *ops, struct ftrace_regs *fregs)
@@ -295,7 +299,7 @@ NOKPROBE_SYMBOL(fprobe_ftrace_entry);
static struct ftrace_ops fprobe_ftrace_ops = {
.func = fprobe_ftrace_entry,
- .flags = FTRACE_OPS_FL_SAVE_REGS,
+ .flags = FTRACE_OPS_FL_SAVE_ARGS,
};
static int fprobe_ftrace_active;
@@ -349,7 +353,7 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
{
return false;
}
-#endif
+#endif /* !FPROBE_USE_FTRACE */
/* fgraph_ops callback, this processes fprobes which have exit_handler. */
static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
@@ -599,7 +603,7 @@ static int fprobe_module_callback(struct notifier_block *nb,
if (alist.index > 0) {
ftrace_set_filter_ips(&fprobe_graph_ops.ops,
alist.addrs, alist.index, 1, 0);
-#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+#ifdef FPROBE_USE_FTRACE
ftrace_set_filter_ips(&fprobe_ftrace_ops,
alist.addrs, alist.index, 1, 0);
#endif
--
2.51.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2025-10-29 2:15 [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
@ 2025-10-29 14:00 ` Steven Rostedt
2025-10-29 14:09 ` Menglong Dong
2025-10-30 0:40 ` Masami Hiramatsu
1 sibling, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2025-10-29 14:00 UTC (permalink / raw)
To: Menglong Dong
Cc: mhiramat, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
On Wed, 29 Oct 2025 10:15:14 +0800
Menglong Dong <menglong8.dong@gmail.com> wrote:
> -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> +#if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
> +#define FPROBE_USE_FTRACE
> +#endif
> +
> +#ifdef FPROBE_USE_FTRACE
> /* ftrace_ops callback, this processes fprobes which have only entry_handler. */
> static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
> struct ftrace_ops *ops, struct ftrace_regs *fregs)
> @@ -295,7 +299,7 @@ NOKPROBE_SYMBOL(fprobe_ftrace_entry);
>
> static struct ftrace_ops fprobe_ftrace_ops = {
> .func = fprobe_ftrace_entry,
> - .flags = FTRACE_OPS_FL_SAVE_REGS,
> + .flags = FTRACE_OPS_FL_SAVE_ARGS,
If an arch defines DYNAMIC_FTRACE_WITH_REGS but not
DYNAMIC_FTRACE_WITH_ARGS, then this will fail to build.
> };
> static int fprobe_ftrace_active;
>
Perhaps do:
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
# define FPROBE_FTRACE_TYPE FTRACE_OPS_FL_SAVE_ARGS
#elif defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
# define FPROBE_FTRACE_TYPE FTRACE_OPS_FL_SAVE_REGS,
#endif
#ifdef FPROBE_FTRACE_TYPE
[..]
static struct ftrace_ops fprobe_ftrace_ops = {
.func = fprobe_ftrace_entry,
.flags = FTRACE_FTRACE_TYPE,
?
-- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2025-10-29 14:00 ` Steven Rostedt
@ 2025-10-29 14:09 ` Menglong Dong
2025-10-29 14:23 ` Steven Rostedt
0 siblings, 1 reply; 6+ messages in thread
From: Menglong Dong @ 2025-10-29 14:09 UTC (permalink / raw)
To: Steven Rostedt
Cc: mhiramat, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
On Wed, Oct 29, 2025 at 10:00 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Wed, 29 Oct 2025 10:15:14 +0800
> Menglong Dong <menglong8.dong@gmail.com> wrote:
>
> > -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> > +#if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
> > +#define FPROBE_USE_FTRACE
> > +#endif
> > +
> > +#ifdef FPROBE_USE_FTRACE
> > /* ftrace_ops callback, this processes fprobes which have only entry_handler. */
> > static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
> > struct ftrace_ops *ops, struct ftrace_regs *fregs)
> > @@ -295,7 +299,7 @@ NOKPROBE_SYMBOL(fprobe_ftrace_entry);
> >
> > static struct ftrace_ops fprobe_ftrace_ops = {
> > .func = fprobe_ftrace_entry,
> > - .flags = FTRACE_OPS_FL_SAVE_REGS,
> > + .flags = FTRACE_OPS_FL_SAVE_ARGS,
>
> If an arch defines DYNAMIC_FTRACE_WITH_REGS but not
> DYNAMIC_FTRACE_WITH_ARGS, then this will fail to build.
Hi, it won't fail here, as FTRACE_OPS_FL_SAVE_ARGS has
following definition:
#ifndef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
#define FTRACE_OPS_FL_SAVE_ARGS FTRACE_OPS_FL_SAVE_REGS
#else
#define FTRACE_OPS_FL_SAVE_ARGS 0
#endif
Which means it will fallback to FTRACE_OPS_FL_SAVE_REGS if
CONFIG_DYNAMIC_FTRACE_WITH_ARGS not defined.
I have commit a PR to the bpf CI, and all testings passed and no
building error happens:
https://github.com/kernel-patches/bpf/pull/10110
Thanks!
Menglong Dong
>
> > };
> > static int fprobe_ftrace_active;
> >
>
> Perhaps do:
>
> #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
> # define FPROBE_FTRACE_TYPE FTRACE_OPS_FL_SAVE_ARGS
> #elif defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
> # define FPROBE_FTRACE_TYPE FTRACE_OPS_FL_SAVE_REGS,
> #endif
>
> #ifdef FPROBE_FTRACE_TYPE
> [..]
> static struct ftrace_ops fprobe_ftrace_ops = {
> .func = fprobe_ftrace_entry,
> .flags = FTRACE_FTRACE_TYPE,
>
>
> ?
>
> -- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2025-10-29 14:09 ` Menglong Dong
@ 2025-10-29 14:23 ` Steven Rostedt
0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2025-10-29 14:23 UTC (permalink / raw)
To: Menglong Dong
Cc: mhiramat, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
On Wed, 29 Oct 2025 22:09:40 +0800
Menglong Dong <menglong8.dong@gmail.com> wrote:
> Hi, it won't fail here, as FTRACE_OPS_FL_SAVE_ARGS has
> following definition:
>
> #ifndef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
> #define FTRACE_OPS_FL_SAVE_ARGS FTRACE_OPS_FL_SAVE_REGS
> #else
> #define FTRACE_OPS_FL_SAVE_ARGS 0
> #endif
Bah, I should have known that, as I think I requested it :-p
[ chalks this up for a senior moment! ]
>
> Which means it will fallback to FTRACE_OPS_FL_SAVE_REGS if
> CONFIG_DYNAMIC_FTRACE_WITH_ARGS not defined.
>
> I have commit a PR to the bpf CI, and all testings passed and no
> building error happens:
> https://github.com/kernel-patches/bpf/pull/10110
OK, thanks,
-- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2025-10-29 2:15 [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
2025-10-29 14:00 ` Steven Rostedt
@ 2025-10-30 0:40 ` Masami Hiramatsu
2025-10-30 2:43 ` Menglong Dong
1 sibling, 1 reply; 6+ messages in thread
From: Masami Hiramatsu @ 2025-10-30 0:40 UTC (permalink / raw)
To: Menglong Dong
Cc: rostedt, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
On Wed, 29 Oct 2025 10:15:14 +0800
Menglong Dong <menglong8.dong@gmail.com> wrote:
> For now, we will use ftrace for the fprobe if fp->exit_handler not exists
> and CONFIG_DYNAMIC_FTRACE_WITH_REGS is enabled.
>
> However, CONFIG_DYNAMIC_FTRACE_WITH_REGS is not supported by some arch,
> such as arm. What we need in the fprobe is the function arguments, so we
> can use ftrace for fprobe if CONFIG_DYNAMIC_FTRACE_WITH_ARGS is enabled.
>
> Therefore, use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_REGS or
> CONFIG_DYNAMIC_FTRACE_WITH_ARGS enabled.
>
> Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> ---
> kernel/trace/fprobe.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index ecd623eef68b..9fad0569f521 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -254,7 +254,11 @@ static inline int __fprobe_kprobe_handler(unsigned long ip, unsigned long parent
> return ret;
> }
>
> -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> +#if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
> +#define FPROBE_USE_FTRACE
> +#endif
> +
> +#ifdef FPROBE_USE_FTRACE
> /* ftrace_ops callback, this processes fprobes which have only entry_handler. */
> static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
> struct ftrace_ops *ops, struct ftrace_regs *fregs)
> @@ -295,7 +299,7 @@ NOKPROBE_SYMBOL(fprobe_ftrace_entry);
>
> static struct ftrace_ops fprobe_ftrace_ops = {
> .func = fprobe_ftrace_entry,
> - .flags = FTRACE_OPS_FL_SAVE_REGS,
> + .flags = FTRACE_OPS_FL_SAVE_ARGS,
> };
> static int fprobe_ftrace_active;
>
> @@ -349,7 +353,7 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
> {
> return false;
> }
> -#endif
> +#endif /* !FPROBE_USE_FTRACE */
>
> /* fgraph_ops callback, this processes fprobes which have exit_handler. */
> static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
> @@ -599,7 +603,7 @@ static int fprobe_module_callback(struct notifier_block *nb,
> if (alist.index > 0) {
> ftrace_set_filter_ips(&fprobe_graph_ops.ops,
> alist.addrs, alist.index, 1, 0);
> -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> +#ifdef FPROBE_USE_FTRACE
> ftrace_set_filter_ips(&fprobe_ftrace_ops,
> alist.addrs, alist.index, 1, 0);
> #endif
Instead of introducing FPROBE_USE_FTRACE, I think it is better to add another
wrapper to be called here.
#if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove, int reset)
{
ftrace_set_filter_ips(&fprobe_graph_ops.ops,
alist.addrs, alist.index, 1, 0);
ftrace_set_filter_ips(&fprobe_ftrace_ops,
alist.addrs, alist.index, 1, 0);
}
...
#else
static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove, int reset)
{
ftrace_set_filter_ips(&fprobe_graph_ops.ops,
alist.addrs, alist.index, 1, 0);
}
#endif
Thank you,
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2025-10-30 0:40 ` Masami Hiramatsu
@ 2025-10-30 2:43 ` Menglong Dong
0 siblings, 0 replies; 6+ messages in thread
From: Menglong Dong @ 2025-10-30 2:43 UTC (permalink / raw)
To: Menglong Dong, Masami Hiramatsu
Cc: rostedt, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
On 2025/10/30 08:40, Masami Hiramatsu wrote:
> On Wed, 29 Oct 2025 10:15:14 +0800
> Menglong Dong <menglong8.dong@gmail.com> wrote:
>
> > For now, we will use ftrace for the fprobe if fp->exit_handler not exists
> > and CONFIG_DYNAMIC_FTRACE_WITH_REGS is enabled.
> >
> > However, CONFIG_DYNAMIC_FTRACE_WITH_REGS is not supported by some arch,
> > such as arm. What we need in the fprobe is the function arguments, so we
> > can use ftrace for fprobe if CONFIG_DYNAMIC_FTRACE_WITH_ARGS is enabled.
> >
> > Therefore, use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_REGS or
> > CONFIG_DYNAMIC_FTRACE_WITH_ARGS enabled.
> >
> > Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> > ---
> > kernel/trace/fprobe.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > index ecd623eef68b..9fad0569f521 100644
> > --- a/kernel/trace/fprobe.c
> > +++ b/kernel/trace/fprobe.c
> > @@ -254,7 +254,11 @@ static inline int __fprobe_kprobe_handler(unsigned long ip, unsigned long parent
> > return ret;
> > }
> >
> > -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> > +#if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
> > +#define FPROBE_USE_FTRACE
> > +#endif
> > +
> > +#ifdef FPROBE_USE_FTRACE
> > /* ftrace_ops callback, this processes fprobes which have only entry_handler. */
> > static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
> > struct ftrace_ops *ops, struct ftrace_regs *fregs)
> > @@ -295,7 +299,7 @@ NOKPROBE_SYMBOL(fprobe_ftrace_entry);
> >
> > static struct ftrace_ops fprobe_ftrace_ops = {
> > .func = fprobe_ftrace_entry,
> > - .flags = FTRACE_OPS_FL_SAVE_REGS,
> > + .flags = FTRACE_OPS_FL_SAVE_ARGS,
> > };
> > static int fprobe_ftrace_active;
> >
> > @@ -349,7 +353,7 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
> > {
> > return false;
> > }
> > -#endif
> > +#endif /* !FPROBE_USE_FTRACE */
> >
> > /* fgraph_ops callback, this processes fprobes which have exit_handler. */
> > static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
> > @@ -599,7 +603,7 @@ static int fprobe_module_callback(struct notifier_block *nb,
> > if (alist.index > 0) {
> > ftrace_set_filter_ips(&fprobe_graph_ops.ops,
> > alist.addrs, alist.index, 1, 0);
> > -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> > +#ifdef FPROBE_USE_FTRACE
> > ftrace_set_filter_ips(&fprobe_ftrace_ops,
> > alist.addrs, alist.index, 1, 0);
> > #endif
>
> Instead of introducing FPROBE_USE_FTRACE, I think it is better to add another
> wrapper to be called here.
Sounds better! I'll modify it in the next version.
Thanks!
Menglong Dong
>
> #if defined(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) || defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
>
> static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove, int reset)
> {
> ftrace_set_filter_ips(&fprobe_graph_ops.ops,
> alist.addrs, alist.index, 1, 0);
> ftrace_set_filter_ips(&fprobe_ftrace_ops,
> alist.addrs, alist.index, 1, 0);
> }
> ...
> #else
> static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove, int reset)
> {
> ftrace_set_filter_ips(&fprobe_graph_ops.ops,
> alist.addrs, alist.index, 1, 0);
> }
> #endif
>
> Thank you,
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-10-30 2:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 2:15 [PATCH] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
2025-10-29 14:00 ` Steven Rostedt
2025-10-29 14:09 ` Menglong Dong
2025-10-29 14:23 ` Steven Rostedt
2025-10-30 0:40 ` Masami Hiramatsu
2025-10-30 2:43 ` Menglong Dong
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).