linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* kallsyms_lookup_name should return the text addres
@ 2006-01-10 20:39 Anil S Keshavamurthy
  2006-01-10 20:39 ` [patch 1/2] [BUG]kallsyms_lookup_name " Anil S Keshavamurthy
  2006-01-10 20:39 ` [patch 2/2] Link new module to the tail of module list Anil S Keshavamurthy
  0 siblings, 2 replies; 12+ messages in thread
From: Anil S Keshavamurthy @ 2006-01-10 20:39 UTC (permalink / raw)
  To: Linux Kernel, akpm; +Cc: tony.luck, Systemtap, Jim Keniston, Keith Owens

On architectures like IA64, kallsyms_lookup_name(name) returns
the actual text address corresponding to the "name" and sometimes
returns address of the function descriptor, the behavior is
not consistent.

The bug is kallsyms_lookup_name() -> module_kallsyms_lookup_name(mod, name)
search the name in the given module and returns the address when
name is matched. This address very well could be the address of 'U' type
which is different address than 't' type.

Example:
Here is the output of cat /proc/kallsyms when we have test1.ko using the
my_test_reentrant_export_function.
-----------------------------------------------------------------
a00000020008c090 U my_test_reentrant_export_function    [test1]
a00000020008c0a0 r __ksymtab_my_test_reentrant_export_function  [mon_dummy]
a00000020008c0b0 r __kstrtab_my_test_reentrant_export_function  [mon_dummy]
a00000020008c0d8 r __kcrctab_my_test_reentrant_export_function  [mon_dummy]
00000000a356bab8 a __crc_my_test_reentrant_export_function      [mon_dummy]
a00000020008c000 T my_test_reentrant_export_function    [mon_dummy]
---------------------------------------------------------------

When we have test1.ko loaded, 
kallsyms_lookup_name(my_test_reentrant_export_function)
returns 0xa00000020008c090 which is a function descriptor address and 
when test1.ko is removed
kallsyms_lookup_name(my_test_reentrant_export_function)
returns 0xa00000020008c000 which is the actual text address

The patch following this mail fixes this issue.

-Anil Keshavamurthy


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

* [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-10 20:39 kallsyms_lookup_name should return the text addres Anil S Keshavamurthy
@ 2006-01-10 20:39 ` Anil S Keshavamurthy
  2006-01-10 20:45   ` Paulo Marques
  2006-01-10 20:39 ` [patch 2/2] Link new module to the tail of module list Anil S Keshavamurthy
  1 sibling, 1 reply; 12+ messages in thread
From: Anil S Keshavamurthy @ 2006-01-10 20:39 UTC (permalink / raw)
  To: Linux Kernel, akpm; +Cc: tony.luck, Systemtap, Jim Keniston, Keith Owens

[-- Attachment #1: kallsyms_lookup_name_fix.patch --]
[-- Type: text/plain, Size: 2615 bytes --]

[PATCH][BUG]kallsyms_lookup_name should return the text addres

On architectures like IA64, kallsyms_lookup_name(name) returns
the actual text address corresponding to the "name" and sometimes
returns address of the function descriptor, the behavior is
not consistent.

The bug is kallsyms_lookup_name() -> module_kallsyms_lookup_name(mod, name)
search the name in the given module and returns the address when
name is matched. This address very well could be the address of 'U' type
which is different address than 't' type.

Example:
Here is the output of cat /proc/kallsyms when we have test1.ko using the
my_test_reentrant_export_function.
-----------------------------------------------------------------
a00000020008c090 U my_test_reentrant_export_function    [test1]
a00000020008c0a0 r __ksymtab_my_test_reentrant_export_function  [mon_dummy]
a00000020008c0b0 r __kstrtab_my_test_reentrant_export_function  [mon_dummy]
a00000020008c0d8 r __kcrctab_my_test_reentrant_export_function  [mon_dummy]
00000000a356bab8 a __crc_my_test_reentrant_export_function      [mon_dummy]
a00000020008c000 T my_test_reentrant_export_function    [mon_dummy]
---------------------------------------------------------------

When we have test1.ko loaded, 
kallsyms_lookup_name(my_test_reentrant_export_function)
returns 0xa00000020008c090 which is a function descriptor address and 
when test1.ko is removed
kallsyms_lookup_name(my_test_reentrant_export_function)
returns 0xa00000020008c000 which is the actual text address

The current patch check for 't' type(text type) and always returns
text address. 

With this below fix, kallsyms_lookup_name(name) always 
returns consistent text address.

Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
-------------------------------------------------------------------

 kernel/module.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Index: linux-2.6.15-mm1/kernel/module.c
===================================================================
--- linux-2.6.15-mm1.orig/kernel/module.c
+++ linux-2.6.15-mm1/kernel/module.c
@@ -2085,13 +2085,14 @@ struct module *module_get_kallsym(unsign
 	up(&module_mutex);
 	return NULL;
 }
-
+/* Return the text address corresponding to this name */
 static unsigned long mod_find_symname(struct module *mod, const char *name)
 {
 	unsigned int i;
 
 	for (i = 0; i < mod->num_symtab; i++)
-		if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0)
+		if ((strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0) &&
+			(mod->symtab[i].st_info == 't'))
 			return mod->symtab[i].st_value;
 	return 0;
 }

--


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

* [patch 2/2] Link new module to the tail of module list
  2006-01-10 20:39 kallsyms_lookup_name should return the text addres Anil S Keshavamurthy
  2006-01-10 20:39 ` [patch 1/2] [BUG]kallsyms_lookup_name " Anil S Keshavamurthy
@ 2006-01-10 20:39 ` Anil S Keshavamurthy
  1 sibling, 0 replies; 12+ messages in thread
From: Anil S Keshavamurthy @ 2006-01-10 20:39 UTC (permalink / raw)
  To: Linux Kernel, akpm
  Cc: tony.luck, Systemtap, Jim Keniston, Keith Owens, Anil S Keshavamurthy

[-- Attachment #1: module_link_order.patch --]
[-- Type: text/plain, Size: 1350 bytes --]

[PATCH] Link new module to the tail of module list

When we are linking/adding a new module, it would be
better to insert the new module to the tail of the
module list. 

The reason is when kallsyms_lookup_name(name)
looks for the text address corresponding to the name
from the head of the module list, we always hit the
module exporting the text address first and then the
module using the text address later. This helps
kallsyms_lookup_name() search which indeed need
the text address.

Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
-------------------------------------------------------------------

 kernel/module.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6.15-mm1/kernel/module.c
===================================================================
--- linux-2.6.15-mm1.orig/kernel/module.c
+++ linux-2.6.15-mm1/kernel/module.c
@@ -1911,7 +1911,12 @@ static struct module *load_module(void _
 static int __link_module(void *_mod)
 {
 	struct module *mod = _mod;
-	list_add(&mod->list, &modules);
+	/* Insert the new modules at the tail of the list,
+	 * so kallsyms_lookup_name finds the module exporting
+	 * the text address of a function first and quickens
+	 * the search when searching based on function name
+	 */
+	list_add_tail(&mod->list, &modules);
 	return 0;
 }
 

--


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-10 20:39 ` [patch 1/2] [BUG]kallsyms_lookup_name " Anil S Keshavamurthy
@ 2006-01-10 20:45   ` Paulo Marques
  2006-01-10 21:07     ` Keshavamurthy Anil S
  0 siblings, 1 reply; 12+ messages in thread
From: Paulo Marques @ 2006-01-10 20:45 UTC (permalink / raw)
  To: Anil S Keshavamurthy
  Cc: Linux Kernel, akpm, tony.luck, Systemtap, Jim Keniston, Keith Owens

Anil S Keshavamurthy wrote:
> [...]
> The bug is kallsyms_lookup_name() -> module_kallsyms_lookup_name(mod, name)
> search the name in the given module and returns the address when
> name is matched. This address very well could be the address of 'U' type
> which is different address than 't' type.
> [...]

>  	for (i = 0; i < mod->num_symtab; i++)
> -		if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0)
> +		if ((strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0) &&
> +			(mod->symtab[i].st_info == 't'))

This conflicts with a similar patch from Keith Owens earlier this week.

In his patch he did "mod->symtab[i].st_info != 'U'" instead of 
"mod->symtab[i].st_info == 't'".

I actually prefer Keith's version as it is the one which solves the bug 
by changing as least as possible the current behavior.

-- 
Paulo Marques - www.grupopie.com

Pointy-Haired Boss: I don't see anything that could stand in our way.
            Dilbert: Sanity? Reality? The laws of physics?

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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-10 20:45   ` Paulo Marques
@ 2006-01-10 21:07     ` Keshavamurthy Anil S
  2006-01-10 23:11       ` Keith Owens
  0 siblings, 1 reply; 12+ messages in thread
From: Keshavamurthy Anil S @ 2006-01-10 21:07 UTC (permalink / raw)
  To: Paulo Marques
  Cc: Anil S Keshavamurthy, Linux Kernel, akpm, tony.luck, Systemtap,
	Jim Keniston, Keith Owens

On Tue, Jan 10, 2006 at 08:45:02PM +0000, Paulo Marques wrote:
> 
> This conflicts with a similar patch from Keith Owens earlier this week.
In fact I was the one who brought this issue to Keith and I missed seeing his
patch on the mailing list.

> I actually prefer Keith's version as it is the one which solves the bug 
> by changing as least as possible the current behavior.
That's fine, we can live with Keith's patch.
As long as the bug is solved, I am happy a man:-)

But my [patch 2/2] speeds up the lookup and that can go in, I think.
Please ack that patch if you think so.

-Anil


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-10 21:07     ` Keshavamurthy Anil S
@ 2006-01-10 23:11       ` Keith Owens
  2006-01-10 23:29         ` Keshavamurthy Anil S
  0 siblings, 1 reply; 12+ messages in thread
From: Keith Owens @ 2006-01-10 23:11 UTC (permalink / raw)
  To: Keshavamurthy Anil S
  Cc: Paulo Marques, Linux Kernel, akpm, tony.luck, Systemtap, Jim Keniston

Keshavamurthy Anil S (on Tue, 10 Jan 2006 13:07:37 -0800) wrote:
>On Tue, Jan 10, 2006 at 08:45:02PM +0000, Paulo Marques wrote:
>> 
>> This conflicts with a similar patch from Keith Owens earlier this week.
>In fact I was the one who brought this issue to Keith and I missed seeing his
>patch on the mailing list.
>
>> I actually prefer Keith's version as it is the one which solves the bug 
>> by changing as least as possible the current behavior.
>That's fine, we can live with Keith's patch.
>As long as the bug is solved, I am happy a man:-)
>
>But my [patch 2/2] speeds up the lookup and that can go in, I think.
>Please ack that patch if you think so.

Your second patch changes the behaviour of kallsyms lookup w.r.t
duplicate symbols.


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-10 23:11       ` Keith Owens
@ 2006-01-10 23:29         ` Keshavamurthy Anil S
  2006-01-11  0:02           ` Keith Owens
  0 siblings, 1 reply; 12+ messages in thread
From: Keshavamurthy Anil S @ 2006-01-10 23:29 UTC (permalink / raw)
  To: Keith Owens
  Cc: Keshavamurthy Anil S, Paulo Marques, Linux Kernel, akpm,
	tony.luck, Systemtap, Jim Keniston

On Wed, Jan 11, 2006 at 10:11:26AM +1100, Keith Owens wrote:
> Keshavamurthy Anil S (on Tue, 10 Jan 2006 13:07:37 -0800) wrote:
> >On Tue, Jan 10, 2006 at 08:45:02PM +0000, Paulo Marques wrote:
> >But my [patch 2/2] speeds up the lookup and that can go in, I think.
> >Please ack that patch if you think so.
> 
> Your second patch changes the behaviour of kallsyms lookup w.r.t
> duplicate symbols.
With this send patch, kallsyms lookup first finds 
the real text address which is what we want. If you consider
this as the change in behaviour, what is the negetive effect of this
I am unable to get it.

In fact on arch which has the same address for 'U' and 't' type,
the search will first find the 't' type and ends the search soon, 
if we have my second patch.


regards,
-Anil


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-10 23:29         ` Keshavamurthy Anil S
@ 2006-01-11  0:02           ` Keith Owens
  2006-01-11  0:07             ` Randy.Dunlap
  0 siblings, 1 reply; 12+ messages in thread
From: Keith Owens @ 2006-01-11  0:02 UTC (permalink / raw)
  To: Keshavamurthy Anil S
  Cc: Paulo Marques, Linux Kernel, akpm, tony.luck, Systemtap, Jim Keniston

Keshavamurthy Anil S (on Tue, 10 Jan 2006 15:29:05 -0800) wrote:
>On Wed, Jan 11, 2006 at 10:11:26AM +1100, Keith Owens wrote:
>> Keshavamurthy Anil S (on Tue, 10 Jan 2006 13:07:37 -0800) wrote:
>> >On Tue, Jan 10, 2006 at 08:45:02PM +0000, Paulo Marques wrote:
>> >But my [patch 2/2] speeds up the lookup and that can go in, I think.
>> >Please ack that patch if you think so.
>> 
>> Your second patch changes the behaviour of kallsyms lookup w.r.t
>> duplicate symbols.
>With this send patch, kallsyms lookup first finds 
>the real text address which is what we want. If you consider
>this as the change in behaviour, what is the negetive effect of this
>I am unable to get it.

Local symbols can be (and are) duplicated in the kernel code, and these
duplicate symbols can appear in modules.  Changing the list order of
loaded modules also changes which version of a duplicated symbol is
returned by the kallsyms code.  Not a big deal, but annoying enough to
say "don't change the module list order".

Changing the thread slightly, kallsyms_lookup_name() has never coped
with duplicate local symbols and it cannot do so without changing its
API, and all its callers.  For debugging purposes, it would be nicer if
the kernel did not have any duplicate symbols.  Perhaps some kernel
janitor would like to take that task on.


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-11  0:02           ` Keith Owens
@ 2006-01-11  0:07             ` Randy.Dunlap
  2006-01-11  0:23               ` Keith Owens
  0 siblings, 1 reply; 12+ messages in thread
From: Randy.Dunlap @ 2006-01-11  0:07 UTC (permalink / raw)
  To: Keith Owens
  Cc: Keshavamurthy Anil S, Paulo Marques, Linux Kernel, akpm,
	tony.luck, Systemtap, Jim Keniston

On Wed, 11 Jan 2006, Keith Owens wrote:

> Keshavamurthy Anil S (on Tue, 10 Jan 2006 15:29:05 -0800) wrote:
> >On Wed, Jan 11, 2006 at 10:11:26AM +1100, Keith Owens wrote:
> >> Keshavamurthy Anil S (on Tue, 10 Jan 2006 13:07:37 -0800) wrote:
> >> >On Tue, Jan 10, 2006 at 08:45:02PM +0000, Paulo Marques wrote:
> >> >But my [patch 2/2] speeds up the lookup and that can go in, I think.
> >> >Please ack that patch if you think so.
> >>
> >> Your second patch changes the behaviour of kallsyms lookup w.r.t
> >> duplicate symbols.
> >With this send patch, kallsyms lookup first finds
> >the real text address which is what we want. If you consider
> >this as the change in behaviour, what is the negetive effect of this
> >I am unable to get it.
>
> Local symbols can be (and are) duplicated in the kernel code, and these
> duplicate symbols can appear in modules.  Changing the list order of
> loaded modules also changes which version of a duplicated symbol is
> returned by the kallsyms code.  Not a big deal, but annoying enough to
> say "don't change the module list order".
>
> Changing the thread slightly, kallsyms_lookup_name() has never coped
> with duplicate local symbols and it cannot do so without changing its
> API, and all its callers.  For debugging purposes, it would be nicer if
> the kernel did not have any duplicate symbols.  Perhaps some kernel
> janitor would like to take that task on.

Jesper Juhl was doing some -Wshadow patches.  Would that detect
duplicate symbols?

-- 
~Randy  [sees nothing wrong with dup. local symbols, except for debugging]

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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-11  0:07             ` Randy.Dunlap
@ 2006-01-11  0:23               ` Keith Owens
  2006-01-11  0:39                 ` Keshavamurthy Anil S
  0 siblings, 1 reply; 12+ messages in thread
From: Keith Owens @ 2006-01-11  0:23 UTC (permalink / raw)
  To: Randy.Dunlap
  Cc: Keshavamurthy Anil S, Paulo Marques, Linux Kernel, akpm,
	tony.luck, Systemtap, Jim Keniston

"Randy.Dunlap" (on Tue, 10 Jan 2006 16:07:55 -0800 (PST)) wrote:
>On Wed, 11 Jan 2006, Keith Owens wrote:
>> Changing the thread slightly, kallsyms_lookup_name() has never coped
>> with duplicate local symbols and it cannot do so without changing its
>> API, and all its callers.  For debugging purposes, it would be nicer if
>> the kernel did not have any duplicate symbols.  Perhaps some kernel
>> janitor would like to take that task on.
>
>Jesper Juhl was doing some -Wshadow patches.  Would that detect
>duplicate symbols?

No, the duplicate symbols are (a) static and (b) in separate source
files.  Run this against a System.map.

 awk '{print $NF}' System.map | egrep -v '^__ks|^__func' | sort | uniq -dc | LANG=C sort -k2


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-11  0:23               ` Keith Owens
@ 2006-01-11  0:39                 ` Keshavamurthy Anil S
  2006-01-11  2:26                   ` Frank Ch. Eigler
  0 siblings, 1 reply; 12+ messages in thread
From: Keshavamurthy Anil S @ 2006-01-11  0:39 UTC (permalink / raw)
  To: Keith Owens
  Cc: Randy.Dunlap, Keshavamurthy Anil S, Paulo Marques, Linux Kernel,
	akpm, tony.luck, Systemtap, Jim Keniston

On Wed, Jan 11, 2006 at 11:23:28AM +1100, Keith Owens wrote:
> "Randy.Dunlap" (on Tue, 10 Jan 2006 16:07:55 -0800 (PST)) wrote:
> >On Wed, 11 Jan 2006, Keith Owens wrote:
> >> Changing the thread slightly, kallsyms_lookup_name() has never coped
> >> with duplicate local symbols and it cannot do so without changing its
> >> API, and all its callers.  For debugging purposes, it would be nicer if
> >> the kernel did not have any duplicate symbols.  Perhaps some kernel
> >> janitor would like to take that task on.
> >
> >Jesper Juhl was doing some -Wshadow patches.  Would that detect
> >duplicate symbols?
> 
> No, the duplicate symbols are (a) static and (b) in separate source
> files.  Run this against a System.map.
> 
>  awk '{print $NF}' System.map | egrep -v '^__ks|^__func' | sort | uniq -dc | LANG=C sort -k2

Humm..This duplication of symbols in the kernel will be a 
problem for systemtap scripts, as we might end up putting probes
in the unwanted places :-(

I agree with you Keith, from the debugging purposes, it 
would make sense not to have any duplicate symbols.

Thanks,
Anil


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

* Re: [patch 1/2] [BUG]kallsyms_lookup_name should return the text addres
  2006-01-11  0:39                 ` Keshavamurthy Anil S
@ 2006-01-11  2:26                   ` Frank Ch. Eigler
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Ch. Eigler @ 2006-01-11  2:26 UTC (permalink / raw)
  To: Keshavamurthy Anil S
  Cc: Keith Owens, Randy.Dunlap, Paulo Marques, Linux Kernel, akpm,
	tony.luck, Systemtap, Jim Keniston


anil.s.keshavamurthy@intel.com writes:

> [...]  Humm..This duplication of symbols in the kernel will be a
> problem for systemtap scripts, as we might end up putting probes in
> the unwanted places :-( [...]

Not at all.  Systemtap does not look in System.map.  It can qualify
function names with the compilation unit name to make unique the probe
target.  For that matter, it only uses /proc/kallsyms as a table to
drive the address-to-name mappings in debug output.

- FChE

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

end of thread, other threads:[~2006-01-11  2:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-10 20:39 kallsyms_lookup_name should return the text addres Anil S Keshavamurthy
2006-01-10 20:39 ` [patch 1/2] [BUG]kallsyms_lookup_name " Anil S Keshavamurthy
2006-01-10 20:45   ` Paulo Marques
2006-01-10 21:07     ` Keshavamurthy Anil S
2006-01-10 23:11       ` Keith Owens
2006-01-10 23:29         ` Keshavamurthy Anil S
2006-01-11  0:02           ` Keith Owens
2006-01-11  0:07             ` Randy.Dunlap
2006-01-11  0:23               ` Keith Owens
2006-01-11  0:39                 ` Keshavamurthy Anil S
2006-01-11  2:26                   ` Frank Ch. Eigler
2006-01-10 20:39 ` [patch 2/2] Link new module to the tail of module list Anil S Keshavamurthy

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