Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1386231 > unrolled thread

[RFC] perf probe: Fix offline module name missmatch issue

Started byRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
First post2016-04-25 12:50 +0200
Last post2016-04-26 16:40 +0200
Articles 9 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [RFC] perf probe: Fix offline module name missmatch issue Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-04-25 12:50 +0200
    Re: [RFC] perf probe: Fix offline module name missmatch issue Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-25 23:30 +0200
      Re: [RFC] perf probe: Fix offline module name missmatch issue Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-26 04:20 +0200
        Re: [RFC] perf probe: Fix offline module name missmatch issue Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-04-26 11:10 +0200
      Re: [RFC] perf probe: Fix offline module name missmatch issue Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-04-26 11:00 +0200
        Re: [RFC] perf probe: Fix offline module name missmatch issue "Wangnan (F)" <wangnan0@huawei.com> - 2016-04-26 11:20 +0200
          Re: [RFC] perf probe: Fix offline module name missmatch issue Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-04-26 12:50 +0200
        Re: [RFC] perf probe: Fix offline module name missmatch issue Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-26 12:50 +0200
          Re: [RFC] perf probe: Fix offline module name missmatch issue Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-04-26 16:40 +0200

#1386231 — [RFC] perf probe: Fix offline module name missmatch issue

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-04-25 12:50 +0200
Subject[RFC] perf probe: Fix offline module name missmatch issue
Message-ID<rrM5Q-4ay-5@gated-at.bofh.it>
Perf can add a probe on kernel module which has not been loaded yet.
Current implementation finds module name from path. But if filename
is different from actual module name then perf fails to register
probe while loading module because of mismatch in names. For example,
samples/kobject/kobject-example.ko is loaded as kobject_example.

Before applying patch:

  $ sudo ./perf probe -m /linux/samples/kobject/kobject-example.ko foo_show
    Added new event:
      probe:foo_show       (on foo_show in kobject-example)

    You can now use it in all perf tools, such as:

    perf record -e probe:foo_show -aR sleep 1

  $ cat /sys/kernel/debug/tracing/kprobe_events
    p:probe/foo_show kobject-example:foo_show

  $ insmod kobject-example.ko

  $ lsmod
    Module                  Size  Used by
    kobject_example        16384  0

  Generate read to /sys/kernel/kobject_example/foo while recording data
  with below command
  $ sudo ./perf record -e probe:foo_show -a
    [ perf record: Woken up 1 times to write data ]
    [ perf record: Captured and wrote 0.093 MB perf.data ]

  $./perf report --stdio -F overhead,comm,dso,sym
    Error:
    The perf.data.old file has no samples!

After applying patch:

  $ sudo ./perf probe -m /linux/samples/kobject/kobject-example.ko foo_show
    Added new event:
      probe:foo_show       (on foo_show in kobject_example)

    You can now use it in all perf tools, such as:

    perf record -e probe:foo_show -aR sleep 1

  $ sudo cat /sys/kernel/debug/tracing/kprobe_events
    p:probe/foo_show kobject_example:foo_show

  $ insmod kobject-example.ko

  $ lsmod
    Module                  Size  Used by
    kobject_example        16384  0

  Generate read to /sys/kernel/kobject_example/foo while recording data
  with below command
  $ sudo ./perf record -e probe:foo_show -a
    [ perf record: Woken up 1 times to write data ]
    [ perf record: Captured and wrote 0.097 MB perf.data (8 samples) ]

  $ sudo ./perf report  --stdio -F overhead,comm,dso,sym
    ...
    # Samples: 8  of event 'probe:foo_show'
    # Event count (approx.): 8
    #
    # Overhead  Command  Shared Object      Symbol
    # ........  .......  .................  ............
    #
       100.00%  cat      [kobject_example]  [k] foo_show

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
---
 tools/perf/util/probe-event.c | 78 +++++++++++++++++++++++++++++++++++--------
 tools/perf/util/probe-event.h |  2 ++
 2 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 8319fbb..05d0905 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
 	return true;
 }
 
+/*
+ * NOTE:
+ * '.gnu.linkonce.this_module' section of kernel module elf directly
+ * maps to 'struct module' from linux/module.h. This section contains
+ * actual module name which will be used by kernel after loading it.
+ * But, we cannot use 'struct module' here since linux/module.h is not
+ * exposed to user-space. Offset of 'name' has remained same from long
+ * time, so hardcoding it here.
+ */
+#ifdef __LP64__
+#define MOD_NAME_OFFSET 24
+#else
+#define MOD_NAME_OFFSET 12
+#endif
+
+/*
+ * @module can be module name of module file path. In case of path,
+ * inspect elf and find out what is actual module name.
+ * Caller has to free mod_name after using it.
+ */
+char *find_module_name(const char *module)
+{
+	int fd;
+	Elf *elf;
+	GElf_Ehdr ehdr;
+	GElf_Shdr shdr;
+	Elf_Data *data;
+	Elf_Scn *sec;
+	char *mod_name = NULL;
+
+	fd = open(module, O_RDONLY);
+	if (fd < 0)
+		return NULL;
+
+	elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
+	if (elf == NULL)
+		goto elf_err;
+
+	if (gelf_getehdr(elf, &ehdr) == NULL)
+		goto ret_err;
+
+	sec = elf_section_by_name(elf, &ehdr, &shdr,
+			".gnu.linkonce.this_module", NULL);
+	if (!sec)
+		goto ret_err;
+
+	data = elf_getdata(sec, NULL);
+	if (!data || !data->d_buf)
+		goto ret_err;
+
+	mod_name = strdup((char *)data->d_buf + MOD_NAME_OFFSET);
+
+ret_err:
+	elf_end(elf);
+elf_err:
+	close(fd);
+	return mod_name;
+}
+
 #ifdef HAVE_DWARF_SUPPORT
 
 static int kernel_get_module_dso(const char *module, struct dso **pdso)
@@ -583,32 +642,23 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
 					    int ntevs, const char *module)
 {
 	int i, ret = 0;
-	char *tmp;
+	char *mod_name;
 
 	if (!module)
 		return 0;
 
-	tmp = strrchr(module, '/');
-	if (tmp) {
-		/* This is a module path -- get the module name */
-		module = strdup(tmp + 1);
-		if (!module)
-			return -ENOMEM;
-		tmp = strchr(module, '.');
-		if (tmp)
-			*tmp = '\0';
-		tmp = (char *)module;	/* For free() */
-	}
+	mod_name = find_module_name(module);
 
 	for (i = 0; i < ntevs; i++) {
-		tevs[i].point.module = strdup(module);
+		tevs[i].point.module =
+			strdup(mod_name ? mod_name : module);
 		if (!tevs[i].point.module) {
 			ret = -ENOMEM;
 			break;
 		}
 	}
 
-	free(tmp);
+	free(mod_name);
 	return ret;
 }
 
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index e54e7b0..0468fa3 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -166,4 +166,6 @@ int e_snprintf(char *str, size_t size, const char *format, ...)
 int copy_to_probe_trace_arg(struct probe_trace_arg *tvar,
 			    struct perf_probe_arg *pvar);
 
+char *find_module_name(const char *module);
+
 #endif /*_PROBE_EVENT_H */
-- 
2.1.4

[toc] | [next] | [standalone]


#1386905

FromMasami Hiramatsu <mhiramat@kernel.org>
Date2016-04-25 23:30 +0200
Message-ID<rrWeR-49v-3@gated-at.bofh.it>
In reply to#1386231
Hi Ravi,

On Mon, 25 Apr 2016 16:08:27 +0530
Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:

> Perf can add a probe on kernel module which has not been loaded yet.
> Current implementation finds module name from path. But if filename
> is different from actual module name then perf fails to register
> probe while loading module because of mismatch in names. For example,
> samples/kobject/kobject-example.ko is loaded as kobject_example.

Ah! right, good catch!
Have some comment below;

>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 8319fbb..05d0905 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
>  	return true;
>  }
>  
> +/*
> + * NOTE:
> + * '.gnu.linkonce.this_module' section of kernel module elf directly
> + * maps to 'struct module' from linux/module.h. This section contains
> + * actual module name which will be used by kernel after loading it.
> + * But, we cannot use 'struct module' here since linux/module.h is not
> + * exposed to user-space. Offset of 'name' has remained same from long
> + * time, so hardcoding it here.
> + */
> +#ifdef __LP64__
> +#define MOD_NAME_OFFSET 24
> +#else
> +#define MOD_NAME_OFFSET 12
> +#endif
> +
> +/*
> + * @module can be module name of module file path. In case of path,
> + * inspect elf and find out what is actual module name.
> + * Caller has to free mod_name after using it.
> + */
> +char *find_module_name(const char *module)

Could you make this function static, since there is no caller outside
this file?

> +{
> +	int fd;
> +	Elf *elf;
> +	GElf_Ehdr ehdr;
> +	GElf_Shdr shdr;
> +	Elf_Data *data;
> +	Elf_Scn *sec;
> +	char *mod_name = NULL;
> +
> +	fd = open(module, O_RDONLY);
> +	if (fd < 0)
> +		return NULL;
> +
> +	elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
> +	if (elf == NULL)
> +		goto elf_err;
> +
> +	if (gelf_getehdr(elf, &ehdr) == NULL)
> +		goto ret_err;
> +
> +	sec = elf_section_by_name(elf, &ehdr, &shdr,
> +			".gnu.linkonce.this_module", NULL);
> +	if (!sec)
> +		goto ret_err;
> +
> +	data = elf_getdata(sec, NULL);
> +	if (!data || !data->d_buf)
> +		goto ret_err;
> +
> +	mod_name = strdup((char *)data->d_buf + MOD_NAME_OFFSET);
> +
> +ret_err:
> +	elf_end(elf);
> +elf_err:
> +	close(fd);
> +	return mod_name;
> +}
> +
>  #ifdef HAVE_DWARF_SUPPORT
>  
>  static int kernel_get_module_dso(const char *module, struct dso **pdso)
> @@ -583,32 +642,23 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
>  					    int ntevs, const char *module)
>  {
>  	int i, ret = 0;
> -	char *tmp;
> +	char *mod_name;
>  
>  	if (!module)
>  		return 0;
>  
> -	tmp = strrchr(module, '/');
> -	if (tmp) {
> -		/* This is a module path -- get the module name */
> -		module = strdup(tmp + 1);
> -		if (!module)
> -			return -ENOMEM;
> -		tmp = strchr(module, '.');
> -		if (tmp)
> -			*tmp = '\0';
> -		tmp = (char *)module;	/* For free() */
> -	}
> +	mod_name = find_module_name(module);
>  
>  	for (i = 0; i < ntevs; i++) {
> -		tevs[i].point.module = strdup(module);
> +		tevs[i].point.module =
> +			strdup(mod_name ? mod_name : module);
>  		if (!tevs[i].point.module) {
>  			ret = -ENOMEM;
>  			break;
>  		}
>  	}
>  
> -	free(tmp);
> +	free(mod_name);
>  	return ret;
>  }
>  
> diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
> index e54e7b0..0468fa3 100644
> --- a/tools/perf/util/probe-event.h
> +++ b/tools/perf/util/probe-event.h
> @@ -166,4 +166,6 @@ int e_snprintf(char *str, size_t size, const char *format, ...)
>  int copy_to_probe_trace_arg(struct probe_trace_arg *tvar,
>  			    struct perf_probe_arg *pvar);
>  
> +char *find_module_name(const char *module);

And remove this.

Others looks good to me!

Thank you,

> +
>  #endif /*_PROBE_EVENT_H */
> -- 
> 2.1.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1387083

FromMasami Hiramatsu <mhiramat@kernel.org>
Date2016-04-26 04:20 +0200
Message-ID<rs0Lw-89e-9@gated-at.bofh.it>
In reply to#1386905
On Tue, 26 Apr 2016 06:24:38 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:
> > +/*
> > + * NOTE:
> > + * '.gnu.linkonce.this_module' section of kernel module elf directly
> > + * maps to 'struct module' from linux/module.h. This section contains
> > + * actual module name which will be used by kernel after loading it.
> > + * But, we cannot use 'struct module' here since linux/module.h is not
> > + * exposed to user-space. Offset of 'name' has remained same from long
> > + * time, so hardcoding it here.
> > + */

BTW, is there no way to get the module name avoiding to access
this "hidden" data structure?
This looks very tricky way...

Thanks,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1387255

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-04-26 11:10 +0200
Message-ID<rs7ak-4SP-35@gated-at.bofh.it>
In reply to#1387083
Thanks Masami,

On Tuesday 26 April 2016 07:49 AM, Masami Hiramatsu wrote:
> On Tue, 26 Apr 2016 06:24:38 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
>>> +/*
>>> + * NOTE:
>>> + * '.gnu.linkonce.this_module' section of kernel module elf directly
>>> + * maps to 'struct module' from linux/module.h. This section contains
>>> + * actual module name which will be used by kernel after loading it.
>>> + * But, we cannot use 'struct module' here since linux/module.h is not
>>> + * exposed to user-space. Offset of 'name' has remained same from long
>>> + * time, so hardcoding it here.
>>> + */
> BTW, is there no way to get the module name avoiding to access
> this "hidden" data structure?
> This looks very tricky way...

So this is the same approach kernel use to find module name when module is
loaded. Please refer this function for more detail:

kernel/module.c ::  static struct module *setup_load_info(...)

Regards,
Ravi

[toc] | [prev] | [next] | [standalone]


#1387237

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-04-26 11:00 +0200
Message-ID<rs70C-4qA-17@gated-at.bofh.it>
In reply to#1386905
Thanks Masami for reviewing.

Please find my replies to your comment.

On Tuesday 26 April 2016 02:54 AM, Masami Hiramatsu wrote:
> Hi Ravi,
>
> On Mon, 25 Apr 2016 16:08:27 +0530
> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>
>> Perf can add a probe on kernel module which has not been loaded yet.
>> Current implementation finds module name from path. But if filename
>> is different from actual module name then perf fails to register
>> probe while loading module because of mismatch in names. For example,
>> samples/kobject/kobject-example.ko is loaded as kobject_example.
> Ah! right, good catch!
> Have some comment below;
>
>> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
>> index 8319fbb..05d0905 100644
>> --- a/tools/perf/util/probe-event.c
>> +++ b/tools/perf/util/probe-event.c
>> @@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
>>   	return true;
>>   }
>>   
>> +/*
>> + * NOTE:
>> + * '.gnu.linkonce.this_module' section of kernel module elf directly
>> + * maps to 'struct module' from linux/module.h. This section contains
>> + * actual module name which will be used by kernel after loading it.
>> + * But, we cannot use 'struct module' here since linux/module.h is not
>> + * exposed to user-space. Offset of 'name' has remained same from long
>> + * time, so hardcoding it here.
>> + */
>> +#ifdef __LP64__
>> +#define MOD_NAME_OFFSET 24
>> +#else
>> +#define MOD_NAME_OFFSET 12
>> +#endif
>> +
>> +/*
>> + * @module can be module name of module file path. In case of path,
>> + * inspect elf and find out what is actual module name.
>> + * Caller has to free mod_name after using it.
>> + */
>> +char *find_module_name(const char *module)
> Could you make this function static, since there is no caller outside
> this file?

Yes. no caller outside of this file. But,

In this patch, function find_module_name is defined outside of
#ifdef HAVE_DWARF_SUPPORT while it's being called from inside of
#ifdef HAVE_DWARF_SUPPORT.

If I make it static and if there is no dwarf support, there will be 
compilation
error about function defined but not used.

And in second patch("perf probe: Fix module probe issue if no dwarf 
support"),
I'm calling it from outside of #ifdef HAVE_DWARF_SUPPORT.

So I have two options:
1. merge both the patches and make definition as static
2. make function static in second patch

I've chose second approach and sent v2. But please let me know if there is
better way to do it.

Regards,
Ravi

[toc] | [prev] | [next] | [standalone]


#1387274

From"Wangnan (F)" <wangnan0@huawei.com>
Date2016-04-26 11:20 +0200
Message-ID<rs7jZ-4Yn-11@gated-at.bofh.it>
In reply to#1387237

On 2016/4/26 16:56, Ravi Bangoria wrote:
> Thanks Masami for reviewing.
>
> Please find my replies to your comment.
>
> On Tuesday 26 April 2016 02:54 AM, Masami Hiramatsu wrote:
>> Hi Ravi,
>>
>> On Mon, 25 Apr 2016 16:08:27 +0530
>> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>>
>>> Perf can add a probe on kernel module which has not been loaded yet.
>>> Current implementation finds module name from path. But if filename
>>> is different from actual module name then perf fails to register
>>> probe while loading module because of mismatch in names. For example,
>>> samples/kobject/kobject-example.ko is loaded as kobject_example.
>> Ah! right, good catch!
>> Have some comment below;
>>
>>> diff --git a/tools/perf/util/probe-event.c 
>>> b/tools/perf/util/probe-event.c
>>> index 8319fbb..05d0905 100644
>>> --- a/tools/perf/util/probe-event.c
>>> +++ b/tools/perf/util/probe-event.c
>>> @@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char 
>>> *symbol, unsigned long address)
>>>       return true;
>>>   }
>>>   +/*
>>> + * NOTE:
>>> + * '.gnu.linkonce.this_module' section of kernel module elf directly
>>> + * maps to 'struct module' from linux/module.h. This section contains
>>> + * actual module name which will be used by kernel after loading it.
>>> + * But, we cannot use 'struct module' here since linux/module.h is not
>>> + * exposed to user-space. Offset of 'name' has remained same from long
>>> + * time, so hardcoding it here.
>>> + */
>>> +#ifdef __LP64__
>>> +#define MOD_NAME_OFFSET 24
>>> +#else
>>> +#define MOD_NAME_OFFSET 12
>>> +#endif
>>> +
>>> +/*
>>> + * @module can be module name of module file path. In case of path,
>>> + * inspect elf and find out what is actual module name.
>>> + * Caller has to free mod_name after using it.
>>> + */
>>> +char *find_module_name(const char *module)
>> Could you make this function static, since there is no caller outside
>> this file?
>
> Yes. no caller outside of this file. But,
>
> In this patch, function find_module_name is defined outside of
> #ifdef HAVE_DWARF_SUPPORT while it's being called from inside of
> #ifdef HAVE_DWARF_SUPPORT.
>
> If I make it static and if there is no dwarf support, there will be 
> compilation
> error about function defined but not used.
>
> And in second patch("perf probe: Fix module probe issue if no dwarf 
> support"),
> I'm calling it from outside of #ifdef HAVE_DWARF_SUPPORT.
>
> So I have two options:
> 1. merge both the patches and make definition as static
> 2. make function static in second patch
>
> I've chose second approach and sent v2. But please let me know if 
> there is
> better way to do it.
>

Try __maybe_unused directive?

Thank you.

[toc] | [prev] | [next] | [standalone]


#1387356

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-04-26 12:50 +0200
Message-ID<rs8J4-691-11@gated-at.bofh.it>
In reply to#1387274

On Tuesday 26 April 2016 02:45 PM, Wangnan (F) wrote:
>
>
> On 2016/4/26 16:56, Ravi Bangoria wrote:
>> Thanks Masami for reviewing.
>>
>> Please find my replies to your comment.
>>
>> On Tuesday 26 April 2016 02:54 AM, Masami Hiramatsu wrote:
>>> Hi Ravi,
>>>
>>> On Mon, 25 Apr 2016 16:08:27 +0530
>>> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>>>
>>>> Perf can add a probe on kernel module which has not been loaded yet.
>>>> Current implementation finds module name from path. But if filename
>>>> is different from actual module name then perf fails to register
>>>> probe while loading module because of mismatch in names. For example,
>>>> samples/kobject/kobject-example.ko is loaded as kobject_example.
>>> Ah! right, good catch!
>>> Have some comment below;
>>>
>>>> diff --git a/tools/perf/util/probe-event.c 
>>>> b/tools/perf/util/probe-event.c
>>>> index 8319fbb..05d0905 100644
>>>> --- a/tools/perf/util/probe-event.c
>>>> +++ b/tools/perf/util/probe-event.c
>>>> @@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char 
>>>> *symbol, unsigned long address)
>>>>       return true;
>>>>   }
>>>>   +/*
>>>> + * NOTE:
>>>> + * '.gnu.linkonce.this_module' section of kernel module elf directly
>>>> + * maps to 'struct module' from linux/module.h. This section contains
>>>> + * actual module name which will be used by kernel after loading it.
>>>> + * But, we cannot use 'struct module' here since linux/module.h is 
>>>> not
>>>> + * exposed to user-space. Offset of 'name' has remained same from 
>>>> long
>>>> + * time, so hardcoding it here.
>>>> + */
>>>> +#ifdef __LP64__
>>>> +#define MOD_NAME_OFFSET 24
>>>> +#else
>>>> +#define MOD_NAME_OFFSET 12
>>>> +#endif
>>>> +
>>>> +/*
>>>> + * @module can be module name of module file path. In case of path,
>>>> + * inspect elf and find out what is actual module name.
>>>> + * Caller has to free mod_name after using it.
>>>> + */
>>>> +char *find_module_name(const char *module)
>>> Could you make this function static, since there is no caller outside
>>> this file?
>>
>> Yes. no caller outside of this file. But,
>>
>> In this patch, function find_module_name is defined outside of
>> #ifdef HAVE_DWARF_SUPPORT while it's being called from inside of
>> #ifdef HAVE_DWARF_SUPPORT.
>>
>> If I make it static and if there is no dwarf support, there will be 
>> compilation
>> error about function defined but not used.
>>
>> And in second patch("perf probe: Fix module probe issue if no dwarf 
>> support"),
>> I'm calling it from outside of #ifdef HAVE_DWARF_SUPPORT.
>>
>> So I have two options:
>> 1. merge both the patches and make definition as static
>> 2. make function static in second patch
>>
>> I've chose second approach and sent v2. But please let me know if 
>> there is
>> better way to do it.
>>
>
> Try __maybe_unused directive?
>

Thanks Wangnan for suggestion,

Actually I tried to use __maybe_unused with definition of 
find_module_name but
it throws following compilation error:

util/probe-event.c:289:1: error: expected ‘,’ or ‘;’ before ‘{’ token
  {
  ^
util/probe-event.c:288:14: error: ‘find_module_name’ declared ‘static’ 
but never defined [-Werror=unused-function]
  static char *find_module_name(const char *module) __maybe_unused
               ^
   CC       util/zlib.o
cc1: all warnings being treated as errors


I've to declare prototype of function with __maybe_unused before it's 
definition to
resolve this error. And, anyway this is temporary and need to be removed 
in patch 2,
I think no need to do this change.

Regards,
Ravi

[toc] | [prev] | [next] | [standalone]


#1387358

FromMasami Hiramatsu <mhiramat@kernel.org>
Date2016-04-26 12:50 +0200
Message-ID<rs8J4-691-15@gated-at.bofh.it>
In reply to#1387237
On Tue, 26 Apr 2016 14:26:48 +0530
Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:

> Thanks Masami for reviewing.
> 
> Please find my replies to your comment.
> 
> On Tuesday 26 April 2016 02:54 AM, Masami Hiramatsu wrote:
> > Hi Ravi,
> >
> > On Mon, 25 Apr 2016 16:08:27 +0530
> > Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
> >
> >> Perf can add a probe on kernel module which has not been loaded yet.
> >> Current implementation finds module name from path. But if filename
> >> is different from actual module name then perf fails to register
> >> probe while loading module because of mismatch in names. For example,
> >> samples/kobject/kobject-example.ko is loaded as kobject_example.
> > Ah! right, good catch!
> > Have some comment below;
> >
> >> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> >> index 8319fbb..05d0905 100644
> >> --- a/tools/perf/util/probe-event.c
> >> +++ b/tools/perf/util/probe-event.c
> >> @@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
> >>   	return true;
> >>   }
> >>   
> >> +/*
> >> + * NOTE:
> >> + * '.gnu.linkonce.this_module' section of kernel module elf directly
> >> + * maps to 'struct module' from linux/module.h. This section contains
> >> + * actual module name which will be used by kernel after loading it.
> >> + * But, we cannot use 'struct module' here since linux/module.h is not
> >> + * exposed to user-space. Offset of 'name' has remained same from long
> >> + * time, so hardcoding it here.
> >> + */
> >> +#ifdef __LP64__
> >> +#define MOD_NAME_OFFSET 24
> >> +#else
> >> +#define MOD_NAME_OFFSET 12
> >> +#endif
> >> +
> >> +/*
> >> + * @module can be module name of module file path. In case of path,
> >> + * inspect elf and find out what is actual module name.
> >> + * Caller has to free mod_name after using it.
> >> + */
> >> +char *find_module_name(const char *module)
> > Could you make this function static, since there is no caller outside
> > this file?
> 
> Yes. no caller outside of this file. But,
> 
> In this patch, function find_module_name is defined outside of
> #ifdef HAVE_DWARF_SUPPORT while it's being called from inside of
> #ifdef HAVE_DWARF_SUPPORT.
> 
> If I make it static and if there is no dwarf support, there will be 
> compilation
> error about function defined but not used.
> 
> And in second patch("perf probe: Fix module probe issue if no dwarf 
> support"),
> I'm calling it from outside of #ifdef HAVE_DWARF_SUPPORT.
> 
> So I have two options:
> 1. merge both the patches and make definition as static
> 2. make function static in second patch
> 
> I've chose second approach and sent v2. But please let me know if there is
> better way to do it.

Ah, I see.
In that case, you can swap the patch in the series and move find_module_name
in the other patch ;)

Thanks!

-- 
Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1387551

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-04-26 16:40 +0200
Message-ID<rscjE-TC-37@gated-at.bofh.it>
In reply to#1387358

On Tuesday 26 April 2016 04:16 PM, Masami Hiramatsu wrote:
> On Tue, 26 Apr 2016 14:26:48 +0530
> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>
>> Thanks Masami for reviewing.
>>
>> Please find my replies to your comment.
>>
>> On Tuesday 26 April 2016 02:54 AM, Masami Hiramatsu wrote:
>>> Hi Ravi,
>>>
>>> On Mon, 25 Apr 2016 16:08:27 +0530
>>> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>>>
>>>> Perf can add a probe on kernel module which has not been loaded yet.
>>>> Current implementation finds module name from path. But if filename
>>>> is different from actual module name then perf fails to register
>>>> probe while loading module because of mismatch in names. For example,
>>>> samples/kobject/kobject-example.ko is loaded as kobject_example.
>>> Ah! right, good catch!
>>> Have some comment below;
>>>
>>>> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
>>>> index 8319fbb..05d0905 100644
>>>> --- a/tools/perf/util/probe-event.c
>>>> +++ b/tools/perf/util/probe-event.c
>>>> @@ -265,6 +265,65 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
>>>>    	return true;
>>>>    }
>>>>    
>>>> +/*
>>>> + * NOTE:
>>>> + * '.gnu.linkonce.this_module' section of kernel module elf directly
>>>> + * maps to 'struct module' from linux/module.h. This section contains
>>>> + * actual module name which will be used by kernel after loading it.
>>>> + * But, we cannot use 'struct module' here since linux/module.h is not
>>>> + * exposed to user-space. Offset of 'name' has remained same from long
>>>> + * time, so hardcoding it here.
>>>> + */
>>>> +#ifdef __LP64__
>>>> +#define MOD_NAME_OFFSET 24
>>>> +#else
>>>> +#define MOD_NAME_OFFSET 12
>>>> +#endif
>>>> +
>>>> +/*
>>>> + * @module can be module name of module file path. In case of path,
>>>> + * inspect elf and find out what is actual module name.
>>>> + * Caller has to free mod_name after using it.
>>>> + */
>>>> +char *find_module_name(const char *module)
>>> Could you make this function static, since there is no caller outside
>>> this file?
>> Yes. no caller outside of this file. But,
>>
>> In this patch, function find_module_name is defined outside of
>> #ifdef HAVE_DWARF_SUPPORT while it's being called from inside of
>> #ifdef HAVE_DWARF_SUPPORT.
>>
>> If I make it static and if there is no dwarf support, there will be
>> compilation
>> error about function defined but not used.
>>
>> And in second patch("perf probe: Fix module probe issue if no dwarf
>> support"),
>> I'm calling it from outside of #ifdef HAVE_DWARF_SUPPORT.
>>
>> So I have two options:
>> 1. merge both the patches and make definition as static
>> 2. make function static in second patch
>>
>> I've chose second approach and sent v2. But please let me know if there is
>> better way to do it.
> Ah, I see.
> In that case, you can swap the patch in the series and move find_module_name
> in the other patch ;)

Thanks :)  Sent patch with changes. Please review it.

Regards,
Ravi

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web