linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] samples: Use KSYM_NAME_LEN for fprobe and kprobes
@ 2022-06-07  9:35 Tiezhu Yang
  2022-06-07 16:17 ` Masami Hiramatsu
  0 siblings, 1 reply; 3+ messages in thread
From: Tiezhu Yang @ 2022-06-07  9:35 UTC (permalink / raw)
  To: Masami Hiramatsu, Steven Rostedt; +Cc: Xuefeng Li, linux-kernel

It is better and enough to use KSYM_NAME_LEN for fprobe and kprobes
in samples, no need to define and use the other values.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 samples/fprobe/fprobe_example.c     | 9 ++++-----
 samples/kprobes/kprobe_example.c    | 5 ++---
 samples/kprobes/kretprobe_example.c | 5 ++---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c
index 24d3cf1..1ed1a69 100644
--- a/samples/fprobe/fprobe_example.c
+++ b/samples/fprobe/fprobe_example.c
@@ -19,13 +19,12 @@
 #include <linux/slab.h>
 
 #define BACKTRACE_DEPTH 16
-#define MAX_SYMBOL_LEN 4096
 struct fprobe sample_probe;
 
-static char symbol[MAX_SYMBOL_LEN] = "kernel_clone";
-module_param_string(symbol, symbol, sizeof(symbol), 0644);
-static char nosymbol[MAX_SYMBOL_LEN] = "";
-module_param_string(nosymbol, nosymbol, sizeof(nosymbol), 0644);
+static char symbol[KSYM_NAME_LEN] = "kernel_clone";
+module_param_string(symbol, symbol, KSYM_NAME_LEN, 0644);
+static char nosymbol[KSYM_NAME_LEN] = "";
+module_param_string(nosymbol, nosymbol, KSYM_NAME_LEN, 0644);
 static bool stackdump = true;
 module_param(stackdump, bool, 0644);
 
diff --git a/samples/kprobes/kprobe_example.c b/samples/kprobes/kprobe_example.c
index f991a66..fd346f5 100644
--- a/samples/kprobes/kprobe_example.c
+++ b/samples/kprobes/kprobe_example.c
@@ -16,9 +16,8 @@
 #include <linux/module.h>
 #include <linux/kprobes.h>
 
-#define MAX_SYMBOL_LEN	64
-static char symbol[MAX_SYMBOL_LEN] = "kernel_clone";
-module_param_string(symbol, symbol, sizeof(symbol), 0644);
+static char symbol[KSYM_NAME_LEN] = "kernel_clone";
+module_param_string(symbol, symbol, KSYM_NAME_LEN, 0644);
 
 /* For each probe you need to allocate a kprobe structure */
 static struct kprobe kp = {
diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c
index 228321e..cbf1654 100644
--- a/samples/kprobes/kretprobe_example.c
+++ b/samples/kprobes/kretprobe_example.c
@@ -23,11 +23,10 @@
 #include <linux/module.h>
 #include <linux/kprobes.h>
 #include <linux/ktime.h>
-#include <linux/limits.h>
 #include <linux/sched.h>
 
-static char func_name[NAME_MAX] = "kernel_clone";
-module_param_string(func, func_name, NAME_MAX, S_IRUGO);
+static char func_name[KSYM_NAME_LEN] = "kernel_clone";
+module_param_string(func, func_name, KSYM_NAME_LEN, 0644);
 MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the"
 			" function's execution time");
 
-- 
2.1.0


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

* Re: [PATCH] samples: Use KSYM_NAME_LEN for fprobe and kprobes
  2022-06-07  9:35 [PATCH] samples: Use KSYM_NAME_LEN for fprobe and kprobes Tiezhu Yang
@ 2022-06-07 16:17 ` Masami Hiramatsu
  2022-06-08  0:20   ` Tiezhu Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu @ 2022-06-07 16:17 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: Steven Rostedt, Xuefeng Li, linux-kernel

On Tue,  7 Jun 2022 17:35:36 +0800
Tiezhu Yang <yangtiezhu@loongson.cn> wrote:

> It is better and enough to use KSYM_NAME_LEN for fprobe and kprobes
> in samples, no need to define and use the other values.
> 

This is good for kprobe and kretprobe examples because it will get
a single symbol name, but not good for the fprobe. It can take
several comma separated symbols.

-----
static int __init fprobe_init(void)
{
...
        /* Comma separated symbols */
        symbuf = kstrdup(symbol, GFP_KERNEL);
        if (!symbuf)
                return -ENOMEM;
        p = symbuf;
        count = 1;
        while ((p = strchr(++p, ',')) != NULL)
                count++;

        pr_info("%d symbols found\n", count);
-----

Can you drop the fprobe_example.c part?

Thank you,

> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  samples/fprobe/fprobe_example.c     | 9 ++++-----
>  samples/kprobes/kprobe_example.c    | 5 ++---
>  samples/kprobes/kretprobe_example.c | 5 ++---
>  3 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c
> index 24d3cf1..1ed1a69 100644
> --- a/samples/fprobe/fprobe_example.c
> +++ b/samples/fprobe/fprobe_example.c
> @@ -19,13 +19,12 @@
>  #include <linux/slab.h>
>  
>  #define BACKTRACE_DEPTH 16
> -#define MAX_SYMBOL_LEN 4096
>  struct fprobe sample_probe;
>  
> -static char symbol[MAX_SYMBOL_LEN] = "kernel_clone";
> -module_param_string(symbol, symbol, sizeof(symbol), 0644);
> -static char nosymbol[MAX_SYMBOL_LEN] = "";
> -module_param_string(nosymbol, nosymbol, sizeof(nosymbol), 0644);
> +static char symbol[KSYM_NAME_LEN] = "kernel_clone";
> +module_param_string(symbol, symbol, KSYM_NAME_LEN, 0644);
> +static char nosymbol[KSYM_NAME_LEN] = "";
> +module_param_string(nosymbol, nosymbol, KSYM_NAME_LEN, 0644);
>  static bool stackdump = true;
>  module_param(stackdump, bool, 0644);
>  
> diff --git a/samples/kprobes/kprobe_example.c b/samples/kprobes/kprobe_example.c
> index f991a66..fd346f5 100644
> --- a/samples/kprobes/kprobe_example.c
> +++ b/samples/kprobes/kprobe_example.c
> @@ -16,9 +16,8 @@
>  #include <linux/module.h>
>  #include <linux/kprobes.h>
>  
> -#define MAX_SYMBOL_LEN	64
> -static char symbol[MAX_SYMBOL_LEN] = "kernel_clone";
> -module_param_string(symbol, symbol, sizeof(symbol), 0644);
> +static char symbol[KSYM_NAME_LEN] = "kernel_clone";
> +module_param_string(symbol, symbol, KSYM_NAME_LEN, 0644);
>  
>  /* For each probe you need to allocate a kprobe structure */
>  static struct kprobe kp = {
> diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c
> index 228321e..cbf1654 100644
> --- a/samples/kprobes/kretprobe_example.c
> +++ b/samples/kprobes/kretprobe_example.c
> @@ -23,11 +23,10 @@
>  #include <linux/module.h>
>  #include <linux/kprobes.h>
>  #include <linux/ktime.h>
> -#include <linux/limits.h>
>  #include <linux/sched.h>
>  
> -static char func_name[NAME_MAX] = "kernel_clone";
> -module_param_string(func, func_name, NAME_MAX, S_IRUGO);
> +static char func_name[KSYM_NAME_LEN] = "kernel_clone";
> +module_param_string(func, func_name, KSYM_NAME_LEN, 0644);
>  MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the"
>  			" function's execution time");
>  
> -- 
> 2.1.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

* Re: [PATCH] samples: Use KSYM_NAME_LEN for fprobe and kprobes
  2022-06-07 16:17 ` Masami Hiramatsu
@ 2022-06-08  0:20   ` Tiezhu Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Tiezhu Yang @ 2022-06-08  0:20 UTC (permalink / raw)
  To: Masami Hiramatsu (Google); +Cc: Steven Rostedt, Xuefeng Li, linux-kernel



On 06/08/2022 12:17 AM, Masami Hiramatsu (Google) wrote:
> On Tue,  7 Jun 2022 17:35:36 +0800
> Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
>> It is better and enough to use KSYM_NAME_LEN for fprobe and kprobes
>> in samples, no need to define and use the other values.
>>
>
> This is good for kprobe and kretprobe examples because it will get
> a single symbol name, but not good for the fprobe. It can take
> several comma separated symbols.
>
> -----
> static int __init fprobe_init(void)
> {
> ...
>         /* Comma separated symbols */
>         symbuf = kstrdup(symbol, GFP_KERNEL);
>         if (!symbuf)
>                 return -ENOMEM;
>         p = symbuf;
>         count = 1;
>         while ((p = strchr(++p, ',')) != NULL)
>                 count++;
>
>         pr_info("%d symbols found\n", count);
> -----
>
> Can you drop the fprobe_example.c part?
>

OK, I will send v2 later, thank you.

Thanks,
Tiezhu


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

end of thread, other threads:[~2022-06-08  2:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07  9:35 [PATCH] samples: Use KSYM_NAME_LEN for fprobe and kprobes Tiezhu Yang
2022-06-07 16:17 ` Masami Hiramatsu
2022-06-08  0:20   ` Tiezhu Yang

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).