perf tools: Do not swap mmap2 fields in case it contains build id
authorJiri Olsa <jolsa@kernel.org>
Mon, 14 Dec 2020 10:54:47 +0000 (11:54 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 28 Dec 2020 12:58:40 +0000 (09:58 -0300)
If the PERF_RECORD_MISC_MMAP_BUILD_ID misc bit is set, mmap2 events
carries a build id, placed in the following union:

  union {
          struct {
                  u32       maj;
                  u32       min;
                  u64       ino;
                  u64       ino_generation;
          };
          struct {
                  u8        build_id_size;
                  u8        __reserved_1;
                  u16       __reserved_2;
                  u8        build_id[20];
          };
  };

In this case we can't swap above fields.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20201214105457.543111-6-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/session.c

index 50ff9795a4f112acb8f73e6750fef60f26d6f48a..357d6b972b9da2637a834a23cad85e1d7ff3fddf 100644 (file)
@@ -593,10 +593,13 @@ static void perf_event__mmap2_swap(union perf_event *event,
        event->mmap2.start = bswap_64(event->mmap2.start);
        event->mmap2.len   = bswap_64(event->mmap2.len);
        event->mmap2.pgoff = bswap_64(event->mmap2.pgoff);
-       event->mmap2.maj   = bswap_32(event->mmap2.maj);
-       event->mmap2.min   = bswap_32(event->mmap2.min);
-       event->mmap2.ino   = bswap_64(event->mmap2.ino);
-       event->mmap2.ino_generation = bswap_64(event->mmap2.ino_generation);
+
+       if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) {
+               event->mmap2.maj   = bswap_32(event->mmap2.maj);
+               event->mmap2.min   = bswap_32(event->mmap2.min);
+               event->mmap2.ino   = bswap_64(event->mmap2.ino);
+               event->mmap2.ino_generation = bswap_64(event->mmap2.ino_generation);
+       }
 
        if (sample_id_all) {
                void *data = &event->mmap2.filename;