* [PATCH v3] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
@ 2025-11-03 6:34 Menglong Dong
2025-11-03 13:52 ` Masami Hiramatsu
0 siblings, 1 reply; 2+ messages in thread
From: Menglong Dong @ 2025-11-03 6:34 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>
---
v3:
- fix the build warning when CONFIG_MODULES not enabled
v2:
- remove the definition of FPROBE_USE_FTRACE
---
kernel/trace/fprobe.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index ecd623eef68b..0b1ee8e585f2 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -44,6 +44,7 @@
static struct hlist_head fprobe_table[FPROBE_TABLE_SIZE];
static struct rhltable fprobe_ip_table;
static DEFINE_MUTEX(fprobe_mutex);
+static struct fgraph_ops fprobe_graph_ops;
static u32 fprobe_node_hashfn(const void *data, u32 len, u32 seed)
{
@@ -254,7 +255,7 @@ 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)
/* 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 +296,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;
@@ -335,6 +336,15 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
{
return !fp->exit_handler;
}
+
+#ifdef CONFIG_MODULES
+static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove,
+ int reset)
+{
+ ftrace_set_filter_ips(&fprobe_graph_ops.ops, ips, cnt, remove, reset);
+ ftrace_set_filter_ips(&fprobe_ftrace_ops, ips, cnt, remove, reset);
+}
+#endif
#else
static int fprobe_ftrace_add_ips(unsigned long *addrs, int num)
{
@@ -349,7 +359,15 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
{
return false;
}
+
+#ifdef CONFIG_MODULES
+static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove,
+ int reset)
+{
+ ftrace_set_filter_ips(&fprobe_graph_ops.ops, ips, cnt, remove, reset);
+}
#endif
+#endif /* !CONFIG_DYNAMIC_FTRACE_WITH_ARGS && !CONFIG_DYNAMIC_FTRACE_WITH_REGS */
/* fgraph_ops callback, this processes fprobes which have exit_handler. */
static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
@@ -596,14 +614,8 @@ static int fprobe_module_callback(struct notifier_block *nb,
} while (node == ERR_PTR(-EAGAIN));
rhashtable_walk_exit(&iter);
- if (alist.index > 0) {
- ftrace_set_filter_ips(&fprobe_graph_ops.ops,
- alist.addrs, alist.index, 1, 0);
-#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
- ftrace_set_filter_ips(&fprobe_ftrace_ops,
- alist.addrs, alist.index, 1, 0);
-#endif
- }
+ if (alist.index > 0)
+ fprobe_set_ips(alist.addrs, alist.index, 1, 0);
mutex_unlock(&fprobe_mutex);
kfree(alist.addrs);
--
2.51.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2025-11-03 6:34 [PATCH v3] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
@ 2025-11-03 13:52 ` Masami Hiramatsu
0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2025-11-03 13:52 UTC (permalink / raw)
To: Menglong Dong
Cc: rostedt, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
linux-trace-kernel
On Mon, 3 Nov 2025 14:34:34 +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.
>
Looks good to me. Thanks!
> Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> ---
> v3:
> - fix the build warning when CONFIG_MODULES not enabled
>
> v2:
> - remove the definition of FPROBE_USE_FTRACE
> ---
> kernel/trace/fprobe.c | 32 ++++++++++++++++++++++----------
> 1 file changed, 22 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index ecd623eef68b..0b1ee8e585f2 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -44,6 +44,7 @@
> static struct hlist_head fprobe_table[FPROBE_TABLE_SIZE];
> static struct rhltable fprobe_ip_table;
> static DEFINE_MUTEX(fprobe_mutex);
> +static struct fgraph_ops fprobe_graph_ops;
>
> static u32 fprobe_node_hashfn(const void *data, u32 len, u32 seed)
> {
> @@ -254,7 +255,7 @@ 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)
> /* 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 +296,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;
>
> @@ -335,6 +336,15 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
> {
> return !fp->exit_handler;
> }
> +
> +#ifdef CONFIG_MODULES
> +static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove,
> + int reset)
> +{
> + ftrace_set_filter_ips(&fprobe_graph_ops.ops, ips, cnt, remove, reset);
> + ftrace_set_filter_ips(&fprobe_ftrace_ops, ips, cnt, remove, reset);
> +}
> +#endif
> #else
> static int fprobe_ftrace_add_ips(unsigned long *addrs, int num)
> {
> @@ -349,7 +359,15 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
> {
> return false;
> }
> +
> +#ifdef CONFIG_MODULES
> +static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove,
> + int reset)
> +{
> + ftrace_set_filter_ips(&fprobe_graph_ops.ops, ips, cnt, remove, reset);
> +}
> #endif
> +#endif /* !CONFIG_DYNAMIC_FTRACE_WITH_ARGS && !CONFIG_DYNAMIC_FTRACE_WITH_REGS */
>
> /* fgraph_ops callback, this processes fprobes which have exit_handler. */
> static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
> @@ -596,14 +614,8 @@ static int fprobe_module_callback(struct notifier_block *nb,
> } while (node == ERR_PTR(-EAGAIN));
> rhashtable_walk_exit(&iter);
>
> - if (alist.index > 0) {
> - ftrace_set_filter_ips(&fprobe_graph_ops.ops,
> - alist.addrs, alist.index, 1, 0);
> -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> - ftrace_set_filter_ips(&fprobe_ftrace_ops,
> - alist.addrs, alist.index, 1, 0);
> -#endif
> - }
> + if (alist.index > 0)
> + fprobe_set_ips(alist.addrs, alist.index, 1, 0);
> mutex_unlock(&fprobe_mutex);
>
> kfree(alist.addrs);
> --
> 2.51.2
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-03 13:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 6:34 [PATCH v3] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
2025-11-03 13:52 ` Masami Hiramatsu
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).