Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Fix dso_id inode generation comparison

Synthesized MMAP events have zero ino_generation, so do not compare
them to DSOs with a real ino_generation otherwise we end up with a DSO
without a build id.

Fixes: 0e3149f86b99ddab ("perf dso: Move dso_id from 'struct map' to 'struct dso'")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: kvm@vger.kernel.org
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20220711093218.10967-2-adrian.hunter@intel.com
[ Added clarification to the comment from Ian + more detailed explanation from Adrian ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
68566a7c a6bd98c4

+13 -2
+13 -2
tools/perf/util/dsos.c
··· 23 23 if (a->ino > b->ino) return -1; 24 24 if (a->ino < b->ino) return 1; 25 25 26 - if (a->ino_generation > b->ino_generation) return -1; 27 - if (a->ino_generation < b->ino_generation) return 1; 26 + /* 27 + * Synthesized MMAP events have zero ino_generation, avoid comparing 28 + * them with MMAP events with actual ino_generation. 29 + * 30 + * I found it harmful because the mismatch resulted in a new 31 + * dso that did not have a build ID whereas the original dso did have a 32 + * build ID. The build ID was essential because the object was not found 33 + * otherwise. - Adrian 34 + */ 35 + if (a->ino_generation && b->ino_generation) { 36 + if (a->ino_generation > b->ino_generation) return -1; 37 + if (a->ino_generation < b->ino_generation) return 1; 38 + } 28 39 29 40 return 0; 30 41 }