Skip to content

Commit 7f73070

Browse files
committed
perf maps: Introduce map__set_kmap_maps() for kernel maps
JIRA: https://issues.redhat.com/browse/RHEL-77936 upstream ======== commit 99deaf5 Author: Arnaldo Carvalho de Melo <[email protected]> Date: Fri Feb 28 18:17:29 2025 -0300 description =========== We need to set it in other places than __maps__insert(), so that we can have access to the 'struct maps' from a kernel 'struct map'. When building perf with 'DEBUG=1' we can notice it failing a consistency check done in the check_invariants() function: root@number:~# perf record -- perf test -w offcpu [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.040 MB perf.data (23 samples) ] perf: util/maps.c:95: check_invariants: Assertion `map__end(prev) <= map__end(map)' failed. Aborted (core dumped) root@number:~# The investigation on that was happening bisected to 876e80c ("perf tools: Fixup end address of modules"), and the following patches will plug the problems found, this patch is just legwork on that direction. Use the map__set_kmap_maps() name as per a review comment from Ian Rogers, later there are further suggestions from him on getting rid of the kmaps variable, see the thread referenced in the Link below. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Namhyung Kim <[email protected]> Reviewed-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/lkml/Z74V0hZXrTLM6VIJ@x1 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Michael Petlan <[email protected]>
1 parent 2f38f4d commit 7f73070

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

tools/perf/util/maps.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,29 @@ static unsigned int maps__by_name_index(const struct maps *maps, const struct ma
428428
return -1;
429429
}
430430

431+
static void map__set_kmap_maps(struct map *map, struct maps *maps)
432+
{
433+
struct dso *dso;
434+
435+
if (map == NULL)
436+
return;
437+
438+
dso = map__dso(map);
439+
440+
if (dso && dso__kernel(dso)) {
441+
struct kmap *kmap = map__kmap(map);
442+
443+
if (kmap)
444+
kmap->kmaps = maps;
445+
else
446+
pr_err("Internal error: kernel dso with non kernel map\n");
447+
}
448+
}
449+
431450
static int __maps__insert(struct maps *maps, struct map *new)
432451
{
433452
struct map **maps_by_address = maps__maps_by_address(maps);
434453
struct map **maps_by_name = maps__maps_by_name(maps);
435-
const struct dso *dso = map__dso(new);
436454
unsigned int nr_maps = maps__nr_maps(maps);
437455
unsigned int nr_allocate = RC_CHK_ACCESS(maps)->nr_maps_allocated;
438456

@@ -483,14 +501,9 @@ static int __maps__insert(struct maps *maps, struct map *new)
483501
}
484502
if (map__end(new) < map__start(new))
485503
RC_CHK_ACCESS(maps)->ends_broken = true;
486-
if (dso && dso__kernel(dso)) {
487-
struct kmap *kmap = map__kmap(new);
488504

489-
if (kmap)
490-
kmap->kmaps = maps;
491-
else
492-
pr_err("Internal error: kernel dso with non kernel map\n");
493-
}
505+
map__set_kmap_maps(new, maps);
506+
494507
return 0;
495508
}
496509

0 commit comments

Comments
 (0)