linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] perf map: fix overlapped map handling
@ 2019-09-28  1:39 Steve MacLean
  2019-09-29 15:44 ` Jiri Olsa
  0 siblings, 1 reply; 2+ messages in thread
From: Steve MacLean @ 2019-09-28  1:39 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim
  Cc: Eric Saint-Etienne, John Keeping, Andi Kleen, Song Liu,
	Davidlohr Bueso, Leo Yan, linux-kernel, Brian Robbins,
	Tom McDonald, John Salem, Stephane Eranian

Whenever an mmap/mmap2 event occurs, the map tree must be updated to add a new
entry. If a new map overlaps a previous map, the overlapped section of the
previous map is effectively unmapped, but the non-overlapping sections are
still valid.

maps__fixup_overlappings() is responsible for creating any new map entries from
the previously overlapped map. It optionally creates a before and an after map.

When creating the after map the existing code failed to adjust the map.pgoff.
This meant the new after map would incorrectly calculate the file offset
for the ip. This results in incorrect symbol name resolution for any ip in the
after region.

Make maps__fixup_overlappings() correctly populate map.pgoff.

Add an assert that new mapping matches old mapping at the beginning of
the after map.

Committer-testing:

Validated correct parsing of libcoreclr.so symbols from .NET Core 3.0 preview9
(which didn't strip symbols).

Preparation:

~/dotnet3.0-preview9/dotnet new webapi -o perfSymbol
cd perfSymbol
~/dotnet3.0-preview9/dotnet publish
perf record ~/dotnet3.0-preview9/dotnet \
    bin/Debug/netcoreapp3.0/publish/perfSymbol.dll
^C

Before:

perf script --show-mmap-events 2>&1 | grep -e MMAP -e unknown |\
   grep libcoreclr.so | head -n 4
      dotnet  1907 373352.698780: PERF_RECORD_MMAP2 1907/1907: \
          [0x7fe615726000(0x768000) @ 0 08:02 5510620 765057155]: \
          r-xp .../3.0.0-preview9-19423-09/libcoreclr.so
      dotnet  1907 373352.701091: PERF_RECORD_MMAP2 1907/1907: \
          [0x7fe615974000(0x1000) @ 0x24e000 08:02 5510620 765057155]: \
          rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
      dotnet  1907 373352.701241: PERF_RECORD_MMAP2 1907/1907: \
          [0x7fe615c42000(0x1000) @ 0x51c000 08:02 5510620 765057155]: \
          rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
      dotnet  1907 373352.705249:     250000 cpu-clock: \
           7fe6159a1f99 [unknown] \
           (.../3.0.0-preview9-19423-09/libcoreclr.so)

After:

perf script --show-mmap-events 2>&1 | grep -e MMAP -e unknown |\
   grep libcoreclr.so | head -n 4
      dotnet  1907 373352.698780: PERF_RECORD_MMAP2 1907/1907: \
          [0x7fe615726000(0x768000) @ 0 08:02 5510620 765057155]: \
          r-xp .../3.0.0-preview9-19423-09/libcoreclr.so
      dotnet  1907 373352.701091: PERF_RECORD_MMAP2 1907/1907: \
          [0x7fe615974000(0x1000) @ 0x24e000 08:02 5510620 765057155]: \
          rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
      dotnet  1907 373352.701241: PERF_RECORD_MMAP2 1907/1907: \
          [0x7fe615c42000(0x1000) @ 0x51c000 08:02 5510620 765057155]: \
          rwxp .../3.0.0-preview9-19423-09/libcoreclr.so

All the [unknown] symbols were resolved.

Tested-by: Brian Robbins <brianrob@microsoft.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Steve MacLean <Steve.MacLean@Microsoft.com>
---
 tools/perf/util/map.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 5b83ed1..eec9b28 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include "symbol.h"
+#include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <limits.h>
@@ -850,6 +851,8 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
 			}
 
 			after->start = map->end;
+			after->pgoff += map->end - pos->start;
+			assert(pos->map_ip(pos, map->end) == after->map_ip(after, map->end));
 			__map_groups__insert(pos->groups, after);
 			if (verbose >= 2 && !use_browser)
 				map__fprintf(after, fp);
-- 
2.7.4

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

* Re: [PATCH 1/4] perf map: fix overlapped map handling
  2019-09-28  1:39 [PATCH 1/4] perf map: fix overlapped map handling Steve MacLean
@ 2019-09-29 15:44 ` Jiri Olsa
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Olsa @ 2019-09-29 15:44 UTC (permalink / raw)
  To: Steve MacLean
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Namhyung Kim,
	Eric Saint-Etienne, John Keeping, Andi Kleen, Song Liu,
	Davidlohr Bueso, Leo Yan, linux-kernel, Brian Robbins,
	Tom McDonald, John Salem, Stephane Eranian

On Sat, Sep 28, 2019 at 01:39:00AM +0000, Steve MacLean wrote:

SNIP

> Before:
> 
> perf script --show-mmap-events 2>&1 | grep -e MMAP -e unknown |\
>    grep libcoreclr.so | head -n 4
>       dotnet  1907 373352.698780: PERF_RECORD_MMAP2 1907/1907: \
>           [0x7fe615726000(0x768000) @ 0 08:02 5510620 765057155]: \
>           r-xp .../3.0.0-preview9-19423-09/libcoreclr.so
>       dotnet  1907 373352.701091: PERF_RECORD_MMAP2 1907/1907: \
>           [0x7fe615974000(0x1000) @ 0x24e000 08:02 5510620 765057155]: \
>           rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
>       dotnet  1907 373352.701241: PERF_RECORD_MMAP2 1907/1907: \
>           [0x7fe615c42000(0x1000) @ 0x51c000 08:02 5510620 765057155]: \
>           rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
>       dotnet  1907 373352.705249:     250000 cpu-clock: \
>            7fe6159a1f99 [unknown] \
>            (.../3.0.0-preview9-19423-09/libcoreclr.so)
> 
> After:
> 
> perf script --show-mmap-events 2>&1 | grep -e MMAP -e unknown |\
>    grep libcoreclr.so | head -n 4
>       dotnet  1907 373352.698780: PERF_RECORD_MMAP2 1907/1907: \
>           [0x7fe615726000(0x768000) @ 0 08:02 5510620 765057155]: \
>           r-xp .../3.0.0-preview9-19423-09/libcoreclr.so
>       dotnet  1907 373352.701091: PERF_RECORD_MMAP2 1907/1907: \
>           [0x7fe615974000(0x1000) @ 0x24e000 08:02 5510620 765057155]: \
>           rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
>       dotnet  1907 373352.701241: PERF_RECORD_MMAP2 1907/1907: \
>           [0x7fe615c42000(0x1000) @ 0x51c000 08:02 5510620 765057155]: \
>           rwxp .../3.0.0-preview9-19423-09/libcoreclr.so
> 
> All the [unknown] symbols were resolved.
> 
> Tested-by: Brian Robbins <brianrob@microsoft.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Stephane Eranian <eranian@google.com>
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Steve MacLean <Steve.MacLean@Microsoft.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/util/map.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index 5b83ed1..eec9b28 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -1,5 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #include "symbol.h"
> +#include <assert.h>
>  #include <errno.h>
>  #include <inttypes.h>
>  #include <limits.h>
> @@ -850,6 +851,8 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
>  			}
>  
>  			after->start = map->end;
> +			after->pgoff += map->end - pos->start;
> +			assert(pos->map_ip(pos, map->end) == after->map_ip(after, map->end));
>  			__map_groups__insert(pos->groups, after);
>  			if (verbose >= 2 && !use_browser)
>  				map__fprintf(after, fp);
> -- 
> 2.7.4

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

end of thread, other threads:[~2019-09-29 15:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-28  1:39 [PATCH 1/4] perf map: fix overlapped map handling Steve MacLean
2019-09-29 15:44 ` Jiri Olsa

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