Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] perf tools: Fix object code reading for PTI entry trampolines
@ 2018-06-05  7:30 Adrian Hunter
  2018-06-05 13:41 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Hunter @ 2018-06-05  7:30 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, linux-perf-users

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.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/tests/code-reading.c |  1 +
 tools/perf/util/map.c           | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index afa4ce21ba7c..4892bd2dc33e 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -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) {
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 92abc8e248c5..89ac5b5dc218 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -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;
 
-- 
1.9.1

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

* Re: [PATCH] perf tools: Fix object code reading for PTI entry trampolines
  2018-06-05  7:30 [PATCH] perf tools: Fix object code reading for PTI entry trampolines Adrian Hunter
@ 2018-06-05 13:41 ` Arnaldo Carvalho de Melo
  2018-06-05 14:08   ` Adrian Hunter
  0 siblings, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-06-05 13:41 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel, linux-perf-users

Em Tue, Jun 05, 2018 at 10:30:00AM +0300, Adrian Hunter escreveu:
> 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.

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

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

* Re: [PATCH] perf tools: Fix object code reading for PTI entry trampolines
  2018-06-05 13:41 ` Arnaldo Carvalho de Melo
@ 2018-06-05 14:08   ` Adrian Hunter
  2018-06-05 15:31     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Hunter @ 2018-06-05 14:08 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, linux-perf-users

On 05/06/18 16:41, Arnaldo Carvalho de Melo wrote:
> Em Tue, Jun 05, 2018 at 10:30:00AM +0300, Adrian Hunter escreveu:
>> 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.
> 
> 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 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.

So is it related to the "deleted" in "File is: /home/acme/bin/perf (deleted)"?

> 
> But now at least on a quiet system it works.
> 
> - Arnaldo
> 

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

* Re: [PATCH] perf tools: Fix object code reading for PTI entry trampolines
  2018-06-05 14:08   ` Adrian Hunter
@ 2018-06-05 15:31     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-06-05 15:31 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel, linux-perf-users

Em Tue, Jun 05, 2018 at 05:08:35PM +0300, Adrian Hunter escreveu:
> On 05/06/18 16:41, Arnaldo Carvalho de Melo wrote:
> > 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.

> 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

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

end of thread, other threads:[~2018-06-05 15:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-05  7:30 [PATCH] perf tools: Fix object code reading for PTI entry trampolines Adrian Hunter
2018-06-05 13:41 ` Arnaldo Carvalho de Melo
2018-06-05 14:08   ` Adrian Hunter
2018-06-05 15:31     ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox