linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
@ 2025-10-31  2:40 Menglong Dong
  2025-11-01 18:20 ` kernel test robot
  2025-11-03  3:16 ` Masami Hiramatsu
  0 siblings, 2 replies; 4+ messages in thread
From: Menglong Dong @ 2025-10-31  2:40 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>
---
v2:
- remove the definition of FPROBE_USE_FTRACE
---
 kernel/trace/fprobe.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index ecd623eef68b..742ad5a61d46 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,13 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
 {
 	return !fp->exit_handler;
 }
+
+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);
+}
 #else
 static int fprobe_ftrace_add_ips(unsigned long *addrs, int num)
 {
@@ -349,7 +357,13 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
 {
 	return false;
 }
-#endif
+
+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 /* !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 +610,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] 4+ messages in thread

* Re: [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
  2025-10-31  2:40 [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
@ 2025-11-01 18:20 ` kernel test robot
  2025-11-03  3:16 ` Masami Hiramatsu
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-11-01 18:20 UTC (permalink / raw)
  To: Menglong Dong, mhiramat
  Cc: oe-kbuild-all, rostedt, jolsa, mathieu.desnoyers, jiang.biao,
	linux-kernel, linux-trace-kernel

Hi Menglong,

kernel test robot noticed the following build warnings:

[auto build test WARNING on trace/for-next]
[also build test WARNING on next-20251031]
[cannot apply to linus/master v6.18-rc3]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Menglong-Dong/tracing-fprobe-use-ftrace-if-CONFIG_DYNAMIC_FTRACE_WITH_ARGS/20251031-104301
base:   https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next
patch link:    https://lore.kernel.org/r/20251031024038.19176-1-dongml2%40chinatelecom.cn
patch subject: [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
config: loongarch-randconfig-002-20251102 (https://download.01.org/0day-ci/archive/20251102/202511020220.bv169Bd9-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251102/202511020220.bv169Bd9-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511020220.bv169Bd9-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> kernel/trace/fprobe.c:340:13: warning: 'fprobe_set_ips' defined but not used [-Wunused-function]
     340 | static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove,
         |             ^~~~~~~~~~~~~~


vim +/fprobe_set_ips +340 kernel/trace/fprobe.c

   339	
 > 340	static void fprobe_set_ips(unsigned long *ips, unsigned int cnt, int remove,
   341				   int reset)
   342	{
   343		ftrace_set_filter_ips(&fprobe_graph_ops.ops, ips, cnt, remove, reset);
   344		ftrace_set_filter_ips(&fprobe_ftrace_ops, ips, cnt, remove, reset);
   345	}
   346	#else
   347	static int fprobe_ftrace_add_ips(unsigned long *addrs, int num)
   348	{
   349		return -ENOENT;
   350	}
   351	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
  2025-10-31  2:40 [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
  2025-11-01 18:20 ` kernel test robot
@ 2025-11-03  3:16 ` Masami Hiramatsu
  2025-11-03  6:17   ` Menglong Dong
  1 sibling, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2025-11-03  3:16 UTC (permalink / raw)
  To: Menglong Dong
  Cc: rostedt, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
	linux-trace-kernel

On Fri, 31 Oct 2025 10:40:38 +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>
> ---
> v2:
> - remove the definition of FPROBE_USE_FTRACE
> ---
>  kernel/trace/fprobe.c | 30 +++++++++++++++++++-----------
>  1 file changed, 19 insertions(+), 11 deletions(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index ecd623eef68b..742ad5a61d46 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,13 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
>  {
>  	return !fp->exit_handler;
>  }
> +

Ah, the new function depends on MODULES. 

#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	/* CONFIG_MODULES */

>  #else

#ifdef CONFIG_MODULES

>  static int fprobe_ftrace_add_ips(unsigned long *addrs, int num)
>  {
> @@ -349,7 +357,13 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
>  {
>  	return false;
>  }

#endif	/* CONFIG_MODULES */

are needed.

Thank you,

> -#endif
> +
> +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 /* !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 +610,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] 4+ messages in thread

* Re: [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS
  2025-11-03  3:16 ` Masami Hiramatsu
@ 2025-11-03  6:17   ` Menglong Dong
  0 siblings, 0 replies; 4+ messages in thread
From: Menglong Dong @ 2025-11-03  6:17 UTC (permalink / raw)
  To: Menglong Dong, Masami Hiramatsu
  Cc: rostedt, jolsa, mathieu.desnoyers, jiang.biao, linux-kernel,
	linux-trace-kernel

On 2025/11/3 11:16, Masami Hiramatsu wrote:
> On Fri, 31 Oct 2025 10:40:38 +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>
> > ---
> > v2:
> > - remove the definition of FPROBE_USE_FTRACE
> > ---
> >  kernel/trace/fprobe.c | 30 +++++++++++++++++++-----------
> >  1 file changed, 19 insertions(+), 11 deletions(-)
> > 
> > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > index ecd623eef68b..742ad5a61d46 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,13 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
> >  {
> >  	return !fp->exit_handler;
> >  }
> > +
> 
> Ah, the new function depends on MODULES. 
> 
> #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	/* CONFIG_MODULES */

Yeah, I saw the CI's build warning. I'll send a V3 to fix
this issue.

Thanks!
Menglong Dong

> 
> >  #else
> 
> #ifdef CONFIG_MODULES
> 
> >  static int fprobe_ftrace_add_ips(unsigned long *addrs, int num)
> >  {
> > @@ -349,7 +357,13 @@ static bool fprobe_is_ftrace(struct fprobe *fp)
> >  {
> >  	return false;
> >  }
> 
> #endif	/* CONFIG_MODULES */
> 
> are needed.
> 
> Thank you,
> 
> > -#endif
> > +
> > +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 /* !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 +610,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);
> 
> 
> 





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-03  6:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31  2:40 [PATCH v2] tracing: fprobe: use ftrace if CONFIG_DYNAMIC_FTRACE_WITH_ARGS Menglong Dong
2025-11-01 18:20 ` kernel test robot
2025-11-03  3:16 ` Masami Hiramatsu
2025-11-03  6:17   ` 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).