Commit f30232b2 authored by James Clark's avatar James Clark Committed by Arnaldo Carvalho de Melo
Browse files

perf symbols: Update kcore map before merging in remaining symbols



When loading kcore, the main vmlinux map is updated in the same loop
that merges the remaining maps. If a map that overlaps is merged in
before kcore, the list can become unsortable when the main map addresses
are updated. This will later trigger the check_invariants() assert:

  $ perf record
  $ perf report

  util/maps.c:96: check_invariants: Assertion `map__end(prev) <=
    map__start(map) || map__start(prev) == map__start(map)' failed.
  Aborted

Fix it by moving the main map update prior to the loop so that
maps__merge_in() can split it if necessary.

Fixes: 659ad349 ("perf maps: Switch from rbtree to lazily sorted array for addresses")
Signed-off-by: default avatarJames Clark <james.clark@arm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240507141210.195939-4-james.clark@arm.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent fd81f52e
Loading
Loading
Loading
Loading
+21 −19
Original line number Diff line number Diff line
@@ -1290,7 +1290,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
{
	struct maps *kmaps = map__kmaps(map);
	struct kcore_mapfn_data md;
	struct map *replacement_map = NULL;
	struct map *map_ref, *replacement_map = NULL;
	struct machine *machine;
	bool is_64_bit;
	int err, fd;
@@ -1368,31 +1368,33 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
	if (!replacement_map)
		replacement_map = list_entry(md.maps.next, struct map_list_node, node)->map;

	/* Add new maps */
	while (!list_empty(&md.maps)) {
		struct map_list_node *new_node = list_entry(md.maps.next, struct map_list_node, node);
		struct map *new_map = new_node->map;

		list_del_init(&new_node->node);

		if (RC_CHK_EQUAL(new_map, replacement_map)) {
			struct map *map_ref;

			/* Ensure maps are correctly ordered */
	/*
	 * Update addresses of vmlinux map. Re-insert it to ensure maps are
	 * correctly ordered. Do this before using maps__merge_in() for the
	 * remaining maps so vmlinux gets split if necessary.
	 */
	map_ref = map__get(map);
	maps__remove(kmaps, map_ref);

			map__set_start(map_ref, map__start(new_map));
			map__set_end(map_ref, map__end(new_map));
			map__set_pgoff(map_ref, map__pgoff(new_map));
			map__set_mapping_type(map_ref, map__mapping_type(new_map));
	map__set_start(map_ref, map__start(replacement_map));
	map__set_end(map_ref, map__end(replacement_map));
	map__set_pgoff(map_ref, map__pgoff(replacement_map));
	map__set_mapping_type(map_ref, map__mapping_type(replacement_map));

	err = maps__insert(kmaps, map_ref);
	map__put(map_ref);
			map__put(new_map);
	if (err)
		goto out_err;
		} else {

	/* Add new maps */
	while (!list_empty(&md.maps)) {
		struct map_list_node *new_node = list_entry(md.maps.next, struct map_list_node, node);
		struct map *new_map = new_node->map;

		list_del_init(&new_node->node);

		/* skip if replacement_map, already inserted above */
		if (!RC_CHK_EQUAL(new_map, replacement_map)) {
			/*
			 * Merge kcore map into existing maps,
			 * and ensure that current maps (eBPF)