s390/perf:fix 'start' address of module's map
RFC PATCH v4 1/1 s390/perf:fix 'start' address of module's map
Change log:
Quoted 1 line
From V3:
1.move fixup function to tools/perf/arch/s390/util/machine.c;
2. Add acked-by info from Jiri Olsa <[email protected]>;
Quoted 1 line
From V2:
1. remove redundancy string 'module_name';
Quoted 1 line
From V1:
1.change func name from 'fix__arch_module_baseaddr' to 'fix__arch_module_text_start';
2.Parse '.text' start addr from 'sys' through 'sysfs__read_ull', not 'hex2u64()';
2.Perfect code: check return value and allocated pointer by 'strdup'.
Song Shan Gong (1):
s390/perf: fix 'start' address of module's map
tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/sym-handling.c | 27 +++++++++++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 38 insertions(+) create mode 100644 tools/perf/arch/s390/util/sym-handling.c
Signature · 1 line
2.3.0
PATCH 1/1 s390/perf: fix 'start' address of module's map
At preset, when creating module's map, perf gets 'start' address by parsing '/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '/proc/modules'.
--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.c
tools/perf/arch/s390/util/Build +2 -0
@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.o
tools/perf/arch/s390/util/machine.c new file +19 -0
@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}
tools/perf/util/machine.c +8 -0
@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;
tools/perf/util/machine.h +1 -0
@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter);
Signature · 1 line
2.3.0
Re: [PATCH] s390/perf: fix 'start' address of module's map
Has the patch been accepted by upstream?
Quoted 93 lines · Song Shan Gong
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-0@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter);
Signature · 1 line
SongShan Gong
Re: [PATCH] s390/perf: fix 'start' address of module's map
Quoted 15 lines · Songshan Gong
Has the patch been accepted by upstream?
Quoted 12 lines · Song Shan Gong
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>
I think it's good to go, Arnaldo, could you please take this one?
thanks,
jirka
Arnaldo Carvalho de Melo
maintainerRe: [PATCH] s390/perf: fix 'start' address of module's map
In reply to Song Shan GongEm Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.
I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this arch__ hook? I.e. if I look here in my x86_64 notebook I see:
[acme@jouet linux]$ cat /sys/module/tun/sections/.text 0xffffffffc0af2000
[acme@jouet linux]$ grep tun /proc/modules tun 28672 4 vhost_net, Live 0xffffffffc0af2000 [acme@jouet linux]$
So I could as well use what is in /sys/module/tun/sections/.text instead of reading it from /proc/modules and, in s390, reading it from /sys/module/tun/sections/.text.
Do you see any problem with using this approach for _all_ arches?
- Arnaldo
Quoted 87 lines
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-0@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter);Signature · 1 line
2.3.0
Re: [PATCH] s390/perf: fix 'start' address of module's map
Quoted 19 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$
Quoted 5 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
I wouldn't be surprised if other architectures than s390 actually have the same issue, so doing this for everybody might atually fix this somewhere else.
Quoted 91 lines
- Arnaldo
Quoted 87 lines
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-0@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter);Signature · 1 line
2.3.0
Arnaldo Carvalho de Melo
maintainerRe: [PATCH] s390/perf: fix 'start' address of module's map
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 20 lines · Arnaldo Carvalho de Melo
Quoted 19 lines
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$
Quoted 8 lines
Quoted 5 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
Quoted 3 lines
I wouldn't be surprised if other architectures than s390 actually have the same issue, so doing this for everybody might atually fix this somewhere else.
Would be nice to get info from other arch people, Michael, how this goes on ppc?
- Arnaldo
Quoted 91 lines
Quoted 91 lines
- Arnaldo
Quoted 87 lines
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-0@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter);Signature · 1 line
2.3.0
Re: [PATCH] s390/perf: fix 'start' address of module's map
Quoted 34 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 20 lines · Arnaldo Carvalho de Melo
Quoted 19 lines
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$Quoted 8 lines
Quoted 5 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
Quoted 6 lines
Quoted 3 lines
I wouldn't be surprised if other architectures than s390 actually have the same issue, so doing this for everybody might atually fix this somewhere else.
Would be nice to get info from other arch people, Michael, how this goes on ppc?
It doesn't look like this is a problem on powerpc - at least I haven't heard of it.
Looking at a system I have here, for all modules (26) the value in /proc/modules matches the .text section in /sys.
So I think using /sys should be fine for us.
cheers
Re: [PATCH] s390/perf: fix 'start' address of module's map
In reply to Arnaldo Carvalho de MeloQuoted 19 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$
Quoted 4 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.
I also think it should be OK for most archs.
Quoted 92 lines
Do you see any problem with using this approach for _all_ arches?
- Arnaldo
Quoted 87 lines
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-1@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter); --2.3.0
Signature · 1 line
SongShan Gong
Re: [PATCH] s390/perf: fix 'start' address of module's map
In reply to Arnaldo Carvalho de MeloQuoted 25 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 24 lines · Arnaldo Carvalho de Melo
Quoted 23 lines
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
Good idea!
Quoted 102 lines
Quoted 4 lines
I wouldn't be surprised if other architectures than s390 actually have the same issue, so doing this for everybody might atually fix this somewhere else.
Would be nice to get info from other arch people, Michael, how this goes on ppc?
- Arnaldo
Quoted 91 lines
Quoted 91 lines
- Arnaldo
Quoted 87 lines
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-1@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter); --2.3.0
Signature · 1 line
SongShan Gong
tip-bot for Song Shan Gong
merge bot[tip:perf/urgent] perf s390: Fix 'start' address of module's map
In reply to Song Shan Gongperf s390: Fix 'start' address of module's map
Commit-ID: 203d8a4aa6edf2c19206316d439ec5dae52ce581 Gitweb: http://git.kernel.org/tip/203d8a4aa6edf2c19206316d439ec5dae52ce581 Author: Song Shan Gong <[email protected]> AuthorDate: Thu, 21 Jul 2016 11:10:51 +0800 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 26 Jul 2016 16:46:12 -0300
perf s390: Fix 'start' address of module's map
At present, when creating module's map, perf gets 'start' address by parsing '/proc/modules', but it's the module base address, it isn't the start address of the '.text' section.
In most arches, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '/proc/modules'.
--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+)
tools/perf/arch/s390/util/Build +2 -0
@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.o
tools/perf/arch/s390/util/machine.c new file +19 -0
@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}
tools/perf/util/machine.c +8 -0
@@ -1093,12 +1093,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;
tools/perf/util/machine.h +1 -0
@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter);
Re: [PATCH] s390/perf: fix 'start' address of module's map
In reply to Arnaldo Carvalho de MeloQuoted 25 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 24 lines · Arnaldo Carvalho de Melo
Quoted 23 lines
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
One question: how to get arch info except machine->env->arch? It seems that machine->env->arch could be NULL sometimes.
Quoted 101 lines
Quoted 3 lines
I wouldn't be surprised if other architectures than s390 actually have the same issue, so doing this for everybody might atually fix this somewhere else.
Would be nice to get info from other arch people, Michael, how this goes on ppc?
- Arnaldo
Quoted 91 lines
Quoted 91 lines
- Arnaldo
Quoted 87 lines
Fix this bug by getting 'start' address of module's map from parsing '/sys/module/[module name]/sections/.text', not from '
/proc/modules'.Signed-off-by Song Shan Gong <[email protected]>Acked-by Jiri Olsa <[email protected]>--- tools/perf/arch/s390/util/Build | 2 ++ tools/perf/arch/s390/util/machine.c | 19 +++++++++++++++++++ tools/perf/util/machine.c | 8 ++++++++ tools/perf/util/machine.h | 1 + 4 files changed, 30 insertions(+) create mode 100644 tools/perf/arch/s390/util/machine.ctools/perf/arch/s390/util/Build +2
-0@@ -2,3 +2,5 @@ libperf-y += header.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o + +libperf-y += machine.otools/perf/arch/s390/util/machine.c new file +19
-0@@ -0,0 +1,19 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" +#include "machine.h" +#include "api/fs/fs.h" + +int arch__fix_module_text_start (u64 *start,const char *name) +{ +char path[PATH_MAX ]; + +snprintf (path,PATH_MAX ,"module/%.*s/sections/.text" , + (int )strlen (name) -2 , name +1 ); + +if (sysfs__read_ull (path, (unsigned long long *)start) <0 ) +return -1 ; + +return 0 ; +}tools/perf/util/machine.c +8
-0@@ -1091,12 +1091,20 @@ static int machine__set_modules_path(struct machine *machine)return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); } +int __weak arch__fix_module_text_start (u64 *start__maybe_unused , +const char *name__maybe_unused ) +{ +return 0 ; +}static int machine__create_module (void *arg,const char *name,u64 start) {struct machine *machine = arg;struct map *map; +if (arch__fix_module_text_start (&start, name) <0 ) +return -1 ; + map =machine__findnew_module_map (machine, start, name);if (map ==NULL )return -1 ;tools/perf/util/machine.h +1
-1@@ -216,6 +216,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,struct map *machine__findnew_module_map (struct machine *machine,u64 start,const char *filename); +int arch__fix_module_text_start (u64 *start,const char *name);int __machine__load_kallsyms (struct machine *machine,const char *filename,enum map_type type,bool no_kcore,symbol_filter_t filter); --2.3.0
Signature · 1 line
SongShan Gong
Arnaldo Carvalho de Melo
maintainerRe: [PATCH] s390/perf: fix 'start' address of module's map
In reply to Michael EllermanEm Wed, Jul 27, 2016 at 07:24:26PM +1000, Michael Ellerman escreveu:
Quoted 23 lines
Quoted 15 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 9 lines · Arnaldo Carvalho de Melo
Quoted 5 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
Quoted 6 lines
Quoted 3 lines
I wouldn't be surprised if other architectures than s390 actually have the same issue, so doing this for everybody might atually fix this somewhere else.
Would be nice to get info from other arch people, Michael, how this goes on ppc?
Quoted 7 lines
It doesn't look like this is a problem on powerpc - at least I haven't heard of it.
Looking at a system I have here, for all modules (26) the value in
/proc/modulesmatches the .text section in /sys.So I think using /sys should be fine for us.
Thanks for checking.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH] s390/perf: fix 'start' address of module's map
In reply to Songshan GongEm Wed, Jul 27, 2016 at 06:49:48PM +0800, Songshan Gong escreveu:
Quoted 33 lines · Arnaldo Carvalho de Melo
Quoted 30 lines
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 19 lines
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$Quoted 5 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Quoted 6 lines
Quoted 4 lines
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
One question: how to get arch info except
machine->env->arch? It seems thatmachine->env->archcould be NULL sometimes.
That is not what you want to look at, as it is related to perf.data, which may not be related to what you want, which is the running machine.
For that use uname() -> utsname.machine.
But then, why would you need it for reading /sys/module/*/sections/.text? The arch name isn't there :-)
- Arnaldo
Re: [PATCH] s390/perf: fix 'start' address of module's map
Quoted 41 lines · Arnaldo Carvalho de Melo
Em Wed, Jul 27, 2016 at 06:49:48PM +0800, Songshan Gong escreveu:
Quoted 33 lines · Arnaldo Carvalho de Melo
Quoted 30 lines
Em Tue, Jul 26, 2016 at 10:14:18PM +0200, Christian Borntraeger escreveu:
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 19 lines
Em Thu, Jul 21, 2016 at 11:10:51AM +0800, Song Shan Gong escreveu:
Quoted 6 lines
At preset, when creating module's map, perf gets 'start' address by parsing '
/proc/modules', but it's module base address, isn't the start address of '.text' section. In most archs, it's OK. But for s390, it places 'GOT' and 'PLT' relocations before '.text' section. So there exists an offset between module base address and '.text' section, which will incur wrong symbol resolution for modules.I'll apply this as it fixes the problem for you and we need to get fixes in ASAP to get this into 4.8, but why can't we just use your method for all arches and get rid of this
arch__hook? I.e. if I look here in myx86_64notebook I see:[acme@jouet linux]$ cat
/sys/module/tun/sections/.text0xffffffffc0af2000
[acme@jouet linux]$ grep tun/proc/modulestun 28672 4vhost_net, Live0xffffffffc0af2000[acme@jouet linux]$Quoted 5 lines
So I could as well use what is in
/sys/module/tun/sections/.textinstead of reading it from/proc/modulesand, in s390, reading it from/sys/module/tun/sections/.text.Do you see any problem with using this approach for _all_ arches?
I think it should work well for _all_ arches but it will probably be hard to test this without help.
Quoted 6 lines
Quoted 4 lines
Well, we could check for the cases we don't know, i.e. read from both and warn about cases where it is different, except for s390 where we now which is the right one to pick.
One question: how to get arch info except
machine->env->arch? It seems thatmachine->env->archcould be NULL sometimes.
Quoted 7 lines
That is not what you want to look at, as it is related to perf.data, which may not be related to what you want, which is the running machine.
For that use
uname()-> utsname.machine.But then, why would you need it for reading
/sys/module/*/sections/.text? The arch name isn't there :-)
Yes, it's no use for this patch. Thanks a lot.
Quoted 3 lines
- Arnaldo
Signature · 1 line
SongShan Gong