perf tools: Fix object code reading for PTI entry trampolines
Adrian Hunter
reviewerPATCH 1/1 perf tools: Fix object code reading for PTI entry trampolines
Fix object code reading and the "Object code reading" test for PTI entry trampolines.
perf tools uses map__rip_2objdump() to calculate objdump virtual addresses. map__rip_2objdump() needs to be amended to deal with PTI entry trampolines. Also the "Object code reading" test will not create maps for the PTI entry trampolines unless the machine environment exists to show that the arch is x86_64.
--- tools/perf/tests/code-reading.c | 1 + tools/perf/util/map.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
tools/perf/tests/code-reading.c +1 -0
@@ -560,6 +560,7 @@ static int do_test_code_reading(bool try_kcore) pid =getpid (); machine =machine__new_host (); + machine->env = &perf_env; ret =machine__create_kernel_maps (machine);if (ret <0 ) {
tools/perf/util/map.c +14 -0
@@ -449,6 +449,20 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,*/ u64 map__rip_2objdump (struct map *map,u64 rip) { +struct kmap *kmap =__map__kmap (map); + +/* +* vmlinux does not have program headers for PTI entry trampolines and +* kcore may not either. However the trampoline object code is on the +* main kernel map, so just use that instead. +*/ +if (kmap &&is_entry_trampoline (kmap->name) && kmap->kmaps && kmap->kmaps->machine) { +struct map *kernel_map =machine__kernel_map (kmap->kmaps->machine); + +if (kernel_map) + map = kernel_map; + } +if (!map->dso->adjust_symbols)return rip;
Signature · 1 line
1.9.1
Arnaldo Carvalho de Melo
maintainerEm Tue, Jun 05, 2018 at 10:30:00AM +0300, Adrian Hunter escreveu:
Quoted 8 lines
Fix object code reading and the "Object code reading" test for PTI entry trampolines.
perf tools uses
map__rip_2objdump()to calculate objdump virtual addresses.map__rip_2objdump()needs to be amended to deal with PTI entry trampolines. Also the "Object code reading" test will not create maps for the PTI entry trampolines unless the machine environment exists to show that the arch isx86_64.
So, I split it into two patches, right at the "Also" part in your description:
[acme@seventh perf]$ git log --oneline -236800a71b000 (HEAD -> perf/core) perf map: Consider PTI entry trampolines in rip_2objdump() 2f6777b74f6d perf test code-reading: Fix perf_env setup for PTI entry trampolines [acme@seventh perf]$
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=perf/core
And this test fails way less often, but still does, for instance:
# while true ; do perf test -v object 2>out.txt ; grep -i fail out.txt && break ; done dso__data_read_offset failed Object code reading: FAILED! # [root@seventh ~]# tail out.txt File is: /proc/kcore On file address is: 0x7fff892300df kcore map tested already - skipping Reading object code for memory address: 0x4a020f File is: /home/acme/bin/perf (deleted) On file address is: 0xa020f dso__data_read_offset failed test child finished with -1 ---- end ---- Object code reading: FAILED! [root@seventh ~]#
I start that loop and then try running 'make -C tools/perf O=/tmp/build/perf install-bin', to generate some load.
But now at least on a quiet system it works.
- Arnaldo
Adrian Hunter
reviewerQuoted 39 lines · Arnaldo Carvalho de Melo
Em Tue, Jun 05, 2018 at 10:30:00AM +0300, Adrian Hunter escreveu:
Quoted 8 lines
Fix object code reading and the "Object code reading" test for PTI entry trampolines.
perf tools uses
map__rip_2objdump()to calculate objdump virtual addresses.map__rip_2objdump()needs to be amended to deal with PTI entry trampolines. Also the "Object code reading" test will not create maps for the PTI entry trampolines unless the machine environment exists to show that the arch isx86_64.So, I split it into two patches, right at the "Also" part in your description:
[acme@seventh perf]$ git log --oneline -2
36800a71b000(HEAD -> perf/core) perf map: Consider PTI entry trampolines inrip_2objdump()2f6777b74f6dperf test code-reading: Fixperf_envsetup for PTI entry trampolines [acme@seventh perf]$https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=perf/core
And this test fails way less often, but still does, for instance:
# while true ; do perf test -v object 2>out.txt ; grep -i fail out.txt && break ; done dso__data_read_offset failed Object code reading: FAILED! # [root@seventh ~]# tail out.txt File is: /proc/kcore On file address is: 0x7fff892300df kcore map tested already - skipping Reading object code for memory address: 0x4a020f File is: /home/acme/bin/perf (deleted) On file address is: 0xa020f dso__data_read_offset failed test child finished with -1 ---- end ---- Object code reading: FAILED! [root@seventh ~]#
Quoted 2 lines
I start that loop and then try running 'make -C
tools/perfO=/tmp/build/perf install-bin', to generate some load.
So is it related to the "deleted" in "File is: /home/acme/bin/perf (deleted)"?
Quoted 5 lines
But now at least on a quiet system it works.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerEm Tue, Jun 05, 2018 at 05:08:35PM +0300, Adrian Hunter escreveu:
Quoted 20 lines · Arnaldo Carvalho de Melo
Quoted 18 lines
And this test fails way less often, but still does, for instance:
# while true ; do perf test -v object 2>out.txt ; grep -i fail out.txt && break ; done dso__data_read_offset failed Object code reading: FAILED! # [root@seventh ~]# tail out.txt File is: /proc/kcore On file address is: 0x7fff892300df kcore map tested already - skipping Reading object code for memory address: 0x4a020f File is: /home/acme/bin/perf (deleted) On file address is: 0xa020f dso__data_read_offset failed test child finished with -1 ---- end ---- Object code reading: FAILED! [root@seventh ~]#
Quoted 4 lines
Quoted 2 lines
I start that loop and then try running 'make -C
tools/perfO=/tmp/build/perf install-bin', to generate some load.So is it related to the "deleted" in "File is:
/home/acme/bin/perf(deleted)"?
Probably, Jiri? Probably it'll be difficult to sort this out, as the original for that file probably isn't available anymore and probably we didn't had the opportunity to have already read its build-id to lookup it in the ~/.debug/ cache... So probably we should notice that and skip this, not considering it as an error?
- Arnaldo
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf test code-reading: Fix perf_env setup for PTI entry trampolines
In reply to Adrian Hunterperf test code-reading: Fix perf_env setup for PTI entry trampolines
Commit-ID: f6c66d73bb8192d357bb5fb8cd5826920f811d8c Gitweb: https://git.kernel.org/tip/f6c66d73bb8192d357bb5fb8cd5826920f811d8c Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 5 Jun 2018 10:30:00 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 6 Jun 2018 12:52:05 -0300
perf test code-reading: Fix perf_env setup for PTI entry trampolines
The "Object code reading" test will not create maps for the PTI entry trampolines unless the machine environment exists to show that the arch is x86_64.
--- tools/perf/tests/code-reading.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/tests/code-reading.c +1 -0
@@ -560,6 +560,7 @@ static int do_test_code_reading(bool try_kcore) pid =getpid (); machine =machine__new_host (); + machine->env = &perf_env; ret =machine__create_kernel_maps (machine);if (ret <0 ) {
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf map: Consider PTI entry trampolines in rip_2objdump()
In reply to Adrian Hunterperf map: Consider PTI entry trampolines in rip_2objdump()
Commit-ID: 97802f3b81dc0d1da0f89c498249547d73a01164 Gitweb: https://git.kernel.org/tip/97802f3b81dc0d1da0f89c498249547d73a01164 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 5 Jun 2018 10:30:00 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 6 Jun 2018 12:52:06 -0300
perf map: Consider PTI entry trampolines in rip_2objdump()
perf tools uses map__rip_2objdump() to calculate objdump virtual addresses. map__rip_2objdump() needs to be amended to deal with PTI entry trampolines.
--- tools/perf/util/map.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/perf/util/map.c +14 -0
@@ -449,6 +449,20 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,*/ u64 map__rip_2objdump (struct map *map,u64 rip) { +struct kmap *kmap =__map__kmap (map); + +/* +* vmlinux does not have program headers for PTI entry trampolines and +* kcore may not either. However the trampoline object code is on the +* main kernel map, so just use that instead. +*/ +if (kmap &&is_entry_trampoline (kmap->name) && kmap->kmaps && kmap->kmaps->machine) { +struct map *kernel_map =machine__kernel_map (kmap->kmaps->machine); + +if (kernel_map) + map = kernel_map; + } +if (!map->dso->adjust_symbols)return rip;